git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@15039 f3b2605a-c512-4ea7-a41b-209d697bcdaa

This commit is contained in:
sjplimp 2016-05-12 13:53:40 +00:00
parent dfb0f528c0
commit c3a95c782b
2 changed files with 34 additions and 12 deletions

View File

@ -2,16 +2,18 @@
# copy LAMMPS src/liblammps.so and lammps.py to system dirs # copy LAMMPS src/liblammps.so and lammps.py to system dirs
from __future__ import print_function
instructions = """ instructions = """
Syntax: python install.py [-h] [pydir] Syntax: python install.py [-h] [pydir]
pydir = target dir for lammps.py and liblammps.so pydir = target dir for lammps.py and liblammps.so
default = Python site-packages dir default = Python site-packages dir
""" """
import sys,os,commands import sys,os,shutil
if (len(sys.argv) > 1 and sys.argv[1] == "-h") or len(sys.argv) > 2: if (len(sys.argv) > 1 and sys.argv[1] == "-h") or len(sys.argv) > 2:
print instructions print(instructions)
sys.exit() sys.exit()
if len(sys.argv) == 2: pydir = sys.argv[1] if len(sys.argv) == 2: pydir = sys.argv[1]
@ -22,18 +24,24 @@ else: pydir = ""
if pydir: if pydir:
if not os.path.isdir(pydir): if not os.path.isdir(pydir):
print "ERROR: pydir %s does not exist" % pydir print( "ERROR: pydir %s does not exist" % pydir)
sys.exit() sys.exit()
str = "cp ../python/lammps.py %s" % pydir str = "cp ../python/lammps.py %s" % pydir
print str print(str)
outstr = commands.getoutput(str) try:
if len(outstr.strip()): print outstr shutil.copyfile("../python/lammps.py", os.path.join(pydir,'lammps.py') )
except shutil.Error:
pass # source and destination are identical
str = "cp ../src/liblammps.so %s" % pydir str = "cp ../src/liblammps.so %s" % pydir
print str print(str)
outstr = commands.getoutput(str) try:
shutil.copyfile("../src/liblammps.so", os.path.join(pydir,"liblammps.so") )
except shutil.Error:
pass # source and destination are identical
sys.exit() sys.exit()
print "installing lammps.py in Python site-packages dir" print("installing lammps.py in Python site-packages dir")
os.chdir('../python') # in case invoked via make in src dir os.chdir('../python') # in case invoked via make in src dir
@ -60,7 +68,7 @@ try:
data_files = [(get_python_lib(), ["../src/liblammps.so"])]) data_files = [(get_python_lib(), ["../src/liblammps.so"])])
except: except:
tryuser=True tryuser=True
print "Installation into global site-packages dir failed.\nTrying user site dir %s now." % site.USER_SITE print ("Installation into global site-packages dir failed.\nTrying user site dir %s now." % site.USER_SITE)
if tryuser: if tryuser:
@ -75,7 +83,7 @@ if tryuser:
py_modules = ["lammps"], py_modules = ["lammps"],
data_files = [(site.USER_SITE, ["../src/liblammps.so"])]) data_files = [(site.USER_SITE, ["../src/liblammps.so"])])
except: except:
print "Installation into user site package dir failed.\nGo to ../python and install manually." print("Installation into user site package dir failed.\nGo to ../python and install manually.")

View File

@ -53,7 +53,7 @@ class lammps:
except: except:
if not name: self.lib = CDLL("liblammps.so",RTLD_GLOBAL) if not name: self.lib = CDLL("liblammps.so",RTLD_GLOBAL)
else: self.lib = CDLL("liblammps_%s.so" % name,RTLD_GLOBAL) else: self.lib = CDLL("liblammps_%s.so" % name,RTLD_GLOBAL)
# if no ptr provided, create an instance of LAMMPS # if no ptr provided, create an instance of LAMMPS
# don't know how to pass an MPI communicator from PyPar # don't know how to pass an MPI communicator from PyPar
# but we can pass an MPI communicator from mpi4py v2.0.0 and later # but we can pass an MPI communicator from mpi4py v2.0.0 and later
@ -125,12 +125,15 @@ class lammps:
return self.lib.lammps_version(self.lmp) return self.lib.lammps_version(self.lmp)
def file(self,file): def file(self,file):
file = file.encode()
self.lib.lammps_file(self.lmp,file) self.lib.lammps_file(self.lmp,file)
def command(self,cmd): def command(self,cmd):
cmd = cmd.encode()
self.lib.lammps_command(self.lmp,cmd) self.lib.lammps_command(self.lmp,cmd)
def extract_global(self,name,type): def extract_global(self,name,type):
name = name.encode()
if type == 0: if type == 0:
self.lib.lammps_extract_global.restype = POINTER(c_int) self.lib.lammps_extract_global.restype = POINTER(c_int)
elif type == 1: elif type == 1:
@ -140,6 +143,7 @@ class lammps:
return ptr[0] return ptr[0]
def extract_atom(self,name,type): def extract_atom(self,name,type):
name = name.encode()
if type == 0: if type == 0:
self.lib.lammps_extract_atom.restype = POINTER(c_int) self.lib.lammps_extract_atom.restype = POINTER(c_int)
elif type == 1: elif type == 1:
@ -153,6 +157,7 @@ class lammps:
return ptr return ptr
def extract_compute(self,id,style,type): def extract_compute(self,id,style,type):
id = id.encode()
if type == 0: if type == 0:
if style > 0: return None if style > 0: return None
self.lib.lammps_extract_compute.restype = POINTER(c_double) self.lib.lammps_extract_compute.restype = POINTER(c_double)
@ -172,6 +177,7 @@ class lammps:
# double was allocated by library interface function # double was allocated by library interface function
def extract_fix(self,id,style,type,i=0,j=0): def extract_fix(self,id,style,type,i=0,j=0):
id = ide.encode()
if style == 0: if style == 0:
self.lib.lammps_extract_fix.restype = POINTER(c_double) self.lib.lammps_extract_fix.restype = POINTER(c_double)
ptr = self.lib.lammps_extract_fix(self.lmp,id,style,type,i,j) ptr = self.lib.lammps_extract_fix(self.lmp,id,style,type,i,j)
@ -195,6 +201,8 @@ class lammps:
# memory was allocated by library interface function # memory was allocated by library interface function
def extract_variable(self,name,group,type): def extract_variable(self,name,group,type):
name = name.encode()
group = group.encode()
if type == 0: if type == 0:
self.lib.lammps_extract_variable.restype = POINTER(c_double) self.lib.lammps_extract_variable.restype = POINTER(c_double)
ptr = self.lib.lammps_extract_variable(self.lmp,name,group) ptr = self.lib.lammps_extract_variable(self.lmp,name,group)
@ -218,6 +226,8 @@ class lammps:
# returns 0 for success, -1 if failed # returns 0 for success, -1 if failed
def set_variable(self,name,value): def set_variable(self,name,value):
name = name.encode()
value = str(value).encode()
return self.lib.lammps_set_variable(self.lmp,name,str(value)) return self.lib.lammps_set_variable(self.lmp,name,str(value))
# return total number of atoms in system # return total number of atoms in system
@ -228,6 +238,7 @@ class lammps:
# return vector of atom properties gathered across procs, ordered by atom ID # return vector of atom properties gathered across procs, ordered by atom ID
def gather_atoms(self,name,type,count): def gather_atoms(self,name,type,count):
name = name.encode()
natoms = self.lib.lammps_get_natoms(self.lmp) natoms = self.lib.lammps_get_natoms(self.lmp)
if type == 0: if type == 0:
data = ((count*natoms)*c_int)() data = ((count*natoms)*c_int)()
@ -242,4 +253,7 @@ class lammps:
# assume vector is of correct type and length, as created by gather_atoms() # assume vector is of correct type and length, as created by gather_atoms()
def scatter_atoms(self,name,type,count,data): def scatter_atoms(self,name,type,count,data):
name = name.encode()
self.lib.lammps_scatter_atoms(self.lmp,name,type,count,data) self.lib.lammps_scatter_atoms(self.lmp,name,type,count,data)