2010-09-17 03:46:13 +08:00
|
|
|
<HTML>
|
|
|
|
<CENTER><A HREF = "http://lammps.sandia.gov">LAMMPS WWW Site</A> - <A HREF = "Manual.html">LAMMPS Documentation</A> - <A HREF = "Section_commands.html#comm">LAMMPS Commands</A>
|
|
|
|
</CENTER>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<HR>
|
|
|
|
|
|
|
|
<H3>fix external command
|
|
|
|
</H3>
|
|
|
|
<P><B>Syntax:</B>
|
|
|
|
</P>
|
2013-01-05 01:15:59 +08:00
|
|
|
<PRE>fix ID group-ID external mode args
|
2010-09-17 03:46:13 +08:00
|
|
|
</PRE>
|
2013-01-05 01:15:59 +08:00
|
|
|
<UL><LI>ID, group-ID are documented in <A HREF = "fix.html">fix</A> command
|
|
|
|
|
2010-09-17 03:46:13 +08:00
|
|
|
<LI>external = style name of this fix command
|
2013-01-05 01:15:59 +08:00
|
|
|
|
|
|
|
<LI>mode = <I>pf/callback</I> or <I>pf/array</I>
|
|
|
|
|
|
|
|
<PRE> <I>pf/callback</I> args = Ncall Napply
|
|
|
|
Ncall = make callback every Ncall steps
|
|
|
|
Napply = apply callback forces every Napply steps
|
|
|
|
<I>pf/array</I> args = Napply
|
|
|
|
Napply = apply array forces every Napply steps
|
|
|
|
</PRE>
|
|
|
|
|
2010-09-17 03:46:13 +08:00
|
|
|
</UL>
|
|
|
|
<P><B>Examples:</B>
|
|
|
|
</P>
|
2013-01-05 01:15:59 +08:00
|
|
|
<PRE>fix 1 all external pf/callback 1 1
|
|
|
|
fix 1 all external pf/callback 100 1
|
|
|
|
fix 1 all external pf/array 10
|
2010-09-17 03:46:13 +08:00
|
|
|
</PRE>
|
|
|
|
<P><B>Description:</B>
|
|
|
|
</P>
|
2013-01-05 01:15:59 +08:00
|
|
|
<P>This fix allows external programs that are running LAMMPS through its
|
|
|
|
<A HREF = "Section_howto.html#howto_19">library interface</A> to modify certain
|
|
|
|
LAMMPS properties on specific timesteps, similar to the way other
|
|
|
|
fixes do. The external driver can be a <A HREF = "Section_howto.html#howto_19">C/C++ or Fortran
|
|
|
|
program</A> or a <A HREF = "Section_python.html">Python
|
|
|
|
script</A>.
|
2010-09-17 03:46:13 +08:00
|
|
|
</P>
|
2013-01-05 01:15:59 +08:00
|
|
|
<HR>
|
|
|
|
|
|
|
|
<P>If mode is <I>pf/callback</I> then the fix will make a callback every
|
2013-07-30 08:16:10 +08:00
|
|
|
<I>Ncall</I> timesteps or minimization iterations to the external program.
|
2013-01-05 01:15:59 +08:00
|
|
|
The external program computes forces on atoms by setting values in an
|
|
|
|
array owned by the fix. The fix then adds these forces to each atom
|
|
|
|
in the group, once every <I>Napply</I> steps, similar to the way the <A HREF = "fix_addforce.html">fix
|
|
|
|
addforce</A> command works. Note that if <I>Ncall</I> >
|
|
|
|
<I>Napply</I>, the force values produced by one callback will persist, and
|
|
|
|
be used multiple times to update atom forces.
|
|
|
|
</P>
|
2013-01-05 01:20:04 +08:00
|
|
|
<P>The callback function "foo" is invoked by the fix as:
|
2010-09-17 03:46:13 +08:00
|
|
|
</P>
|
2013-01-05 01:20:04 +08:00
|
|
|
<PRE>foo(void *ptr, bigint timestep, int nlocal, int *ids, double **x, double **fexternal);
|
2010-09-17 03:46:13 +08:00
|
|
|
</PRE>
|
|
|
|
<P>The arguments are as follows:
|
|
|
|
</P>
|
|
|
|
<UL><LI>ptr = pointer provided by and simply passed back to external driver
|
|
|
|
<LI>timestep = current LAMMPS timestep
|
|
|
|
<LI>nlocal = # of atoms on this processor
|
|
|
|
<LI>ids = list of atom IDs on this processor
|
|
|
|
<LI>x = coordinates of atoms on this processor
|
2013-01-05 01:15:59 +08:00
|
|
|
<LI>fexternal = forces to add to atoms on this processor
|
2010-09-17 03:46:13 +08:00
|
|
|
</UL>
|
2013-01-05 01:20:04 +08:00
|
|
|
<P>Note that timestep is a "bigint" which is defined in src/lmptype.h,
|
|
|
|
typically as a 64-bit integer.
|
|
|
|
</P>
|
2013-01-05 01:15:59 +08:00
|
|
|
<P>Fexternal are the forces returned by the driver program.
|
2010-09-17 03:46:13 +08:00
|
|
|
</P>
|
2013-01-05 01:15:59 +08:00
|
|
|
<P>The fix has a set_callback() method which the external driver can call
|
|
|
|
to pass a pointer to its foo() function. See the
|
|
|
|
couple/lammps_quest/lmpqst.cpp file in the LAMMPS distribution for an
|
|
|
|
example of how this is done. This sample application performs
|
|
|
|
classical MD using quantum forces computed by a density functional
|
|
|
|
code <A HREF = "http://dft.sandia.gov/Quest">Quest</A>.
|
2010-09-17 03:46:13 +08:00
|
|
|
</P>
|
|
|
|
|
|
|
|
|
2013-01-05 01:15:59 +08:00
|
|
|
<HR>
|
|
|
|
|
|
|
|
<P>If mode is <I>pf/array</I> then the fix simply stores force values in an
|
|
|
|
array. The fix adds these forces to each atom in the group, once
|
|
|
|
every <I>Napply</I> steps, similar to the way the <A HREF = "fix_addforce.html">fix
|
2013-01-05 01:20:04 +08:00
|
|
|
addforce</A> command works.
|
2013-01-05 01:15:59 +08:00
|
|
|
</P>
|
2013-07-30 08:16:10 +08:00
|
|
|
<P>The name of the public force array provided by the FixExternal
|
|
|
|
class is
|
|
|
|
</P>
|
|
|
|
<PRE>double **fexternal;
|
|
|
|
</PRE>
|
|
|
|
<P>It is allocated by the FixExternal class as an (N,3) array where N is
|
|
|
|
the number of atoms owned by a processor. The 3 corresponds to the
|
|
|
|
fx, fy, fz components of force.
|
|
|
|
</P>
|
2013-01-05 01:20:04 +08:00
|
|
|
<P>It is up to the external program to set the values in this array to
|
|
|
|
the desired quantities, as often as desired. For example, the driver
|
|
|
|
program might perform an MD run in stages of 1000 timesteps each. In
|
|
|
|
between calls to the LAMMPS <A HREF = "run.html">run</A> command, it could retrieve
|
2013-07-30 08:16:10 +08:00
|
|
|
atom coordinates from LAMMPS, compute forces, set values in fexternal,
|
|
|
|
etc.
|
|
|
|
</P>
|
|
|
|
<HR>
|
|
|
|
|
|
|
|
<P>To use this fix during energy minimization, the energy corresponding
|
|
|
|
to the added forces must also be set so as to be consistent with the
|
|
|
|
added forces. Otherwise the minimization will not converge correctly.
|
|
|
|
</P>
|
|
|
|
<P>This can be done from the external driver by calling this public
|
|
|
|
method of the FixExternal class:
|
|
|
|
</P>
|
|
|
|
<PRE>void set_energy(double eng);
|
|
|
|
</PRE>
|
|
|
|
<P>where eng is the potential energy. Eng is an extensive quantity,
|
|
|
|
meaning it should be the sum over per-atom energies of all affected
|
|
|
|
atoms. It should also be provided in <A HREF = "units.html">energy units</A>
|
|
|
|
consistent with the simulation. See the details below for how to
|
|
|
|
insure this energy setting is used appropriately in a minimization.
|
2013-01-05 01:20:04 +08:00
|
|
|
</P>
|
|
|
|
<HR>
|
|
|
|
|
2010-09-17 03:46:13 +08:00
|
|
|
<P><B>Restart, fix_modify, output, run start/stop, minimize info:</B>
|
|
|
|
</P>
|
|
|
|
<P>No information about this fix is written to <A HREF = "restart.html">binary restart
|
2013-07-30 08:16:10 +08:00
|
|
|
files</A>.
|
|
|
|
</P>
|
|
|
|
<P>The <A HREF = "fix_modify.html">fix_modify</A> <I>energy</I> option is supported by this
|
|
|
|
fix to add the potential "energy" set by the external driver to the
|
|
|
|
system's potential energy as part of <A HREF = "thermo_style.html">thermodynamic
|
|
|
|
output</A>. This is a fictitious quantity but is
|
|
|
|
needed so that the <A HREF = "minimize.html">minimize</A> command can include the
|
|
|
|
forces added by this fix in a consistent manner. I.e. there is a
|
|
|
|
decrease in potential energy when atoms move in the direction of the
|
|
|
|
added force.
|
|
|
|
</P>
|
|
|
|
<P>This fix computes a global scalar which can be accessed by various
|
|
|
|
<A HREF = "Section_howto.html#howto_15">output commands</A>. The scalar is the
|
|
|
|
potential energy discussed above. The scalar stored by this fix
|
|
|
|
is "extensive".
|
|
|
|
</P>
|
|
|
|
<P>No parameter of this fix can be used with the <I>start/stop</I> keywords of
|
|
|
|
the <A HREF = "run.html">run</A> command.
|
2010-11-22 23:58:11 +08:00
|
|
|
</P>
|
|
|
|
<P>The forces due to this fix are imposed during an energy minimization,
|
2013-07-30 08:16:10 +08:00
|
|
|
invoked by the <A HREF = "minimize.html">minimize</A> command.
|
|
|
|
</P>
|
|
|
|
<P>IMPORTANT NOTE: If you want the fictitious potential energy associated
|
|
|
|
with the added forces to be included in the total potential energy of
|
|
|
|
the system (the quantity being minimized), you MUST enable the
|
|
|
|
<A HREF = "fix_modify.html">fix_modify</A> <I>energy</I> option for this fix.
|
2010-09-17 03:46:13 +08:00
|
|
|
</P>
|
|
|
|
<P><B>Restrictions:</B> none
|
|
|
|
</P>
|
|
|
|
<P><B>Related commands:</B> none
|
|
|
|
</P>
|
|
|
|
<P><B>Default:</B> none
|
|
|
|
</P>
|
|
|
|
</HTML>
|