Skip to content
Snippets Groups Projects
Commit 84065dde authored by Ryan S. Elliott's avatar Ryan S. Elliott
Browse files

Refactor lib/kim/Install.py; works with phtyon 3 2.7

parent 355aad96
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python #!/usr/bin/env python
# install.pa tool to setup the kim-api library # install.py tool to setup the kim-api library
# used to automate the steps described in the README file in this dir # used to automate the steps described in the README file in this dir
from __future__ import print_function from __future__ import print_function
import sys,os,re,subprocess import sys,os,re,subprocess
...@@ -8,28 +8,25 @@ try: from urllib.request import urlretrieve as geturl ...@@ -8,28 +8,25 @@ try: from urllib.request import urlretrieve as geturl
except: from urllib import urlretrieve as geturl except: from urllib import urlretrieve as geturl
help = """ help = """
Syntax from src dir: make lib-kim args="-v version -b kim-install-dir kim-name -a kim-name" Syntax from src dir: make lib-kim args="-v version -b -a kim-name"
Syntax from lib dir: python Install.py -v version -b kim-install-dir kim-name -a kim-name Syntax from lib dir: python Install.py -v version -b -a kim-name
specify one or more options, order does not matter specify one or more options, order does not matter
-v = version of KIM API library to use -v = version of KIM API library to use
default = kim-api-v1.8.2 (current as of June 2017) default = kim-api-v1.8.2 (current as of June 2017)
-b = download and build KIM API library with KIM models -b = download and build KIM API library with example Models
kim-dir = where to install/build the KIM API library
use "." to install in lib/kim
kim-name = none to install only the example KIM models
kim-name = KIM model name (see example below) + examples
kim-name = OpenKIM to install all models
from the openkim.org site (this can take 30 minutes or more)
-a = add single KIM model or model driver with kim-name -a = add single KIM model or model driver with kim-name
to existing KIM API lib (see example below) 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
Examples: Examples:
make lib-kim args="-b . none" # install KIM API lib with only example models make lib-kim args="-b" # install KIM API lib with only example models
make lib-kim args="-b . Glue_Ercolessi_Adams_Al__MO_324507536345_001" # ditto plus one model make lib-kim args="-b -a Glue_Ercolessi_Adams_Al__MO_324507536345_001" # Ditto plus one model
make lib-kim args="-b . OpenKIM" # install KIM API lib with all models make lib-kim args="-b -a everything" # install KIM API lib with all models
make lib-kim args="-a EAM_Dynamo_Ackland_W__MO_141627196590_002" # add one model or model driver make lib-kim args="-a EAM_Dynamo_Ackland_W__MO_141627196590_002" # add one model or model driver
See the list of KIM model drivers here: See the list of KIM model drivers here:
...@@ -57,7 +54,9 @@ thisdir = os.environ['PWD'] ...@@ -57,7 +54,9 @@ thisdir = os.environ['PWD']
version = "kim-api-v1.8.2" version = "kim-api-v1.8.2"
buildflag = False buildflag = False
everythingflag = False
addflag = False addflag = False
verboseflag = False
iarg = 0 iarg = 0
while iarg < len(args): while iarg < len(args):
...@@ -67,15 +66,19 @@ while iarg < len(args): ...@@ -67,15 +66,19 @@ while iarg < len(args):
iarg += 2 iarg += 2
elif args[iarg] == "-b": elif args[iarg] == "-b":
buildflag = True buildflag = True
if iarg+3 > len(args): error() iarg += 1
dir = args[iarg+1]
modelname = args[iarg+2]
iarg += 3
elif args[iarg] == "-a": elif args[iarg] == "-a":
addflag = True addflag = True
if iarg+2 > len(args): error() if iarg+2 > len(args): error()
addmodelname = args[iarg+1] addmodelname = args[iarg+1]
if addmodelname == "everything":
buildflag = True
everythingflag = True
addflag = False
iarg += 2 iarg += 2
elif args[iarg] == "-vv":
verboseflag = True
iarg += 1
else: error() else: error()
thisdir = os.path.abspath(thisdir) thisdir = os.path.abspath(thisdir)
...@@ -88,14 +91,14 @@ if buildflag: ...@@ -88,14 +91,14 @@ if buildflag:
# set install directory # set install directory
dir = os.path.join(os.path.abspath(dir), "installed-" + version) dir = os.path.join(os.path.abspath(thisdir), "installed-" + version)
# check to see if an installed kim-api already exists and wipe it out. # check to see if an installed kim-api already exists and wipe it out.
if os.path.isdir(dir): if os.path.isdir(dir):
print("kim-api is already installed at %s.\nRemoving it for re-install" % dir) print("kim-api is already installed at %s.\nRemoving it for re-install" % dir)
cmd = "rm -rf %s" % dir cmd = "rm -rf %s" % dir
subprocess.check_output(cmd,shell=True) subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
# configure LAMMPS to use kim-api to be installed # configure LAMMPS to use kim-api to be installed
...@@ -116,44 +119,48 @@ if buildflag: ...@@ -116,44 +119,48 @@ if buildflag:
geturl(url,"%s/%s.tgz" % (thisdir,version)) geturl(url,"%s/%s.tgz" % (thisdir,version))
print("Unpacking kim-api tarball ...") print("Unpacking kim-api tarball ...")
cmd = "cd %s; rm -rf %s; tar zxvf %s.tgz" % (thisdir,version,version) cmd = "cd %s; rm -rf %s; tar zxvf %s.tgz" % (thisdir,version,version)
subprocess.check_output(cmd,shell=True) subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
# configure kim-api # configure kim-api
print("Configuring kim-api ...") print("Configuring kim-api ...")
cmd = "cd %s/%s; ./configure --prefix='%s'" % (thisdir,version,dir) cmd = "cd %s/%s; ./configure --prefix='%s'" % (thisdir,version,dir)
subprocess.check_output(cmd,shell=True) subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
# build kim-api # build kim-api
print("Configuring model : %s" % modelname) print("Configuring example Models")
if modelname == "none": cmd = "cd %s/%s; make add-examples" % (thisdir,version)
cmd = "cd %s/%s; make add-examples" % (thisdir,version) txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
else: if verboseflag: print (txt.decode("UTF-8"))
if modelname == "OpenKIM":
print("configuring all OpenKIM models, this will take a while ...") if everythingflag:
cmd = "cd %s/%s; make add-examples; make add-%s" % \ print("Configuring all OpenKIM models, this will take a while ...")
(thisdir,version,modelname) cmd = "cd %s/%s; make add-OpenKIM" % (thisdir,version)
subprocess.check_output(cmd,shell=True) txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
if verboseflag: print(txt.decode("UTF-8"))
print("Building kim-api ...") print("Building kim-api ...")
cmd = "cd %s/%s; make" % (thisdir,version) cmd = "cd %s/%s; make" % (thisdir,version)
subprocess.check_output(cmd,shell=True) txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
if verboseflag: print(txt.decode("UTF-8"))
# install kim-api # install kim-api
print("Installing kim-api ...") print("Installing kim-api ...")
cmd = "cd %s/%s; make install" % (thisdir,version) cmd = "cd %s/%s; make install" % (thisdir,version)
subprocess.check_output(cmd,shell=True) txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
if verboseflag: print(txt.decode("UTF-8"))
cmd = "cd %s/%s; make install-set-default-to-v1" %(thisdir,version) cmd = "cd %s/%s; make install-set-default-to-v1" %(thisdir,version)
subprocess.check_output(cmd,shell=True) txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
if verboseflag: print(txt.decode("UTF-8"))
# remove source files # remove source files
print("Removing kim-api source and build files ...") print("Removing kim-api source and build files ...")
cmd = "cd %s; rm -rf %s; rm -rf %s.tgz" % (thisdir,version,version) cmd = "cd %s; rm -rf %s; rm -rf %s.tgz" % (thisdir,version,version)
subprocess.check_output(cmd,shell=True) subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
# add a single model (and possibly its driver) to existing KIM installation # add a single model (and possibly its driver) to existing KIM installation
...@@ -166,19 +173,18 @@ if addflag: ...@@ -166,19 +173,18 @@ if addflag:
error() error()
else: else:
cmd = "cd %s; make -f Makefile.KIM_DIR print_dir" % thisdir cmd = "cd %s; make -f Makefile.KIM_DIR print_dir" % thisdir
dir = subprocess.check_output(cmd,shell=True)[1] dir = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)[1]
# download single model # download single model
# try first via urllib # try first via urllib
# if fails (probably due to no SSL support), use wget
print("Downloading item tarball ...") print("Downloading tarball for %s..." % addmodelname)
url = "https://openkim.org/download/%s.tgz" % addmodelname url = "https://openkim.org/download/%s.tgz" % addmodelname
geturl(url,"%s/%s.tgz" % (thisdir,addmodelname)) geturl(url,"%s/%s.tgz" % (thisdir,addmodelname))
print("Unpacking item tarball ...") print("Unpacking item tarball ...")
cmd = "cd %s; tar zxvf %s.tgz" % (thisdir,addmodelname) cmd = "cd %s; tar zxvf %s.tgz" % (thisdir,addmodelname)
subprocess.check_output(cmd,shell=True) subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
print("Building item ...") print("Building item ...")
cmd = "cd %s/%s; make; make install" %(thisdir,addmodelname) cmd = "cd %s/%s; make; make install" %(thisdir,addmodelname)
...@@ -187,19 +193,19 @@ if addflag: ...@@ -187,19 +193,19 @@ if addflag:
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
# Error: but first, check to see if it needs a driver # Error: but first, check to see if it needs a driver
firstRunOutput = e.output.decode() firstRunOutput = e.output.decode("UTF-8")
cmd = "cd %s/%s; make kim-item-type" % (thisdir,addmodelname) cmd = "cd %s/%s; make kim-item-type" % (thisdir,addmodelname)
txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
txt = txt.decode().strip() txt = txt.decode("UTF-8")
if txt == "ParameterizedModel": if txt == "ParameterizedModel":
# Get and install driver # Get and install driver
cmd = "cd %s/%s; make model-driver-name" % (thisdir,addmodelname) cmd = "cd %s/%s; make model-driver-name" % (thisdir,addmodelname)
txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
adddrivername = txt.decode().strip() adddrivername = txt.decode("UTF-8").strip()
print("First installing model driver: %s" % adddrivername) print("First installing model driver: %s..." % adddrivername)
cmd = "cd %s; python Install.py -a %s" % (thisdir,adddrivername) cmd = "cd %s; python Install.py -a %s" % (thisdir,adddrivername)
try: try:
txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
...@@ -207,6 +213,8 @@ if addflag: ...@@ -207,6 +213,8 @@ if addflag:
print(e.output) print(e.output)
sys.exit() sys.exit()
if verboseflag: print(txt.decode("UTF-8"))
# now install the model that needed the driver # now install the model that needed the driver
print("Now installing model : %s" % addmodelname) print("Now installing model : %s" % addmodelname)
...@@ -216,7 +224,7 @@ if addflag: ...@@ -216,7 +224,7 @@ if addflag:
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
print(e.output) print(e.output)
sys.exit() sys.exit()
print(txt.decode()) print(txt.decode("UTF-8"))
sys.exit() sys.exit()
else: else:
print(firstRunOutput) print(firstRunOutput)
...@@ -226,7 +234,7 @@ if addflag: ...@@ -226,7 +234,7 @@ if addflag:
# success the first time # success the first time
print(txt) if verboseflag: print(txt.decode("UTF-8"))
print("Removing kim item source and build files ...") print("Removing kim item source and build files ...")
cmd = "cd %s; rm -rf %s; rm -rf %s.tgz" %(thisdir,addmodelname,addmodelname) cmd = "cd %s; rm -rf %s; rm -rf %s.tgz" %(thisdir,addmodelname,addmodelname)
subprocess.check_output(cmd,shell=True) subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment