git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@13233 f3b2605a-c512-4ea7-a41b-209d697bcdaa
This commit is contained in:
@ -8,14 +8,13 @@ doc/Section_python.html and in doc/Section_start.html#start_5.
|
|||||||
|
|
||||||
Basically you need to follow these steps in the src directory:
|
Basically you need to follow these steps in the src directory:
|
||||||
|
|
||||||
% make makeshlib # creates Makefile.shlib
|
% make g++ mode=shlib # build for whatever machine target you wish
|
||||||
% make -f Makefile.shlib g++ # build for whatever machine target you wish
|
|
||||||
% make install-python # may need to do this via sudo
|
% make install-python # may need to do this via sudo
|
||||||
|
|
||||||
You can replace the last step with running the python/install.py
|
You can replace the last step by a one-time setting of environment
|
||||||
script directly to give you more control over where two relevant files
|
variables in your shell script. Or you can run the python/install.py
|
||||||
are installed, or by setting environment variables in your shell
|
script directly to give you more control over where the two relevant
|
||||||
script. See doc/Section_python.html for details.
|
files are installed. See doc/Section_python.html for details.
|
||||||
|
|
||||||
You can then launch Python and instantiate an instance of LAMMPS:
|
You can then launch Python and instantiate an instance of LAMMPS:
|
||||||
|
|
||||||
|
|||||||
@ -17,7 +17,7 @@ import sys,traceback,types
|
|||||||
from ctypes import *
|
from ctypes import *
|
||||||
|
|
||||||
class lammps:
|
class lammps:
|
||||||
def __init__(self,name="",cmdargs=None):
|
def __init__(self,name="",cmdargs=None,ptr=None):
|
||||||
|
|
||||||
# load liblammps.so by default
|
# load liblammps.so by default
|
||||||
# if name = "g++", load liblammps_g++.so
|
# if name = "g++", load liblammps_g++.so
|
||||||
@ -30,28 +30,39 @@ class lammps:
|
|||||||
traceback.print_exception(type,value,tb)
|
traceback.print_exception(type,value,tb)
|
||||||
raise OSError,"Could not load LAMMPS dynamic library"
|
raise OSError,"Could not load LAMMPS dynamic library"
|
||||||
|
|
||||||
# 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
|
||||||
# no_mpi call lets LAMMPS use MPI_COMM_WORLD
|
# no_mpi call lets LAMMPS use MPI_COMM_WORLD
|
||||||
# cargs = array of C strings from args
|
# cargs = array of C strings from args
|
||||||
|
# if ptr, then are embedding Python in LAMMPS input script
|
||||||
|
# ptr is the desired instance of LAMMPS
|
||||||
|
# just convert it to ctypes ptr and store in self.lmp
|
||||||
|
|
||||||
if cmdargs:
|
if not ptr:
|
||||||
cmdargs.insert(0,"lammps.py")
|
self.opened = 1
|
||||||
narg = len(cmdargs)
|
if cmdargs:
|
||||||
cargs = (c_char_p*narg)(*cmdargs)
|
cmdargs.insert(0,"lammps.py")
|
||||||
self.lmp = c_void_p()
|
narg = len(cmdargs)
|
||||||
self.lib.lammps_open_no_mpi(narg,cargs,byref(self.lmp))
|
cargs = (c_char_p*narg)(*cmdargs)
|
||||||
|
self.lmp = c_void_p()
|
||||||
|
self.lib.lammps_open_no_mpi(narg,cargs,byref(self.lmp))
|
||||||
|
else:
|
||||||
|
self.lmp = c_void_p()
|
||||||
|
self.lib.lammps_open_no_mpi(0,None,byref(self.lmp))
|
||||||
|
# could use just this if LAMMPS lib interface supported it
|
||||||
|
# self.lmp = self.lib.lammps_open_no_mpi(0,None)
|
||||||
else:
|
else:
|
||||||
self.lmp = c_void_p()
|
self.opened = 0
|
||||||
self.lib.lammps_open_no_mpi(0,None,byref(self.lmp))
|
# magic to convert ptr to ctypes ptr
|
||||||
# could use just this if LAMMPS lib interface supported it
|
pythonapi.PyCObject_AsVoidPtr.restype = c_void_p
|
||||||
# self.lmp = self.lib.lammps_open_no_mpi(0,None)
|
pythonapi.PyCObject_AsVoidPtr.argtypes = [py_object]
|
||||||
|
self.lmp = c_void_p(pythonapi.PyCObject_AsVoidPtr(ptr))
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
if self.lmp: self.lib.lammps_close(self.lmp)
|
if self.lmp and self.opened: self.lib.lammps_close(self.lmp)
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
self.lib.lammps_close(self.lmp)
|
if self.opened: self.lib.lammps_close(self.lmp)
|
||||||
self.lmp = None
|
self.lmp = None
|
||||||
|
|
||||||
def file(self,file):
|
def file(self,file):
|
||||||
@ -142,6 +153,13 @@ class lammps:
|
|||||||
return result
|
return result
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
# set variable value
|
||||||
|
# value is converted to string
|
||||||
|
# returns 0 for success, -1 if failed
|
||||||
|
|
||||||
|
def set_variable(self,name,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
|
||||||
|
|
||||||
def get_natoms(self):
|
def get_natoms(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user