summaryrefslogtreecommitdiff
path: root/var/spack/repos/builtin/packages/plumed/package.py
blob: 02d9852add0ac9773844e538cf66f7c9d0a00796 (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
##############################################################################
# Copyright (c) 2013-2016, 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/llnl/spack
# Please also see the LICENSE file 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
##############################################################################
import subprocess

from spack import *


class Plumed(Package):
    """PLUMED is an open source library for free energy calculations in
    molecular systems which works together with some of the most popular
    molecular dynamics engines.

    Free energy calculations can be performed as a function of many order
    parameters with a particular focus on biological problems, using state
    of the art methods such as metadynamics, umbrella sampling and
    Jarzynski-equation based steered MD.

    The software, written in C++, can be easily interfaced with both fortran
    and C/C++ codes.
    """
    homepage = 'http://www.plumed.org/'
    url = 'https://github.com/plumed/plumed2'

    version('2.2.3', git="https://github.com/plumed/plumed2.git", tag='v2.2.3')

    # Variants. PLUMED by default builds a number of optional modules.
    # The ones listed here are not built by default for various reasons,
    # such as stability, lack of testing, or lack of demand.
    variant('crystallization', default=False,
            description='Build support for optional crystallization module.')
    variant('imd', default=False,
            description='Build support for optional imd module.')
    variant('manyrestraints', default=False,
            description='Build support for optional manyrestraints module.')
    variant('shared', default=True, description='Builds shared libraries')
    variant('mpi', default=True, description='Activates MPI support')
    variant('gsl', default=True, description='Activates GSL support')

    # Dependencies. LAPACK and BLAS are recommended but not essential.
    depends_on('zlib')
    depends_on('blas')
    depends_on('lapack')

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

    # Dictionary mapping PLUMED versions to the patches it provides
    # interactively
    plumed_patches = {
        '2.2.3': {
            'amber-14': '1',
            'gromacs-4.5.7': '2',
            'gromacs-4.6.7': '3',
            'gromacs-5.0.7': '4',
            'gromacs-5.1.2': '5',
            'lammps-6Apr13': '6',
            'namd-2.8': '7',
            'namd-2.9': '8',
            'espresso-5.0.2': '9'
        }
    }

    def apply_patch(self, other):
        plumed = subprocess.Popen(
            [join_path(self.spec.prefix.bin, 'plumed'), 'patch', '-p'],
            stdin=subprocess.PIPE
        )
        opts = Plumed.plumed_patches[str(self.version)]
        search = '{0.name}-{0.version}'.format(other)
        choice = opts[search] + '\n'
        plumed.stdin.write(choice)
        plumed.wait()

    def setup_dependent_package(self, module, ext_spec):
        # Make plumed visible from dependent packages
        module.plumed = Executable(join_path(self.spec.prefix.bin, 'plumed'))

    def install(self, spec, prefix):
        # From plumed docs :
        # Also consider that this is different with respect to what some other
        # configure script does in that variables such as MPICXX are
        # completely ignored here. In case you work on a machine where CXX is
        # set to a serial compiler and MPICXX to a MPI compiler, to compile
        # with MPI you should use:
        #
        # > ./configure CXX="$MPICXX"
        configure_opts = ['--prefix=' + prefix]

        # If using MPI then ensure the correct compiler wrapper is used.
        if '+mpi' in spec:
            configure_opts.extend([
                '--enable-mpi',
                'CXX={0}'.format(spec['mpi'].mpicxx)
            ])

            # If the MPI dependency is provided by the intel-mpi package then
            # the following additional argument is required to allow it to
            # build.
            if spec.satisfies('^intel-mpi'):
                configure_opts.extend([
                    'STATIC_LIBS=-mt_mpi'
                ])

        # Additional arguments
        configure_opts.extend([
            '--enable-shared={0}'.format('yes' if '+shared' in spec else 'no'),
            '--enable-gsl={0}'.format('yes' if '+gsl' in spec else 'no')
        ])

        # Construct list of optional modules
        module_opts = []
        module_opts.extend([
            '+crystallization' if (
                '+crystallization' in spec) else '-crystallization',
            '+imd' if '+imd' in spec else '-imd',
            '+manyrestraints' if (
                '+manyrestraints' in spec) else '-manyrestraints'
        ])

        # If we have specified any optional modules then add the argument to
        # enable or disable them.
        if module_opts:
            configure_opts.extend([
                '--enable-modules={0}'.format("".join(module_opts))])

        configure(*configure_opts)
        make()
        make('install')