Skip to content

Commit 422e096

Browse files
committed
Exclude other bridge atoms from physical neighbours where possible.
1 parent 3674fa4 commit 422e096

1 file changed

Lines changed: 19 additions & 5 deletions

File tree

src/ghostly/_ghostly.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,16 +208,25 @@ def modify(
208208
bridges0[c].append(ghost)
209209
# Work out the indices of the other physical atoms that are connected to
210210
# the bridge atoms, sorted by the atom index. These are "core" physical
211-
# atoms, i.e. they are physical in both end states.
211+
# atoms, i.e. they are physical in both end states and are not
212+
# themselves bridge atoms. Other bridges are not stable anchors for
213+
# junction classification since they have their own ghost connections.
212214
physical0 = {}
215+
bridge_idx_set0 = set(b.value() for b in bridges0)
213216
for b in bridges0:
214-
physical0[b] = []
217+
all_phys = []
218+
non_bridge_phys = []
215219
for c in connectivity0.connections_to(b):
216220
if (
217221
not _is_ghost(mol, [c])[0]
218222
and not _is_ghost(mol, [c], is_lambda1=True)[0]
219223
):
220-
physical0[b].append(c)
224+
all_phys.append(c)
225+
if c.value() not in bridge_idx_set0:
226+
non_bridge_phys.append(c)
227+
# Prefer non-bridge physical neighbours, but fall back to
228+
# including bridges if they are the only anchors available.
229+
physical0[b] = non_bridge_phys if non_bridge_phys else all_phys
221230
for b in physical0:
222231
physical0[b].sort(key=lambda x: x.value())
223232

@@ -231,14 +240,19 @@ def modify(
231240
else:
232241
bridges1[c].append(ghost)
233242
physical1 = {}
243+
bridge_idx_set1 = set(b.value() for b in bridges1)
234244
for b in bridges1:
235-
physical1[b] = []
245+
all_phys = []
246+
non_bridge_phys = []
236247
for c in connectivity1.connections_to(b):
237248
if (
238249
not _is_ghost(mol, [c])[0]
239250
and not _is_ghost(mol, [c], is_lambda1=True)[0]
240251
):
241-
physical1[b].append(c)
252+
all_phys.append(c)
253+
if c.value() not in bridge_idx_set1:
254+
non_bridge_phys.append(c)
255+
physical1[b] = non_bridge_phys if non_bridge_phys else all_phys
242256
for b in physical1:
243257
physical1[b].sort(key=lambda x: x.value())
244258

0 commit comments

Comments
 (0)