Hi,
I am working on a project involving energy minimization for 3D Lennard-Jones binary glass with an external force field. Here below is the description:
(1) The force field is a bending force field, the function of which depends on positions of particles and depends on three variables, a, b and c. At any given configuration during an energy minimization step, I can solve linear equations to update a,b and c, in order to make total force and total torque equal to zero. To summarize, given a configuration, I can use an analytical expression from positions of particles to calculate a,b and c, and then update my force field.
Have you taken a look at "fix momentum"?
https://lammps.sandia.gov/doc/fix_momentum.htmlfix_momentum.cpp
Even if it doesn't do what you want, it might be a good starting point
for writing a new fix. (Terminology "fix" refers to any code which
controls the way atoms move during a simulation.) The C++ code for
"fix momentum" is located in these two files "fix_momentum.cpp" and
"fix_momentum.h". If you want to write your own custom fix, copy
these files and give them new names
Also check out "fix recenter"
https://lammps.sandia.gov/doc/fix_recenter.html
...and "fix spring"
https://lammps.sandia.gov/doc/fix_spring.html
https://lammps.sandia.gov/doc/fix_spring_self.html
--- how to create your own custom fix (if you need to) ---
replace "FixMomentum" with "FixNAMEofNEWfix" everwhere it appears in
"fix_momentum.h" and "fix_momentum.cpp".
Also change "momentum" to "name_of_new_fix" everywhere it appears.
If your fix requires numerical parameters to be supplied by the user,
then edit the constructor
(IE, FixMomentum::FixMomentum() near lines 33-67 of "fix_momentum.cpp")
The actual code that modifies the movement of the atoms is located in
FixMomentum::end_of_step()
...however if you are simply adding forces to the existing forces
acting on these atoms, then perhaps instead you should put this code
in
post_force() instead of end_of_step(). That's what "fix addforce" does.
The code for fix addforce is "fix_addforce.cpp"
For details, see:
https://lammps.sandia.gov/doc/Developer.pdf
here is another link:
https://lammps.sandia.gov/threads/msg77779.html
(probably irrelevant to what you are trying to do)
There may be other changes you need to make, but hopefully this gives
you some idea what to do.
Basically, find a fix which is similar to what you want to do, copy
the corresponding .h and .cpp files, rename the fix. You don't have
to understand what every line of code does. Just use these files as a
template.
Hope this helps get you started.
Andrew
P.S. Also, if you are unfamiliar with C++, perhaps these web sites
will help. (I did not choose these web sites very carefully)
http://www.cplusplus.com/doc/tutorial/classes/
http://www.learncpp.com/cpp-tutorial/89-class-code-and-header-files/