Variable/atom does not update compute

Hello.
A bit of my input file is

compute  neighs     all coord/atom cutoff 1.5
variable is_monomer  atom c_neighs==0
variable not_monomer atom c_neighs!=0
group    monomers  variable is_monomer
group    clustered variable not_monomer

LAMMPS output:

999739 atoms in group monomers
0 atoms in group clustered

However, according to compute clusters all cluster/atom 1.5 output, there are clustered atoms at the same timestep.
It seems like variable is_monomer atom c_neighs==0 does not invokes compute_peratom() function of ComputeCoordAtom.
Is it right?
Is there a workaround for it to force compute update?

Please read and follow the forum guidelines posted here: Please Read This First: Guidelines and Suggestions for posting LAMMPS questions

Those state that you should always provide information about which LAMMPS version you are using and what platform you are running on, and how you configure/compiled it in case you compiled it yourself.

When I add this to the peptide example, I get the following error:

ERROR: Variable is_monomer: Variable formula compute cannot be invoked before initialization by a run (src/variable.cpp:1737)
Last command: group    monomers  variable is_monomer

Even if placed after the run, so you are not providing sufficient information here or else you should get the same error. Or you are using an older version of LAMMPS that does not print an error but should.

LAMMPS Version: (27 Jun 2024) (from github)
Platform:

Linux "SUSE Linux Enterprise Server 12 SP3" 4.4.73-5-default x86_64
GNU C++ 10.2.1 20201202 [revision e563687cf9d3d1278f45aaebd03e0f66531076c9] with OpenMP 4.5

Configuration:

cmake -D CMAKE_BUILD_TYPE=Release 
      -D BUILD_SHARED_LIBS=yes 
      -D BUILD_LIB=yes 
      -D PKG_PYTHON=yes 
      -D BUILD_MPI=yes 
      -D PKG_OPEMP=yes 
      -D BUILD_OMP=yes 
      -D LAMMPS_MACHINE=mpi 
      -D BUILD_TOOLS=yes 
      -D BUILD_LAMMPS_SHELL=no 
      -D BUILD_LAMMPS_GUI=no 
      -D PKG_ADIOS=yes 
      -D ADIOS2_DIR=/scratch/repos/ADIOS2/build_mpi/ 
      -D CMAKE_INSTALL_PREFIX=$VIRTUAL_ENV 
      -D Python_EXECUTABLE=$VIRTUAL_ENV/bin/python3.8 
       ../cmake
cmake --build . --parallel -j 16
make install
make install-python

in.file:


region allbox block 0 350 0 350 0 350 side in units box
create_box 1 allbox
mass 1 24
pair_style lj/cut 2.5
pair_coeff 1 1 1 1
pair_modify shift yes
timestep 0.01

read_data data.lmp add append
compute neighs all coord/atom cutoff 1.5
run 0

variable is_monomer atom c_neighs==0
variable not_monomer atom c_neighs!=0
group monomers variable is_monomer
group non_monomers variable not_monomer

My output (log.lammps):

LAMMPS (27 Jun 2024)
region allbox block 0 350 0 350 0 350 side in units box
create_box 1 allbox
Created orthogonal box = (0 0 0) to (350 350 350)
  1 by 1 by 1 MPI processor grid
mass 1 24
pair_style lj/cut 2.5
pair_coeff 1 1 1 1
pair_modify shift yes
timestep 0.01
read_data data.lmp add append
Reading data file ...
  orthogonal box = (0 0 0) to (350 350 350)
  1 by 1 by 1 MPI processor grid
  reading atoms ...
  1000188 atoms
  reading velocities ...
  1000188 velocities
  read_data CPU = 14.290 seconds
compute neighs all coord/atom cutoff 1.5
run 0

CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE

Your simulation uses code contributions which should be cited:

- Type Label Framework: https://doi.org/10.1021/acs.jpcb.3c08419

@Article{Gissinger24,
 author = {Jacob R. Gissinger, Ilia Nikiforov, Yaser Afshar, Brendon Waters, Moon-ki Choi, Daniel S. Karls, Alexander Stukowski, Wonpil Im, Hendrik Heinz, Axel Kohlmeyer, and Ellad B. Tadmor},
 title = {Type Label Framework for Bonded Force Fields in LAMMPS},
 journal = {J. Phys. Chem. B},
 year =    2024,
 volume =  128,
 number =  13,
 pages =   {3282–-3297}
}

CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE

WARNING: No fixes with time integration, atoms won't move (src/verlet.cpp:60)
Generated 0 of 0 mixed pair_coeff terms from geometric mixing rule
Neighbor list info ...
  update: every = 1 steps, delay = 0 steps, check = yes
  max neighbors/atom: 2000, page size: 100000
  master list distance cutoff = 2.8
  ghost atom cutoff = 2.8
  binsize = 1.4, bins = 251 251 251
  3 neighbor lists, perpetual/occasional/extra = 1 2 0
  (1) pair lj/cut, perpetual
      attributes: half, newton on
      pair build: half/bin/atomonly/newton
      stencil: half/bin/3d
      bin: standard
  (2) compute cluster/atom, occasional
      attributes: full, newton on
      pair build: full/bin/atomonly
      stencil: full/bin/3d
      bin: standard
  (3) compute coord/atom, occasional
      attributes: full, newton on
      pair build: full/bin/atomonly
      stencil: full/bin/3d
      bin: standard
Per MPI rank memory allocation (min/avg/max) = 279.5 | 279.5 | 279.5 Mbytes
   Step          Temp          E_pair         E_mol          TotEng         Press     
         0   0.65041229    -0.29642269     0              0.67919476     0.011745204  
Loop time of 6.8e-07 on 1 procs for 0 steps with 1000188 atoms

735.3% CPU use with 1 MPI tasks x 1 OpenMP threads

MPI task timing breakdown:
Section |  min time  |  avg time  |  max time  |%varavg| %total
---------------------------------------------------------------
Pair    | 0          | 0          | 0          |   0.0 |  0.00
Neigh   | 0          | 0          | 0          |   0.0 |  0.00
Comm    | 0          | 0          | 0          |   0.0 |  0.00
Output  | 0          | 0          | 0          |   0.0 |  0.00
Modify  | 0          | 0          | 0          |   0.0 |  0.00
Other   |            | 6.8e-07    |            |       |100.00

Nlocal:    1.00019e+06 ave 1.00019e+06 max 1.00019e+06 min
Histogram: 1 0 0 0 0 0 0 0 0 0
Nghost:          33647 ave       33647 max       33647 min
Histogram: 1 0 0 0 0 0 0 0 0 0
Neighs:     1.4329e+06 ave  1.4329e+06 max  1.4329e+06 min
Histogram: 1 0 0 0 0 0 0 0 0 0
FullNghs:            0 ave           0 max           0 min
Histogram: 1 0 0 0 0 0 0 0 0 0

Total # of neighbors = 1432901
Ave neighs/atom = 1.4326317
Neighbor list builds = 0
Dangerous builds = 0
variable is_monomer atom c_neighs==0
variable not_monomer atom c_neighs!=0
group monomers variable is_monomer
1000188 atoms in group monomers
group non_monomers variable not_monomer
0 atoms in group non_monomers
Total wall time: 0:00:15

Data file: Google Drive

Yes, this version has a known bug that is already fixed in the develop branch. Previously, LAMMPS would refuse to access computes in between runs altogether, but this was recently relaxed, however in this case by too much.

A compute must be “consumed” to have data available, and in general it is better to have a fix act as the consumer and access its data, since they have persistent storage while computes may become invalid, if the system changes. Typical fixes for this could be fix ave/atom 1 1 1 or fix store/state. E.g. with:

compute neighs all coord/atom cutoff 1.5
fix neighs all store/state 0 c_neighs
run 0 post no

variable is_monomer atom f_neighs==0
variable not_monomer atom f_neighs!=0
group monomers variable is_monomer
group non_monomers variable not_monomer

# clean up after the job is done
variable is_monomer delete
variable not_monomer delete
unfix neighs
uncompute neighs

This results in the output:

527222 atoms in group monomers
472966 atoms in group non_monomers
1 Like