Comments below.
Steve
Hi Everyone,
I am using the (21 Dec 2011) LAMMPS version and am trying to apply a
potential dependent on only the x coordinate of particles in my system using
the fix addforce command, but have run into a few problems. After searching
the mail list and the user manual for what I believe were relevant keywords
and commands, I am still rather confused about what I should do. I apologize
for the length of this message, but I tried to keep it as simple and concise
as possible.
To verify that the potential has the shape I want, I decided to:
create a box and insert a single test particle
loop over several x coordinates for that particle. For each iteration, I use
"run 0" then print the x-coord and the potential energy to an output file.
plot the potential energy vs. x-coord
The following is an excerpt of my input script:
____________________
variable force_x atom 2x
fix the_potential sodium addforce v_force_x NULL NULL
fix_modify the_potential energy yes
variable curr_x equal 5
variable delta_x equal 1
variable valx loop 5000
label next_one
variable curr_x equal \{curr\_x\}\-{delta_x}
set group sodium x \{curr\_x\}
run 0
variable spe equal f\_the\_potential
shell echo {curr_x} \{spe\} >> pe\_vs\_x\.dat
if "{curr_x} <= 0" then "jump in.no_crystal_edit
exit_loop"
next valx
jump in.no_crystal_edit next_one
label exit_loop
____________________
I receive the following error message in my log file after line 10: "ERROR:
Invalid syntax in variable formula"
My questions:
* According to my version's LAMMPS manual fix addforce doc page, it appears
I need to use v_variable, not ${variable} to call my force variables.
Additionally, v_variable must be of the "atom" type if I want to have a
per-atom potential calculated in the future. Am I correct in my
interpretation?
yes
* Why is the following the case?
- When I hard-code "2x" into line 2 and change nothing else in the script,
my output file (pe_vs_x.dat) file gives me exactly what I would expect:
5 -10
4 -8
3 -6
2 -4
1 -2
0 0
- But if I hard-code something like "sin(x)" or "exp(x)," the potential
energy for every x-coord is 0 in my output file. I also tried "sin(2.0*x)"
to make the numbers floats in case that was the problem, but still got 0 PE
for all x-coord.
* Do I need to modify line 11 of the excerpt in some way?
* Do you have any other suggestions for where I could look or what I could
do?
Thank you so much for your time and attention. I really appreciate any
thoughts or suggestions you have to offer!
With best regards,
Carol (incoming first-year graduate student at UCSB)
2x is in not a valid syntax for a variable formula. It has to be 2*x.
When I put these lines in bench/in.lj
variable force_x atom 2x
fix the_potential all addforce v_force_x NULL NULL
dump 1 all custom 10 tmp.dump id x y x fx fy fz
run 0
I get this error:
ERROR: Invalid syntax in variable formula (variable.cpp:713)
If you don't get that error, are you running the current version of LAMMPS?
If I replace 2x by 2*x, it runs fine and the dump file shows
that every atom has a force that is twice its x coord, which is
the correct result. I suggest you dump
forces on your atom into a file and look at them directly.
Once you are confident those are correct you can debug the
rest of your script and its loop to see if you can get them printed
to the screen.
Steve