2017-07-11 10:05:29 +08:00
|
|
|
#!/usr/bin/env python
|
2017-06-23 11:33:09 +08:00
|
|
|
|
2017-07-21 01:02:50 +08:00
|
|
|
# install.py tool to setup the kim-api library
|
2017-06-23 11:33:09 +08:00
|
|
|
# used to automate the steps described in the README file in this dir
|
2017-07-16 01:03:04 +08:00
|
|
|
from __future__ import print_function
|
2017-07-19 06:06:18 +08:00
|
|
|
import sys,os,re,subprocess
|
2017-08-05 02:47:32 +08:00
|
|
|
|
|
|
|
# transparently use either urllib or an external tool
|
|
|
|
try:
|
|
|
|
import ssl
|
|
|
|
try: from urllib.request import urlretrieve as geturl
|
|
|
|
except: from urllib import urlretrieve as geturl
|
|
|
|
except:
|
|
|
|
def geturl(url,fname):
|
|
|
|
cmd = "curl -o %s %s" % (fname,url)
|
|
|
|
txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
|
|
|
return txt
|
2017-06-23 11:33:09 +08:00
|
|
|
|
|
|
|
help = """
|
2017-08-05 02:47:32 +08:00
|
|
|
Syntax from src dir: make lib-kim args="-v version -a kim-name"
|
|
|
|
Syntax from lib dir: python Install.py -v version -a kim-name
|
2017-07-15 06:25:16 +08:00
|
|
|
|
|
|
|
specify one or more options, order does not matter
|
|
|
|
|
|
|
|
-v = version of KIM API library to use
|
|
|
|
default = kim-api-v1.8.2 (current as of June 2017)
|
2017-08-05 02:47:32 +08:00
|
|
|
-b = download and build base KIM API library with example Models (default)
|
|
|
|
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 location of KIM API installation (implies -n)
|
2017-07-15 06:25:16 +08:00
|
|
|
-a = add single KIM model or model driver with kim-name
|
2017-07-21 01:02:50 +08:00
|
|
|
to existing KIM API lib (see example below).
|
|
|
|
If kim-name = everything, then rebuild KIM API library with
|
|
|
|
all available OpenKIM Models (this implies -b).
|
|
|
|
-vv = be more verbose about what is happening while the script runs
|
2017-07-15 06:25:16 +08:00
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
2017-08-05 02:47:32 +08:00
|
|
|
make lib-kim # install KIM API lib with only example models
|
|
|
|
make lib-kim args="-a Glue_Ercolessi_Adams_Al__MO_324507536345_001" # Ditto plus one model
|
|
|
|
make lib-kim args="-a everything" # install KIM API lib with all models
|
|
|
|
make lib-kim args="-n -a EAM_Dynamo_Ackland_W__MO_141627196590_002" # only add one model or model driver
|
2017-07-15 06:25:16 +08:00
|
|
|
|
|
|
|
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
|
2017-06-23 11:33:09 +08:00
|
|
|
"""
|
|
|
|
|
|
|
|
def error():
|
2017-07-16 01:03:04 +08:00
|
|
|
print(help)
|
2017-06-23 11:33:09 +08:00
|
|
|
sys.exit()
|
|
|
|
|
2017-08-05 02:47:32 +08:00
|
|
|
# expand to full path name
|
|
|
|
# process leading '~' or relative path
|
|
|
|
|
|
|
|
def fullpath(path):
|
|
|
|
return os.path.abspath(os.path.expanduser(path))
|
|
|
|
|
2017-06-23 11:33:09 +08:00
|
|
|
# parse args
|
|
|
|
|
2017-07-15 06:25:16 +08:00
|
|
|
args = sys.argv[1:]
|
|
|
|
nargs = len(args)
|
2017-06-23 11:33:09 +08:00
|
|
|
|
2017-07-07 04:46:36 +08:00
|
|
|
thisdir = os.environ['PWD']
|
2017-06-23 11:33:09 +08:00
|
|
|
version = "kim-api-v1.8.2"
|
|
|
|
|
2017-08-05 02:47:32 +08:00
|
|
|
buildflag = True
|
2017-07-21 01:02:50 +08:00
|
|
|
everythingflag = False
|
2017-07-16 01:03:04 +08:00
|
|
|
addflag = False
|
2017-07-21 01:02:50 +08:00
|
|
|
verboseflag = False
|
2017-08-05 02:47:32 +08:00
|
|
|
pathflag = False
|
2017-07-07 04:46:36 +08:00
|
|
|
|
2017-07-15 06:25:16 +08:00
|
|
|
iarg = 0
|
2017-06-23 11:33:09 +08:00
|
|
|
while iarg < len(args):
|
|
|
|
if args[iarg] == "-v":
|
|
|
|
if iarg+2 > len(args): error()
|
|
|
|
version = args[iarg+1]
|
|
|
|
iarg += 2
|
2017-07-07 04:46:36 +08:00
|
|
|
elif args[iarg] == "-b":
|
2017-07-16 01:03:04 +08:00
|
|
|
buildflag = True
|
2017-07-21 01:02:50 +08:00
|
|
|
iarg += 1
|
2017-08-05 02:47:32 +08:00
|
|
|
elif args[iarg] == "-n":
|
|
|
|
buildflag = False
|
|
|
|
iarg += 1
|
|
|
|
elif args[iarg] == "-p":
|
|
|
|
if iarg+2 > len(args): error()
|
|
|
|
kimdir = fullpath(args[iarg+1])
|
|
|
|
pathflag = True
|
|
|
|
buildflag = False
|
|
|
|
iarg += 2
|
2017-07-07 04:46:36 +08:00
|
|
|
elif args[iarg] == "-a":
|
2017-07-16 01:03:04 +08:00
|
|
|
addflag = True
|
2017-07-07 04:46:36 +08:00
|
|
|
if iarg+2 > len(args): error()
|
|
|
|
addmodelname = args[iarg+1]
|
2017-07-21 01:02:50 +08:00
|
|
|
if addmodelname == "everything":
|
|
|
|
buildflag = True
|
|
|
|
everythingflag = True
|
|
|
|
addflag = False
|
2017-07-07 04:46:36 +08:00
|
|
|
iarg += 2
|
2017-07-21 01:02:50 +08:00
|
|
|
elif args[iarg] == "-vv":
|
|
|
|
verboseflag = True
|
|
|
|
iarg += 1
|
2017-06-23 11:33:09 +08:00
|
|
|
else: error()
|
|
|
|
|
2017-07-07 04:46:36 +08:00
|
|
|
thisdir = os.path.abspath(thisdir)
|
2017-06-23 11:33:09 +08:00
|
|
|
url = "https://s3.openkim.org/kim-api/%s.tgz" % version
|
|
|
|
|
2017-08-05 02:47:32 +08:00
|
|
|
# set KIM API directory
|
2017-07-15 06:25:16 +08:00
|
|
|
|
2017-08-05 02:47:32 +08:00
|
|
|
if pathflag:
|
|
|
|
if not os.path.isdir(kimdir):
|
|
|
|
print("\nkim-api is not installed at %s" % kimdir)
|
|
|
|
error()
|
2017-07-15 06:25:16 +08:00
|
|
|
|
2017-08-05 02:47:32 +08:00
|
|
|
# configure LAMMPS to use existing kim-api installation
|
|
|
|
with open("%s/Makefile.KIM_DIR" % thisdir, 'w') as mkfile:
|
|
|
|
mkfile.write("KIM_INSTALL_DIR=%s\n\n" % kimdir)
|
|
|
|
mkfile.write(".DUMMY: print_dir\n\n")
|
|
|
|
mkfile.write("print_dir:\n")
|
|
|
|
mkfile.write(" @printf $(KIM_INSTALL_DIR)\n")
|
|
|
|
|
|
|
|
with open("%s/Makefile.KIM_Config" % thisdir, 'w') as cfgfile:
|
|
|
|
cfgfile.write("include %s/lib/kim-api/Makefile.KIM_Config" % kimdir)
|
2017-07-20 05:19:44 +08:00
|
|
|
|
2017-08-05 02:47:32 +08:00
|
|
|
print("Created %s/Makefile.KIM_DIR\n using %s" % (thisdir,kimdir))
|
|
|
|
else:
|
|
|
|
kimdir = os.path.join(os.path.abspath(thisdir), "installed-" + version)
|
|
|
|
|
|
|
|
# download KIM tarball, unpack, build KIM
|
|
|
|
if buildflag:
|
2017-07-15 06:25:16 +08:00
|
|
|
|
2017-07-20 05:19:44 +08:00
|
|
|
# check to see if an installed kim-api already exists and wipe it out.
|
2017-07-15 06:25:16 +08:00
|
|
|
|
2017-08-05 02:47:32 +08:00
|
|
|
if os.path.isdir(kimdir):
|
|
|
|
print("kim-api is already installed at %s.\nRemoving it for re-install" % kimdir)
|
|
|
|
cmd = "rm -rf %s" % kimdir
|
2017-07-21 01:02:50 +08:00
|
|
|
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
2017-06-23 11:33:09 +08:00
|
|
|
|
2017-07-15 06:25:16 +08:00
|
|
|
# configure LAMMPS to use kim-api to be installed
|
2017-07-07 04:46:36 +08:00
|
|
|
|
2017-07-16 01:03:04 +08:00
|
|
|
with open("%s/Makefile.KIM_DIR" % thisdir, 'w') as mkfile:
|
2017-08-05 02:47:32 +08:00
|
|
|
mkfile.write("KIM_INSTALL_DIR=%s\n\n" % kimdir)
|
2017-07-19 06:06:18 +08:00
|
|
|
mkfile.write(".DUMMY: print_dir\n\n")
|
|
|
|
mkfile.write("print_dir:\n")
|
|
|
|
mkfile.write(" @printf $(KIM_INSTALL_DIR)\n")
|
2017-07-16 01:03:04 +08:00
|
|
|
|
|
|
|
with open("%s/Makefile.KIM_Config" % thisdir, 'w') as cfgfile:
|
2017-08-05 02:47:32 +08:00
|
|
|
cfgfile.write("include %s/lib/kim-api/Makefile.KIM_Config" % kimdir)
|
2017-07-16 01:03:04 +08:00
|
|
|
|
2017-08-05 02:47:32 +08:00
|
|
|
print("Created %s/Makefile.KIM_DIR\n using %s" % (thisdir,kimdir))
|
2017-07-07 04:46:36 +08:00
|
|
|
|
2017-07-15 06:25:16 +08:00
|
|
|
# download entire kim-api tarball
|
2017-07-07 04:46:36 +08:00
|
|
|
|
2017-07-16 01:03:04 +08:00
|
|
|
print("Downloading kim-api tarball ...")
|
2017-07-20 05:19:44 +08:00
|
|
|
geturl(url,"%s/%s.tgz" % (thisdir,version))
|
2017-07-16 01:03:04 +08:00
|
|
|
print("Unpacking kim-api tarball ...")
|
2017-07-07 04:46:36 +08:00
|
|
|
cmd = "cd %s; rm -rf %s; tar zxvf %s.tgz" % (thisdir,version,version)
|
2017-07-21 01:02:50 +08:00
|
|
|
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
2017-07-07 04:46:36 +08:00
|
|
|
|
|
|
|
# configure kim-api
|
2017-07-15 06:25:16 +08:00
|
|
|
|
2017-07-16 01:03:04 +08:00
|
|
|
print("Configuring kim-api ...")
|
2017-08-05 02:47:32 +08:00
|
|
|
cmd = "cd %s/%s; ./configure --prefix='%s'" % (thisdir,version,kimdir)
|
2017-07-21 01:02:50 +08:00
|
|
|
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
2017-07-07 04:46:36 +08:00
|
|
|
|
|
|
|
# build kim-api
|
2017-07-15 06:25:16 +08:00
|
|
|
|
2017-07-21 01:02:50 +08:00
|
|
|
print("Configuring example Models")
|
|
|
|
cmd = "cd %s/%s; make add-examples" % (thisdir,version)
|
|
|
|
txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
|
|
|
if verboseflag: print (txt.decode("UTF-8"))
|
|
|
|
|
|
|
|
if everythingflag:
|
|
|
|
print("Configuring all OpenKIM models, this will take a while ...")
|
|
|
|
cmd = "cd %s/%s; make add-OpenKIM" % (thisdir,version)
|
|
|
|
txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
|
|
|
if verboseflag: print(txt.decode("UTF-8"))
|
2017-07-15 06:25:16 +08:00
|
|
|
|
2017-07-16 01:03:04 +08:00
|
|
|
print("Building kim-api ...")
|
2017-07-07 04:46:36 +08:00
|
|
|
cmd = "cd %s/%s; make" % (thisdir,version)
|
2017-07-21 01:02:50 +08:00
|
|
|
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
|
2017-07-15 06:25:16 +08:00
|
|
|
|
2017-07-16 01:03:04 +08:00
|
|
|
print("Installing kim-api ...")
|
2017-07-07 04:46:36 +08:00
|
|
|
cmd = "cd %s/%s; make install" % (thisdir,version)
|
2017-07-21 01:02:50 +08:00
|
|
|
txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
|
|
|
if verboseflag: print(txt.decode("UTF-8"))
|
2017-07-15 06:25:16 +08:00
|
|
|
|
2017-07-07 04:46:36 +08:00
|
|
|
cmd = "cd %s/%s; make install-set-default-to-v1" %(thisdir,version)
|
2017-07-21 01:02:50 +08:00
|
|
|
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
|
2017-07-15 06:25:16 +08:00
|
|
|
|
2017-07-16 01:03:04 +08:00
|
|
|
print("Removing kim-api source and build files ...")
|
2017-07-07 04:46:36 +08:00
|
|
|
cmd = "cd %s; rm -rf %s; rm -rf %s.tgz" % (thisdir,version,version)
|
2017-07-21 01:02:50 +08:00
|
|
|
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
2017-07-07 04:46:36 +08:00
|
|
|
|
2017-07-15 06:25:16 +08:00
|
|
|
# add a single model (and possibly its driver) to existing KIM installation
|
|
|
|
|
2017-07-16 01:03:04 +08:00
|
|
|
if addflag:
|
2017-07-15 06:25:16 +08:00
|
|
|
|
2017-08-05 02:47:32 +08:00
|
|
|
if not os.path.isdir(kimdir):
|
|
|
|
print("\nkim-api is not installed")
|
2017-07-15 06:25:16 +08:00
|
|
|
error()
|
|
|
|
|
|
|
|
# download single model
|
|
|
|
|
2017-07-21 01:02:50 +08:00
|
|
|
print("Downloading tarball for %s..." % addmodelname)
|
2017-07-15 06:25:16 +08:00
|
|
|
url = "https://openkim.org/download/%s.tgz" % addmodelname
|
2017-07-20 05:19:44 +08:00
|
|
|
geturl(url,"%s/%s.tgz" % (thisdir,addmodelname))
|
2017-07-15 06:25:16 +08:00
|
|
|
|
2017-07-16 01:03:04 +08:00
|
|
|
print("Unpacking item tarball ...")
|
2017-07-07 04:46:36 +08:00
|
|
|
cmd = "cd %s; tar zxvf %s.tgz" % (thisdir,addmodelname)
|
2017-07-21 01:02:50 +08:00
|
|
|
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
2017-07-15 06:25:16 +08:00
|
|
|
|
2017-07-16 01:03:04 +08:00
|
|
|
print("Building item ...")
|
2017-07-11 05:43:23 +08:00
|
|
|
cmd = "cd %s/%s; make; make install" %(thisdir,addmodelname)
|
2017-07-20 01:54:33 +08:00
|
|
|
try:
|
|
|
|
txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
|
|
|
except subprocess.CalledProcessError as e:
|
|
|
|
|
2017-07-15 06:25:16 +08:00
|
|
|
# Error: but first, check to see if it needs a driver
|
2017-07-21 01:02:50 +08:00
|
|
|
firstRunOutput = e.output.decode("UTF-8")
|
2017-07-20 01:54:33 +08:00
|
|
|
|
2017-07-15 06:25:16 +08:00
|
|
|
cmd = "cd %s/%s; make kim-item-type" % (thisdir,addmodelname)
|
2017-07-20 01:54:33 +08:00
|
|
|
txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
2017-07-21 01:02:50 +08:00
|
|
|
txt = txt.decode("UTF-8")
|
2017-07-20 01:54:33 +08:00
|
|
|
if txt == "ParameterizedModel":
|
2017-07-15 06:25:16 +08:00
|
|
|
|
|
|
|
# Get and install driver
|
|
|
|
|
|
|
|
cmd = "cd %s/%s; make model-driver-name" % (thisdir,addmodelname)
|
2017-07-20 01:54:33 +08:00
|
|
|
txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
2017-07-21 01:02:50 +08:00
|
|
|
adddrivername = txt.decode("UTF-8").strip()
|
|
|
|
print("First installing model driver: %s..." % adddrivername)
|
2017-08-05 02:47:32 +08:00
|
|
|
cmd = "cd %s; python Install.py -n -a %s" % (thisdir,adddrivername)
|
2017-07-20 01:54:33 +08:00
|
|
|
try:
|
|
|
|
txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
|
|
|
except subprocess.CalledProcessError as e:
|
|
|
|
print(e.output)
|
|
|
|
sys.exit()
|
|
|
|
|
2017-07-21 01:02:50 +08:00
|
|
|
if verboseflag: print(txt.decode("UTF-8"))
|
|
|
|
|
2017-07-20 01:54:33 +08:00
|
|
|
# now install the model that needed the driver
|
|
|
|
|
2017-07-20 05:19:44 +08:00
|
|
|
print("Now installing model : %s" % addmodelname)
|
2017-08-05 02:47:32 +08:00
|
|
|
cmd = "cd %s; python Install.py -n -a %s" % (thisdir,addmodelname)
|
2017-07-20 01:54:33 +08:00
|
|
|
try:
|
|
|
|
txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
|
|
|
except subprocess.CalledProcessError as e:
|
|
|
|
print(e.output)
|
|
|
|
sys.exit()
|
2017-07-21 01:02:50 +08:00
|
|
|
print(txt.decode("UTF-8"))
|
2017-07-20 01:54:33 +08:00
|
|
|
sys.exit()
|
2017-07-15 06:25:16 +08:00
|
|
|
else:
|
2017-07-16 01:03:04 +08:00
|
|
|
print(firstRunOutput)
|
2017-07-20 01:54:33 +08:00
|
|
|
print("Error, unable to build and install OpenKIM item: %s" \
|
|
|
|
% addmodelname)
|
|
|
|
sys.exit()
|
2017-07-15 06:25:16 +08:00
|
|
|
|
2017-07-20 01:54:33 +08:00
|
|
|
# success the first time
|
2017-07-19 06:06:18 +08:00
|
|
|
|
2017-07-21 01:02:50 +08:00
|
|
|
if verboseflag: print(txt.decode("UTF-8"))
|
2017-07-20 01:54:33 +08:00
|
|
|
print("Removing kim item source and build files ...")
|
|
|
|
cmd = "cd %s; rm -rf %s; rm -rf %s.tgz" %(thisdir,addmodelname,addmodelname)
|
2017-07-21 01:02:50 +08:00
|
|
|
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|