lammps/lib/kim/Install.py

193 lines
6.4 KiB
Python
Raw Normal View History

#!/usr/bin/env python
# install.py tool to download, compile, and setup the kim-api library
# used to automate the steps described in the README file in this dir
from __future__ import print_function
import sys,os,re,subprocess,shutil
2018-12-04 08:47:10 +08:00
sys.path.append('..')
from install_helpers import error,fullpath,which,geturl
# help message
help = """
Syntax from src dir: make lib-kim args="-b -v version -a kim-name"
or: make lib-kim args="-b -a everything"
or: make lib-kim args="-n -a kim-name"
or: make lib-kim args="-p /home/bob/kim -a kim-name"
Syntax from lib dir: python Install.py -b -v version -a kim-name
or: python Install.py -b -a everything
or: python Install.py -n -a kim-name
or: python Install.py -p /home/bob/kim -a kim-name
specify one or more options, order does not matter
-v = version of KIM API library to use
2018-12-13 06:21:54 +08:00
default = kim-api-v2.0.0-beta.3 (current as of December 2018)
-b = download and build base KIM API library with example Models
this will delete any previous installation in the current folder
-n = do NOT download and build base KIM API library.
Use an existing installation
-p = specify install prefix of KIM API installation (implies -n)
-a = add single KIM model or model driver with kim-name
to existing KIM API lib (see example below).
If kim-name = everything, then rebuild KIM API library with
*all* available OpenKIM Models (make take a long time).
-vv = be more verbose about what is happening while the script runs
Examples:
make lib-kim args="-b" # install KIM API lib with only example models
2018-12-13 06:21:54 +08:00
make lib-kim args="-a EAM_ErcolessiAdams_1994_Al__MO_324507536345_002" # Ditto plus one model
make lib-kim args="-b -a everything" # install KIM API lib with all models
2018-12-13 06:21:54 +08:00
make lib-kim args="-n -a EAM_Dynamo_Ackland_2003_W__MO_141627196590_005" # only add one model or model driver
See the list of KIM model drivers here:
https://openkim.org/kim-items/model-drivers/alphabetical
See the list of all KIM models here:
https://openkim.org/kim-items/models/by-model-drivers
See the list of example KIM models included by default here:
https://openkim.org/kim-api
in the "What is in the KIM API source package?" section
"""
# parse args
args = sys.argv[1:]
nargs = len(args)
2018-12-04 08:47:10 +08:00
if nargs == 0: error(help=help)
2018-12-04 08:47:10 +08:00
thisdir = fullpath('.')
2018-12-13 06:21:54 +08:00
version = "kim-api-v2-2.0.0-beta.3"
buildflag = False
everythingflag = False
addflag = False
verboseflag = False
pathflag = False
2017-07-07 04:46:36 +08:00
iarg = 0
while iarg < len(args):
if args[iarg] == "-v":
2018-12-04 08:47:10 +08:00
if iarg+2 > len(args): error(help=help)
version = args[iarg+1]
iarg += 2
2017-07-07 04:46:36 +08:00
elif args[iarg] == "-b":
buildflag = True
iarg += 1
elif args[iarg] == "-n":
buildflag = False
iarg += 1
elif args[iarg] == "-p":
2018-12-04 08:47:10 +08:00
if iarg+2 > len(args): error(help=help)
kimdir = fullpath(args[iarg+1])
pathflag = True
buildflag = False
iarg += 2
2017-07-07 04:46:36 +08:00
elif args[iarg] == "-a":
addflag = True
2018-12-04 08:47:10 +08:00
if iarg+2 > len(args): error(help=help)
2017-07-07 04:46:36 +08:00
addmodelname = args[iarg+1]
if addmodelname == "everything":
buildflag = True
everythingflag = True
addflag = False
2017-07-07 04:46:36 +08:00
iarg += 2
elif args[iarg] == "-vv":
verboseflag = True
iarg += 1
2018-12-04 08:47:10 +08:00
else: error(help=help)
2017-10-10 02:11:16 +08:00
url = "https://s3.openkim.org/kim-api/%s.txz" % version
# set KIM API directory
if pathflag:
if not os.path.isdir(kimdir):
print("\nkim-api is not installed at %s" % kimdir)
2018-12-04 08:47:10 +08:00
error(help=help)
# configure LAMMPS to use existing kim-api installation
with open("%s/kim-prefix.txt" % thisdir, 'w') as pffile:
pffile.write("%s" % kimdir)
print("Created %s/kim-prefix.txt\n using %s" % (thisdir,kimdir))
else:
kimdir = os.path.join(os.path.abspath(thisdir), "installed-" + version)
# download KIM tarball, unpack, build KIM
if buildflag:
# check to see if an installed kim-api already exists and wipe it out.
if os.path.isdir(kimdir):
print("kim-api is already installed at %s.\nRemoving it for re-install" % kimdir)
shutil.rmtree(kimdir)
# configure LAMMPS to use kim-api to be installed
2017-07-07 04:46:36 +08:00
with open("%s/kim-prefix.txt" % thisdir, 'w') as pffile:
pffile.write("%s" % kimdir)
print("Created %s/kim-prefix.txt\n using %s" % (thisdir,kimdir))
2017-07-07 04:46:36 +08:00
# download entire kim-api tarball
2017-07-07 04:46:36 +08:00
print("Downloading kim-api tarball ...")
2017-10-10 02:11:16 +08:00
geturl(url,"%s/%s.txz" % (thisdir,version))
print("Unpacking kim-api tarball ...")
2017-10-10 02:11:16 +08:00
cmd = 'cd "%s"; rm -rf "%s"; tar -xJvf %s.txz' % (thisdir,version,version)
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
2017-07-07 04:46:36 +08:00
# configure kim-api
print("Configuring kim-api ...")
cmd = 'cd "%s/%s" && mkdir build && cd build && cmake .. -DCMAKE_INSTALL_PREFIX="%s" -DCMAKE_BUILD_TYPE=Release' % (thisdir,version,kimdir)
txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
if verboseflag: print(txt.decode("UTF-8"))
2017-07-07 04:46:36 +08:00
# build kim-api
print("Building kim-api ...")
cmd = 'cd "%s/%s/build" && make' % (thisdir,version)
txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
if verboseflag: print(txt.decode("UTF-8"))
2017-07-07 04:46:36 +08:00
# install kim-api
print("Installing kim-api ...")
cmd = 'cd "%s/%s/build" && make install' % (thisdir,version)
txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
if verboseflag: print(txt.decode("UTF-8"))
2017-07-07 04:46:36 +08:00
# remove source files
print("Removing kim-api source and build files ...")
2017-10-10 02:11:16 +08:00
cmd = 'cd "%s"; rm -rf %s; rm -rf %s.txz' % (thisdir,version,version)
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
2017-07-07 04:46:36 +08:00
2017-10-10 02:11:16 +08:00
# add all OpenKIM models, if desired
if everythingflag:
print("Adding all OpenKIM models, this will take a while ...")
cmd = '%s/bin/kim-api-v2-collections-management install system OpenKIM' % (kimdir)
2017-10-10 02:11:16 +08:00
txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
if verboseflag: print(txt.decode("UTF-8"))
2017-10-10 02:11:16 +08:00
# add single OpenKIM model
if addflag:
pf_path = os.path.join(thisdir, "kim-prefix.txt")
if os.path.isfile(pf_path):
cmd = 'cat %s' % pf_path
kimdir = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
if not os.path.isdir(kimdir):
print("\nkim-api is not installed")
2018-12-04 08:47:10 +08:00
error(help=help)
# download single model
cmd = '%s/bin/kim-api-v2-collections-management install system %s' % (kimdir.decode("UTF-8"), addmodelname)
2017-10-10 02:11:16 +08:00
txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
if verboseflag: print (txt.decode("UTF-8"))