Hello everyone.
Now, I want to find neighbor list of each atom in each timestep. I followed Neighbor list access in LAMMPS but perhaps, it only shows neighbor list in the last timestep.
Thank you!
You have to explain in more detail what you are doing and how. Best would be to provide an example script that showcases your problem.
VARIABLES
variable n_iter equal 20000
######################################
INITIALIZATION
units metal
dimension 3
boundary p p p
atom_style atomic
variable latparam equal 4.05######################################
ATOM DEFINITION
lattice fcc ${latparam} orient x 1 0 0 orient y 0 1 0 orient z 0 0 1
region whole block 0 10 0 10 0 10
create_box 1 whole
create_atoms 1 region whole######################################
DEFINE INTERATOMIC POTENTIAL
pair_style eam/alloy
pair_coeff * * Al99.eam.alloy Al######################################
DEFINE COMPUTES
compute csym all centro/atom fcc
compute peratom all pe/atom######################################
EQUILIBRATION
reset_timestep 0
timestep 0.001
velocity all create 300 12345 mom yes rot no
fix 1 all npt temp 300 300 1 iso 0 0 1 drag 1Set thermo output
thermo 1000
thermo_style custom step lx ly lz press pxx pyy pzz pe tempRun for at least 10 picosecond (assuming 1 fs timestep)
run ${n_iter}
unfix 1Store final cell length for strain calculations
variable tmp equal “lx”
variable L0 equal {tmp} print "Initial Length, L0: {L0}"######################################
DEFORMATION
reset_timestep 0
fix 1 all npt temp 300 300 1 y 0 0 1 z 0 0 1 drag 1
variable srate equal 1.0e10
variable srate1 equal “v_srate / 1.0e12”
fix 2 all deform 1 x erate ${srate1} units box remap xOutput strain and stress info to file
for units metal, pressure is in [bars] = 100 [kPa] = 1/10000 [GPa]
p2, p3, p4 are in GPa
variable strain equal “(lx - v_L0)/v_L0”
variable p1 equal “v_strain”
variable p2 equal “-pxx/10000”
variable p3 equal “-pyy/10000”
variable p4 equal “-pzz/10000”
fix def1 all print 100 “{p1} {p2} {p3} {p4}” file Al_tens_100.def1.txt screen noUse cfg for AtomEye
dump 1 all cfg 250 dump.tens_*.cfg mass type xs ys zs c_csym c_peratom fx fy fz
dump_modify 1 element AlDisplay thermo
thermo 1000
thermo_style custom step v_strain temp v_p2 v_p3 v_p4 ke pe press
run ${n_iter}######################################
SIMULATION DONE
print “All done”
Above is my problem. I want to find out neighbor list of each atom in each timestep.
Thank you.
This is just a LAMMPS input running an MD simulation. There is no python involved here.
During a simulation run, you can only access the neighbor list from within LAMMPS, that means you have to write code on your own that is run (regularly) and then processes the neighborlist.
The access to the neighbor list from Python can only be done outside a run, so if you want to check the neighbor list in every step, you would have to do run 1 pre no post no
(assuming you make no changes to the system that require pre yes
).
What do you want to use the neighbor lists for? Storing all neighbor list data for every time step is prohibitively time and space consuming (LAMMPS usually optimizes the neighbor list rebuilds, so they often don’t change every step). In general, since typically everything you program in Python is about 100 times slower than what it would be in C++ code, this doesn’t sound like a good idea.
P.S.: your input file is not properly quoted and parts are not readable because the forum software interprets special characters as markup. If you had properly followed the forum guidelines, you would have used triple backquotes (```) instead.
from lammps import lammps
import numpy as np
lmp = lammps()
lmp.command(‘units lj’)
lmp.command(‘atom_style atomic’)
lmp.command (‘lattice fcc 0.8442’)
lmp.command(‘region box block 0 10 0 10 0 10’)
lmp.command(‘create_box 1 box’)
lmp.command(‘create_atoms 1 box’)
lmp.command(‘mass 1 1.0’)
lmp.command(‘velocity all create 1.44 87287 loop geom’)
lmp.command(‘pair_style lj/cut 2.5’)
lmp.command(‘pair_coeff 1 1 1.0 1.0 2.5’)
lmp.command(‘neighbor 0.3 bin’)
lmp.command(‘neigh_modify delay 0 every 20 check no’)
lmp.command(‘fix 1 all nve’)
lmp.command(‘run 100’)
nlidx = lmp.find_pair_neighlist(‘lj/cut’) # find neighbor list index of pair style neighbor list # returns: neighbot list index if found, otherwise -1 # return type: int
nl = lmp.numpy.get_neighlist(nlidx )
tags = lmp.extract_atom(‘id’)
print(“half neighbor list with {} entries”.format(nl.size))print neighbor list contents
for i in range(0,nl.size):
idx, nlist = nl.get(i) # return: tuple with atom local index, numpy arrat of neighbor local atom indices
print(“\natom {} with ID {} has {} neighbors:”.format(idx,tags[idx],nlist.size))
if nlist.size > 0:
for n in np.nditer(nlist): # nditer is to visit every element of an array
print(" atom {} with ID {}".format(n,tags[n]))
Above is python code which I want to run LAMMPS via python (it is just an example)
Actually, I want to find out neighbor list of each atom in each timestep which LAMMPS uses to calculate.
Your question: “What do you want to use the neighbor lists for?” - I need to find out neighbor list of each atom in each timestep to build a graph for Graph neural networks.
Could you help me give some code examples?
Thank you.
I already explained what you have to do, make a loop in python where you do 1 step MD, then access the neighbor list and repeat. As already mentioned, it will be hellishly inefficient.
Yes, thank you very much.
What about compute pair/local?