forked from lijiext/lammps
Some adjustments to kim Install.py
This commit is contained in:
parent
23ce00f366
commit
a9b0fb9e9d
|
@ -1,46 +1,43 @@
|
||||||
#!/usr/bin/env python
|
#!/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
|
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
|
from __future__ import print_function
|
||||||
import sys,os,re,subprocess,shutil
|
import sys, os, subprocess, shutil
|
||||||
|
from argparse import ArgumentParser
|
||||||
|
|
||||||
sys.path.append('..')
|
sys.path.append('..')
|
||||||
from install_helpers import error,fullpath,which,geturl
|
from install_helpers import fullpath, geturl
|
||||||
|
|
||||||
|
parser = ArgumentParser(prog='Install.py',
|
||||||
|
description="LAMMPS library build wrapper script")
|
||||||
|
|
||||||
|
# settings
|
||||||
|
|
||||||
|
thisdir = fullpath('.')
|
||||||
|
version = "kim-api-v2-2.0.0-beta.3"
|
||||||
|
|
||||||
# help message
|
# help message
|
||||||
|
|
||||||
help = """
|
HELP = """
|
||||||
Syntax from src dir: make lib-kim args="-b -v version -a kim-name"
|
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="-b -a everything"
|
||||||
or: make lib-kim args="-n -a kim-name"
|
or: make lib-kim args="-n -a kim-name"
|
||||||
or: make lib-kim args="-p /home/bob/kim -a kim-name"
|
or: make lib-kim args="-p /usr/local/open-kim -a kim-name"
|
||||||
Syntax from lib dir: python Install.py -b -v version -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 -b -a everything
|
||||||
or: python Install.py -n -a kim-name
|
or: python Install.py -n -a kim-name
|
||||||
or: python Install.py -p /home/bob/kim -a kim-name
|
or: python Install.py -p /usr/local/open-kim -a kim-name
|
||||||
|
|
||||||
specify one or more options, order does not matter
|
|
||||||
|
|
||||||
-v = version of KIM API library to use
|
|
||||||
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:
|
Examples:
|
||||||
|
|
||||||
make lib-kim args="-b" # 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="-a EAM_ErcolessiAdams_1994_Al__MO_324507536345_002" # 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 -a everything" # 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="-n -a EAM_Dynamo_Ackland_2003_W__MO_141627196590_005" # only add one model or model driver
|
make lib-kim args="-n -a EAM_Dynamo_Ackland_W__MO_141627196590_002" # only add one model or model driver
|
||||||
|
|
||||||
See the list of KIM model drivers here:
|
See the list of KIM model drivers here:
|
||||||
https://openkim.org/kim-items/model-drivers/alphabetical
|
https://openkim.org/kim-items/model-drivers/alphabetical
|
||||||
|
@ -53,62 +50,49 @@ https://openkim.org/kim-api
|
||||||
in the "What is in the KIM API source package?" section
|
in the "What is in the KIM API source package?" section
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# parse args
|
pgroup = parser.add_mutually_exclusive_group()
|
||||||
|
pgroup.add_argument("-b", "--build", action="store_true",
|
||||||
|
help="download and build base KIM API library with example Models.")
|
||||||
|
pgroup.add_argument("-n", "--nobuild", action="store_true",
|
||||||
|
help="use the previously downloaded and compiled base KIM API.")
|
||||||
|
pgroup.add_argument("-p", "--path",
|
||||||
|
help="specify location of existing KIM API installation.")
|
||||||
|
parser.add_argument("-v", "--version", default=version,
|
||||||
|
help="set version of KIM API library to download and build (default: %s)" % version)
|
||||||
|
parser.add_argument("-a", "--add",
|
||||||
|
help="add single KIM model or model driver. If adding 'everything', then all available OpenKIM models are added (may take a long time)")
|
||||||
|
parser.add_argument("-vv", "--verbose", action="store_true",
|
||||||
|
help="be more verbose about is happening while this script runs")
|
||||||
|
|
||||||
args = sys.argv[1:]
|
args = parser.parse_args()
|
||||||
nargs = len(args)
|
|
||||||
if nargs == 0: error(help=help)
|
|
||||||
|
|
||||||
thisdir = fullpath('.')
|
# print help message and exit, if neither build nor path options are given
|
||||||
version = "kim-api-v2-2.0.0-beta.3"
|
if not args.build and not args.path and not args.nobuild:
|
||||||
|
parser.print_help()
|
||||||
|
sys.exit(HELP)
|
||||||
|
|
||||||
buildflag = False
|
buildflag = args.build
|
||||||
|
pathflag = args.path is not None
|
||||||
|
addflag = args.add is not None
|
||||||
|
addmodelname = args.add
|
||||||
everythingflag = False
|
everythingflag = False
|
||||||
addflag = False
|
if addflag and addmodelname == "everything":
|
||||||
verboseflag = False
|
|
||||||
pathflag = False
|
|
||||||
|
|
||||||
iarg = 0
|
|
||||||
while iarg < len(args):
|
|
||||||
if args[iarg] == "-v":
|
|
||||||
if iarg+2 > len(args): error(help=help)
|
|
||||||
version = args[iarg+1]
|
|
||||||
iarg += 2
|
|
||||||
elif args[iarg] == "-b":
|
|
||||||
buildflag = True
|
|
||||||
iarg += 1
|
|
||||||
elif args[iarg] == "-n":
|
|
||||||
buildflag = False
|
|
||||||
iarg += 1
|
|
||||||
elif args[iarg] == "-p":
|
|
||||||
if iarg+2 > len(args): error(help=help)
|
|
||||||
kimdir = fullpath(args[iarg+1])
|
|
||||||
pathflag = True
|
|
||||||
buildflag = False
|
|
||||||
iarg += 2
|
|
||||||
elif args[iarg] == "-a":
|
|
||||||
addflag = True
|
|
||||||
if iarg+2 > len(args): error(help=help)
|
|
||||||
addmodelname = args[iarg+1]
|
|
||||||
if addmodelname == "everything":
|
|
||||||
buildflag = True
|
|
||||||
everythingflag = True
|
everythingflag = True
|
||||||
addflag = False
|
buildflag = True
|
||||||
iarg += 2
|
verboseflag = args.verbose
|
||||||
elif args[iarg] == "-vv":
|
|
||||||
verboseflag = True
|
if pathflag:
|
||||||
iarg += 1
|
buildflag = False
|
||||||
else: error(help=help)
|
kimdir = args.path
|
||||||
|
if not os.path.isdir(kimdir):
|
||||||
|
sys.exit("KIM API path %s does not exist" % kimdir)
|
||||||
|
kimdir = fullpath(kimdir)
|
||||||
|
|
||||||
url = "https://s3.openkim.org/kim-api/%s.txz" % version
|
url = "https://s3.openkim.org/kim-api/%s.txz" % version
|
||||||
|
|
||||||
# set KIM API directory
|
# set KIM API directory
|
||||||
|
|
||||||
if pathflag:
|
if pathflag:
|
||||||
if not os.path.isdir(kimdir):
|
|
||||||
print("\nkim-api is not installed at %s" % kimdir)
|
|
||||||
error(help=help)
|
|
||||||
|
|
||||||
# configure LAMMPS to use existing kim-api installation
|
# configure LAMMPS to use existing kim-api installation
|
||||||
with open("%s/kim-prefix.txt" % thisdir, 'w') as pffile:
|
with open("%s/kim-prefix.txt" % thisdir, 'w') as pffile:
|
||||||
pffile.write("%s" % kimdir)
|
pffile.write("%s" % kimdir)
|
||||||
|
@ -116,6 +100,8 @@ if pathflag:
|
||||||
print("Created %s/kim-prefix.txt\n using %s" % (thisdir,kimdir))
|
print("Created %s/kim-prefix.txt\n using %s" % (thisdir,kimdir))
|
||||||
else:
|
else:
|
||||||
kimdir = os.path.join(os.path.abspath(thisdir), "installed-" + version)
|
kimdir = os.path.join(os.path.abspath(thisdir), "installed-" + version)
|
||||||
|
if args.nobuild and not os.path.isdir(kimdir):
|
||||||
|
sys.exit("Cannot use -n/--nobuild without first building the KIM API with -b")
|
||||||
|
|
||||||
# download KIM tarball, unpack, build KIM
|
# download KIM tarball, unpack, build KIM
|
||||||
if buildflag:
|
if buildflag:
|
||||||
|
@ -136,10 +122,10 @@ if buildflag:
|
||||||
# download entire kim-api tarball
|
# download entire kim-api tarball
|
||||||
|
|
||||||
print("Downloading kim-api tarball ...")
|
print("Downloading kim-api tarball ...")
|
||||||
geturl(url,"%s/%s.txz" % (thisdir,version))
|
geturl(url, "%s/%s.txz" % (thisdir, version))
|
||||||
print("Unpacking kim-api tarball ...")
|
print("Unpacking kim-api tarball ...")
|
||||||
cmd = 'cd "%s"; rm -rf "%s"; tar -xJvf %s.txz' % (thisdir,version,version)
|
cmd = 'cd "%s"; rm -rf "%s"; tar -xJvf %s.txz' % (thisdir, version, version)
|
||||||
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True)
|
||||||
|
|
||||||
# configure kim-api
|
# configure kim-api
|
||||||
|
|
||||||
|
@ -150,29 +136,32 @@ if buildflag:
|
||||||
|
|
||||||
# build kim-api
|
# build kim-api
|
||||||
print("Building kim-api ...")
|
print("Building kim-api ...")
|
||||||
cmd = 'cd "%s/%s/build" && make' % (thisdir,version)
|
cmd = 'cd "%s/%s/build" && make' % (thisdir, version)
|
||||||
txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
txt = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True)
|
||||||
if verboseflag: print(txt.decode("UTF-8"))
|
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/build" && make install' % (thisdir,version)
|
cmd = 'cd "%s/%s/build" && make install' % (thisdir, version)
|
||||||
txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
txt = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True)
|
||||||
if verboseflag: print(txt.decode("UTF-8"))
|
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.txz' % (thisdir,version,version)
|
cmd = 'cd "%s"; rm -rf %s; rm -rf %s.txz' % (thisdir, version, version)
|
||||||
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True)
|
||||||
|
|
||||||
# add all OpenKIM models, if desired
|
# add all OpenKIM models, if desired
|
||||||
if everythingflag:
|
if everythingflag:
|
||||||
print("Adding all OpenKIM models, this will take a while ...")
|
print("Adding all OpenKIM models, this will take a while ...")
|
||||||
cmd = '%s/bin/kim-api-v2-collections-management install system OpenKIM' % (kimdir)
|
cmd = '%s/bin/kim-api-v2-collections-management install system OpenKIM' % (kimdir)
|
||||||
txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
txt = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True)
|
||||||
if verboseflag: print(txt.decode("UTF-8"))
|
if verboseflag:
|
||||||
|
print(txt.decode("UTF-8"))
|
||||||
|
|
||||||
# add single OpenKIM model
|
# add single OpenKIM model
|
||||||
if addflag:
|
if addflag:
|
||||||
|
@ -183,10 +172,10 @@ if addflag:
|
||||||
kimdir = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
kimdir = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
||||||
|
|
||||||
if not os.path.isdir(kimdir):
|
if not os.path.isdir(kimdir):
|
||||||
print("\nkim-api is not installed")
|
sys.exit("\nkim-api is not installed")
|
||||||
error(help=help)
|
|
||||||
|
|
||||||
# download single model
|
# download single model
|
||||||
cmd = '%s/bin/kim-api-v2-collections-management install system %s' % (kimdir.decode("UTF-8"), addmodelname)
|
cmd = '%s/bin/kim-api-v2-collections-management install system %s' % (kimdir.decode("UTF-8"), addmodelname)
|
||||||
txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
txt = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True)
|
||||||
if verboseflag: print (txt.decode("UTF-8"))
|
if verboseflag:
|
||||||
|
print(txt.decode("UTF-8"))
|
||||||
|
|
Loading…
Reference in New Issue