Vikas,

Try this:

variable dist_sq equal v_a1*v_a1+v_a2*v_a2+v_a3*v_a3

instead of:

variable dist_sq equal {a1}*{a1}+{a2}*{a2}+{a3}*{a3}

Also, please see:

http://lammps.sandia.gov/doc/variable.html

Specifically the following, which I’ll cut and paste from that page:

"Using a $x, the value of the include variable is substituted for immediately when the line is read from the input script, just as it would be in other input script command. This could be the desired behavior if a static value is desired. Or it could be the desired behavior for an equal-style variable if the variable command appears in a loop (see the jump and next commands), since the substitution will be performed anew each time thru the loop as the command is re-read. Note that if the variable formula is enclosed in double quotes, this prevents variable substitution and thus an error will be generated when the variable formula is evaluated.

Using a v_x, the value of the included variable will not be accessed until the variable formula is evaluated. Thus the value may change each time the evaluation is performed. This may also be desired behavior.

As an example, if the current simulation box volume is 1000.0, then these lines:

```
variable x equal vol
variable y equal 2*$x
```

will associate the equation string “2*1000.0” with variable y.

By contrast, these lines:

```
variable x equal vol
variable y equal 2*v_x
```

will associate the equation string “2*v_x” with variable y.

Thus if the variable y were evaluated periodically during a run where the box volume changed, the resulting value would always be 2000.0 for the first case, but would change dynamically for the second case."

Paul