Segfault of angle_style hybrid with angle_style spica (sdk)

With “angle_style hybrid sdk harmonic”, we get a segfault when applying only “harmonic” angle_coeff to molecules included in a target system, while no segfault occurs when applying only “sdk” angle_coeff.
This may be because a variable “repscale” in the init_style() of angle_spica.cpp is not allocated due to no use of the angle spica potential in the actual simulation.
This is a kind of special case of angle_style when using the “hybrid” with “spica (sdk)”. But, could you let me know which is better behavior of “angle_style hybrid”, in LAMMPS all of declared styles following “hybrid” should work with no use of some of them, or not? I’d like to modify this segfault in accordance with LAMMPS convention.


void AngleSPICA::init_style()

// make sure we use an SPICA pair_style and that we need the 1-3 repulsion

repflag = 0;
for (int i = 1; i <= atom->nangletypes; i++)
if (repscale[i] > 0.0) repflag = 1;

There are two issues at hand here. The behavior of angle style hybrid to allow defining an angle style as a sub-style and then not use it in the simulation is inconsistent with the (older) pair style hybrid where all sub-styles must be used. I will look to implement such a test.

The segfault itself is not the fault of angle style hybrid, but a failure of the angle style spica not considering that it may be used as a hybrid sub-style. This is not a surprise, since its implementation predates the implementation of angle style hybrid by a significant margin. Unlike in pair styles, where there is an init_one() function that is called for each combination of atom types individually, and thus will trigger pair style initialization only for such pairs of atom types. It should be possible to avoid this scenario by augmenting the if statement to: if (repscale && (repscale[i] > 0.0)) repflag = 1;

I will add such a change to a pending pull request, too.

FYI the changes I mentioned are included in Collected small changes and fixes by akohlmey · Pull Request #3539 · lammps/lammps · GitHub and will soon be merged into the develop branch.

I am sorry for not checking the pull request.
I sincerely appreciate your detailed explanation about the segfault and hybrid styles.

No need to be sorry. The changes were implemented because of your post. So you should be happy to have contributed to making LAMMPS more consistent and being subject to fewer segfaults.

You are right. I should have been happy to do this.
Thank you very much.