From c3a95c782bd65a027cacd854859b35721af854b5 Mon Sep 17 00:00:00 2001 From: sjplimp Date: Thu, 12 May 2016 13:53:40 +0000 Subject: [PATCH] git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@15039 f3b2605a-c512-4ea7-a41b-209d697bcdaa --- python/install.py | 30 +++++++++++++++++++----------- python/lammps.py | 16 +++++++++++++++- 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/python/install.py b/python/install.py index d733273fe7..9308506fd2 100644 --- a/python/install.py +++ b/python/install.py @@ -2,16 +2,18 @@ # copy LAMMPS src/liblammps.so and lammps.py to system dirs +from __future__ import print_function + instructions = """ Syntax: python install.py [-h] [pydir] pydir = target dir for lammps.py and liblammps.so 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: - print instructions + print(instructions) sys.exit() if len(sys.argv) == 2: pydir = sys.argv[1] @@ -22,18 +24,24 @@ else: pydir = "" if 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() str = "cp ../python/lammps.py %s" % pydir - print str - outstr = commands.getoutput(str) - if len(outstr.strip()): print outstr + print(str) + try: + 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 - print str - outstr = commands.getoutput(str) + print(str) + try: + shutil.copyfile("../src/liblammps.so", os.path.join(pydir,"liblammps.so") ) + except shutil.Error: + pass # source and destination are identical 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 @@ -60,7 +68,7 @@ try: data_files = [(get_python_lib(), ["../src/liblammps.so"])]) except: 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: @@ -75,7 +83,7 @@ if tryuser: py_modules = ["lammps"], data_files = [(site.USER_SITE, ["../src/liblammps.so"])]) 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.") diff --git a/python/lammps.py b/python/lammps.py index c6a4b6168e..cb818841f2 100644 --- a/python/lammps.py +++ b/python/lammps.py @@ -53,7 +53,7 @@ class lammps: except: if not name: self.lib = CDLL("liblammps.so",RTLD_GLOBAL) else: self.lib = CDLL("liblammps_%s.so" % name,RTLD_GLOBAL) - + # if no ptr provided, create an instance of LAMMPS # 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 @@ -125,12 +125,15 @@ class lammps: return self.lib.lammps_version(self.lmp) def file(self,file): + file = file.encode() self.lib.lammps_file(self.lmp,file) def command(self,cmd): + cmd = cmd.encode() self.lib.lammps_command(self.lmp,cmd) def extract_global(self,name,type): + name = name.encode() if type == 0: self.lib.lammps_extract_global.restype = POINTER(c_int) elif type == 1: @@ -140,6 +143,7 @@ class lammps: return ptr[0] def extract_atom(self,name,type): + name = name.encode() if type == 0: self.lib.lammps_extract_atom.restype = POINTER(c_int) elif type == 1: @@ -153,6 +157,7 @@ class lammps: return ptr def extract_compute(self,id,style,type): + id = id.encode() if type == 0: if style > 0: return None self.lib.lammps_extract_compute.restype = POINTER(c_double) @@ -172,6 +177,7 @@ class lammps: # double was allocated by library interface function def extract_fix(self,id,style,type,i=0,j=0): + id = ide.encode() if style == 0: self.lib.lammps_extract_fix.restype = POINTER(c_double) 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 def extract_variable(self,name,group,type): + name = name.encode() + group = group.encode() if type == 0: self.lib.lammps_extract_variable.restype = POINTER(c_double) ptr = self.lib.lammps_extract_variable(self.lmp,name,group) @@ -218,6 +226,8 @@ class lammps: # returns 0 for success, -1 if failed 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 total number of atoms in system @@ -228,6 +238,7 @@ class lammps: # return vector of atom properties gathered across procs, ordered by atom ID def gather_atoms(self,name,type,count): + name = name.encode() natoms = self.lib.lammps_get_natoms(self.lmp) if type == 0: data = ((count*natoms)*c_int)() @@ -242,4 +253,7 @@ class lammps: # assume vector is of correct type and length, as created by gather_atoms() def scatter_atoms(self,name,type,count,data): + name = name.encode() self.lib.lammps_scatter_atoms(self.lmp,name,type,count,data) + +