help in lammps

I want to define an electric field consisted of two parts:
variable p2 atom “y^2+z^2”
if "p2 = 0 " then “fix h a efield v_Ex 0 0”
else &
“fix h a efield v_Ex v_Ey v_Ez”
so I have two different fields,I already know that I can’t use v_x in if command and it should be as $x but I can’t use $x in atom style.

pls help me.
mahdi

I want to define an electric field consisted of two parts:
variable p2 atom "y^2+z^2"
if "p2 = 0 " then "fix h a efield v_Ex 0 0"
else &
"fix h a efield v_Ex v_Ey v_Ez"
so I have two different fields,I already know that I can't use v_x in if
command and it should be as $x but I can't use $x in atom style

​this is wrong ​and confusing on so many levels, i don't really know where
to begin:

on 'if "p2 = 0"' :

1) "=" is not for comparing equality, "==" is.

2) you are comparing strings, p2 is not referring to the p2 variable

3) it is a very bad idea to compare floating point numbers (which is what
v_p2 would evaluate to) for equality due to the idiosyncrasies of floating
point math

4) the if statement is a global comparison that is only evaluated when the
input line is processed, so it doesn't make sense to use a variable that
may change later

5) the purpose of the if statement is apparently, apply one fix definition
to all atoms when the condition is true and the other fix to atoms when the
condition is false. that is not how LAMMPS works. the fix commands creates
a global instance of the fix. you can select which atoms it applies to via
groups. using the if statement this way is against the entire logic of
LAMMPS scripting.

6) this is implied in the previous point, but it makes not sense at all to
use an atom style variable in a global context.

on using two different fields:

7) it is not clear whether you want to decide which atoms to assign the two
fields dynamically during the run or is this a one time choice. the latter
case is easy to handle: define two groups, define two fixes each working on
one of the two groups. the former case is a bad idea. you'll having a step
function in the force which will result in all kinds of artefacts, e.g.
density anomalies around the singularity.

​8) of course, if you absolutely insist, you *can* implement this kind of
thing in LAMMPS, and you only need one fix for it, as you can use boolean
expressions in atom and equal style variables​. they will evaluate to
either 0.0 or 1.0 depending on whether the expression is false or true. so
just multiplying an optional component with the boolean expression with
turn it on or off automatically.

​on "$x vs v_x":

9) i honestly don't understand what you mean by this, but since you have
pretty much misunderstood everything else related to what you quoted as
script code, it is safe to assume that you are misunderstanding something
here as well.​

pls help me.

​you have to help yourself first. and a *lot*. ​from what you present, you
have to reread the documentation with much more care and revisit all the
details that you have misunderstood. you obviously are trying something
that is far too advanced for you level of understanding. that is bound to
send you on the road to frustration, confusion and ultimately doom.

axel.