Add new potential to lammps

Dear all,

I want add a new potential to lammps but I don’t know how l should do that. Can someone help me?
I know that should create .h and .cpp file but don’t know what I should do after that. The details of works that I should do after creating these files is not clear for me.

F.kazemi sabet

Ph.D. Candidate of Mechanical Engineering
University of Tehran, Tehran, Iran.

There is a whole section in the manual dedicated to modifying and extending LAMMPS. If that is not sufficient, you should ask more specific questions.


First of all, LAMMPS already includes several "table" force-field
styles which usually eliminate the need to write your own custom code.
Please read the following web sites before proceeding:
    ...Hopefully one of these "table" force field styles can
accomplish what you are trying to do. (Incidentally, the main
limitation with pair_style table is that it lacks automatic mixing
rules so you must create a new table for every pair of atom types.)

     If you prefer not to use one of these "table" styles, then first
check if somebody else didn't already implement what you are trying to
do first. I assume you have checked all of the existing force-field

     ....If these still do not do what you need, (and if if you are
familiar with C++), then follow the instructions below:

1) It's impractical to create a new potential file completely from
scratch. I suggest that you modify an existing pair style (or bond,
angle, dihedral, or improper style). It's much easier to understand
the code if you choose one of the simple examples. You will modify
the code for these examples later (lj/cut has a simple
equation but it uses RESPA) (simple because it
does not use RESPA)

2) First download the most recent version of the lammps source code.
One way to do that is to use "git":

git clone ~/lammps

3) enter the "src" subdirectory. The source files corresponding to
the force fields above are named:

pair_lj_cut.cpp, pair_lj_cut.h
pair_lj_gromacs.cpp, pair_lj_gromacs.h
bond_harmonic.cpp, bond_harmonic.h
angle_harmonic.cpp, angle_harmonic.h
dihedral_fourier.cpp, dihedral_fourier.h
improper_harmonic.cpp, improper_harmonic.h

Copy the corresponding source files which are similar to the kind of
force field you want to implement. Give the .cpp and .h files new
names which do not clash with the existing file names.

4) Then edit the .h and .cpp file and change the name of the C++ class
so that it does not conflict with the original name. (For example,
replace "PairLJCut" with "Pair_MY_NEW_STYLE" everwhere it appears in
"pair_lj_cut.cpp" and "pair_lj_cut.h".

5) Also change "lj/cut" to "MY/NEW/STYLE", and "LJ_CUT" to
"MY_NEW_STYLE" everywhere they appear in "pair_lj_cut.h".)

6) Then edit "compute()" function and replace the equation for the
forces and the energies with the equation you prefer. (Do the same
thing in the "single()" function, if there is one.)

7) If the new formula requires different parameters not present in the
original formula, then you must edit the "coeff()" function. You will
probably need to add some lines that resemble these lines below:
NEW_PARAMETER1 = force->numeric(FLERR,arg[5]);
NEW_PARAMETER2 = force->numeric(FLERR,arg[6]);

8) Read the "Developer" documentation here:

9) Once your code is tested and working, create new documentation for
it by copying the corresponding .txt file in the "doc/src"
subdirectory. For example:


If you think your new force field style might be useful to the
community, and you have tested it, then feel free to submit it.
(Issuing a git-pull-request is the best way, but email also works.)