Creating Custom pair_style, bond_style, fix_style etc

is there some lecture or cource or forum where I can learn how to write a custom pair_style, bond_style with full read, write_restart, etc support? Also, if there is any thread, where someone teaches how to create custom pair_style, bond_style, fix etc please share.

Please check out the LAMMPS manual.

Hi, Thanks.

If you are asking this question with little prior experience, you should first build a reference implementation. That is, you should come up with some external program (maybe in Python) that reliably prints out the force between two particles as a function of the parameters and their distance.

You should then read the various table methods and attempt to implement your pair style as a table in LAMMPS. If that works well enough, you will have saved yourself lots of time.

Even if you ultimately decide to write in C++, a reference implementation will save you many weeks of work. That’s because, when (not if) your simulation with your new pair style does something weird or throws an error, you need to be able to determine: is my C++ code returning the same forces as my reference implementation (in which case the bug may not be there), or is the force different from my reference (and therefore it’s definitely bugged)?

It is especially important to build the reference implementation before writing custom code. If you build it afterwards, while you are frantically trying to debug your pair style, you will almost certainly write any comparison in such a way that it matches your pair style after it has been debugged … for that one bug. Any other subtle bugs in your code will then have been replicated into your (now very flawed) reference, and you will then take much longer to detect them.

1 Like