summaryrefslogtreecommitdiff
path: root/var/spack/repos/builtin/packages/abinit/package.py
blob: 59040cd0d8cf5a97b8faef99fad389e6a41a1a36 (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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
##############################################################################
# Copyright (c) 2013-2017, Lawrence Livermore National Security, LLC.
# Produced at the Lawrence Livermore National Laboratory.
#
# This file is part of Spack.
# Created by Todd Gamblin, tgamblin@llnl.gov, All rights reserved.
# LLNL-CODE-647188
#
# For details, see https://github.com/spack/spack
# Please also see the NOTICE and LICENSE files for our notice and the LGPL.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License (as
# published by the Free Software Foundation) version 2.1, February 1999.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms and
# conditions of the GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##############################################################################
#
# Author: Matteo Giantomassi <matteo.giantomassiNOSPAM AT uclouvain.be>
# Date: October 11, 2016
from spack import *


class Abinit(AutotoolsPackage):
    """ABINIT is a package whose main program allows one to find the total
    energy, charge density and electronic structure of systems made of
    electrons and nuclei (molecules and periodic solids) within
    Density Functional Theory (DFT), using pseudopotentials and a planewave
    or wavelet basis.

    ABINIT also includes options to optimize the geometry according to the
    DFT forces and stresses, or to perform molecular dynamics
    simulations using these forces, or to generate dynamical matrices,
    Born effective charges, and dielectric tensors, based on Density-Functional
    Perturbation Theory, and many more properties. Excited states can be
    computed within the Many-Body Perturbation Theory (the GW approximation and
    the Bethe-Salpeter equation), and Time-Dependent Density Functional Theory
    (for molecules). In addition to the main ABINIT code, different utility
    programs are provided.
    """

    homepage = 'http://www.abinit.org'
    url      = 'http://ftp.abinit.org/abinit-8.0.8b.tar.gz'

    version('8.2.2', '5f25250e06fdc0815c224ffd29858860')
    # Versions before 8.0.8b are not supported.
    version('8.0.8b', 'abc9e303bfa7f9f43f95598f87d84d5d')

    variant('mpi', default=True,
            description='Builds with MPI support. Requires MPI2+')
    variant('openmp', default=False,
            description='Enables OpenMP threads. Use threaded FFTW3')
    variant('scalapack', default=False,
            description='Enables scalapack support. Requires MPI')
    # variant('elpa', default=False,
    #         description='Uses elpa instead of scalapack. Requires MPI')

    # TODO: To be tested.
    # It was working before the last `git pull` but now all tests crash.
    # For the time being, the default is netcdf3 and the internal fallbacks
    # FIXME: rename (trio?) and use multivalued variants to cover
    # --with-trio-flavor={netcdf, none}
    # Note that Abinit@8: does not support etsf_io anymore because it is not
    # compatible with HDF5 and MPI-IO
    variant('hdf5', default=False,
            description='Enables HDF5+Netcdf4 with MPI. WARNING: experimental')

    # Add dependencies
    # currently one cannot forward options to virtual packages, see #1712.
    # depends_on('blas', when='~openmp')
    # depends_on('blas+openmp', when='+openmp')
    depends_on('blas')
    depends_on('lapack')

    # Require MPI2+
    depends_on('mpi@2:', when='+mpi')

    depends_on('scalapack', when='+scalapack+mpi')

    # depends_on('elpa~openmp', when='+elpa+mpi~openmp')
    # depends_on('elpa+openmp', when='+elpa+mpi+openmp')

    depends_on('fftw+float', when='~openmp')
    depends_on('fftw+float+openmp', when='+openmp')

    depends_on('netcdf-fortran', when='+hdf5')
    depends_on('hdf5+mpi', when='+mpi+hdf5')  # required for NetCDF-4 support

    # pin libxc version
    depends_on("libxc@2.2.2")

    # Cannot ask for +scalapack if it does not depend on MPI
    conflicts('+scalapack', when='~mpi')

    # Elpa is a substitute for scalapack and needs mpi
    # conflicts('+elpa', when='~mpi')
    # conflicts('+elpa', when='+scalapack')

    def configure_args(self):

        spec = self.spec

        options = []
        oapp = options.append

        if '+mpi' in spec:
            # MPI version:
            # let the configure script auto-detect MPI support from mpi_prefix
            oapp('--with-mpi-prefix={0}'.format(spec['mpi'].prefix))
            oapp('--enable-mpi=yes')
            oapp('--enable-mpi-io=yes')

        # Activate OpenMP in Abinit Fortran code.
        if '+openmp' in spec:
            oapp('--enable-openmp=yes')

        # BLAS/LAPACK/SCALAPACK-ELPA
        linalg = spec['lapack'].libs + spec['blas'].libs
        if '+scalapack' in spec:
            oapp('--with-linalg-flavor=custom+scalapack')
            linalg = spec['scalapack'].libs + linalg

        # elif '+elpa' in spec:
        else:
            oapp('--with-linalg-flavor=custom')

        oapp('--with-linalg-libs={0}'.format(linalg.ld_flags))

        # FFTW3: use sequential or threaded version if +openmp
        fftflavor, fftlibs = 'fftw3', '-lfftw3 -lfftw3f'
        if '+openmp' in spec:
            fftflavor = 'fftw3-threads'
            fftlibs = '-lfftw3_omp -lfftw3 -lfftw3f'

        options.extend([
            '--with-fft-flavor=%s' % fftflavor,
            '--with-fft-incs=-I%s' % spec['fftw'].prefix.include,
            '--with-fft-libs=-L%s %s' % (spec['fftw'].prefix.lib, fftlibs),
        ])
        oapp('--with-dft-flavor=atompaw+libxc')

        # LibXC library
        libxc = spec['libxc:fortran']
        options.extend([
            'with_libxc_incs={0}'.format(libxc.headers.cpp_flags),
            'with_libxc_libs={0}'.format(libxc.libs.ld_flags + ' -lm')
        ])

        # Netcdf4/HDF5
        if '+hdf5' in spec:
            oapp('--with-trio-flavor=netcdf')
            # Since version 8, Abinit started to use netcdf4 + hdf5 and we have
            # to link with the high level HDF5 library
            hdf5 = spec['hdf5:hl']
            netcdff = spec['netcdf-fortran:shared']
            options.extend([
                '--with-netcdf-incs={0}'.format(netcdff.headers.cpp_flags),
                '--with-netcdf-libs={0}'.format(
                    netcdff.libs.ld_flags + ' ' + hdf5.libs.ld_flags
                ),
            ])
        else:
            # In Spack we do our best to avoid building any internally provided
            # dependencies, such as netcdf3 in this case.
            oapp('--with-trio-flavor=none')

        return options

    def check(self):
        """This method is called after the build phase if tests have been
        explicitly activated by user.
        """
        make('check')
        make('tests_in')