Skip to content

Commit 1d20776

Browse files
committed
fix: select the minimum interstitial distance
Fixes #1902 Coding-Agent: Codex Codex-Version: codex-cli 0.149.0 Model: gpt-5.6-sol Reasoning-Effort: xhigh
1 parent d5ce577 commit 1d20776

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

dpgen/auto_test/Interstitial.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@
1313
from dpgen.auto_test.reproduce import make_repro, post_repro
1414

1515

16+
def _smallest_nonzero_distance(distance_matrix):
17+
"""Return the minimum positive distance from a structure distance matrix."""
18+
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+
24+
1625
class Interstitial(Property):
1726
def __init__(self, parameter, inter_param=None):
1827
parameter["reproduce"] = parameter.get("reproduce", False)
@@ -191,7 +200,9 @@ def make_confs(self, path_to_work, path_to_equi, refine=False):
191200
temp = jj.get_supercell_structure(
192201
sc_mat=np.diag(self.supercell, k=0)
193202
)
194-
smallest_distance = list(set(temp.distance_matrix.ravel()))[1]
203+
smallest_distance = _smallest_nonzero_distance(
204+
temp.distance_matrix
205+
)
195206
if (
196207
"conf_filters" in self.parameter
197208
and "min_dist" in self.parameter["conf_filters"]
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import unittest
2+
3+
import numpy as np
4+
5+
from dpgen.auto_test.Interstitial import _smallest_nonzero_distance
6+
7+
8+
class TestInterstitialDistance(unittest.TestCase):
9+
def test_smallest_nonzero_distance(self):
10+
distance_matrix = np.array(
11+
[
12+
[0.0, 2.5, 1.25],
13+
[2.5, 0.0, 3.0],
14+
[1.25, 3.0, 0.0],
15+
]
16+
)
17+
self.assertEqual(_smallest_nonzero_distance(distance_matrix), 1.25)
18+
19+
20+
if __name__ == "__main__":
21+
unittest.main()

0 commit comments

Comments
 (0)