Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Expose neighbor lists via library interface - Second iteration #1674
Exposes neighbor lists via the C library interface and in the Python library.
L = lammps() L.file('in.melt') nlocal = L.extract_global("nlocal", 0) nghost = L.extract_global("nghost", 0) x = L.numpy.extract_atom_darray("x", nlocal+nghost, dim=3) v = L.numpy.extract_atom_darray("v", nlocal+nghost, dim=3) f = L.numpy.extract_atom_darray("f", nlocal+nghost, dim=3) # return neighbor list object, which encapsulates access via library interface mylist = L.find_pair_neighlist("lj/cut") # return length of list len(mylist) # or mylist.size # get neighbors of list element 0 iatom, numneigh, neighs = mylist # ^ ^ ^ # | | | # | | + ------- neighbors of iatom (numpy arrray of integer indices) # | +-------------- number of neighbors of iatom # +--------------------- index of atom that is element 0 in neighbor list # equivalent: iatom, numneigh, neighs = mylist.get(0) # neighbor list can also be used as iterator for iatom, numneigh, neighs in mylist: print(x[iatom], v[iatom], f[iatom], " : ", numneigh, "Neighbors") for jatom in neighs: if jatom < nlocal: print(" * [LOCAL]", jatom, x[jatom], v[jatom], f[jatom]) else: print(" * [GHOST]", jatom, x[jatom], v[jatom], f[jatom])
@rbberger (Temple U)
By submitting this pull request, I agree, that my contribution will be included in LAMMPS and redistributed under either the GNU General Public License version 2 (GPL v2) or the GNU Lesser General Public License version 2.1 (LGPL v2.1).
Adds the following library functions to the library interface:
// search for neighbor list for pair style, returns index int lammps_find_pair_neighlist(void* ptr, char * style, int nsub, int request); // search for neighbor list for fix, returns index int lammps_find_fix_neighlist(void* ptr, char * id, int request); // search for neighbor list for compute, returns index int lammps_find_compute_neighlist(void* ptr, char * id, int request); // get total size of neighbor list of given index int lammps_neighlist_num_elements(void* ptr, int idx); // return atom id, numneigh and neighbors of neighbor list element void lammps_neighlist_element_neighbors(void * ptr, int idx, int element, int * iatom, int * numneigh, int ** neighbors);
The Python library interface uses these functions via CTypes. For ease of use they have been wrapped in a utility class called
def get_neighlist(self, idx): .... def find_pair_neighlist(self, style, nsub=0, request=0): .... def find_fix_neighlist(self, fixid, request=0): ... def find_compute_neighlist(self, computeid, request): ...
To enable the
Post Submission Checklist
Please check the fields below as they are completed after the pull request has been submitted. Delete lines that don't apply
Further Information, Files, and Links
Put any additional information here, attach relevant text or image files, and URLs to external sites (e.g. DOIs or webpages)
sjplimp left a comment
Looking good - just document more for user
@rbberger I like the added examples/python script. I like the (added?) Python library doc page.
@rbberger Ah, now I did a make html on the doc pages and see the Neigh list content added at the end of Python_library.html. I didn't see how that was done in the *.rst file. So that content is coming from library.cpp itself? Is the plan to do that for all the methods, both in Python_library and in Howto_library? Are you wanting to wait on this PR until that is done?
@sjplimp so what I did is getting source documentation from Python code (
If you approve, I could then add markup in
The alternative is to write it manually in
@rbberger What I don't understand about this syntax for either Python or cpp files is how much flexibility there is to adding comments or explanations. In the current Howto_library.rst I think the section that explains the lib methods in paragraphs is useful in addition to the prototypes. Similiarly there are text explanations in library.cpp beyond just one line per argument. Maybe if you could send me the 2 actual HTML pages and corresponding Python and library.cpp files, I would understand better.
@rberger I'm not clear if you are waiting on me for something on this one. I am fine with the code additions. Just a good way to document both the lib and Python interface is what I am still unclear on.