Skip to content
Snippets Groups Projects
Commit e7d9aabc authored by Axel Kohlmeyer's avatar Axel Kohlmeyer
Browse files

Merge branch 'kim-install' into install-and-docs-reviewed

parents e3973796 715c797d
No related branches found
No related tags found
No related merge requests found
......@@ -27,13 +27,34 @@ pair_coeff * * Ar Ar :pre
[Description:]
This pair style is a wrapper on the "Knowledge Base for Interatomic
Models (KIM)"_https://openkim.org repository of interatomic potentials,
so that they can be used by LAMMPS scripts.
Models (OpenKIM)"_https://openkim.org repository of interatomic
potentials, so that they can be used by LAMMPS scripts.
In KIM lingo, a potential is a "model" and a model contains both the
analytic formulas that define the potential as well as the parameters
needed to run it for one or more materials, including coefficients and
cutoffs.
Note that in LAMMPS lingo, a KIM model driver is a pair style
(e.g. EAM or Tersoff). A KIM model is a pair style for a particular
element or alloy and set of parameters, e.g. EAM for Cu with a
specific EAM potential file.
See the current list of "KIM model
drivers"_https://openkim.org/kim-items/model-drivers/alphabetical.
See the current list of all "KIM
models"_https://openkim.org/kim-items/models/by-model-drivers
See the list of "example KIM models"_https://openkim.org/kim-api which
are included in the KIM library by default, in the "What is in the KIM
API source package?" section.
To use this pair style, you must first download and install the KIM
API library from the "OpenKIM website"_https://openkim.org. The "KIM
section of Section packages"_Section_packages.html#kim-package has
instructions on how to do this with a simple make command, when
building LAMMPS.
See the examples/kim dir for an input script that uses a KIM model
(potential) for Lennard-Jones.
:line
The argument {virialmode} determines how the global virial is
calculated. If {KIMvirial} is specified, the KIM model performs the
......
#!/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
from __future__ import print_function
import sys,os,re,subprocess
......@@ -8,28 +8,25 @@ try: from urllib.request import urlretrieve as geturl
except: from urllib import urlretrieve as geturl
help = """
Syntax from src dir: make lib-kim args="-v version -b kim-install-dir kim-name -a kim-name"
Syntax from lib dir: python Install.py -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 -a kim-name
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)
-b = download and build KIM API library with KIM 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)
-b = download and build KIM API library with example Models
-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:
make lib-kim args="-b . none" # 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 . OpenKIM" # install KIM API lib with all models
make lib-kim args="-b" # install KIM API lib with only example models
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="-a EAM_Dynamo_Ackland_W__MO_141627196590_002" # add one model or model driver
See the list of KIM model drivers here:
......@@ -57,7 +54,9 @@ thisdir = os.environ['PWD']
version = "kim-api-v1.8.2"
buildflag = False
everythingflag = False
addflag = False
verboseflag = False
iarg = 0
while iarg < len(args):
......@@ -67,15 +66,19 @@ while iarg < len(args):
iarg += 2
elif args[iarg] == "-b":
buildflag = True
if iarg+3 > len(args): error()
dir = args[iarg+1]
modelname = args[iarg+2]
iarg += 3
iarg += 1
elif args[iarg] == "-a":
addflag = True
if iarg+2 > len(args): error()
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()
thisdir = os.path.abspath(thisdir)
......@@ -88,14 +91,14 @@ if buildflag:
# 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.
if os.path.isdir(dir):
print("kim-api is already installed at %s.\nRemoving it for re-install" % 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
......@@ -116,44 +119,48 @@ if buildflag:
geturl(url,"%s/%s.tgz" % (thisdir,version))
print("Unpacking kim-api tarball ...")
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
print("Configuring kim-api ...")
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
print("Configuring model : %s" % modelname)
if modelname == "none":
cmd = "cd %s/%s; make add-examples" % (thisdir,version)
else:
if modelname == "OpenKIM":
print("configuring all OpenKIM models, this will take a while ...")
cmd = "cd %s/%s; make add-examples; make add-%s" % \
(thisdir,version,modelname)
subprocess.check_output(cmd,shell=True)
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"))
print("Building kim-api ...")
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
print("Installing kim-api ...")
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)
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
print("Removing kim-api source and build files ...")
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
......@@ -166,19 +173,18 @@ if addflag:
error()
else:
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
# 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
geturl(url,"%s/%s.tgz" % (thisdir,addmodelname))
print("Unpacking item tarball ...")
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 ...")
cmd = "cd %s/%s; make; make install" %(thisdir,addmodelname)
......@@ -187,19 +193,19 @@ if addflag:
except subprocess.CalledProcessError as e:
# 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)
txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
txt = txt.decode().strip()
txt = txt.decode("UTF-8")
if txt == "ParameterizedModel":
# Get and install driver
cmd = "cd %s/%s; make model-driver-name" % (thisdir,addmodelname)
txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
adddrivername = txt.decode().strip()
print("First installing model driver: %s" % adddrivername)
adddrivername = txt.decode("UTF-8").strip()
print("First installing model driver: %s..." % adddrivername)
cmd = "cd %s; python Install.py -a %s" % (thisdir,adddrivername)
try:
txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
......@@ -207,6 +213,8 @@ if addflag:
print(e.output)
sys.exit()
if verboseflag: print(txt.decode("UTF-8"))
# now install the model that needed the driver
print("Now installing model : %s" % addmodelname)
......@@ -216,7 +224,7 @@ if addflag:
except subprocess.CalledProcessError as e:
print(e.output)
sys.exit()
print(txt.decode())
print(txt.decode("UTF-8"))
sys.exit()
else:
print(firstRunOutput)
......@@ -226,7 +234,7 @@ if addflag:
# success the first time
print(txt)
if verboseflag: print(txt.decode("UTF-8"))
print("Removing kim item source and build files ...")
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)
# files to ignore
/liblink
/includelink
/voro++-*
......@@ -10,27 +10,23 @@ except: from urllib import urlretrieve as geturl
# help message
help = """
Syntax from src dir: make lib-voronoi args="-v version -h hpath hdir -g -b -l"
Syntax from lib dir: python Install.py -v version -h hpath hdir -g -b -l
Syntax from src dir: make lib-voronoi
or: make lib-voronoi args="-p /usr/local/voro++-0.4.6"
or: make lib-voronoi args="-v voro++-0.4.6 -b"
Syntax from lib dir: python Install.py -v voro++-0.4.6 -b
or: python Install.py
or: python Install.py -p /usr/local/voro++-0.4.6
specify one or more options, order does not matter
-b = download and build the Voro++ library (default)
-p = specify folder of existing Voro++ installation
-v = version of Voro++ to download and build
default version = voro++-0.4.6 (current as of Jan 2015)
-h = set home dir of Voro++ to be hpath/hdir
hpath can be full path, contain '~' or '.' chars
default hpath = . = lib/voronoi
default hdir = voro++-0.4.6 = what tarball unpacks to
-g = grab (download) tarball from math.lbl.gov/voro++ website
unpack it to hpath/hdir
hpath must already exist
if hdir already exists, it will be deleted before unpack
-b = build Voro++ library in its src dir
-l = create 2 softlinks (includelink,liblink) in lib/voronoi to Voro++ src dir
Example:
make lib-voronoi args="-g -b -l" # download/build in lib/voronoi/voro++-0.4.6
make lib-voronoi args="-b" # download/build in lib/voronoi/voro++-0.4.6
"""
# settings
......@@ -47,10 +43,10 @@ def error(str=None):
# expand to full path name
# process leading '~' or relative path
def fullpath(path):
return os.path.abspath(os.path.expanduser(path))
# parse args
args = sys.argv[1:]
......@@ -60,9 +56,10 @@ if nargs == 0: error()
homepath = "."
homedir = version
grabflag = False
buildflag = False
linkflag = False
grabflag = True
buildflag = True
pathflag = False
linkflag = True
iarg = 0
while iarg < nargs:
......@@ -70,42 +67,43 @@ while iarg < nargs:
if iarg+2 > nargs: error()
version = args[iarg+1]
iarg += 2
elif args[iarg] == "-h":
if iarg+3 > nargs: error()
homepath = args[iarg+1]
homedir = args[iarg+2]
iarg += 3
elif args[iarg] == "-g":
grabflag = True
iarg += 1
elif args[iarg] == "-p":
if iarg+2 > nargs: error()
voropath = fullpath(args[iarg+1])
pathflag = True
buildflag = False
iarg += 2
elif args[iarg] == "-b":
buildflag = True
iarg += 1
elif args[iarg] == "-l":
linkflag = True
iarg += 1
else: error()
homepath = fullpath(homepath)
if not os.path.isdir(homepath): error("Voro++ path does not exist")
homedir = "%s/%s" % (homepath,homedir)
homedir = "%s/%s" % (homepath,version)
if (pathflag):
if not os.path.isdir(voropath): error("Voro++ path does not exist")
homedir = voropath
if (buildflag and pathflag):
error("Cannot use -b and -p flag at the same time")
# download and unpack Voro++ tarball
if grabflag:
print("Downloading Voro++ ...")
geturl(url,"%s/%s.tar.gz" % (homepath,version))
print("Unpacking Voro++ tarball ...")
if os.path.exists("%s/%s" % (homepath,version)):
cmd = 'rm -rf "%s/%s"' % (homepath,version)
subprocess.check_output(cmd,shell=True)
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
cmd = 'cd "%s"; tar -xzvf %s.tar.gz' % (homepath,version)
subprocess.check_output(cmd,shell=True)
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
if os.path.basename(homedir) != version:
if os.path.exists(homedir):
cmd = 'rm -rf "%s"' % homedir
subprocess.check_output(cmd,shell=True)
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
os.rename("%s/%s" % (homepath,version),homedir)
# build Voro++
......@@ -113,8 +111,8 @@ if grabflag:
if buildflag:
print("Building Voro++ ...")
cmd = 'cd "%s"; make' % homedir
txt = subprocess.check_output(cmd,shell=True)
print(txt)
txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
print(txt.decode('UTF-8'))
# create 2 links in lib/voronoi to Voro++ src dir
......@@ -125,6 +123,6 @@ if linkflag:
if os.path.isfile("liblink") or os.path.islink("liblink"):
os.remove("liblink")
cmd = ['ln -s "%s/src" includelink' % homedir, 'includelink']
subprocess.check_output(cmd,shell=True)
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
cmd = ['ln -s "%s/src" liblink' % homedir]
subprocess.check_output(cmd,shell=True)
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
......@@ -22,7 +22,7 @@ Instructions:
or somewhere else on your system.
2. compile Voro++ from within its home directory
% make
% make
3. There is no need to install Voro++ if you only wish
to use it from LAMMPS. You can install it if you
......
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