# IT4Innovations
# LK 2024

easyblock = 'CMakeMake'

name = 'QuantumESPRESSO'
version = '7.3.1'

homepage = 'https://www.quantum-espresso.org'
description = """Quantum ESPRESSO  is an integrated suite of computer codes
for electronic-structure calculations and materials modeling at the nanoscale.
It is based on density-functional theory, plane waves, and pseudopotentials
(both norm-conserving and ultrasoft).
"""

toolchain = {'name': 'NVHPC', 'version': '24.3-CUDA-12.3.0'}

import os
if os.environ.get("CLUSTERNAME") in ["KAROLINA"]:
   toolchainopts = {'pic': True,  'optarch': 'march=core-avx2'}
else:
   toolchainopts = {'pic': True}

if os.environ.get("CLUSTERNAME") in ["KAROLINA"]:
   prebuildopts = "echo %(builddir)s && while read i; do echo $i; sed 's|-xHost|-march=core-avx2|g' -i $i; done < <(grep xHost %(builddir)s -R | cut -d ':' -f 1 | sort -u) && "

source_urls = [
    'https://github.com/QEF/q-e/releases/download/qe-%(version)s.0/',
    'https://github.com/dceresoli/qe-gipaw/archive/',
    'https://github.com/wannier-developers/wannier90/archive/',
    'https://github.com/QEF/q-e/archive/refs/tags/'
]
sources = [
    'qe-%(version)s.tar.gz',
    {'filename': 'qe-gipaw-%(version)s.tar.gz', 'download_filename': '%(version)s.tar.gz'},
    {'filename': 'wannier90-3.1.0.tar.gz', 'download_filename': 'v3.1.0.tar.gz'},
]
checksums = [
    '2c58b8fadfe4177de5a8b69eba447db5e623420b070dea6fd26c1533b081d844',  # qe-%(version)s.tar.gz
    '2dee75ecf7d0f4c65047b7ef6a8af54f091cc4cf63e764a1f039ead087f2a3e8',  # qe-gipaw-%(version)s.tar.gz
    '40651a9832eb93dec20a8360dd535262c261c34e13c41b6755fa6915c936b254',  # wannier90-3.1.0.tar.gz
]

dependencies = [
    ('HDF5', '1.14.3'),
    ('libxc', '6.2.2'),
    ('FFTW', '3.3.10'),
    ('OpenMPI', '4.1.6'),
    ('CMake', '3.24.3', '', ('GCCcore', '12.2.0')),
]

# config
configopts = 'FC=pgfortran F77=pgfortran F90=pgfortran CC=pgcc CXX=pgc++ '
configopts += '-DQE_ENABLE_CUDA=ON -DQE_ENABLE_MPI_GPU_AWARE=ON '
configopts += '-DNVFORTRAN_CUDA_VERSION=12.3 '

import os
if os.environ.get("CLUSTERNAME") in ["KAROLINA"]:
    configopts += '-DNVFORTRAN_CUDA_CC=80 '
elif os.environ.get("CLUSTERNAME") in ["BARBORA"]:
    configopts += '-DNVFORTRAN_CUDA_CC=70 '

# The third party packages should be installed separately and added as
# dependencies.  The exception is w90, which is force built, and gipaw
# which depends on qe source
buildopts = 'all gwl xspectra couple epw w90'

# parallel build tends to fail
parallel = 1

moduleclass = 'chem'
