<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
useful in this context:</p>
<preclass="literal-block">
int index = atom->find_custom(char *name, int &flag);
</pre>
<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
accessed using the returned index as</p>
<preclass="literal-block">
int *ivector = atom->ivector[index];
double *dvector = atom->dvector[index];
</pre>
<p>Ivector or dvector are vectors of length Nlocal = # of owned atoms,
which store the attributes of individual atoms.</p>
<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
of arguments:</p>
<preclass="literal-block">
thermo keywords = ke, vol, atoms, ...
other variables = v_a, v_myvar, ...
math functions = div(x,y), mult(x,y), add(x,y), ...
<spanid="mod-15"></span><h2>10.15. Submitting new features for inclusion in LAMMPS</h2>
<p>We encourage users to submit new features or modifications for
LAMMPS to <aclass="reference external"href="http://lammps.sandia.gov/authors.html">the core developers</a>
so they can be added to the LAMMPS distribution. The preferred way to
manage and coordinate this is as of Fall 2016 via the LAMMPS project on
<aclass="reference external"href="https://github.com/lammps/lammps">GitHub</a>. An alternative is to contact
the LAMMPS developers or the indicated developer of a package or feature
directly and send in your contribution via e-mail.</p>
<p>For any larger modifications or programming project, you are encouraged
to contact the LAMMPS developers ahead of time, in order to discuss
implementation strategies and coding guidelines, that will make it
easier to integrate your contribution and result in less work for
everybody involved. You are also encouraged to search through the list
of <aclass="reference external"href="https://github.com/lammps/lammps/issues">open issues on GitHub</a> and
submit a new issue for a planned feature, so you would not duplicate
the work of others (and possibly get scooped by them) or have your work
duplicated by others.</p>
<p>How quickly your contribution will be integrated
depends largely on how much effort it will cause to integrate and test
it, how much it requires changes to the core codebase, and of how much
interest it is to the larger LAMMPS community. Please see below for a
checklist of typical requirements. Once you have prepared everything,
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 through a GitHub pull request. If you
prefer to submit patches or full files, you should first make certain,
that your code works correctly with the latest patch-level version of
LAMMPS and contains all bugfixes from it. Then create a gzipped tar
file of all changed or added files or a corresponding patch file using
‘diff -u’ or ‘diff -c’ and compress it with gzip. Please only use
gzip compression, as this works well on all platforms.</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 is a checklist of 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. If you are uncertain, please ask.</p>
<ulclass="simple">
<li>All source files you provide must compile with the most current
version of LAMMPS with multiple configurations. In particular you
need to test compiling LAMMPS from scratch with -DLAMMPS_BIGBIG
set in addition to the default -DLAMMPS_SMALLBIG setting. Your code
will need to work correctly in serial and in parallel using MPI.</li>
<li>For consistency with the rest of LAMMPS and especially, if you want
your contribution(s) to be added to main LAMMPS code or one of its
standard packages, it needs to be written in a style compatible with
other LAMMPS source files. This means: 2-character indentation per
level, <strong>no tabs</strong>, no lines over 80 characters. I/O is done via
the C-style stdio library, class header files should not import any
system headers outside <stdio.h>, STL containers should be avoided
in headers, and forward declarations used where possible or needed.
All added code should be placed into the LAMMPS_NS namespace or a
sub-namespace; global or static variables should be avoided, as they
conflict with the modular nature of LAMMPS and the C++ class structure.
Header files must <strong>not</strong> import namespaces with <em>using</em>.
This all is so the developers can more easily understand, integrate,
and maintain your contribution and reduce conflicts with other parts
of LAMMPS. 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 *.cpp and *.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 <strong>must</strong> also create a <strong>documentation</strong> file for each new command or
style you are adding to LAMMPS. For simplicity and convenience, the
documentation of groups of closely related commands or styles may be
combined into a single file. This will be one file for a single-file
feature. For a package, it might be several files. These are simple
text files with a specific markup language, that are then auto-converted
to HTML and PDF. The tools for this conversion are included in the
source distribution, and the translation can be as simple as doing
“make html pdf” in the doc folder.
Thus the documentation source files must be in the same format and
style as other *.txt files in the lammps/doc/src directory for similar
commands and styles; use one or more of them as a starting point.
A description of the markup can also be found in
lammps/doc/utils/txt2html/README.html
As appropriate, the text files can include links to equations
(see doc/Eqs/*.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
prerequiste for building the HTML format files are Python 3.x and
virtualenv, the requirement for generating the PDF format manual
is the <aclass="reference external"href="http://www.htmldoc.org/">htmldoc</a> software. Please run at least
“make html” and carefully inspect and proofread the resuling HTML format
doc page before submitting your code.</li>
<li>For a new package (or even a single command) you should include one or
more example scripts demonstrating its use. These should run in no
more than a couple minutes, 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.
These example inputs are also required for validating memory accesses
and testing for memory leaks with valgrind</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 *.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 documentation 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>.