# IT4Innovations 2022
# JK

easyblock = 'MakeCp'

name = 'VASP'
version = '6.3.0'
versionsuffix = '-mkl=sequential'

homepage = 'http://www.vasp.at'
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 academic licenses from University of Wiena. Follow the instructions https://www.vasp.at/index.php/faqs.

Then send us please a list of authorized users and their ID for which you need this access. Please use only http://support.it4i.cz/rt. We are responsible for verifying your licenses. After succesful verification You will be granted access to VASP in our enviroment."""

toolchain = {'name': 'intel', 'version': '2021b'}
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.tgz']
patches = ['VASP-6.3.1-intel-2021b-cluster-independent.patch']
checksums = [
    'adcf83bdfd98061016baae31616b54329563aa2739573f069dd9df19c2071ad3',  # vasp.6.3.0.tgz
    # VASP-6.3.1-intel-2021b-cluster-independent.patch
    '074393cb052982469e2b8d67363f69807b75584564b1bd2e51eaf56085d3951c',
]

# cluster independent settings - Wannier90 and HDF5 settings, FFLAGS etc.
dependencies = [
    ('HDF5', '1.12.1', '-parallel'),
    ('Wannier90', '3.1.0', '-serial'),
]

# copy over makefile.include for intel toolchain
prebuildopts = 'cp arch/makefile.include.intel ./makefile.include && '

# Cluster specific options!
# check for each VASP version to make sure it's consistent
import os
if os.environ.get("CLUSTERNAME") in ["KAROLINA"]:
    prebuildopts += 'sed -i -e "s|\(OFLAG\s\+=\) -O2|\\1 -O3 -ip -march=core-avx2|" makefile.include && '
    prebuildopts += 'sed -i "s|-xHOST|-march=core-avx2|" makefile.include && '
else:
    prebuildopts += 'sed -i -e "s|\(OFLAG\s\+=\) -O2|\\1 -O3 -ip -march=xHost|" 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'
