[lammps-users] compute vector quantity

Simple question; Once I perform a compute that generates a global vector, how can I ‘get’ that vector (either for writing to a file or using in computations)?

I’m trying to print/dump the c_ID[] variable that should be created by the compute but this only causes errors when run. Here’s an abridged example of what I’m trying on a my elco class:


units metal
boundary p p p
atom_style atomic
neighbor 0.3 bin
neigh_modify delay 5
lattice fcc 4.078
region box block 0 4 0 4 0 4
create_box 1 box
create_atoms 1 box
pair_style eam/alloy
pair_coeff * * some_potential

#where i’m confused
fix 1 all nve
compute 1 all elco #
run 1
print $c_1 #also tried: fix 1 all print $c_1[0] and many variations there of

The error:

ERROR on proc 0: Substitution for illegal variable
[0] MPI Abort by user Aborting program !
[0] Aborting program!
p0_7266: p4_error: : 1

I’ve also tried other (stable/working) computes such as thermo, heat_flux, and pressure which all use global vectors.

It feels like I’m missing something that would force the compute_vector() function to be called (and create the $c_1 variable) but I can’t seem to figure out what that is. Appreciate the help guys.


I would suggest that you define a variable in terms of the desired
compute and then print out that variable. For example,

compute 1 all elco
variable a equal c_1
run 1
print $a


I’ve tried that as well, and it comes up with the same error.

I think I am having the same problem. I get the same error with your script, with a slightly different wording:
ERROR on proc 0: Substitution for illegal variable
ERROR on proc 1: Substitution for illegal variable
(etc. for all the processors)
MPI_ABORT invoked on rank 0 in communicator MPI_COMM_WORLD with errorcode 1 (etc …rank 1, 2 …)

I have also been trying to print global vectors using fix ave/time; that is why I tried using compute reduce; because I can instead print out a global scalar. If I use fix ave/time with a global vector I get a different error from what fix print says:
ERROR: Fix ave/time compute does not calculate a vector

Fix ave/time seems to works for me sometimes (depending on what compute I used, I think?) for a global scalar. So, if you think your problem is that your compute isn’t being called at all, perhaps you can try to spit it out from fix ave/time, the whole vector or just c_1[1], and see what happens.


I’m unable to get a valid fix ave/time command working which is probably due to it being a Friday evening.

However, my fix ave/time matches the example command in the manual. So again it seems like the problem is that c_ID[] is not being computed or we’re not accessing it properly.

BTW my code for the fix ave/time:

compute 1 all temp
fix 2 all ave/time 1 1 1 c_1[1] title1 “Fix ave/time output:”


Add these lines to bench/in.lj - they illustrate all the options.
Note that compute temp can produce both a scalar and a 6-vector.

compute 1 all temp
fix 2 all ave/time 100 1 100 c_1 file tmp.scalar
fix 3 all ave/time 100 1 100 c_1 mode vector file tmp.vector
fix 4 all ave/time 100 1 100 c_1[1] file tmp.scalar_from_vector

Also note, that if you want fix ave/time to work on vectors, you need
to give it the mode vector option.

You can't do something like "print $c_1[1]".
You can define a variable that evaluates c_1[1] and then
print that variable.


Answer below.