if command for atom style variable

Hi,
I’m going to implement an electric field on a polymer.I have a condition for my field.my code is something like this
variable ex atom x
variable Ex atom v_E
variable Ey atom v_diry/v_r
variable Ez atom v_dir
z/v_r

fix h a efield v_Ex v_Ey v_Ez

I want to have a condition in this form : if ex <0 then dir = 1 else then dir=-1
this is what I wrote based on manual but it didn’t work :

variable ex atom x

if “(v_ex)<0” then “variable dir equal 1” else “variable dir equal -1”

and also tried this :

if “${ex}<0” then “variable dir equal 1” else “variable dir equal -1”

variable Ex atom v_E
variable Ey atom v_diry/v_r
variable Ez atom v_dir
z/v_r

fix h a efield v_Ex v_Ey v_Ez

and I’m getting this error constantly

if “v_ex<0” then “variable dir equal 1” else “variable dir equal -1”
ERROR: Invalid Boolean syntax in if command (…/variable.cpp:3825)

please help me.

Hi,
I'm going to implement an electric field on a polymer.I have a condition for
my field.my code is something like this
variable ex atom x
variable Ex atom v_E
variable Ey atom v_dir*y/v_r
variable Ez atom v_dir*z/v_r

fix h a efield v_Ex v_Ey v_Ez

I want to have a condition in this form : if ex <0 then dir = 1 else then
dir=-1
this is what I wrote based on manual but it didn't work :

variable ex atom x

if "(v_ex)<0" then "variable dir equal 1" else "variable dir equal -1"
and also tried this :
if "${ex}<0" then "variable dir equal 1" else "variable dir equal -1"

variable Ex atom v_E
variable Ey atom v_dir*y/v_r
variable Ez atom v_dir*z/v_r

fix h a efield v_Ex v_Ey v_Ez

and I'm getting this error constantly

and it is a well deserved error. the way you want to use the if
command makes no sense at all. it doesn't operate like this. just look
at its documentation and you should understand. you simply cannot have
a global operation being executed on a per (local) atom basis.

if "v_ex<0" then "variable dir equal 1" else "variable dir equal -1"
ERROR: Invalid Boolean syntax in if command (../variable.cpp:3825)

please help me.

you need to include your logical expressions into the atom style
variable definitions, because what you want is a decision that is made
locally not globally. keep in mind that logical expressions in a
variable formula will evaluate to either 1.0 or 0.0 depending on
whether it is true or false. thus your variable expressions would
simply become:

variable Ey atom (x<0)*-y/v_r+(x>=0)*y/v_r
variable Ez atom (x<0)*-z/v_r+(x>=0)*z/v_r

axel.