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.

Axel.

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:
https://lammps.sandia.gov/doc/pair_table.html
https://lammps.sandia.gov/doc/bond_table.html
https://lammps.sandia.gov/doc/angle_table.html
https://lammps.sandia.gov/doc/dihedral_table.html
    ...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
styles?
https://lammps.sandia.gov/doc/pairs.html
https://lammps.sandia.gov/doc/dihedrals.html
https://lammps.sandia.gov/doc/bonds.html
https://lammps.sandia.gov/doc/angles.html
https://lammps.sandia.gov/doc/dihedrals.html
https://lammps.sandia.gov/doc/impropers.html

     ....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

https://lammps.sandia.gov/doc/pair_lj.html (lj/cut has a simple
equation but it uses RESPA)
https://lammps.sandia.gov/doc/pair_gromacs.html (simple because it
does not use RESPA)
https://lammps.sandia.gov/doc/bond_harmonic.html
https://lammps.sandia.gov/doc/angle_harmonic.html
https://lammps.sandia.gov/doc/dihedral_fourier.html
https://lammps.sandia.gov/doc/improper_harmonic.html

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

git clone https://github.com/lammps/lammps ~/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:
https://lammps.sandia.gov/doc/Developer.pdf

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:

doc/src/pair_lj_cut.txt
doc/src/pair_lj_gromacs.txt
doc/src/bond_harmonic.txt
doc/src/angle_harmonic.txt
doc/src/dihedral_fourier.txt
doc/src/improper_harmonic.txt

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.)