2018-07-11 23:39:52 +08:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2018-10-29 09:56:49 +08:00
|
|
|
# Install.py tool to download, unpack, build, and link to the plumed2 library
|
2018-07-11 23:39:52 +08:00
|
|
|
# used to automate the steps described in the README file in this dir
|
|
|
|
|
|
|
|
from __future__ import print_function
|
2018-11-29 09:46:50 +08:00
|
|
|
import sys,os,re,subprocess,hashlib,shutil
|
2018-12-04 08:47:10 +08:00
|
|
|
sys.path.append('..')
|
2018-12-06 07:31:57 +08:00
|
|
|
from install_helpers import get_cpus,fullpath,geturl,checkmd5sum
|
|
|
|
from argparse import ArgumentParser
|
|
|
|
|
|
|
|
parser = ArgumentParser(prog='Install.py',
|
|
|
|
description="LAMMPS library build wrapper script")
|
|
|
|
|
|
|
|
# settings
|
|
|
|
|
2019-01-15 06:47:36 +08:00
|
|
|
version = "2.4.4"
|
2018-12-06 07:31:57 +08:00
|
|
|
mode = "static"
|
2018-07-11 23:39:52 +08:00
|
|
|
|
|
|
|
# help message
|
|
|
|
|
|
|
|
help = """
|
|
|
|
Syntax from src dir: make lib-plumed args="-b"
|
2018-10-31 08:43:20 +08:00
|
|
|
or: make lib-plumed args="-b -v 2.4.3"
|
2018-11-15 10:26:36 +08:00
|
|
|
or: make lib-plumed args="-p /usr/local/plumed2 -m shared"
|
2018-10-31 08:43:20 +08:00
|
|
|
|
|
|
|
Syntax from lib dir: python Install.py -b -v 2.4.3
|
2018-07-11 23:39:52 +08:00
|
|
|
or: python Install.py -b
|
2018-11-15 10:26:36 +08:00
|
|
|
or: python Install.py -p /usr/local/plumed2 -m shared
|
2018-07-11 23:39:52 +08:00
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
make lib-plumed args="-b" # download/build in lib/plumed/plumed2
|
2018-11-29 00:37:24 +08:00
|
|
|
make lib-plumed args="-p $HOME/plumed2 -m shared" # use existing Plumed2 installation in $HOME/plumed2
|
2018-07-11 23:39:52 +08:00
|
|
|
"""
|
|
|
|
|
2018-10-31 08:43:20 +08:00
|
|
|
# known checksums for different PLUMED versions. used to validate the download.
|
|
|
|
checksums = { \
|
2018-11-03 12:21:10 +08:00
|
|
|
'2.4.2' : '88188743a6e03ef076e5377d03ebb0e7', \
|
|
|
|
'2.4.3' : 'b1be7c48971627febc11c61b70767fc5', \
|
2019-01-15 06:47:36 +08:00
|
|
|
'2.4.4' : '71ed465bdc7c2059e282dbda8d564e71', \
|
|
|
|
'2.5.0' : '6224cd089493661e19ceacccd35cf911', \
|
2018-10-31 08:43:20 +08:00
|
|
|
}
|
2018-07-11 23:39:52 +08:00
|
|
|
|
2018-12-06 07:31:57 +08:00
|
|
|
# parse and process arguments
|
|
|
|
|
|
|
|
pgroup = parser.add_mutually_exclusive_group()
|
|
|
|
pgroup.add_argument("-b", "--build", action="store_true",
|
|
|
|
help="download and build the plumed2 library")
|
|
|
|
pgroup.add_argument("-p", "--path",
|
|
|
|
help="specify folder of existing plumed2 installation")
|
|
|
|
parser.add_argument("-v", "--version", default=version, choices=checksums.keys(),
|
|
|
|
help="set version of plumed to download and build (default: %s)" % version)
|
|
|
|
parser.add_argument("-m", "--mode", default=mode, choices=['static', 'shared', 'runtime'],
|
|
|
|
help="set plumed linkage mode: static (default), shared, or runtime")
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
# print help message and exit, if neither build nor path options are given
|
|
|
|
if args.build == False and not args.path:
|
|
|
|
parser.print_help()
|
|
|
|
sys.exit(help)
|
|
|
|
|
|
|
|
buildflag = args.build
|
|
|
|
pathflag = args.path != None
|
|
|
|
plumedpath= args.path
|
|
|
|
|
|
|
|
homepath = fullpath('.')
|
2018-11-28 07:06:50 +08:00
|
|
|
homedir = "%s/plumed2" % (homepath)
|
2018-07-11 23:39:52 +08:00
|
|
|
|
2019-01-15 06:47:36 +08:00
|
|
|
if pathflag:
|
2019-01-15 03:13:40 +08:00
|
|
|
if not os.path.isdir(plumedpath):
|
|
|
|
sys.exit("Plumed2 path %s does not exist" % plumedpath)
|
|
|
|
homedir = fullpath(plumedpath)
|
2018-10-29 06:12:32 +08:00
|
|
|
|
|
|
|
# download and unpack plumed2 tarball
|
2018-07-11 23:39:52 +08:00
|
|
|
|
|
|
|
if buildflag:
|
2018-11-03 12:21:10 +08:00
|
|
|
url = "https://github.com/plumed/plumed2/releases/download/v%s/plumed-src-%s.tgz" % (version,version)
|
|
|
|
filename = "plumed-src-%s.tar.gz" %version
|
2018-07-11 23:39:52 +08:00
|
|
|
print("Downloading plumed ...")
|
2018-10-31 08:43:20 +08:00
|
|
|
geturl(url,filename)
|
|
|
|
|
|
|
|
# verify downloaded archive integrity via md5 checksum, if known.
|
|
|
|
if version in checksums:
|
|
|
|
if not checkmd5sum(checksums[version],filename):
|
2019-01-15 03:13:40 +08:00
|
|
|
sys.exit("Checksum for plumed2 library does not match")
|
2018-10-31 08:43:20 +08:00
|
|
|
|
2018-11-03 12:21:10 +08:00
|
|
|
print("Unpacking plumed2 source tarball ...")
|
|
|
|
if os.path.exists("%s/plumed-%s" % (homepath,version)):
|
2018-11-29 09:46:50 +08:00
|
|
|
shutil.rmtree("%s/plumed-%s" % (homepath,version))
|
2018-11-28 07:06:50 +08:00
|
|
|
if os.path.exists(homedir):
|
2018-11-29 09:46:50 +08:00
|
|
|
shutil.rmtree(homedir)
|
2018-11-03 12:21:10 +08:00
|
|
|
cmd = 'cd "%s"; tar -xzvf %s' % (homepath,filename)
|
2018-07-11 23:39:52 +08:00
|
|
|
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
2018-11-03 12:21:10 +08:00
|
|
|
os.remove("%s/%s" % (homepath,filename))
|
2018-07-11 23:39:52 +08:00
|
|
|
|
2018-11-28 23:09:05 +08:00
|
|
|
# build plumed
|
|
|
|
print("Building plumed ...")
|
2018-12-04 08:47:10 +08:00
|
|
|
n_cpus = get_cpus()
|
2018-11-28 23:09:05 +08:00
|
|
|
cmd = 'cd %s/plumed-%s; ./configure --prefix=%s --enable-static-patch ; make -j%d ; make install' % (homepath,version,homedir,n_cpus)
|
2018-12-04 08:47:10 +08:00
|
|
|
try:
|
|
|
|
txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
|
|
|
print(txt.decode('UTF-8'))
|
|
|
|
except subprocess.CalledProcessError as e:
|
|
|
|
print("Make failed with:\n %s" % e.output.decode('UTF-8'))
|
|
|
|
sys.exit(1)
|
2019-01-15 03:13:40 +08:00
|
|
|
|
2018-10-29 06:12:32 +08:00
|
|
|
# create 2 links in lib/plumed to plumed2 installation dir
|
|
|
|
|
2018-12-06 07:31:57 +08:00
|
|
|
print("Creating links to plumed2 include and lib files")
|
|
|
|
if os.path.isfile("includelink") or os.path.islink("includelink"):
|
|
|
|
os.remove("includelink")
|
|
|
|
if os.path.isfile("liblink") or os.path.islink("liblink"):
|
|
|
|
os.remove("liblink")
|
|
|
|
cmd = 'ln -s "%s/include" includelink' % homedir
|
|
|
|
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
|
|
|
cmd = 'ln -s "%s/lib" liblink' % homedir
|
|
|
|
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
|
|
|
if os.path.isfile("Makefile.lammps.%s" % mode):
|
|
|
|
print("Creating Makefile.lammps")
|
|
|
|
cmd = 'echo PLUMED_LIBDIR="%s/lib" > Makefile.lammps; cat liblink/plumed/src/lib/Plumed.inc.%s Makefile.lammps.%s >> Makefile.lammps' % (homedir,mode,mode)
|
2018-11-29 00:37:24 +08:00
|
|
|
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
2018-11-03 10:52:36 +08:00
|
|
|
|