spack/var/spack/repos/builtin/packages/plumed/package.py

185 lines
6.7 KiB
Python
Raw Normal View History

##############################################################################
# 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(AutotoolsPackage):
"""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/archive/v2.2.3.tar.gz'
version('2.3.0', 'a9b5728f115dca8f0519111f1f5a6fa5')
version('2.2.4', 'afb00da25a3fbd47acf377e53342059d')
version('2.2.3', 'a6e3863e40aac07eb8cf739cbd14ecf8')
# 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.
# FIXME: This needs to be an optional
variant(
'optional_modules',
default='all',
values=lambda x: True,
description='String that is used to build optional modules'
)
variant('shared', default=True, description='Builds shared libraries')
variant('mpi', default=True, description='Activates MPI support')
variant('gsl', default=True, description='Activates GSL support')
2016-08-22 19:09:50 +08:00
# 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')
depends_on('autoconf', type='build')
depends_on('automake', type='build')
depends_on('libtool', type='build')
# Dictionary mapping PLUMED versions to the patches it provides
# interactively
plumed_patches = {
'2.3.0': {
'amber-14': '1',
'gromacs-2016.1': '2',
'gromacs-4.5.7': '3',
'gromacs-5.0.7': '4',
'gromacs-5.1.4': '5',
'lammps-6Apr13': '6',
'namd-2.8': '7',
'namd-2.9': '8',
'espresso-5.0.2': '9'
},
'2.2.4': {
'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'
},
'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'
}
}
force_autoreconf = True
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, dependent_spec):
# Make plumed visible from dependent packages
Python command, libraries, and headers (#3367) ## Motivation Python installations are both important and unfortunately inconsistent. Depending on the Python version, OS, and the strength of the Earth's magnetic field when it was installed, the name of the Python executable, directory containing its libraries, library names, and the directory containing its headers can vary drastically. I originally got into this mess with #3274, where I discovered that Boost could not be built with Python 3 because the executable is called `python3` and we were telling it to use `python`. I got deeper into this mess when I started hacking on #3140, where I discovered just how difficult it is to find the location and name of the Python libraries and headers. Currently, half of the packages that depend on Python and need to know this information jump through hoops to determine the correct information. The other half are hard-coded to use `python`, `spec['python'].prefix.lib`, and `spec['python'].prefix.include`. Obviously, none of these packages would work for Python 3, and there's no reason to duplicate the effort. The Python package itself should contain all of the information necessary to use it properly. This is in line with the recent work by @alalazo and @davydden with respect to `spec['blas'].libs` and friends. ## Prefix For most packages in Spack, we assume that the installation directory is `spec['python'].prefix`. This generally works for anything installed with Spack, but gets complicated when we include external packages. Python is a commonly used external package (it needs to be installed just to run Spack). If it was installed with Homebrew, `which python` would return `/usr/local/bin/python`, and most users would erroneously assume that `/usr/local` is the installation directory. If you peruse through #2173, you'll immediately see why this is not the case. Homebrew actually installs Python in `/usr/local/Cellar/python/2.7.12_2` and symlinks the executable to `/usr/local/bin/python`. `PYTHONHOME` (and presumably most things that need to know where Python is installed) needs to be set to the actual installation directory, not `/usr/local`. Normally I would say, "sounds like user error, make sure to use the real installation directory in your `packages.yaml`". But I think we can make a special case for Python. That's what we decided in #2173 anyway. If we change our minds, I would be more than happy to simplify things. To solve this problem, I created a `spec['python'].home` attribute that works the same way as `spec['python'].prefix` but queries Python to figure out where it was actually installed. @tgamblin Is there any way to overwrite `spec['python'].prefix`? I think it's currently immutable. ## Command In general, Python 2 comes with both `python` and `python2` commands, while Python 3 only comes with a `python3` command. But this is up to the OS developers. For example, `/usr/bin/python` on Gentoo is actually Python 3. Worse yet, if someone is using an externally installed Python, all 3 commands may exist in the same directory! Here's what I'm thinking: If the spec is for Python 3, try searching for the `python3` command. If the spec is for Python 2, try searching for the `python2` command. If neither are found, try searching for the `python` command. ## Libraries Spack installs Python libraries in `spec['python'].prefix.lib`. Except on openSUSE 13, where it installs to `spec['python'].prefix.lib64` (see #2295 and #2253). On my CentOS 6 machine, the Python libraries are installed in `/usr/lib64`. Both need to work. The libraries themselves change name depending on OS and Python version. For Python 2.7 on macOS, I'm seeing: ``` lib/libpython2.7.dylib ``` For Python 3.6 on CentOS 6, I'm seeing: ``` lib/libpython3.so lib/libpython3.6m.so.1.0 lib/libpython3.6m.so -> lib/libpython3.6m.so.1.0 ``` Notice the `m` after the version number. Yeah, that's a thing. ## Headers In Python 2.7, I'm seeing: ``` include/python2.7/pyconfig.h ``` In Python 3.6, I'm seeing: ``` include/python3.6m/pyconfig.h ``` It looks like all Python 3 installations have this `m`. Tested with Python 3.2 and 3.6 on macOS and CentOS 6 Spack has really nice support for libraries (`find_libraries` and `LibraryList`), but nothing for headers. Fixed.
2017-04-30 08:24:13 +08:00
module.plumed = self.spec['plumed'].command
@run_before('autoreconf')
def filter_gslcblas(self):
# This part is needed to avoid linking with gsl cblas
# interface which will mask the cblas interface
# provided by optimized libraries due to linking order
filter_file('-lgslcblas', '', 'configure.ac')
def configure_args(self):
spec = self.spec
# 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 = []
# 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)
])
2016-08-22 20:44:21 +08:00
# If the MPI dependency is provided by the intel-mpi package then
# the following additional argument is required to allow it to
# build.
if 'intel-mpi' in spec:
configure_opts.extend([
'STATIC_LIBS=-mt_mpi'
2016-08-22 19:03:47 +08:00
])
# 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
# If we have specified any optional modules then add the argument to
# enable or disable them.
optional_modules = self.spec.variants['optional_modules'].value
if optional_modules:
# From 'configure --help' @2.3:
# all/none/reset or : separated list such as
# +crystallization:-bias default: reset
configure_opts.append(
'--enable-modules={0}'.format(optional_modules)
)
return configure_opts