diff --git a/python/lammps/core.py b/python/lammps/core.py index be026d5e10..279b0a64dc 100644 --- a/python/lammps/core.py +++ b/python/lammps/core.py @@ -746,12 +746,21 @@ class lammps(object): :type name: string :param dtype: data type of the returned data (see :ref:`py_datatype_constants`) :type dtype: int, optional - :return: value of the property or None - :rtype: int, float, or NoneType + :return: value of the property or list of values or None + :rtype: int, float, list, or NoneType """ + if dtype == LAMMPS_AUTODETECT: dtype = self.extract_global_datatype(name) + # set length of vector for items that are not a scalar + vec_dict = { 'boxlo':3, 'boxhi':3, 'sublo':3, 'subhi':3, + 'sublo_lambda':3, 'subhi_lambda':3, 'periodicity':3 } + if name in vec_dict: + veclen = vec_dict[name] + else: + veclen = 1 + if name: name = name.encode() else: return None @@ -770,10 +779,14 @@ class lammps(object): ptr = self.lib.lammps_extract_global(self.lmp, name) if ptr: - return target_type(ptr[0]) + if veclen > 1: + result = [] + for i in range(0,veclen): + result.append(target_type(ptr[i])) + return result + else: return target_type(ptr[0]) return None - # ------------------------------------------------------------------------- # extract per-atom info datatype diff --git a/unittest/python/python-commands.py b/unittest/python/python-commands.py index c82e2fdb26..c1e4cecef5 100644 --- a/unittest/python/python-commands.py +++ b/unittest/python/python-commands.py @@ -268,6 +268,15 @@ create_atoms 1 single & self.assertEqual(self.lmp.extract_global("boxyhi"), 2.0) self.assertEqual(self.lmp.extract_global("boxzlo"), -3.0) self.assertEqual(self.lmp.extract_global("boxzhi"), 3.0) + self.assertEqual(self.lmp.extract_global("boxlo"), [-1.0, -2.0, -3.0]) + self.assertEqual(self.lmp.extract_global("boxhi"), [1.0, 2.0, 3.0]) + self.assertEqual(self.lmp.extract_global("sublo"), [-1.0, -2.0, -3.0]) + self.assertEqual(self.lmp.extract_global("subhi"), [1.0, 2.0, 3.0]) + self.assertEqual(self.lmp.extract_global("periodicity"), [1,1,1]) + # only valid for triclinic box + self.lmp.command("change_box all triclinic") + self.assertEqual(self.lmp.extract_global("sublo_lambda"), [0.0, 0.0, 0.0]) + self.assertEqual(self.lmp.extract_global("subhi_lambda"), [1.0, 1.0, 1.0]) ############################## if __name__ == "__main__":