[lammps-users] neighbor list not found in i-th pair style when using hybrid pair style

Dear lammps community,

I am trying to access the neighbor lists when using a pair style hybrid. This is my pair style command

pair_style hybrid lj/cut/coul/long 6. platinum 1 2 3 3.2 6.

(don't mind the strange second pair style. That is not the problem.)

I understand that the hybrid pair style itself does not hold the neighbor lists. Therefore, I tried to to get all neighbors by looping over the styles in the hybrid style via

for (ipair = 0; ipair < 2; ipair++) {

tmp\_pair = force\-&gt;pair\_match\(&quot;&quot;, 0, ipair\) \#&lt;\-\- I would have expected this to return the ipair\-th pair style in the hybrid list

inum = tmp\_pair\-&gt;list\-&gt;inum;

\.\.\.

this crashes with a segfault in the last line I show. Using gdb, I find that tmp_pair is something (i.e., the match found something and does not return 0), but tmp_pair->list is not:

(gdb) print tmp_pair
$1 = (LAMMPS_NS::Pair *) 0x8b31ed0
(gdb) print tmp_pair->list
$2 = (LAMMPS_NS::NeighList *) 0x0
(gdb) print ipair
$3 = 0

strangely enough, when I change my code to

tmp_pair = force->pair_match("lj", 0, 0)

(clearly this will now not loop correctly - this was just a test)

the code runs through without crashing. The same holds true if I replace "lj" by "platinum". Why does this happen? Am I misunderstanding how pair_match works?

Additional information: lammps version: 29.09.2021

Thank you for your help,

Best regards,

Katharina

for efficiency reasons, each pair style will create a neighborlist request, and those are collected by the neighbor list code and then post-processed in a way that the correct neighbor list builder is selected and also that this is done with the least amount of redundancy. for hybrid pair styles, there is usually a “master” list (that is not associated with any pair style) and then the lists for individual pair styles are created by a “skip list” builder from that master list. LAMMPS will print a summary of what is done at the beginning of a run. Some pair styles may even have multiple neighbor list requests (e.g. one full and one half neighbor list, and the latter would be built using a half-from-full builder).

furthermore, you are indeed misunderstanding how force->pair_match() works. the “nsub” value only applies if you have multiple substyles of the same name, e.g. if you would have:

pair_style hybrid tersoff tersoff lj/cut

then force->pair_match("tersoff",0,1) matches the first of those two tersoff styles. while force->pair_match("tersoff",0,2) matches the second. for the “lj/cut” style nsub must be 0.

if you want to get access to the individual lo-level neighbor lists directly you should be using the c-library interface:
https://docs.lammps.org/Library_neighbor.html

axel.

p.s.: you may also want to have a look at the (new) LAMMPS paper, that has some more explanations about the building of neighbor lists and/or https://docs.lammps.org/Developer_par_neigh.html

Dear Axel, dear lammps community

Thank you for your answer. You are right, I am simply interested in the “master” list. I find the following in the output:

(1) pair lj/cut/coul/long, perpetual, skip from (3)
attributes: half, newton off
pair build: skip
stencil: none
bin: none
(2) pair platinum, perpetual, skip from (3)
attributes: half, newton off
pair build: skip
stencil: none
bin: none
(3) neighbor class addition, perpetual
attributes: half, newton off
pair build: half/bin/newtoff
stencil: full/bin/3d
bin: standard

Hence, I assume that

neighbor->lists[2]

is the master list in this particular case. This makes sense, because the two skiplists do not have a non-skiplist to skip from yet, so the non-skip list is requested last. Unfortunately, it is not clear to me what the “general” case is, i.e., how can I figure out which list index I need? The “master” list does not seem to be owned by the pair_hybrid in pair->list. I feel very stupid about not figuring this out myself, but the problem that I am having is that even the list attributes (skiplist or not, half vs. full, …) only seem to be known to the requestors and not to the final list, so I cannot even loop over all lists and find the one I need. Maybe it is just me being tired, but I would not say no to another hint…

Thank you and best regards,

Katharina

is the master list in this particular case. This makes sense, because the two skiplists do not have a non-skiplist to skip from yet, so the non-skip list is requested last. Unfortunately, it is not clear to me what the “general” case is, i.e., how can I figure out which list index I need? The “master” list does not seem to be owned by the pair_hybrid in pair->list. I feel very stupid about not figuring this out myself, but the problem that I am having is that even the list attributes (skiplist or not, half vs. full, …) only seem to be known to the requestors and not to the final list, so I cannot even loop over all lists and find the one I need. Maybe it is just me being tired, but I would not say no to another hint…

I can only give you more hints, after you provide more information about why you want to access an existing neighbor list that is not the one from a specific given request, and from where exactly this would happen and how and then what you intend to do with that neighbor list data.

This is because the “normal” way to go about using a neighbor list anywhere outside a specific pair style would be to create a request of your own with the exact settings you need and then leave it to LAMMPS to figure out how to construct it.

Axel.