Error in variable

Dear All,

I am going to compute the number of particles whose displacements are less than a given radius over time.
Using compute displace/atom, I defined a formula as a variable to obtain whether each particle is inside the sphere (radius), and then applied summation using “compute reduce” to get the number.

variable r equal 0.4
compute d all displace/atom
variable OD atom (c_d-${r})<0
compute OF all reduce sum v_OD
fix 1 all ave/time 2 1 2 c_OF file OF_file

But the code gives this error:
“overlapDisplace: Mismatched compute in variable formula”

The error still is there if I have only:
variable OD atom c_d

I have tested other commands and styles to debug the code, but my effort was not fruitful.
Would you please guide me with this?

(I tried to calculate the quantity using a post-processing analysis, but as can be expected it requires much more memory and energy.)

The answer is in the documentation:

A vector of four quantities per atom is calculated by this compute. The first three elements of the vector are the (dx,dy,dx) displacements. The fourth component is the total displacement (i.e. \sqrt{dx^2+dy^2+dz^2}).

Your code variable OD atom (c_d-${r})<0, however implies that the compute only computes a single per-atom property. To get the total displacement, you need to access the 4th element of the vector.

Thank you Axel for your fast reply and your help.