Dear all,
I am simulating a network where a specific atom type is allowed to swap from one junction to another thereby changing its connectivity. I am using fix bond/swap for this. I am also interested in getting the swap locations after every swap event and for this purpose, I am using the compute/property local btype batom1 batom2 with dump local to get the bond topology at a given timestep. I am trying to compare the differences in bond topologies between different timesteps for a specific bond type (btype) to eventually get the indexes of atoms that have swapped/changed their bond connectivity with time. Following is the command I used:
compute 1 all property/local btype batom1 batom2
dump 1 all local ${nevery} bonds.txt c_1[1] c_1[2] c_1[3]
However the dump file will be huge since I write it out after every swap, hence I am looking for a way to output only a specific bond type that I am interested instead of all the bonds. I looked at the documentation and went through previous threads and understand there are very limited ways to access the local vector/array, hence dump_modify does not work. I just wanted to check if there is a way to selectively output this information as an alternative to post-processing the large dump file.
Thank you,
Shalini
This is a bit of a tricky issue and cannot be resolved without some programming.
However, this is also a good example for how one can augment LAMMPS’ functionality with creative use of the python wrapper and PYTHON package interface.
For the following to work, you have to have a version of LAMMPS that includes the PYTHON package AND has the python wrapper installed.
The general idea is to access the data from the local compute from a python function and then process the list and output only the desired data.
The python function is connected to a python style variable, that needs to be triggered in every timestep (but you do not use its result). here is the code:
compute bnd all property/local btype batom1 batom2
variable dummy python blist
python blist input 1 SELF return v_dummy format pi here “”"
def blist (self):
from lammps import lammps,LAMMPS_BIGINT
lmp = lammps(ptr=self)
blen = lmp.extract_compute(“bnd”,2,0)
bonds = lmp.extract_compute(“bnd”,2,2)
step = lmp.extract_global(“ntimestep”,LAMMPS_BIGINT)
for i in range(blen):
if bonds[i][0] == 5:
print("%d: %d d" (step,bonds[i][1],bonds[i][2]))
return 0
“”"
fix trigger all ave/time 1 1 1 v_dummy
To explain:
- the variable command links the python function blist() to the variable dummy
- the fix ave/time is used to invoke the python function in every time step
- the python command defines the python function and specifies, that the pointer to the LAMMPS object is passed as the first argument
- inside the python command, it load the LAMMPS python module and creates a python LAMMPS instance, that is linked to the existing LAMMPS object calling it
- then it extracts the timestep, the local array and its length (will be different on each processor), and then loops over it and outputs the timestep, a colon, and the constituent atoms of the bond of the given bond type 5
- this prints the information to the screen for simplicity, but it is possible to load a python MPI package and then communicate the detected data and have MPI rank 0 output the selected info to a file. this is a trivial exercise in MPI programming.
There is one major caveat. For this to work, you need to fix a bug in the lammps.py wrapper with the following change:
diff --git a/python/lammps.py b/python/lammps.py
index 2e597f9e1…84ce22e9f 100644
— a/python/lammps.py
+++ b/python/lammps.py
@@ -486,6 +486,7 @@ class lammps(object):
return None
elif style == 2:
self.lib.lammps_extract_compute.restype = POINTER(c_int)
- ptr = self.lib.lammps_extract_compute(self.lmp,id,style,type)
return ptr[0]
if type == 1:
self.lib.lammps_extract_compute.restype = POINTER(c_double)
HTH,
Axel.