Re: [lammps-users] Accessing number of bonds in python operated LAMMPS or length of internal LAMMPS data array
Axel Kohlmeyer <akohlmey@...24...>
Fri, 13 Apr 2018 08:53:16 -0400
On Fri, Apr 13, 2018 at 7:51 AM, Robert Meißner <robert.meissner@...3174...27...> wrote:
> Dear LAMMPS Developers,
> since I'm facing the same problem right now, has there been any progress
> achieved on this matter? I want to extract the bond topology to
> create/delete some distinct bonds by identifying atoms from their bonded
> neighbors. If I'm running LAMMPS from python (thus in serial) the following
FWIW, you can also launch the python interpreter in parallel (via
pypar or mpi4py).
> code will give me something which works:
> import numpy as np
> bonds = np.array(,dtype=int).reshape(-1,3);
> def bond_topology(lmpptr):
> from lammps import lammps
> lmp = lammps(ptr=lmpptr)
> global bonds
> lmp.command("compute bonds all property/local btype batom1 batom2")
> lmp.command("run 0")
> nbonds = lmp.extract_global("nbonds",0)
> b = lmp.extract_compute("bonds",2,2)
> for i in range(nbonds):
> if b[i]: bonds = np.vstack([bonds,[b[i],b[i],b[i]]])
> lmp.command("uncompute bonds")
this just works by accident and not by construction. it looks to me,
the straightforward way to address this would be to add a scalar
context to compute bond/local (and other local computes) which then
allows to obtain the desired (and currently inaccessible) information
of the local array lengths.
steve, do you agree? or am i overlooking something?
> However, when running python from LAMMPS obviously every MPI proc starts his
> own python interpreter and has only his local bond topology making this code
> fragment pretty useless since I need the full topology. Maybe someone has
> already made a routine like lmp.gather_bonds(...) or something similar to
> get the topology from python?
what you see (in the source) is what you get. the philosophy is that
library.cpp is deliberately incomplete and that only then functions
are added to library.cpp, when people have a demonstrated need that
cannot be satisfied differently.
yours certainly fits the bill, however, i am not aware of any effort
to make the topology information available.
in general, please be very cautious when making changes to the bond
topology in LAMMPS. it is quite tricky to do so when running in
parallel. for performance reasons, many parts of LAMMPS assume that
the bond topology does not change, so data structures are initialized
at the beginning of a run. so those need to be updated when changes
are made, and in particularly updated consistently across all parallel
ranks. the (rather recently added) ability to access the python
interface from within a run and thus perform modifications, that were
previously only possible outside a run, has opened the door to a lot
of ways to make the internal state of LAMMPS inconsistent. if you are
using the very latest version of LAMMPS, multiple problematic classes
of interface calls are now prohibited.
> Prof Dr.-Ing Robert Horst Meißner
> Institute of Polymer and Composites
> Denickestr. 15
> D-21073 Hamburg
> Tel.: +49 (0)40 42878 2580
> E-mail: robert.meissner@...4427...
> Homepage: www.tuhh.de/alt/kvweb
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> lammps-users mailing list
Dr. Axel Kohlmeyer akohlmey@...24... http://goo.gl/1wk0
College of Science & Technology, Temple University, Philadelphia PA, USA
International Centre for Theoretical Physics, Trieste. Italy.