How to resolve errors in print command output

Respected all,

I am not able to resolve the issue regarding printing a variable or fix print command.
At end of the following script , I have mentioned the various cases and corresponding output.
I want to look at the value of v1 which is actually vx(i), for atom i.

My ultimate aim is to get overall velocity (vel) magnitude for particular atom using vx, vy, vz of corresponding atom and then get its ave/correlate.

Please help me in this context as I am also not able to define variable ‘vel’ in terms of v1,v2,v3 which are actually vx,vy,vz correspondingly.

Respected all,

I am not able to resolve the issue regarding printing a variable or fix print command.
At end of the following script , I have mentioned the various cases and corresponding output.
I want to look at the value of v1 which is actually vx(i), for atom i.

My ultimate aim is to get overall velocity (vel) magnitude for particular atom using vx, vy, vz of corresponding atom and then get its ave/correlate.

Please help me in this context as I am also not able to define variable 'vel' in terms of v1,v2,v3 which are actually vx,vy,vz correspondingly.

variable a loop 4
print "A = $a"
group part id $a

thermo 1
thermo_style custom step temp pe
dump 2 part custom 1 vacf_adp_$a.dat id type x y z vx vy vz

variable tmp atom vx[a\] variable v1 equal tmp \#print " vx = {tmp} "
#print " vx = v_tmp "
print " vx = $(v_v1) "

Cases and errors:
Case A: print " vx = \(v\_v1\) " error : ERROR: Invalid thermo keyword in variable formula \(\.\./variable\.cpp:2037\)               Last command: vx = (v_v1

Case B: print "vx = v_v1"
No error but result is, " vx = v_v1 " in output file.

Case C: print " vx = ${v_v1} "
Error : Substitution for illegal variable (for each processor)

======================================================
I will be thankful, if someone clarify me the reason behind this errors.
Like : 1.how to validate the thermo keyword, or what else can be used?
           2. what is referred as illegal variable?

the illegal variable is "tmp" and the problem is the line

variable v1 equal tmp

I am not able to resolve it out from information given in lammps manual.

the documentation for the variable command clearly states, that you
have to use v_name to refer to the variable "name" inside a variable
formula. any name in a variable formula, that LAMMPS cannot identify
otherwise, is assumed to be a thermo keyword; hence the error message.

if you would be using a more recent LAMMPS version, you would be
getting a more detailed, specific, and helpful error message like
this:

variable tmp equal 1.0
variable v1 equal tmp
print "v1 = \{v1\}" ERROR: Variable v1: Invalid thermo keyword 'tmp' in variable formula \(src/variable\.cpp:2097\) Last command: v1 = {v1

also, your definition of tmp 'variable tmp atom vx[$a]' makes no
sense. while vx is a per-atom property, vx[$a] is not. and an
atom-style variable is not compatible with an equal style expression
(when you correct the definition of v1). so you'll get the following:

variable a equal 1
variable tmp atom vx[a\] variable v1 equal v\_tmp print "vx = {v1}"
ERROR: Variable tmp: Atom-style variable in equal-style variable
formula (src/variable.cpp:1913)
Last command: vx = ${v1

so this would have to be corrected by using

variable tmp equal vx[$a]

all of this *is* documented in the variable command documentation, and
also the print command clearly documents how you have to refer to
variables (almost all of your options are not consistent with that).
it seems, that your search for solutions has been discounting the
fact, that you may have multiple errors in multiple expressions, as
errors in expressions of variables can only be detected when the
variable is evaluated.

axel.

Respected all,

I have tried several options, but still, the error persists.

Respected all,

I have tried several options, but still, the error persists.

well, it is not *the* error, but a plethora of errors, and most of
them have a good explanation, are documented, or are due to your
violating the documented syntax. you need to *significantly* improve
your skills at reading documentation.

=====================================================
variable tmp equal vx[$a]
print " vx = v_tmp "
Not showing any error but just printing " vx = v_tmp " , no value for v_tmp.

yes, that is documented and expected behavior. as the documentation
states, print identifies variables by being prefixed with a '$' not a
'v_'. expecting this to lead to an expansion of the variable is
ignoring the documentation.

===========================================================
variable tmp equal vx[a\] ERROR: Indexed per\-atom vector in variable formula without atom map \(\.\./variable\.cpp:4404\) Last command: vx = {tmp
(But mapping is done in the starting of script)
# Initialization
units metal
boundary p p p
atom_style atomic
atom_modify id yes map yes first part
#read_data Ni3Fe_f100_ADP_3C.dat
label loopa
read_restart npt_Ni3Fe.100

but the read_restart command will override it, if the restart was
stored without an atom map. please see the read_restart documentation
for what properties are stored and read from a restart file.

===============================================================
variable tmp atom vx OR vx[a\] print " vx = {tmp} "
1 atoms in group part
ERROR on proc 0: Substitution for illegal variable tmp (../input.cpp:545)

again, this is documented behavior. you cannot expand an atom style
variable in a scalar context. this has to be an equal or similar style
variable.

================================================================
variable tmp equal vx[$a]
ERROR: Dump custom variable is not atom-style variable (../dump_custom.cpp:1426)
Last command: dump 2 part custom 1 vacf_adp_$a.dat id type x y z vx vy vz v_tmp

again, this is documented behavior (and makes no sense in the first
place). you can only output per-atom properties in (regular) dump
files. an equal style variable is a scalar property and thus does not
qualify, as the error message *clearly* indicates.

====================================================================
variable tmp atom vx[$a]
ERROR: Indexed per-atom vector in variable formula without atom map (../variable.cpp:4404)

Last command: run 10

But this command (atom_modify) is used at the top just after atom_style

Please help me in resolving this. Thankfully.

you need to spend more time reading the documentation and thinking
logically. you seem to be thinking that just trying random things
(most of which are documented to be not applicable in the context you
are using them) and then complaining about them here, is going to
solve your issues. but be aware, that this procedure will alienate
people and thus you may only get help so many times, and will be
ignored, when you are having a serious problem, where asking here is
justified (unlike this issue, which should be easily solvable, but
just following the hints from the error messages and systematically
debugging your input step by step and checking for active settings
etc.).

i already pointed out, that more recent LAMMPS versions, provide much
better help and more detailed information with variable expansion
errors, and there also is the info command, that allows detailed
introspection of all kinds of settings and properties.

this all looks like it is a serious case of PEPKAC.

axel.

To Dr. Axel,

Thank you for your valuable comments, Sir. The error was in read_restart as didn’t have atom_modify command when it was created.
My understanding regarding variable, its type, formula and syntax for it, is enhanced.

Thank you for your patient response respected Sir.