# IT4Innovations
# PH 2024

easyblock = 'CMakeMake'

name = 'DFTB+'
version = '24.1'
versionsuffix = '-CUDA-12.1.1'

homepage = 'https://www.dftb-plus.info'
description = """DFTB+ is a fast and efficient versatile quantum mechanical simulation package.
It is based on the Density Functional Tight Binding (DFTB) method, containing
almost all of the useful extensions which have been developed for the DFTB
framework so far.  Using DFTB+ you can carry out quantum mechanical simulations
like with ab-initio density functional theory based packages, but in an
approximate way gaining typically around two order of magnitude in speed."""

toolchain = {'name': 'foss', 'version': '2023a'}

local_external_dir = '%%(builddir)s/dftbplus-%%(version)s/external/%s/origin/'
local_external_extract = 'mkdir -p %s && tar -C %s' % (local_external_dir, local_external_dir)
local_external_extract += ' --strip-components=1 -xzf %%s'

sources = [
    {
        'source_urls': ['https://github.com/dftbplus/dftbplus/archive'],
        'download_filename': '%(version)s.tar.gz',
        'filename': SOURCE_TAR_GZ,
    },
    {
        'source_urls': ['https://github.com/dftbplus/testparams/archive'],
        'download_filename': 'd0ea16df2b56d14c7c3dc9329a8d3bac9fea50a0.tar.gz',
        'filename': 'slakos-data-%(version)s.tar.gz',
        'extract_cmd': local_external_extract % ('slakos', 'slakos'),
    },
]
checksums = [
    '776d83779666e06bf2930c3b1665cdb8e7409b8003e33e0178fbae8b47f5e0b1',  # DFTB+ 24.1
    '9b64193368a13ae7c238399da8be2b3730a0f3273f9bf6c8054b2ff57d748823',       # slakos-data
]

builddependencies = [
    ('CMake', '3.26.3'),
]

dependencies = [
    ('dftd3-lib', '0.9.2'),
    ('tblite', '0.3.0'),
    # ('arpack-ng', '3.9.0'), # designed for non-MPI, single-node computations
    ('magma', '2.7.2', '-CUDA-12.1.1'),
    #('ELPA', '2022.05.001','-CUDA-12.1.1'),
    ('ELSI', '2.11.0', '-PEXSI-ELPA-2023.05.001-foss-2023a-CUDA-12.1.1'),
    #('ScaLAPACK', '2.2.0', '-fb') # ScaLAPACK-2.2.0-gompi-2023a-fb.eb
    ('ScalapackFx', '1.2'),
]

configopts = ' -DWITH_DFTD3=1 -DCOMPILE_DFTD3=0 -DDFTD3_INCS="-I$EBROOTDFTD3MINLIB/include"'
configopts += ' -DDFTD3_LIBS="-L$EBROOTDFTD3MINLIB/lib -ldftd3"'
configopts += ' -DWITH_TBLITE=1 '
#configopts += ' -DWITH_ARPACK=1 -DARPACK_LIBS="-L$EBROOTARPACKMINNG/lib -larpack" -DARPACK_NEEDS_LAPACK=1'
configopts += ' -DWITH_ARPACK=0'

# Enable GPU support
configopts += ' -DWITH_GPU=1 '
configopts += ' -DMAGMA_INCS="-I$EBROOTMAGMA/include" -DMAGMA_LIBS="-L$EBROOTMAGMA/lib -lmagma"'

# Enable ELPA
configopts += ' -DWITH_ELPA=1 '
configopts += ' -DELPA_INCS="-I$EBROOTELPA/include" -DELPA_LIBS="-L$EBROOTELPA/lib -lelpa"'

# Enable ELSI
configopts += ' -DWITH_ELSI=1 '
configopts += ' -DELSI_INCS="-I$EBROOTELSI/include" -DELSI_LIBS="-L$EBROOTELSI/lib -lelsi"'

# Building with ELSI requires MPI-parallel build enabled
configopts += ' -DWITH_MPI=1 '

# Enable ScaLAPACK
configopts += ' -DWITH_SCALAPACK=1 '  
#configopts += ' -DSCALAPACK_LIBS="-L$EBROOTSCALAPACK/lib -lscalapack" '
configopts += '-DSCALAPACK_LIBRARY="-L$EBROOTSCALAPACK/lib -lscalapack" '
#configopts += ' -DSCALAPACK_INCS="-I$EBROOTSCALAPACK/include" '


installopts = 'INSTALLDIR="%(installdir)s"'

sanity_check_paths = {
    'files': ['bin/' + x for x in ['dftb+', 'modes', 'waveplot']],
    'dirs': []
}

moduleclass = 'phys'
