Skip to content

Commit 3411c64

Browse files
committed
fix: detect exact interstitial overlaps
Coding-Agent: Codex Codex-Version: codex-cli 0.151.0 Model: gpt-5.6-sol Reasoning-Effort: xhigh
1 parent 1d20776 commit 3411c64

2 files changed

Lines changed: 21 additions & 5 deletions

File tree

dpgen/auto_test/Interstitial.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,17 @@
1414

1515

1616
def _smallest_nonzero_distance(distance_matrix):
17-
"""Return the minimum positive distance from a structure distance matrix."""
17+
"""Return the minimum distance between two distinct atoms.
18+
19+
Selecting by matrix index, instead of by value, keeps a real zero distance
20+
caused by coincident atoms while excluding the zero-valued diagonal.
21+
"""
1822
distances = np.asarray(distance_matrix)
19-
positive_distances = distances[distances > 0]
20-
if positive_distances.size == 0:
21-
raise ValueError("distance matrix does not contain a positive distance")
22-
return float(np.min(positive_distances))
23+
atom_pairs = np.triu_indices_from(distances, k=1)
24+
pair_distances = distances[atom_pairs]
25+
if pair_distances.size == 0:
26+
raise ValueError("distance matrix does not contain a pair of atoms")
27+
return float(np.min(pair_distances))
2328

2429

2530
class Interstitial(Property):

tests/auto_test/test_interstitial_distance.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@ def test_smallest_nonzero_distance(self):
1616
)
1717
self.assertEqual(_smallest_nonzero_distance(distance_matrix), 1.25)
1818

19+
def test_exact_overlap_is_retained(self):
20+
"""An off-diagonal zero represents an invalid atomic overlap."""
21+
distance_matrix = np.array(
22+
[
23+
[0.0, 0.0, 1.25],
24+
[0.0, 0.0, 2.5],
25+
[1.25, 2.5, 0.0],
26+
]
27+
)
28+
self.assertEqual(_smallest_nonzero_distance(distance_matrix), 0.0)
29+
1930

2031
if __name__ == "__main__":
2132
unittest.main()

0 commit comments

Comments
 (0)