-
Notifications
You must be signed in to change notification settings - Fork 867
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added _quadrant_integral function in CrystalNN #3974
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1161,7 +1161,7 @@ def _is_in_targets(site, targets): | |
targets ([Element]) List of elements | ||
|
||
Returns: | ||
bool: Whether this site contains a certain list of elements | ||
boolean: Whether this site contains a certain list of elements | ||
""" | ||
elems = _get_elements(site) | ||
return all(elem in targets for elem in elems) | ||
|
@@ -1218,7 +1218,7 @@ def __init__( | |
|
||
# Update any user preference elemental radii | ||
if el_radius_updates: | ||
self.el_radius |= el_radius_updates | ||
self.el_radius.update(el_radius_updates) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
|
||
@property | ||
def structures_allowed(self) -> bool: | ||
|
@@ -1984,7 +1984,7 @@ def get_okeeffe_distance_prediction(el1, el2): | |
"""Get an estimate of the bond valence parameter (bond length) using | ||
the derived parameters from 'Atoms Sizes and Bond Lengths in Molecules | ||
and Crystals' (O'Keeffe & Brese, 1991). The estimate is based on two | ||
experimental parameters: r and c. The value for r is based off radius, | ||
experimental parameters: r and c. The value for r is based off radius, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and here |
||
while c is (usually) the Allred-Rochow electronegativity. Values used | ||
are *not* generated from pymatgen, and are found in | ||
'okeeffe_params.json'. | ||
|
@@ -2755,7 +2755,7 @@ def get_type(self, index): | |
raise ValueError("Index for getting order parameter type out-of-bounds!") | ||
return self._types[index] | ||
|
||
def get_parameters(self, index: int) -> list[float]: | ||
def get_parameters(self, index): | ||
"""Get list of floats that represents | ||
the parameters associated | ||
with calculation of the order | ||
|
@@ -2764,10 +2764,12 @@ def get_parameters(self, index: int) -> list[float]: | |
inputted because of processing out of efficiency reasons. | ||
|
||
Args: | ||
index (int): index of order parameter for which to return associated params. | ||
index (int): | ||
index of order parameter for which associated parameters | ||
are to be returned. | ||
|
||
Returns: | ||
list[float]: parameters of a given OP. | ||
[float]: parameters of a given OP. | ||
""" | ||
if index < 0 or index >= len(self._types): | ||
raise ValueError("Index for getting parameters associated with order parameter calculation out-of-bounds!") | ||
|
@@ -3990,7 +3992,7 @@ def get_nn_data(self, structure: Structure, n: int, length=None): | |
nn_info.append(entry) | ||
cn = len(nn_info) | ||
cn_nninfo[cn] = nn_info | ||
cn_weights[cn] = self._semicircle_integral(dist_bins, idx) | ||
cn_weights[cn] = self._quadrant_integral(dist_bins, idx) | ||
|
||
# add zero coord | ||
cn0_weight = 1 - sum(cn_weights.values()) | ||
|
@@ -4047,10 +4049,13 @@ def get_cn_dict(self, structure: Structure, n: int, use_weights: bool = False, * | |
return super().get_cn_dict(structure, n, use_weights) | ||
|
||
@staticmethod | ||
def _semicircle_integral(dist_bins, idx): | ||
def _semicircle_integral(dist_bins: list, idx: int) -> float: | ||
""" | ||
An internal method to get an integral between two bounds of a unit | ||
semicircle. Used in algorithm to determine bond probabilities. | ||
This function has an issue, which is detailed at | ||
https://github.com/materialsproject/pymatgen/issues/3973. | ||
Therefore, _quadrant_integral is now the method of choice. | ||
|
||
Args: | ||
dist_bins: (float) list of all possible bond weights | ||
|
@@ -4075,6 +4080,35 @@ def _semicircle_integral(dist_bins, idx): | |
|
||
return (area1 - area2) / (0.25 * math.pi * radius**2) | ||
|
||
@staticmethod | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you add a link to your issue to the also, would be good to type-hint both the old and your new method |
||
def _quadrant_integral(dist_bins: list, idx: int) -> float: | ||
""" | ||
An internal method to get an integral between two bounds of a unit | ||
quadrant. Used in algorithm to determine bond probabilities. | ||
|
||
Args: | ||
dist_bins: (float) list of all possible bond weights | ||
idx: (float) index of starting bond weight | ||
|
||
Returns: | ||
float: integral of portion of unit quadrant | ||
""" | ||
radius = 1 | ||
|
||
x1 = dist_bins[idx] | ||
x2 = dist_bins[idx + 1] | ||
|
||
areaquarter = 0.25 * math.pi * radius**2 | ||
|
||
area1 = areaquarter - 0.5 * ( | ||
radius**2 * math.acos(1 - x1 / radius) - (radius - x1) * math.sqrt(2 * radius * x1 - x1**2) | ||
) | ||
area2 = areaquarter - 0.5 * ( | ||
radius**2 * math.acos(1 - x2 / radius) - (radius - x2) * math.sqrt(2 * radius * x2 - x2**2) | ||
) | ||
|
||
return (area2 - area1) / areaquarter | ||
|
||
@staticmethod | ||
def transform_to_length(nn_data, length): | ||
""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should not be reverted