# IT4Innovations 2020
# JK LK

easyblock = 'MakeCp'

name = 'VASP'
version = '5.4.4'

homepage = 'http://www.vasp.at'
docurls = 'https://www.vasp.at/wiki/index.php/The_VASP_Manual'
description = """The Vienna Ab initio Simulation Package (VASP) is a local computer program for atomic scale
materials modelling, e.g. electronic structure calculations and quantum-mechanical molecular dynamics,
from first principles.

To use VASP, you need an academic license from University of Vienna. Follow the instructions at https://www.vasp.at/index.php/faqs.

Please send us a list of authorized users and their IDs for which you need access (use only http://support.it4i.cz/rt). We are responsible for verifying your licenses."""

# 'crashes with intel > 2020a' test
toolchain = {'name': 'intel', 'version': '2020a'}
toolchainopts = {'pic': True, 'usempi': True}

# Vasp is proprietary software, see http://www.vasp.at/index.php/faqs on
# how to get access to the code
sources = ['%(namelower)s.%(version)s.tar.gz']
checksums = ['5bd2449462386f01e575f9adf629c08cb03a13142806ffb6a71309ca4431cfb3']

prebuildopts = 'cp arch/makefile.include.linux_intel ./makefile.include && '

# remove mkl flag (FCL) to prevent mixing dynamic libs with the static libs in
# LIBBLACS/SCALAPACK
prebuildopts += 'sed -i "s|-mkl=sequential ||" makefile.include && '

# OFLAG      = -O2 -xAVX
prebuildopts += 'sed -i "s|\(OFLAG\s\+=\) -O2|\\1 -O3 -ip -march=xHost|" makefile.include && '

# OBJECTS, FFLAGS and MKLROOT
prebuildopts += 'sed -i "s|\(OBJECTS\s\+=\) fftmpiw.o fftmpi_map.o fft3dlib.o fftw3d.o|\\1 fftmpiw.o fftmpi_map.o fft3dlib.o fftw3d.o \$(MKLROOT)/lib/intel64_lin/libfftw3xf_intel.a|" makefile.include && '
prebuildopts += 'sed -i "s|\(FFLAGS\s\+=\) -assume byterecl -w|\\1 -FR -assume byterecl|" makefile.include && '
prebuildopts += 'sed -i "s|\(BLAS\s\+=\)|\\1 -mkl=sequential|" makefile.include && '

# AMD/intel cpu
import os
if os.environ.get("CLUSTERNAME") in ["KAROLINA"]:
    prebuildopts += 'sed -i "s|-march=xHost|-march=core-avx2|" makefile.include && '

# VASP uses LIBS as a list of folders
prebuildopts += 'unset LIBS && '

buildopts = 'std gam ncl '

parallel = 1

files_to_copy = [(['bin/vasp_std', 'bin/vasp_gam', 'bin/vasp_ncl'], 'bin')]

sanity_check_paths = {
    'files': ['bin/vasp_std', 'bin/vasp_gam', 'bin/vasp_ncl'],
    'dirs': []
}

modluafooter = 'add_property("state","license")'

moduleclass = 'chem'
