Skip to content

Commit d5f01ee

Browse files
author
Nils Edvin Richard Zimmermann
committed
Added _quadrant_integral function in CrystalNN and switched over to use that function instead of _semicircle_integral which did not compute circular segments of unit quadrants correctly
1 parent 633e7bd commit d5f01ee

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/pymatgen/analysis/local_env.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3990,7 +3990,7 @@ def get_nn_data(self, structure: Structure, n: int, length=None):
39903990
nn_info.append(entry)
39913991
cn = len(nn_info)
39923992
cn_nninfo[cn] = nn_info
3993-
cn_weights[cn] = self._semicircle_integral(dist_bins, idx)
3993+
cn_weights[cn] = self._quadrant_integral(dist_bins, idx)
39943994

39953995
# add zero coord
39963996
cn0_weight = 1 - sum(cn_weights.values())
@@ -4075,6 +4075,35 @@ def _semicircle_integral(dist_bins, idx):
40754075

40764076
return (area1 - area2) / (0.25 * math.pi * radius**2)
40774077

4078+
@staticmethod
4079+
def _quadrant_integral(dist_bins, idx):
4080+
"""
4081+
An internal method to get an integral between two bounds of a unit
4082+
quadrant. Used in algorithm to determine bond probabilities.
4083+
4084+
Args:
4085+
dist_bins: (float) list of all possible bond weights
4086+
idx: (float) index of starting bond weight
4087+
4088+
Returns:
4089+
float: integral of portion of unit quadrant
4090+
"""
4091+
radius = 1
4092+
4093+
x1 = dist_bins[idx]
4094+
x2 = dist_bins[idx + 1]
4095+
4096+
areaquarter = 0.25 * math.pi * radius**2
4097+
4098+
area1 = areaquarter - 0.5 * (radius**2 * math.acos(
4099+
1 - x1 / radius) - (radius - x1) * math.sqrt(
4100+
2 * radius * x1 - x1**2))
4101+
area2 = areaquarter - 0.5 * (radius**2 * math.acos(
4102+
1 - x2 / radius) - (radius - x2) * math.sqrt(
4103+
2 * radius * x2 - x2**2))
4104+
4105+
return (area2 - area1) / areaquarter
4106+
40784107
@staticmethod
40794108
def transform_to_length(nn_data, length):
40804109
"""

tests/analysis/test_local_env.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,10 @@ def test_all_nn_classes(self):
444444
assert voronoi_nn.get_cn(self.cscl, 0) == 8
445445
assert voronoi_nn.get_cn(self.lifepo4, 0) == 6
446446

447+
assert CrystalNN._quadrant_integral([1,0.36], 0) == approx(
448+
0.7551954297486029)
449+
assert CrystalNN._quadrant_integral([1,0.36,0], 1) == approx(
450+
1 - 0.7551954297486029)
447451
crystal_nn = CrystalNN()
448452
assert crystal_nn.get_cn(self.diamond, 0) == 4
449453
assert crystal_nn.get_cn(self.nacl, 0) == 6

0 commit comments

Comments
 (0)