add python interface with optional numpy support for lammps_gather_bonds()

unit tests are included
This commit is contained in:
Axel Kohlmeyer
2021-07-26 22:36:00 -04:00
parent cc87e7eee3
commit 458253b452
9 changed files with 447 additions and 2 deletions

View File

@ -248,6 +248,24 @@ class numpy_wrapper:
# -------------------------------------------------------------------------
def gather_bonds(self):
"""Retrieve global list of bonds as NumPy array
This is a wrapper around :py:meth:`lammps.gather_bonds() <lammps.lammps.gather_bonds()>`
It behaves the same as the original method, but returns a NumPy array instead
of a ``ctypes`` list.
.. versionadded:: 28Jul2021
:return: the requested data as a 2d-integer numpy array
:rtype: numpy.array(nbonds,3)
"""
import numpy as np
nbonds, value = self.lmp.gather_bonds()
return np.ctypeslib.as_array(value).reshape(nbonds,3)
# -------------------------------------------------------------------------
def fix_external_get_force(self, fix_id):
"""Get access to the array with per-atom forces of a fix external instance with a given fix ID.