# IT4Innovations
# LK 2023

easyblock = 'MakeCp'

name = 'VASP'
version = '6.4.2'
versionsuffix = "-DFT-D4"

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."""

toolchain = {'name': 'intel', 'version': '2022b'}

# 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.tgz']
patches = ['VASP-%(version)s-NVHPC-23.5-CUDA-12.2.0-adjust-makefile.patch']
checksums = [
    {'vasp.%(version)s.tgz': 'b704637f7384673f91adfbc803edc5cc7fe736d9623453461f7cdc29b123410e'},
    {'VASP-%(version)s-NVHPC-23.5-CUDA-12.2.0-adjust-makefile.patch':
     'dfc717642ae2ce9b04ed78439fc4d1072dc0d08df4aca2da881b944f2e75625e'},
]

# use serial compilation of W90, see https://www.vasp.at/wiki/index.php/Makefile.include#Wannier90_.28optional.29
# Important: In case of Wannier90 3.x, you should compile a serial version by removing COMMS=mpi in the make.inc of Wannier90. 
dependencies = [
    ('HDF5', '1.14.0'),
    ('Wannier90', '3.1.0', '-serial'),
    ('DFT-D4', '3.6.0', '-Python-3.10.8'),
]

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

# DFTD4
prebuildopts += 'echo "" >> makefile.include &&'
prebuildopts += 'echo "#DFTD4"  >> makefile.include && '
prebuildopts += 'echo "CPP_OPTIONS += -DDFTD4 " >> makefile.include && '
prebuildopts += 'echo "DFTD4_ROOT  ?= $EBROOTDFTMIND4 " >> makefile.include && '
prebuildopts += 'echo "LLIBS       += $( shell pkg-config --libs dftd4) -ldftd4 " >> makefile.include && '
prebuildopts += 'echo "INCS        += $( shell pkg-config ---flags dftd4)" >> makefile.include && '

# AMD/Intel CPU switch - We set xHost by default; change it to -march=core-avx2 when necessary
import os
if os.environ.get("CLUSTERNAME") in ["KAROLINA"]:
    prebuildopts += 'sed -i "s|-xHOST|-march=core-avx2|" makefile.include && '
    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'
