Commit a9b0fb9e authored by Ryan S. Elliott's avatar Ryan S. Elliott
Browse files

Some adjustments to kim Install.py

parent 23ce00f3
Loading
Loading
Loading
Loading
+81 −92
Original line number Diff line number Diff line
#!/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 = """
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"
                 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

args = sys.argv[1:]
nargs = len(args)
if nargs == 0: error(help=help)

thisdir = fullpath('.')
version = "kim-api-v2-2.0.0-beta.3"

buildflag = False
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 = parser.parse_args()

# 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 = 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

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":
if addflag and addmodelname == "everything":
  everythingflag = True
  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
verboseflag = args.verbose

if pathflag:
  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)
  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:
@@ -152,14 +138,16 @@ if buildflag:
  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"))
  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"))
  if verboseflag:
    print(txt.decode("UTF-8"))

  # remove source files

@@ -172,7 +160,8 @@ if buildflag:
    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"))
    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"))
  if verboseflag:
    print(txt.decode("UTF-8"))