Merge pull request #2935 from akohlmey/python-module-fixes-and-tests
Python module fixes and tests
This commit is contained in:
@ -508,11 +508,6 @@ class PyLammps(object):
|
||||
:py:attr:`PyLammps.last_run`.
|
||||
"""
|
||||
output = self.__getattr__('run')(*args, **kwargs)
|
||||
|
||||
comm = self.lmp.get_mpi_comm()
|
||||
if comm:
|
||||
output = self.lmp.comm.bcast(output, root=0)
|
||||
|
||||
self.runs += get_thermo_data(output)
|
||||
return output
|
||||
|
||||
@ -643,7 +638,7 @@ class PyLammps(object):
|
||||
return [x.strip() for x in value.split('=')]
|
||||
|
||||
def _parse_info_system(self, output):
|
||||
lines = output[6:-2]
|
||||
lines = output[5:-2]
|
||||
system = {}
|
||||
|
||||
for line in lines:
|
||||
@ -704,7 +699,7 @@ class PyLammps(object):
|
||||
return system
|
||||
|
||||
def _parse_info_communication(self, output):
|
||||
lines = output[6:-3]
|
||||
lines = output[5:-3]
|
||||
comm = {}
|
||||
|
||||
for line in lines:
|
||||
@ -725,7 +720,7 @@ class PyLammps(object):
|
||||
return comm
|
||||
|
||||
def _parse_element_list(self, output):
|
||||
lines = output[6:-3]
|
||||
lines = output[5:-3]
|
||||
elements = []
|
||||
|
||||
for line in lines:
|
||||
@ -737,7 +732,7 @@ class PyLammps(object):
|
||||
return elements
|
||||
|
||||
def _parse_groups(self, output):
|
||||
lines = output[6:-3]
|
||||
lines = output[5:-3]
|
||||
groups = []
|
||||
group_pattern = re.compile(r"(?P<name>.+) \((?P<type>.+)\)")
|
||||
|
||||
@ -784,6 +779,10 @@ class PyLammps(object):
|
||||
self.command(cmd)
|
||||
output = capture.output
|
||||
|
||||
comm = self.lmp.get_mpi_comm()
|
||||
if comm:
|
||||
output = self.lmp.comm.bcast(output, root=0)
|
||||
|
||||
if 'verbose' in kwargs and kwargs['verbose']:
|
||||
print(output)
|
||||
|
||||
|
||||
@ -84,5 +84,40 @@ class PythonPyLammps(unittest.TestCase):
|
||||
self.assertEqual(len(self.pylmp.last_run.thermo.TotEng), 2)
|
||||
self.assertEqual(len(self.pylmp.last_run.thermo.Press), 2)
|
||||
|
||||
def test_info_queries(self):
|
||||
self.pylmp.lattice("fcc", 0.8442),
|
||||
self.pylmp.region("box block", 0, 4, 0, 4, 0, 4)
|
||||
self.pylmp.create_box(1, "box")
|
||||
self.pylmp.variable("a equal 10.0")
|
||||
self.pylmp.variable("b string value")
|
||||
self.assertEqual(self.pylmp.variables['a'].value, 10.0)
|
||||
self.assertEqual(self.pylmp.variables['b'].value, 'value')
|
||||
self.assertEqual(len(self.pylmp.variables),2)
|
||||
self.assertEqual(self.pylmp.system.units,'lj')
|
||||
self.assertEqual(self.pylmp.system.atom_style,'atomic')
|
||||
self.assertEqual(self.pylmp.system.ntypes,1)
|
||||
self.assertEqual(self.pylmp.system.natoms,0)
|
||||
self.assertEqual(self.pylmp.communication.comm_style,'brick')
|
||||
self.assertEqual(self.pylmp.communication.comm_layout,'uniform')
|
||||
self.assertEqual(self.pylmp.communication.nprocs,1)
|
||||
self.assertEqual(len(self.pylmp.computes),3)
|
||||
self.assertEqual(self.pylmp.computes[0]['name'], 'thermo_temp')
|
||||
self.assertEqual(self.pylmp.computes[0]['style'], 'temp')
|
||||
self.assertEqual(self.pylmp.computes[0]['group'], 'all')
|
||||
self.assertEqual(self.pylmp.computes[1]['name'], 'thermo_press')
|
||||
self.assertEqual(self.pylmp.computes[1]['style'], 'pressure')
|
||||
self.assertEqual(self.pylmp.computes[1]['group'], 'all')
|
||||
self.assertEqual(self.pylmp.computes[2]['name'], 'thermo_pe')
|
||||
self.assertEqual(self.pylmp.computes[2]['style'], 'pe')
|
||||
self.assertEqual(self.pylmp.computes[2]['group'], 'all')
|
||||
self.assertEqual(len(self.pylmp.dumps),0)
|
||||
self.pylmp.fix('one','all','nve')
|
||||
self.assertEqual(len(self.pylmp.fixes),1)
|
||||
self.assertEqual(self.pylmp.fixes[0]['name'], 'one')
|
||||
self.assertEqual(self.pylmp.fixes[0]['style'], 'nve')
|
||||
self.assertEqual(self.pylmp.fixes[0]['group'], 'all')
|
||||
self.pylmp.group('none','empty')
|
||||
self.assertEqual(len(self.pylmp.groups),2)
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user