Anyone have template for .h file for new pair style

I am defining a new pair style, “foo”, and seek a template for the header file.

I seem to need an Auto-registry block and Class declaration … not sure how to encode them.

If you have a custom pair style you wrote yourself and built into a LAMMPS executable, and are willing to share the .h file with me, I’d be grateful!

Why don’t you start by studying the guide to writing new pair styles in the LAMMPS manual?

I’ve tried, Axel. Too many cpp errors because those little blocks of code in 4.8.1 don’t help me see global strucdture of a working entire script. An entire script, should you happen to have one, would let me see “what goes where” in a cpp header file.

Now getting errors like:

error: ‘using namespace’ is not allowed in classes

48 | using namespace LAMMPS_NS;

warning: extra qualification on member ‘~PairFoo’ [-Wmicrosoft-extra-qualification]

63 | PairFoo::~PairFoo()

error: member initializer ‘a0’ does not name a non-static data member or base class

55 | Pair(lmp), cut(nullptr), a0(nullptr), gamma(nullptr), sigma(nullptr)

Please don’t just cut-n-paste pieces of code without understanding what you are doing. Take a step back and carefully read through the text and apply some common sense. What is confusing you now should start to make sense. If it doesn’t you can ask specific questions.

For starters, the entire selection of pair styles in the LAMMPS distribution can serve as a starting point. The page that I have linked discusses how a specific pair style was added, so it is now part of the distribution and the discussion continues with aspects of more complex pair styles.

This is the file from the worked example in the tutorial - should help understand the C++ structure.

Thats the header - and then theres the accompanying implementation file

Thank you so much, Arthur Reading, for posting the implementation file and header file for a born-gauss potential. This kind of example is just what I (a very marginal cpp programmer) needed. Thanks to help from you, from Axel Kohlmeyer, and also (offline) from Steve Plimpton, I am up and running :slight_smile:

I have no wise advice for those in this group who are not great at cpp and want to write custom LAMMPS code except: 1) read all relevant LAMMPS documentation and then whiteboard before you type anything 2) seek guidance from working examples like those I was generously provided.

Also, a “mistake” I made was trying to utilize “pair_dpd.cpp/h” as examples. For reasons that experts recognize but I do not, there was something slightly special about the naming of the DPD classes that threw me off. Better to take as an example different pair force from “EXTRA-PAIR” src subdir!