Added options to link plumed statically

This commit is contained in:
Gareth Tribello
2018-07-11 16:39:52 +01:00
parent 4d5635a3c4
commit 492e945b5a
4 changed files with 186 additions and 9 deletions

2
lib/plumed/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
# files to ignore
/plumed2*

147
lib/plumed/Install.py Normal file
View File

@ -0,0 +1,147 @@
#!/usr/bin/env python
# Install.py tool to download, unpack, build, and link to the Voro++ library
# used to automate the steps described in the README file in this dir
from __future__ import print_function
import sys,os,re,subprocess
# help message
help = """
Syntax from src dir: make lib-plumed args="-b"
or: make lib-plumed args="-b -v 2.4.2"
Syntax from lib dir: python Install.py -b -v 2.4.2
or: python Install.py -b
specify one or more options, order does not matter
-b = download and build the plumed2 library
-v = set version of Voro++ to download and build (default: latest stable version)
Example:
make lib-plumed args="-b" # download/build in lib/plumed/plumed2
"""
# settings
version = "2.4.2"
# Add known checksums for different PLUMED versions and use them to validate the download
# print error message or help
def error(str=None):
if not str: print(help)
else: print("ERROR",str)
sys.exit()
# expand to full path name
# process leading '~' or relative path
def fullpath(path):
return os.path.abspath(os.path.expanduser(path))
def which(program):
def is_exe(fpath):
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
fpath, fname = os.path.split(program)
if fpath:
if is_exe(program):
return program
else:
for path in os.environ["PATH"].split(os.pathsep):
path = path.strip('"')
exe_file = os.path.join(path, program)
if is_exe(exe_file):
return exe_file
return None
def geturl(url,fname):
success = False
if which('curl') != None:
cmd = 'curl -L -o "%s" %s' % (fname,url)
try:
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
success = True
except subprocess.CalledProcessError as e:
print("Calling curl failed with: %s" % e.output.decode('UTF-8'))
if not success and which('wget') != None:
cmd = 'wget -O "%s" %s' % (fname,url)
try:
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
success = True
except subprocess.CalledProcessError as e:
print("Calling wget failed with: %s" % e.output.decode('UTF-8'))
if not success:
error("Failed to download source code with 'curl' or 'wget'")
return
# Here add function to check fsum
# parse args
args = sys.argv[1:]
nargs = len(args)
if nargs == 0: error()
homepath = "."
buildflag = False
suffixflag = False
linkflag = True
iarg = 0
while iarg < nargs:
if args[iarg] == "-v":
if iarg+2 > nargs: error()
version = args[iarg+1]
iarg += 2
elif args[iarg] == "-b":
buildflag = True
iarg += 1
else: error()
homepath = fullpath(homepath)
# download and unpack plumed tarball
if buildflag:
url = "https://github.com/plumed/plumed2/archive/v%s.tar.gz" % version
filename = "v%s.tar.gz" %version
print("Downloading plumed ...")
geturl(url,filename)
print("Unpacking plumed tarball ...")
if os.path.exists("%s/%s" % (homepath,version)):
cmd = 'rm -rf "%s/%s"' % (homepath,version)
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
cmd = 'cd "%s"; tar -xzvf v%s.tar.gz' % (homepath,version)
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
os.remove("%s/v%s.tar.gz" % (homepath,version))
# build plumed
if buildflag:
print("Building plumed ...")
cmd = 'cd %s/plumed2-%s; ./configure ; make' % (homepath,version)
txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
print(txt.decode('UTF-8'))
#
# # create 2 links in lib/voronoi to Voro++ src dir
#
# if linkflag:
# print("Creating links to Voro++ 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/src" includelink' % homedir
# subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
# cmd = 'ln -s "%s/src" liblink' % homedir
# subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)

View File

@ -5,20 +5,33 @@ if (test $1 = 1) then
if (test -e ../Makefile.package) then
sed -i -e 's|^PKG_LIB =[ \t]*|& $(PLUMED_LOAD) |' ../Makefile.package
if ( ! test -e ../../lib/plumed/plumed2*/src/lib/Plumed.inc.static ) then
sed -i -e 's|^PKG_SYSINC =[ \t]*|& -D__PLUMED_HAS_DLOPEN |' ../Makefile.package
fi
fi
if (test -e ../Makefile.package.settings) then
# This is for statically linking plumed2
if ( test -e ../../lib/plumed/plumed2*/src/lib/Plumed.inc.static ) then
fname=`ls ../../lib/plumed/plumed2*/src/lib/Plumed.inc.static`
sed -i -e "4 i \
include $fname
" ../Makefile.package.settings
dname=`ls ../../lib/plumed/plumed2*/src/wrapper/Plumed.h`
ln -s USER-PLUMED/$dname ../Plumed.h
# This is for linking plumed2 as a runtime library -- this is the default behavior
else
# multiline form needed for BSD sed on Macs
sed -i -e '4 i \
PLUMED_LOAD=-ldl
' ../Makefile.package.settings
cp Plumed.h ..
cp Plumed.cpp ..
fi
fi
cp fix_plumed.cpp ..
cp fix_plumed.h ..
cp Plumed.h ..
cp Plumed.cpp ..
elif (test $1 = 0) then
@ -28,12 +41,16 @@ elif (test $1 = 0) then
fi
if (test -e ../Makefile.package.settings) then
fname=`ls ../../lib/plumed/plumed2*/src/lib/Plumed.inc.static`
sed -i -e "\:include $fname: d" ../Makefile.package.settings
sed -i -e '/PLUMED_LOAD=-ldl/d' ../Makefile.package.settings
fi
rm -f ../fix_plumed.cpp
rm -f ../fix_plumed.h
rm -f ../Plumed.h
if ( test -e ../Plumed.h ) then
rm -f ../Plumed.cpp
fi
fi

View File

@ -192,6 +192,9 @@ void FixPlumed::min_setup(int vflag)
void FixPlumed::post_force(int vflag)
{
// Check tag is enabled
if( !atom->tag_enable ) error->all(FLERR,"to run PLUMED you must have tag_enable==1");
int update_gatindex=0;
// Try to find out if the domain decomposition has been updated:
if(nlocal!=atom->nlocal){
@ -216,10 +219,18 @@ void FixPlumed::post_force(int vflag)
// In case it has been updated, rebuild the local mass/charges array
// and tell plumed about the change:
if(update_gatindex){
for(int i=0;i<nlocal;i++){
gatindex[i]=atom->tag[i]-1;
masses[i]=atom->mass[atom->type[i]];
if(atom->q) charges[i]=atom->q[i];
for(int i=0;i<nlocal;i++) gatindex[i]=atom->tag[i]-1;
// Get masses
if(atom->rmass_flag) {
for(int i=0;i<nlocal;i++) masses[i]=atom->rmass[i];
} else {
for(int i=0;i<nlocal;i++) masses[i]=atom->mass[atom->type[i]];
}
// Get charges
if(atom->q_flag) {
for(int i=0;i<nlocal;i++) charges[i]=atom->q[i];
} else {
for(int i=0;i<nlocal;i++) charges[i]=0.0;
}
p->cmd("setAtomsNlocal",&nlocal);
p->cmd("setAtomsGatindex",gatindex);