summaryrefslogtreecommitdiff
path: root/var/spack/repos/builtin/packages/sirius/package.py
blob: 3cbb3643df8ec840e3c5b83397e7ed56afdb7fca (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# Copyright 2013-2019 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)

import os

from spack import *


class Sirius(CMakePackage):
    """Domain specific library for electronic structure calculations"""

    homepage = "https://github.com/electronic-structure/SIRIUS"
    url      = "https://github.com/electronic-structure/SIRIUS/archive/v6.1.5.tar.gz"
    list_url = "https://github.com/electronic-structure/SIRIUS/releases"

    version('6.1.5', sha256='379f0a2e5208fd6d91c2bd4939c3a5c40002975fb97652946fa1bfe4a3ef97cb')

    variant('shared', default=False, description="Build shared libraries")
    variant('openmp', default=True, description="Build with OpenMP support")
    variant('fortran', default=False, description="Build Fortran bindings")
    variant('elpa', default=False, description="Use ELPA")
    variant('vdwxc', default=False, description="Enable libvdwxc support")
    variant('scalapack', default=False, description="Enable scalapack support")

    depends_on('python')
    depends_on('mpi')
    depends_on('gsl')
    depends_on('lapack')
    depends_on('fftw')  # SIRIUS does not care about MPI-support in FFTW
    depends_on('libxc')
    depends_on('spglib')
    depends_on('hdf5+hl')
    depends_on('pkgconfig', type='build')

    depends_on('elpa+openmp', when='+elpa+openmp')
    depends_on('elpa~openmp', when='+elpa~openmp')
    depends_on('libvdwxc+mpi', when='+vdwxc')
    depends_on('scalapack', when='+scalapack')

    # TODO:
    # add support for MKL, CUDA, MAGMA, CRAY_LIBSCI, Python bindings, testing

    patch("strip-spglib-include-subfolder.patch")
    patch("link-libraries-fortran.patch")

    @property
    def libs(self):
        libraries = []

        if self.spec.satisfies('+fortran'):
            libraries += ['libsirius_f']

        return find_libraries(
            libraries, root=self.prefix,
            shared=self.spec.satisfies('+shared'), recursive=True
        )

    def cmake_args(self):
        def _def(variant, flag=None):
            """Returns "-DUSE_VARIANT:BOOL={ON,OFF}" depending on whether
               +variant is set. If the CMake flag differs from the variant
               name, pass the flag name explicitly.
            """

            return "-D{0}:BOOL={1}".format(
                flag if flag else "USE_{0}".format(
                    variant.strip('+~').upper()
                ),
                "ON" if self.spec.satisfies(variant) else "OFF"
            )

        args = [
            '-DBUILD_SHARED_LIBS=ON',
            _def('+openmp'),
            _def('+elpa'),
            _def('+vdwxc'),
            _def('+scalapack'),
            _def('+fortran', 'CREATE_FORTRAN_BINDINGS'),
        ]

        if self.spec.satisfies('+elpa'):
            elpa = self.spec['elpa']
            elpa_suffix = '_openmp' if elpa.satisfies('+openmp') else ''
            elpa_incdir = os.path.join(
                elpa.prefix,
                'include',
                'elpa{suffix}-{version!s}'.format(
                    suffix=elpa_suffix, version=elpa.version),
                'elpa')

            args += ["-DELPA_INCLUDE_DIR={0}".format(elpa_incdir)]

        return args