don't overwrite string type argument variables with their encoded version

This commit is contained in:
Axel Kohlmeyer
2024-07-16 19:00:18 -04:00
parent 4daba292d7
commit 8d4a80729a

View File

@ -533,11 +533,11 @@ class lammps(object):
:param error_text: :param error_text:
:type error_text: string :type error_text: string
""" """
if error_text: error_text = error_text.encode() if error_text: new_error_text = error_text.encode()
else: error_text = "(unknown error)".encode() else: new_error_text = "(unknown error)".encode()
with ExceptionCheck(self): with ExceptionCheck(self):
self.lib.lammps_error(self.lmp, error_type, error_text) self.lib.lammps_error(self.lmp, error_type, new_error_text)
# ------------------------------------------------------------------------- # -------------------------------------------------------------------------
@ -612,11 +612,11 @@ class lammps(object):
:param path: Name of the file/path with LAMMPS commands :param path: Name of the file/path with LAMMPS commands
:type path: string :type path: string
""" """
if path: path = path.encode() if path: newpath = path.encode()
else: return else: return
with ExceptionCheck(self): with ExceptionCheck(self):
self.lib.lammps_file(self.lmp, path) self.lib.lammps_file(self.lmp, newpath)
# ------------------------------------------------------------------------- # -------------------------------------------------------------------------
@ -629,11 +629,11 @@ class lammps(object):
:param cmd: a single lammps command :param cmd: a single lammps command
:type cmd: string :type cmd: string
""" """
if cmd: cmd = cmd.encode() if cmd: newcmd = cmd.encode()
else: return else: return
with ExceptionCheck(self): with ExceptionCheck(self):
self.lib.lammps_command(self.lmp,cmd) self.lib.lammps_command(self.lmp, newcmd)
# ------------------------------------------------------------------------- # -------------------------------------------------------------------------
@ -667,10 +667,11 @@ class lammps(object):
:param multicmd: text block of lammps commands :param multicmd: text block of lammps commands
:type multicmd: string :type multicmd: string
""" """
if type(multicmd) is str: multicmd = multicmd.encode() if type(multicmd) is str: newmulticmd = multicmd.encode()
else: newmulticmd = multicmd
with ExceptionCheck(self): with ExceptionCheck(self):
self.lib.lammps_commands_string(self.lmp,c_char_p(multicmd)) self.lib.lammps_commands_string(self.lmp,c_char_p(newmulticmd))
# ------------------------------------------------------------------------- # -------------------------------------------------------------------------
@ -757,11 +758,11 @@ class lammps(object):
:return: value of thermo keyword :return: value of thermo keyword
:rtype: double or None :rtype: double or None
""" """
if name: name = name.encode() if name: newname = name.encode()
else: return None else: return None
with ExceptionCheck(self): with ExceptionCheck(self):
return self.lib.lammps_get_thermo(self.lmp,name) return self.lib.lammps_get_thermo(self.lmp, newname)
# ------------------------------------------------------------------------- # -------------------------------------------------------------------------
@property @property
@ -835,9 +836,9 @@ class lammps(object):
:return: value of the setting :return: value of the setting
:rtype: int :rtype: int
""" """
if name: name = name.encode() if name: newname = name.encode()
else: return None else: return None
return int(self.lib.lammps_extract_setting(self.lmp,name)) return int(self.lib.lammps_extract_setting(self.lmp, newname))
# ------------------------------------------------------------------------- # -------------------------------------------------------------------------
# extract global info datatype # extract global info datatype
@ -858,9 +859,9 @@ class lammps(object):
:return: data type of global property, see :ref:`py_datatype_constants` :return: data type of global property, see :ref:`py_datatype_constants`
:rtype: int :rtype: int
""" """
if name: name = name.encode() if name: newname = name.encode()
else: return None else: return None
return self.lib.lammps_extract_global_datatype(self.lmp, name) return self.lib.lammps_extract_global_datatype(self.lmp, newname)
# ------------------------------------------------------------------------- # -------------------------------------------------------------------------
# extract global info # extract global info
@ -904,7 +905,7 @@ class lammps(object):
else: else:
veclen = 1 veclen = 1
if name: name = name.encode() if name: newname = name.encode()
else: return None else: return None
if dtype == LAMMPS_INT: if dtype == LAMMPS_INT:
@ -922,7 +923,7 @@ class lammps(object):
else: else:
target_type = None target_type = None
ptr = self.lib.lammps_extract_global(self.lmp, name) ptr = self.lib.lammps_extract_global(self.lmp, newname)
if ptr: if ptr:
if dtype == LAMMPS_STRING: if dtype == LAMMPS_STRING:
return ptr.decode('utf-8') return ptr.decode('utf-8')
@ -940,6 +941,8 @@ class lammps(object):
def extract_pair_dimension(self, name): def extract_pair_dimension(self, name):
"""Retrieve pair style property dimensionality from LAMMPS """Retrieve pair style property dimensionality from LAMMPS
.. versionadded:: TBD
This is a wrapper around the :cpp:func:`lammps_extract_pair_dimension` This is a wrapper around the :cpp:func:`lammps_extract_pair_dimension`
function of the C-library interface. The list of supported keywords function of the C-library interface. The list of supported keywords
depends on the pair style. This function returns ``None`` if the keyword depends on the pair style. This function returns ``None`` if the keyword
@ -951,10 +954,10 @@ class lammps(object):
:rtype: int :rtype: int
""" """
if name: if name:
name = name.encode() newname = name.encode()
else: else:
return None return None
dim = self.lib.lammps_extract_pair_dimension(self.lmp, name) dim = self.lib.lammps_extract_pair_dimension(self.lmp, newname)
if dim < 0: if dim < 0:
return None return None
@ -967,6 +970,8 @@ class lammps(object):
def extract_pair(self, name): def extract_pair(self, name):
"""Extract pair style data from LAMMPS. """Extract pair style data from LAMMPS.
.. versionadded:: TBD
This is a wrapper around the :cpp:func:`lammps_extract_pair` function This is a wrapper around the :cpp:func:`lammps_extract_pair` function
of the C-library interface. Since there are no pointers in Python, this of the C-library interface. Since there are no pointers in Python, this
method will - unlike the C function - return the value or a list of method will - unlike the C function - return the value or a list of
@ -982,7 +987,7 @@ class lammps(object):
""" """
if name: if name:
name = name.encode() newname = name.encode()
else: else:
return None return None
@ -999,7 +1004,7 @@ class lammps(object):
return None return None
ntypes = self.extract_setting('ntypes') ntypes = self.extract_setting('ntypes')
ptr = self.lib.lammps_extract_pair(self.lmp, name) ptr = self.lib.lammps_extract_pair(self.lmp, newname)
if ptr: if ptr:
if dim == 0: if dim == 0:
return float(ptr[0]) return float(ptr[0])
@ -1061,9 +1066,9 @@ class lammps(object):
:return: data type of per-atom property (see :ref:`py_datatype_constants`) :return: data type of per-atom property (see :ref:`py_datatype_constants`)
:rtype: int :rtype: int
""" """
if name: name = name.encode() if name: newname = name.encode()
else: return None else: return None
return self.lib.lammps_extract_atom_datatype(self.lmp, name) return self.lib.lammps_extract_atom_datatype(self.lmp, newname)
# ------------------------------------------------------------------------- # -------------------------------------------------------------------------
# extract per-atom info # extract per-atom info
@ -1104,7 +1109,7 @@ class lammps(object):
if dtype == LAMMPS_AUTODETECT: if dtype == LAMMPS_AUTODETECT:
dtype = self.extract_atom_datatype(name) dtype = self.extract_atom_datatype(name)
if name: name = name.encode() if name: newname = name.encode()
else: return None else: return None
if dtype == LAMMPS_INT: if dtype == LAMMPS_INT:
@ -1121,7 +1126,7 @@ class lammps(object):
self.lib.lammps_extract_atom.restype = POINTER(POINTER(c_int64)) self.lib.lammps_extract_atom.restype = POINTER(POINTER(c_int64))
else: return None else: return None
ptr = self.lib.lammps_extract_atom(self.lmp, name) ptr = self.lib.lammps_extract_atom(self.lmp, newname)
if ptr: return ptr if ptr: return ptr
else: return None else: return None
@ -1149,47 +1154,47 @@ class lammps(object):
:return: requested data as scalar, pointer to 1d or 2d double array, or None :return: requested data as scalar, pointer to 1d or 2d double array, or None
:rtype: c_double, ctypes.POINTER(c_double), ctypes.POINTER(ctypes.POINTER(c_double)), or NoneType :rtype: c_double, ctypes.POINTER(c_double), ctypes.POINTER(ctypes.POINTER(c_double)), or NoneType
""" """
if cid: cid = cid.encode() if cid: newcid = cid.encode()
else: return None else: return None
if ctype == LMP_TYPE_SCALAR: if ctype == LMP_TYPE_SCALAR:
if cstyle == LMP_STYLE_GLOBAL: if cstyle == LMP_STYLE_GLOBAL:
self.lib.lammps_extract_compute.restype = POINTER(c_double) self.lib.lammps_extract_compute.restype = POINTER(c_double)
with ExceptionCheck(self): with ExceptionCheck(self):
ptr = self.lib.lammps_extract_compute(self.lmp,cid,cstyle,ctype) ptr = self.lib.lammps_extract_compute(self.lmp,newcid,cstyle,ctype)
return ptr[0] return ptr[0]
elif cstyle == LMP_STYLE_ATOM: elif cstyle == LMP_STYLE_ATOM:
return None return None
elif cstyle == LMP_STYLE_LOCAL: elif cstyle == LMP_STYLE_LOCAL:
self.lib.lammps_extract_compute.restype = POINTER(c_int) self.lib.lammps_extract_compute.restype = POINTER(c_int)
with ExceptionCheck(self): with ExceptionCheck(self):
ptr = self.lib.lammps_extract_compute(self.lmp,cid,cstyle,ctype) ptr = self.lib.lammps_extract_compute(self.lmp,newcid,cstyle,ctype)
return ptr[0] return ptr[0]
elif ctype == LMP_TYPE_VECTOR: elif ctype == LMP_TYPE_VECTOR:
self.lib.lammps_extract_compute.restype = POINTER(c_double) self.lib.lammps_extract_compute.restype = POINTER(c_double)
with ExceptionCheck(self): with ExceptionCheck(self):
ptr = self.lib.lammps_extract_compute(self.lmp,cid,cstyle,ctype) ptr = self.lib.lammps_extract_compute(self.lmp,newcid,cstyle,ctype)
return ptr return ptr
elif ctype == LMP_TYPE_ARRAY: elif ctype == LMP_TYPE_ARRAY:
self.lib.lammps_extract_compute.restype = POINTER(POINTER(c_double)) self.lib.lammps_extract_compute.restype = POINTER(POINTER(c_double))
with ExceptionCheck(self): with ExceptionCheck(self):
ptr = self.lib.lammps_extract_compute(self.lmp,cid,cstyle,ctype) ptr = self.lib.lammps_extract_compute(self.lmp,newcid,cstyle,ctype)
return ptr return ptr
elif ctype == LMP_SIZE_COLS: elif ctype == LMP_SIZE_COLS:
if cstyle == LMP_STYLE_GLOBAL or cstyle == LMP_STYLE_ATOM or cstyle == LMP_STYLE_LOCAL: if cstyle == LMP_STYLE_GLOBAL or cstyle == LMP_STYLE_ATOM or cstyle == LMP_STYLE_LOCAL:
self.lib.lammps_extract_compute.restype = POINTER(c_int) self.lib.lammps_extract_compute.restype = POINTER(c_int)
with ExceptionCheck(self): with ExceptionCheck(self):
ptr = self.lib.lammps_extract_compute(self.lmp,cid,cstyle,ctype) ptr = self.lib.lammps_extract_compute(self.lmp,newcid,cstyle,ctype)
return ptr[0] return ptr[0]
elif ctype == LMP_SIZE_VECTOR or ctype == LMP_SIZE_ROWS: elif ctype == LMP_SIZE_VECTOR or ctype == LMP_SIZE_ROWS:
if cstyle == LMP_STYLE_GLOBAL or cstyle == LMP_STYLE_LOCAL: if cstyle == LMP_STYLE_GLOBAL or cstyle == LMP_STYLE_LOCAL:
self.lib.lammps_extract_compute.restype = POINTER(c_int) self.lib.lammps_extract_compute.restype = POINTER(c_int)
with ExceptionCheck(self): with ExceptionCheck(self):
ptr = self.lib.lammps_extract_compute(self.lmp,cid,cstyle,ctype) ptr = self.lib.lammps_extract_compute(self.lmp,newcid,cstyle,ctype)
return ptr[0] return ptr[0]
return None return None
@ -1234,21 +1239,21 @@ class lammps(object):
:rtype: c_double, ctypes.POINTER(c_double), ctypes.POINTER(ctypes.POINTER(c_double)), or NoneType :rtype: c_double, ctypes.POINTER(c_double), ctypes.POINTER(ctypes.POINTER(c_double)), or NoneType
""" """
if fid: fid = fid.encode() if fid: newfid = fid.encode()
else: return None else: return None
if fstyle == LMP_STYLE_GLOBAL: if fstyle == LMP_STYLE_GLOBAL:
if ftype in (LMP_TYPE_SCALAR, LMP_TYPE_VECTOR, LMP_TYPE_ARRAY): if ftype in (LMP_TYPE_SCALAR, LMP_TYPE_VECTOR, LMP_TYPE_ARRAY):
self.lib.lammps_extract_fix.restype = POINTER(c_double) self.lib.lammps_extract_fix.restype = POINTER(c_double)
with ExceptionCheck(self): with ExceptionCheck(self):
ptr = self.lib.lammps_extract_fix(self.lmp,fid,fstyle,ftype,nrow,ncol) ptr = self.lib.lammps_extract_fix(self.lmp,newfid,fstyle,ftype,nrow,ncol)
result = ptr[0] result = ptr[0]
self.lib.lammps_free(ptr) self.lib.lammps_free(ptr)
return result return result
elif ftype in (LMP_SIZE_VECTOR, LMP_SIZE_ROWS, LMP_SIZE_COLS): elif ftype in (LMP_SIZE_VECTOR, LMP_SIZE_ROWS, LMP_SIZE_COLS):
self.lib.lammps_extract_fix.restype = POINTER(c_int) self.lib.lammps_extract_fix.restype = POINTER(c_int)
with ExceptionCheck(self): with ExceptionCheck(self):
ptr = self.lib.lammps_extract_fix(self.lmp,fid,fstyle,ftype,nrow,ncol) ptr = self.lib.lammps_extract_fix(self.lmp,newfid,fstyle,ftype,nrow,ncol)
return ptr[0] return ptr[0]
else: else:
return None return None
@ -1263,7 +1268,7 @@ class lammps(object):
else: else:
return None return None
with ExceptionCheck(self): with ExceptionCheck(self):
ptr = self.lib.lammps_extract_fix(self.lmp,fid,fstyle,ftype,nrow,ncol) ptr = self.lib.lammps_extract_fix(self.lmp,newfid,fstyle,ftype,nrow,ncol)
if ftype == LMP_SIZE_COLS: if ftype == LMP_SIZE_COLS:
return ptr[0] return ptr[0]
else: else:
@ -1279,7 +1284,7 @@ class lammps(object):
else: else:
return None return None
with ExceptionCheck(self): with ExceptionCheck(self):
ptr = self.lib.lammps_extract_fix(self.lmp,fid,fstyle,ftype,nrow,ncol) ptr = self.lib.lammps_extract_fix(self.lmp,newfid,fstyle,ftype,nrow,ncol)
if ftype in (LMP_TYPE_VECTOR, LMP_TYPE_ARRAY): if ftype in (LMP_TYPE_VECTOR, LMP_TYPE_ARRAY):
return ptr return ptr
else: else:
@ -1320,15 +1325,16 @@ class lammps(object):
:return: the requested data :return: the requested data
:rtype: c_double, (c_double), or NoneType :rtype: c_double, (c_double), or NoneType
""" """
if name: name = name.encode() if name: newname = name.encode()
else: return None else: return None
if group: group = group.encode() if group: newgroup = group.encode()
else: newgroup = None
if vartype is None : if vartype is None :
vartype = self.lib.lammps_extract_variable_datatype(self.lmp, name) vartype = self.lib.lammps_extract_variable_datatype(self.lmp, newname)
if vartype == LMP_VAR_EQUAL: if vartype == LMP_VAR_EQUAL:
self.lib.lammps_extract_variable.restype = POINTER(c_double) self.lib.lammps_extract_variable.restype = POINTER(c_double)
with ExceptionCheck(self): with ExceptionCheck(self):
ptr = self.lib.lammps_extract_variable(self.lmp,name,group) ptr = self.lib.lammps_extract_variable(self.lmp, newname, newgroup)
if ptr: result = ptr[0] if ptr: result = ptr[0]
else: return None else: return None
self.lib.lammps_free(ptr) self.lib.lammps_free(ptr)
@ -1338,7 +1344,7 @@ class lammps(object):
result = (c_double*nlocal)() result = (c_double*nlocal)()
self.lib.lammps_extract_variable.restype = POINTER(c_double) self.lib.lammps_extract_variable.restype = POINTER(c_double)
with ExceptionCheck(self): with ExceptionCheck(self):
ptr = self.lib.lammps_extract_variable(self.lmp,name,group) ptr = self.lib.lammps_extract_variable(self.lmp, newname, newgroup)
if ptr: if ptr:
for i in range(nlocal): result[i] = ptr[i] for i in range(nlocal): result[i] = ptr[i]
self.lib.lammps_free(ptr) self.lib.lammps_free(ptr)
@ -1347,7 +1353,7 @@ class lammps(object):
elif vartype == LMP_VAR_VECTOR : elif vartype == LMP_VAR_VECTOR :
nvector = 0 nvector = 0
self.lib.lammps_extract_variable.restype = POINTER(c_int) self.lib.lammps_extract_variable.restype = POINTER(c_int)
ptr = self.lib.lammps_extract_variable(self.lmp,name, ptr = self.lib.lammps_extract_variable(self.lmp, newname,
'LMP_SIZE_VECTOR'.encode()) 'LMP_SIZE_VECTOR'.encode())
if ptr : if ptr :
nvector = ptr[0] nvector = ptr[0]
@ -1356,7 +1362,7 @@ class lammps(object):
return None return None
self.lib.lammps_extract_variable.restype = POINTER(c_double) self.lib.lammps_extract_variable.restype = POINTER(c_double)
result = (c_double*nvector)() result = (c_double*nvector)()
values = self.lib.lammps_extract_variable(self.lmp,name,group) values = self.lib.lammps_extract_variable(self.lmp, newname, newgroup)
if values : if values :
for i in range(nvector) : for i in range(nvector) :
result[i] = values[i] result[i] = values[i]
@ -1367,7 +1373,7 @@ class lammps(object):
elif vartype == LMP_VAR_STRING : elif vartype == LMP_VAR_STRING :
self.lib.lammps_extract_variable.restype = c_char_p self.lib.lammps_extract_variable.restype = c_char_p
with ExceptionCheck(self) : with ExceptionCheck(self) :
ptr = self.lib.lammps_extract_variable(self.lmp, name, group) ptr = self.lib.lammps_extract_variable(self.lmp, newname, newgroup)
return ptr.decode('utf-8') return ptr.decode('utf-8')
return None return None
@ -1398,12 +1404,12 @@ class lammps(object):
:return: either 0 on success or -1 on failure :return: either 0 on success or -1 on failure
:rtype: int :rtype: int
""" """
if name: name = name.encode() if name: newname = name.encode()
else: return -1 else: return -1
if value: value = str(value).encode() if value: newvalue = str(value).encode()
else: return -1 else: return -1
with ExceptionCheck(self): with ExceptionCheck(self):
return self.lib.lammps_set_variable(self.lmp,name,value) return self.lib.lammps_set_variable(self.lmp, newname, newvalue)
# ------------------------------------------------------------------------- # -------------------------------------------------------------------------
@ -1422,12 +1428,12 @@ class lammps(object):
:return: either 0 on success or -1 on failure :return: either 0 on success or -1 on failure
:rtype: int :rtype: int
""" """
if name: name = name.encode() if name: newname = name.encode()
else: return -1 else: return -1
if value: value = str(value).encode() if value: newvalue = str(value).encode()
else: return -1 else: return -1
with ExceptionCheck(self): with ExceptionCheck(self):
return self.lib.lammps_set_string_variable(self.lmp,name,value) return self.lib.lammps_set_string_variable(self.lmp,newname,newvalue)
# ------------------------------------------------------------------------- # -------------------------------------------------------------------------
@ -1446,10 +1452,10 @@ class lammps(object):
:return: either 0 on success or -1 on failure :return: either 0 on success or -1 on failure
:rtype: int :rtype: int
""" """
if name: name = name.encode() if name: newname = name.encode()
else: return -1 else: return -1
with ExceptionCheck(self): with ExceptionCheck(self):
return self.lib.lammps_set_internal_variable(self.lmp,name,value) return self.lib.lammps_set_internal_variable(self.lmp,newname,value)
# ------------------------------------------------------------------------- # -------------------------------------------------------------------------
@ -1463,15 +1469,16 @@ class lammps(object):
# e.g. for Python list or NumPy or ctypes # e.g. for Python list or NumPy or ctypes
def gather_atoms(self,name,dtype,count): def gather_atoms(self,name,dtype,count):
if name: name = name.encode() if name: newname = name.encode()
else: newname = None
natoms = self.get_natoms() natoms = self.get_natoms()
with ExceptionCheck(self): with ExceptionCheck(self):
if dtype == 0: if dtype == 0:
data = ((count*natoms)*c_int)() data = ((count*natoms)*c_int)()
self.lib.lammps_gather_atoms(self.lmp,name,dtype,count,data) self.lib.lammps_gather_atoms(self.lmp,newname,dtype,count,data)
elif dtype == 1: elif dtype == 1:
data = ((count*natoms)*c_double)() data = ((count*natoms)*c_double)()
self.lib.lammps_gather_atoms(self.lmp,name,dtype,count,data) self.lib.lammps_gather_atoms(self.lmp,newname,dtype,count,data)
else: else:
return None return None
return data return data
@ -1479,28 +1486,30 @@ class lammps(object):
# ------------------------------------------------------------------------- # -------------------------------------------------------------------------
def gather_atoms_concat(self,name,dtype,count): def gather_atoms_concat(self,name,dtype,count):
if name: name = name.encode() if name: newname = name.encode()
else: newname = None
natoms = self.get_natoms() natoms = self.get_natoms()
with ExceptionCheck(self): with ExceptionCheck(self):
if dtype == 0: if dtype == 0:
data = ((count*natoms)*c_int)() data = ((count*natoms)*c_int)()
self.lib.lammps_gather_atoms_concat(self.lmp,name,dtype,count,data) self.lib.lammps_gather_atoms_concat(self.lmp,newname,dtype,count,data)
elif dtype == 1: elif dtype == 1:
data = ((count*natoms)*c_double)() data = ((count*natoms)*c_double)()
self.lib.lammps_gather_atoms_concat(self.lmp,name,dtype,count,data) self.lib.lammps_gather_atoms_concat(self.lmp,newname,dtype,count,data)
else: else:
return None return None
return data return data
def gather_atoms_subset(self,name,dtype,count,ndata,ids): def gather_atoms_subset(self,name,dtype,count,ndata,ids):
if name: name = name.encode() if name: newname = name.encode()
else: newname = None
with ExceptionCheck(self): with ExceptionCheck(self):
if dtype == 0: if dtype == 0:
data = ((count*ndata)*c_int)() data = ((count*ndata)*c_int)()
self.lib.lammps_gather_atoms_subset(self.lmp,name,dtype,count,ndata,ids,data) self.lib.lammps_gather_atoms_subset(self.lmp,newname,dtype,count,ndata,ids,data)
elif dtype == 1: elif dtype == 1:
data = ((count*ndata)*c_double)() data = ((count*ndata)*c_double)()
self.lib.lammps_gather_atoms_subset(self.lmp,name,dtype,count,ndata,ids,data) self.lib.lammps_gather_atoms_subset(self.lmp,newname,dtype,count,ndata,ids,data)
else: else:
return None return None
return data return data
@ -1517,16 +1526,18 @@ class lammps(object):
# e.g. for Python list or NumPy or ctypes # e.g. for Python list or NumPy or ctypes
def scatter_atoms(self,name,dtype,count,data): def scatter_atoms(self,name,dtype,count,data):
if name: name = name.encode() if name: newname = name.encode()
else: newname = None
with ExceptionCheck(self): with ExceptionCheck(self):
self.lib.lammps_scatter_atoms(self.lmp,name,dtype,count,data) self.lib.lammps_scatter_atoms(self.lmp,newname,dtype,count,data)
# ------------------------------------------------------------------------- # -------------------------------------------------------------------------
def scatter_atoms_subset(self,name,dtype,count,ndata,ids,data): def scatter_atoms_subset(self,name,dtype,count,ndata,ids,data):
if name: name = name.encode() if name: newname = name.encode()
else: newname = None
with ExceptionCheck(self): with ExceptionCheck(self):
self.lib.lammps_scatter_atoms_subset(self.lmp,name,dtype,count,ndata,ids,data) self.lib.lammps_scatter_atoms_subset(self.lmp,newname,dtype,count,ndata,ids,data)
# ------------------------------------------------------------------------- # -------------------------------------------------------------------------
@ -1632,42 +1643,45 @@ class lammps(object):
# NOTE: need to ensure are converting to/from correct Python type # NOTE: need to ensure are converting to/from correct Python type
# e.g. for Python list or NumPy or ctypes # e.g. for Python list or NumPy or ctypes
def gather(self,name,dtype,count): def gather(self,name,dtype,count):
if name: name = name.encode() if name: newname = name.encode()
else: newname = None
natoms = self.get_natoms() natoms = self.get_natoms()
with ExceptionCheck(self): with ExceptionCheck(self):
if dtype == 0: if dtype == 0:
data = ((count*natoms)*c_int)() data = ((count*natoms)*c_int)()
self.lib.lammps_gather(self.lmp,name,dtype,count,data) self.lib.lammps_gather(self.lmp,newname,dtype,count,data)
elif dtype == 1: elif dtype == 1:
data = ((count*natoms)*c_double)() data = ((count*natoms)*c_double)()
self.lib.lammps_gather(self.lmp,name,dtype,count,data) self.lib.lammps_gather(self.lmp,newname,dtype,count,data)
else: else:
return None return None
return data return data
def gather_concat(self,name,dtype,count): def gather_concat(self,name,dtype,count):
if name: name = name.encode() if name: newname = name.encode()
else: newname = None
natoms = self.get_natoms() natoms = self.get_natoms()
with ExceptionCheck(self): with ExceptionCheck(self):
if dtype == 0: if dtype == 0:
data = ((count*natoms)*c_int)() data = ((count*natoms)*c_int)()
self.lib.lammps_gather_concat(self.lmp,name,dtype,count,data) self.lib.lammps_gather_concat(self.lmp,newname,dtype,count,data)
elif dtype == 1: elif dtype == 1:
data = ((count*natoms)*c_double)() data = ((count*natoms)*c_double)()
self.lib.lammps_gather_concat(self.lmp,name,dtype,count,data) self.lib.lammps_gather_concat(self.lmp,newname,dtype,count,data)
else: else:
return None return None
return data return data
def gather_subset(self,name,dtype,count,ndata,ids): def gather_subset(self,name,dtype,count,ndata,ids):
if name: name = name.encode() if name: newname = name.encode()
else: newname = None
with ExceptionCheck(self): with ExceptionCheck(self):
if dtype == 0: if dtype == 0:
data = ((count*ndata)*c_int)() data = ((count*ndata)*c_int)()
self.lib.lammps_gather_subset(self.lmp,name,dtype,count,ndata,ids,data) self.lib.lammps_gather_subset(self.lmp,newname,dtype,count,ndata,ids,data)
elif dtype == 1: elif dtype == 1:
data = ((count*ndata)*c_double)() data = ((count*ndata)*c_double)()
self.lib.lammps_gather_subset(self.lmp,name,dtype,count,ndata,ids,data) self.lib.lammps_gather_subset(self.lmp,newname,dtype,count,ndata,ids,data)
else: else:
return None return None
return data return data
@ -1682,14 +1696,16 @@ class lammps(object):
# e.g. for Python list or NumPy or ctypes # e.g. for Python list or NumPy or ctypes
def scatter(self,name,dtype,count,data): def scatter(self,name,dtype,count,data):
if name: name = name.encode() if name: newname = name.encode()
else: newname = None
with ExceptionCheck(self): with ExceptionCheck(self):
self.lib.lammps_scatter(self.lmp,name,dtype,count,data) self.lib.lammps_scatter(self.lmp,newname,dtype,count,data)
def scatter_subset(self,name,dtype,count,ndata,ids,data): def scatter_subset(self,name,dtype,count,ndata,ids,data):
if name: name = name.encode() if name: newname = name.encode()
else: newname = None
with ExceptionCheck(self): with ExceptionCheck(self):
self.lib.lammps_scatter_subset(self.lmp,name,dtype,count,ndata,ids,data) self.lib.lammps_scatter_subset(self.lmp,newname,dtype,count,ndata,ids,data)
# ------------------------------------------------------------------------- # -------------------------------------------------------------------------
@ -2442,9 +2458,9 @@ class lammps(object):
:rtype: int :rtype: int
""" """
style = style.encode() newstyle = style.encode()
exact = int(exact) exact = int(exact)
idx = self.lib.lammps_find_pair_neighlist(self.lmp, style, exact, nsub, reqid) idx = self.lib.lammps_find_pair_neighlist(self.lmp, newstyle, exact, nsub, reqid)
return idx return idx
# ------------------------------------------------------------------------- # -------------------------------------------------------------------------
@ -2465,8 +2481,8 @@ class lammps(object):
:rtype: int :rtype: int
""" """
fixid = fixid.encode() newfixid = fixid.encode()
idx = self.lib.lammps_find_fix_neighlist(self.lmp, fixid, reqid) idx = self.lib.lammps_find_fix_neighlist(self.lmp, newfixid, reqid)
return idx return idx
# ------------------------------------------------------------------------- # -------------------------------------------------------------------------
@ -2488,6 +2504,6 @@ class lammps(object):
:rtype: int :rtype: int
""" """
computeid = computeid.encode() newcomputeid = computeid.encode()
idx = self.lib.lammps_find_compute_neighlist(self.lmp, computeid, reqid) idx = self.lib.lammps_find_compute_neighlist(self.lmp, newcomputeid, reqid)
return idx return idx