What cutoff does the neighbor list use if `init_one` is not defined?

Defining the init_one function for a new pair style is officially optional. But, the init_one function is supposed to return a cutoff that determines how the neighbor list is being built. How will the neighbor list be built if init_one is not defined?

I am working on a manybody pair style that uses a global cutoff. I could manually allocate and free memory for setflag and cutsq and define init_one to return the global cutoff for any pair. This seems like boilerplate to me though, as neither individual pair cutoffs nor individual pair settings are possible in my use-case. Is there a good-practice way to not define init_one, not allocate setflag and cutsq, and use a global cutoff for the neighbor list (All parameters are guaranteed to be set if the coeff function passes)?

The setflag and cutsq must be allocated or you’ll get segfaults and they must be set appropriately.

This part of the code still shows strong signs from the time when LAMMPS was translated from Fortran 90 to C++ where people wanted to make life for people modifying LAMMPS easy and thus kept the C++ code very similar to the Fortran code, even at the expense of not following C++ programming best practices and requiring people to follow manual steps.

The simplest solution is to implement init_one() and have it return the global cutoff. If the function is not defined, the dummy version from the Pair class is used which returns 0.0;

1 Like