From a9b0fb9e9d42fd7f54ee0d36426562eec96c3dc4 Mon Sep 17 00:00:00 2001 From: "Ryan S. Elliott" Date: Sun, 3 Feb 2019 12:43:48 -0600 Subject: [PATCH] Some adjustments to kim Install.py --- lib/kim/Install.py | 165 +++++++++++++++++++++------------------------ 1 file changed, 77 insertions(+), 88 deletions(-) diff --git a/lib/kim/Install.py b/lib/kim/Install.py index e7e2128f48..544fe2b65d 100644 --- a/lib/kim/Install.py +++ b/lib/kim/Install.py @@ -1,46 +1,43 @@ #!/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 -import sys,os,re,subprocess,shutil +import sys, os, subprocess, shutil +from argparse import ArgumentParser + 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 = """ -Syntax from src dir: make lib-kim args="-b -v version -a kim-name" +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: 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 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 - 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 + or: python Install.py -p /usr/local/open-kim -a kim-name Examples: 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="-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: 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 """ -# 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:] -nargs = len(args) -if nargs == 0: error(help=help) +args = parser.parse_args() -thisdir = fullpath('.') -version = "kim-api-v2-2.0.0-beta.3" +# print help message and exit, if neither build nor path options are given +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 -addflag = False -verboseflag = False -pathflag = False +if addflag and addmodelname == "everything": + everythingflag = True + buildflag = True +verboseflag = args.verbose -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 - addflag = False - iarg += 2 - elif args[iarg] == "-vv": - verboseflag = True - iarg += 1 - else: error(help=help) +if pathflag: + buildflag = False + 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 # set KIM API directory 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 with open("%s/kim-prefix.txt" % thisdir, 'w') as pffile: pffile.write("%s" % kimdir) @@ -116,6 +100,8 @@ if pathflag: print("Created %s/kim-prefix.txt\n using %s" % (thisdir,kimdir)) else: 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 if buildflag: @@ -136,10 +122,10 @@ if buildflag: # download entire 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 ...") - cmd = 'cd "%s"; rm -rf "%s"; tar -xJvf %s.txz' % (thisdir,version,version) - subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) + cmd = 'cd "%s"; rm -rf "%s"; tar -xJvf %s.txz' % (thisdir, version, version) + subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True) # configure kim-api @@ -150,29 +136,32 @@ if buildflag: # 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")) + 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")) # 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")) + 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")) # remove source files print("Removing kim-api source and build files ...") - cmd = 'cd "%s"; rm -rf %s; rm -rf %s.txz' % (thisdir,version,version) - subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) + cmd = 'cd "%s"; rm -rf %s; rm -rf %s.txz' % (thisdir, version, version) + subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True) # 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) - txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) - if verboseflag: print(txt.decode("UTF-8")) + txt = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True) + if verboseflag: + print(txt.decode("UTF-8")) # add single OpenKIM model if addflag: @@ -183,10 +172,10 @@ if addflag: kimdir = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) if not os.path.isdir(kimdir): - print("\nkim-api is not installed") - error(help=help) + sys.exit("\nkim-api is not installed") # download single model 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) - if verboseflag: print (txt.decode("UTF-8")) + txt = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True) + if verboseflag: + print(txt.decode("UTF-8"))