<liclass="toctree-l2"><aclass="reference internal"href="#submitting-new-features-for-inclusion-in-lammps">10.15. Submitting new features for inclusion in LAMMPS</a></li>
</ul>
</li>
<liclass="toctree-l1"><aclass="reference internal"href="Section_python.html">11. Python interface to LAMMPS</a></li>
<divclass="line">10.6 <aclass="reference internal"href="#mod-6"><spanclass="std std-ref">Fix styles</span></a> which include integrators, temperature and pressure control, force constraints, boundary conditions, diagnostic output, etc</div>
<divclass="line">10.15 <aclass="reference internal"href="#mod-15"><spanclass="std std-ref">Submitting new features for inclusion in LAMMPS</span></a></div>
<divclass="line"><br/></div>
</div>
<p>LAMMPS is designed in a modular fashion so as to be easy to modify and
extend with new functionality. In fact, about 75% of its source code
is files added in this fashion.</p>
<p>In this section, changes and additions users can make are listed along
with minimal instructions. If you add a new feature to LAMMPS and
think it will be of interest to general users, we encourage you to
submit it to the developers for inclusion in the released version of
LAMMPS. Information about how to do this is provided
<td>retreive extra info unique to this atom style (optional)</td>
</tr>
<trclass="row-odd"><td>pack_border</td>
<td>store an atom’s info in a buffer communicated on neighbor re-builds (required)</td>
</tr>
<trclass="row-even"><td>pack_border_vel</td>
<td>add velocity info to buffer (required)</td>
</tr>
<trclass="row-odd"><td>pack_border_hybrid</td>
<td>store extra info unique to this atom style (optional)</td>
</tr>
<trclass="row-even"><td>unpack_border</td>
<td>retrieve an atom’s info from the buffer (required)</td>
</tr>
<trclass="row-odd"><td>unpack_border_vel</td>
<td>also retrieve velocity info (required)</td>
</tr>
<trclass="row-even"><td>unpack_border_hybrid</td>
<td>retreive extra info unique to this atom style (optional)</td>
</tr>
<trclass="row-odd"><td>pack_exchange</td>
<td>store all an atom’s info to migrate to another processor (required)</td>
</tr>
<trclass="row-even"><td>unpack_exchange</td>
<td>retrieve an atom’s info from the buffer (required)</td>
</tr>
<trclass="row-odd"><td>size_restart</td>
<td>number of restart quantities associated with proc’s atoms (required)</td>
</tr>
<trclass="row-even"><td>pack_restart</td>
<td>pack atom quantities into a buffer (required)</td>
</tr>
<trclass="row-odd"><td>unpack_restart</td>
<td>unpack atom quantities from a buffer (required)</td>
</tr>
<trclass="row-even"><td>create_atom</td>
<td>create an individual atom of this style (required)</td>
</tr>
<trclass="row-odd"><td>data_atom</td>
<td>parse an atom line from the data file (required)</td>
</tr>
<trclass="row-even"><td>data_atom_hybrid</td>
<td>parse additional atom info unique to this atom style (optional)</td>
</tr>
<trclass="row-odd"><td>data_vel</td>
<td>parse one line of velocity information from data file (optional)</td>
</tr>
<trclass="row-even"><td>data_vel_hybrid</td>
<td>parse additional velocity data unique to this atom style (optional)</td>
</tr>
<trclass="row-odd"><td>memory_usage</td>
<td>tally memory allocated by atom arrays (required)</td>
</tr>
</tbody>
</table>
<p>The constructor of the derived class sets values for several variables
that you must set when defining a new atom style, which are documented
in atom_vec.h. New atom arrays are defined in atom.cpp. Search for
the word “customize” and you will find locations you will need to
modify.</p>
<divclass="admonition note">
<pclass="first admonition-title">Note</p>
<pclass="last">It is possible to add some attributes, such as a molecule ID, to
atom styles that do not have them via the <aclass="reference internal"href="fix_property_atom.html"><spanclass="doc">fix property/atom</span></a> command. This command also
allows new custom attributes consisting of extra integer or
floating-point values to be added to atoms. See the <aclass="reference internal"href="fix_property_atom.html"><spanclass="doc">fix property/atom</span></a> doc page for examples of cases
where this is useful and details on how to initialize, access, and
output the custom values.</p>
</div>
<p>New <aclass="reference internal"href="pair_style.html"><spanclass="doc">pair styles</span></a>, <aclass="reference internal"href="fix.html"><spanclass="doc">fixes</span></a>, or
<aclass="reference internal"href="compute.html"><spanclass="doc">computes</span></a> can be added to LAMMPS, as discussed below.
The code for these classes can use the per-atom properties defined by
fix property/atom. The Atom class has a find_custom() method that is
<p>The “name” of a custom attribute, as specified in the <aclass="reference internal"href="fix_property_atom.html"><spanclass="doc">fix property/atom</span></a> command, is checked to verify
that it exists and its index is returned. The method also sets flag =
0/1 depending on whether it is an integer or floating-point attribute.
The vector of values associated with the attribute can then be
<p>There is one class that computes and prints thermodynamic information
to the screen and log file; see the file thermo.cpp.</p>
<p>There are two styles defined in thermo.cpp: “one” and “multi”. There
is also a flexible “custom” style which allows the user to explicitly
list keywords for quantities to print when thermodynamic info is
output. See the <aclass="reference internal"href="thermo_style.html"><spanclass="doc">thermo_style</span></a> command for a list
of defined quantities.</p>
<p>The thermo styles (one, multi, etc) are simply lists of keywords.
Adding a new style thus only requires defining a new list of keywords.
Search for the word “customize” with references to “thermo style” in
thermo.cpp to see the two locations where code will need to be added.</p>
<p>New keywords can also be added to thermo.cpp to compute new quantities
for output. Search for the word “customize” with references to
“keyword” in thermo.cpp to see the several locations where code will
need to be added.</p>
<p>Note that the <aclass="reference internal"href="thermo.html"><spanclass="doc">thermo_style custom</span></a> command already allows
for thermo output of quantities calculated by <aclass="reference internal"href="fix.html"><spanclass="doc">fixes</span></a>,
<aclass="reference internal"href="compute.html"><spanclass="doc">computes</span></a>, and <aclass="reference internal"href="variable.html"><spanclass="doc">variables</span></a>. Thus, it may
be simpler to compute what you wish via one of those constructs, than
by adding a new keyword to the thermo command.</p>
<p>There is one class that computes and stores <aclass="reference internal"href="variable.html"><spanclass="doc">variable</span></a>
information in LAMMPS; see the file variable.cpp. The value
associated with a variable can be periodically printed to the screen
via the <aclass="reference internal"href="print.html"><spanclass="doc">print</span></a>, <aclass="reference internal"href="fix_print.html"><spanclass="doc">fix print</span></a>, or
<aclass="reference internal"href="thermo_style.html"><spanclass="doc">thermo_style custom</span></a> commands. Variables of style
“equal” can compute complex equations that involve the following types
<spanid="mod-15"></span><h2>10.15. Submitting new features for inclusion in LAMMPS</h2>
<p>We encourage users to submit new features to <aclass="reference external"href="http://lammps.sandia.gov/authors.html">the developers</a> that they add to
LAMMPS, especially if you think they will be of interest to other
users. The preferred way to do this is via GitHub. Once you have
prepared the content described below, see <aclass="reference internal"href="tutorial_github.html"><spanclass="doc">this tutorial</span></a> for instructions on how to submit
your changes or new files.</p>
<p>If the new features/files are broadly useful we may add them as core
files to LAMMPS or as part of a <aclass="reference internal"href="Section_start.html#start-3"><spanclass="std std-ref">standard package</span></a>. Else we will add them as a
user-contributed file or package. Examples of user packages are in
src sub-directories that start with USER. The USER-MISC package is
simply a collection of (mostly) unrelated single files, which is the
simplest way to have your contribution quickly added to the LAMMPS
distribution. You can see a list of the both standard and user
packages by typing “make package” in the LAMMPS src directory.</p>
<p>Note that by providing us files to release, you are agreeing to make
them open-source, i.e. we can release them under the terms of the GPL,
used as a license for the rest of LAMMPS. See <aclass="reference internal"href="Section_intro.html#intro-4"><spanclass="std std-ref">Section 1.4</span></a> for details.</p>
<p>With user packages and files, all we are really providing (aside from
the fame and fortune that accompanies having your name in the source
code and on the <aclass="reference external"href="http://lammps.sandia.gov/authors.html">Authors page</a>
of the <aclass="reference external"href="http://lammps.sandia.gov">LAMMPS WWW site</a>), is a means for you to distribute your
work to the LAMMPS user community, and a mechanism for others to
easily try out your new feature. This may help you find bugs or make
contact with new collaborators. Note that you’re also implicitly
agreeing to support your code which means answer questions, fix bugs,
and maintain it if LAMMPS changes in some way that breaks it (an
unusual event).</p>
<divclass="admonition note">
<pclass="first admonition-title">Note</p>
<pclass="last">If you prefer to actively develop and support your add-on
feature yourself, then you may wish to make it available for download
from your own website, as a user package that LAMMPS users can add to
their copy of LAMMPS. See the <aclass="reference external"href="http://lammps.sandia.gov/offsite.html">Offsite LAMMPS packages and tools</a> page of the LAMMPS web
site for examples of groups that do this. We are happy to advertise
your package and web site from that page. Simply email the
<aclass="reference external"href="http://lammps.sandia.gov/authors.html">developers</a> with info about
your package and we will post it there.</p>
</div>
<p>The previous sections of this doc page describe how to add new “style”
files of various kinds to LAMMPS. Packages are simply collections of
one or more new class files which are invoked as a new style within a
LAMMPS input script. If designed correctly, these additions typically
do not require changes to the main core of LAMMPS; they are simply
add-on files. If you think your new feature requires non-trivial
changes in core LAMMPS files, you’ll need to <aclass="reference external"href="http://lammps.sandia.gov/authors.html">communicate with the developers</a>, since we may or may
not want to make those changes. An example of a trivial change is
making a parent-class method “virtual” when you derive a new child
class from it.</p>
<p>Here are the steps you need to follow to submit a single file or user
package for our consideration. Following these steps will save both
you and us time. See existing files in packages in the src dir for
examples.</p>
<ulclass="simple">
<li>All source files you provide must compile with the most current
version of LAMMPS.</li>
<li>If you want your file(s) to be added to main LAMMPS or one of its
standard packages, then it needs to be written in a style compatible
with other LAMMPS source files. This is so the developers can
understand it and hopefully maintain it. This basically means that
the code accesses data structures, performs its operations, and is
formatted similar to other LAMMPS source files, including the use of
the error class for error and warning messages.</li>
<li>If you want your contribution to be added as a user-contributed
feature, and it’s a single file (actually a <ahref="#id8"><spanclass="problematic"id="id9">*</span></a>.cpp and <ahref="#id10"><spanclass="problematic"id="id11">*</span></a>.h file) it can
rapidly be added to the USER-MISC directory. Send us the one-line
entry to add to the USER-MISC/README file in that dir, along with the
2 source files. You can do this multiple times if you wish to
contribute several individual features.</li>
<li>If you want your contribution to be added as a user-contribution and
it is several related featues, it is probably best to make it a user
package directory with a name like USER-FOO. In addition to your new
files, the directory should contain a README text file. The README
should contain your name and contact information and a brief
description of what your new package does. If your files depend on
other LAMMPS style files also being installed (e.g. because your file
is a derived class from the other LAMMPS class), then an Install.sh
file is also needed to check for those dependencies. See other README
and Install.sh files in other USER directories as examples. Send us a
tarball of this USER-FOO directory.</li>
<li>Your new source files need to have the LAMMPS copyright, GPL notice,
and your name and email address at the top, like other
user-contributed LAMMPS source files. They need to create a class
that is inside the LAMMPS namespace. If the file is for one of the
USER packages, including USER-MISC, then we are not as picky about the
coding style (see above). I.e. the files do not need to be in the
same stylistic format and syntax as other LAMMPS files, though that
would be nice for developers as well as users who try to read your
code.</li>
<li>You must also create a documentation file for each new command or
style you are adding to LAMMPS. This will be one file for a
single-file feature. For a package, it might be several files. These
are simple text files which we auto-convert to HTML. Thus they must
be in the same format as other <em>.txt files in the lammps/doc directory
for similar commands and styles; use one or more of them as a starting
point. As appropriate, the text files can include links to equations
(see doc/Eqs/</em>.tex for examples, we auto-create the associated JPG
files), or figures (see doc/JPG for examples), or even additional PDF
files with further details (see doc/PDF for examples). The doc page
should also include literature citations as appropriate; see the
bottom of doc/fix_nh.txt for examples and the earlier part of the same
file for how to format the cite itself. The “Restrictions” section of
the doc page should indicate that your command is only available if
LAMMPS is built with the appropriate USER-MISC or USER-FOO package.
See other user package doc files for examples of how to do this. The
txt2html tool we use to convert to HTML can be downloaded from <aclass="reference external"href="http://www.sandia.gov/~sjplimp/download.html">this site</a>, so you can perform
the HTML conversion yourself to proofread your doc page.</li>
<li>For a new package (or even a single command) you can include one or
more example scripts. These should run in no more than 1 minute, even
on a single processor, and not require large data files as input. See
directories under examples/USER for examples of input scripts other
users provided for their packages.</li>
<li>If there is a paper of yours describing your feature (either the
algorithm/science behind the feature itself, or its initial usage, or
its implementation in LAMMPS), you can add the citation to the <ahref="#id12"><spanclass="problematic"id="id13">*</span></a>.cpp
source file. See src/USER-EFF/atom_vec_electron.cpp for an example.
A LaTeX citation is stored in a variable at the top of the file and a
single line of code that references the variable is added to the
constructor of the class. Whenever a user invokes your feature from
their input script, this will cause LAMMPS to output the citation to a
log.cite file and prompt the user to examine the file. Note that you
should only use this for a paper you or your group authored.
E.g. adding a cite in the code for a paper by Nose and Hoover if you
write a fix that implements their integrator is not the intended
usage. That kind of citation should just be in the doc page you
provide.</li>
</ul>
<p>Finally, as a general rule-of-thumb, the more clear and
self-explanatory you make your doc and README files, and the easier
you make it for people to get started, e.g. by providing example
scripts, the more likely it is that users will try out your new
feature.</p>
<pid="foo"><strong>(Foo)</strong> Foo, Morefoo, and Maxfoo, J of Classic Potentials, 75, 345 (1997).</p>
Built with <ahref="http://sphinx-doc.org/">Sphinx</a> using a <ahref="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <ahref="https://readthedocs.org">Read the Docs</a>.