|
24 | 24 | from scipy.spatial import Voronoi
|
25 | 25 |
|
26 | 26 | from pymatgen.analysis.bond_valence import BV_PARAMS, BVAnalyzer
|
27 |
| -from pymatgen.analysis.graphs import MoleculeGraph, StructureGraph |
| 27 | +from pymatgen.analysis.graphs import StructureGraph |
28 | 28 | from pymatgen.analysis.molecule_structure_comparator import CovalentRadius
|
29 | 29 | from pymatgen.core import Element, IStructure, PeriodicNeighbor, PeriodicSite, Site, Species, Structure
|
30 | 30 |
|
|
38 | 38 |
|
39 | 39 | from typing_extensions import Self
|
40 | 40 |
|
| 41 | + from pymatgen.analysis.graphs import MoleculeGraph |
41 | 42 | from pymatgen.core.composition import SpeciesLike
|
42 | 43 | from pymatgen.util.typing import Tuple3Ints
|
43 | 44 |
|
|
55 | 56 |
|
56 | 57 | with open(f"{MODULE_DIR}/op_params.yaml", encoding="utf-8") as file:
|
57 | 58 | DEFAULT_OP_PARAMS: dict[str, dict[str | int, float] | None] = YAML().load(file)
|
| 59 | +default_op_params = DEFAULT_OP_PARAMS # needed externally |
58 | 60 |
|
59 | 61 | with open(f"{MODULE_DIR}/cn_opt_params.yaml", encoding="utf-8") as file:
|
60 | 62 | CN_OPT_PARAMS: dict[int, dict[str, list[str | dict[str, float]]]] = YAML().load(file)
|
| 63 | +cn_opt_params = CN_OPT_PARAMS # needed externally |
61 | 64 |
|
62 | 65 | with open(f"{MODULE_DIR}/ionic_radii.json", encoding="utf-8") as file:
|
63 | 66 | _ION_RADII = json.load(file)
|
@@ -110,9 +113,8 @@ def nearest_key(sorted_vals: list[int], skey: int) -> int:
|
110 | 113 | return sorted_vals[0]
|
111 | 114 | before = sorted_vals[idx - 1]
|
112 | 115 | after = sorted_vals[idx]
|
113 |
| - if after - skey < skey - before: |
114 |
| - return after |
115 |
| - return before |
| 116 | + |
| 117 | + return after if after - skey < skey - before else before |
116 | 118 |
|
117 | 119 | for idx, site in enumerate(self._structure):
|
118 | 120 | if isinstance(site.specie, Element):
|
@@ -214,27 +216,27 @@ def _handle_disorder(structure: Structure, on_disorder: on_disorder_options):
|
214 | 216 | "example since Fe and O have equal occupancy and Fe comes first). 'error' raises an error in case "
|
215 | 217 | f"of disordered structure. Offending {structure = }"
|
216 | 218 | )
|
217 |
| - if on_disorder.startswith("take_"): |
218 |
| - # disordered structures raise AttributeError when passed to NearNeighbors.get_cn() |
219 |
| - # or NearNeighbors.get_bonded_structure() (and probably others too, see GH-2070). |
220 |
| - # As a workaround, we create a new structure with majority species on each site. |
221 |
| - structure = structure.copy() # make a copy so we don't mutate the original structure |
222 |
| - for idx, site in enumerate(structure): |
223 |
| - max_specie = max(site.species, key=site.species.get) |
224 |
| - max_val = site.species[max_specie] |
225 |
| - if max_val <= 0.5: |
226 |
| - if on_disorder == "take_majority_strict": |
227 |
| - raise ValueError( |
228 |
| - f"Site {idx} has no majority species, the max species is {max_specie} with occupancy {max_val}" |
229 |
| - ) |
230 |
| - if on_disorder == "take_majority_drop": |
231 |
| - continue |
232 |
| - |
233 |
| - # this is the take_max_species case |
234 |
| - site.species = max_specie # set site species in copied structure to max specie |
235 |
| - else: |
| 219 | + if not on_disorder.startswith("take_"): |
236 | 220 | raise ValueError(f"Unexpected {on_disorder = }, should be one of {get_args(on_disorder_options)}")
|
237 | 221 |
|
| 222 | + # disordered structures raise AttributeError when passed to NearNeighbors.get_cn() |
| 223 | + # or NearNeighbors.get_bonded_structure() (and probably others too, see GH-2070). |
| 224 | + # As a workaround, we create a new structure with majority species on each site. |
| 225 | + structure = structure.copy() # make a copy so we don't mutate the original structure |
| 226 | + for idx, site in enumerate(structure): |
| 227 | + max_specie = max(site.species, key=site.species.get) |
| 228 | + max_val = site.species[max_specie] |
| 229 | + if max_val <= 0.5: |
| 230 | + if on_disorder == "take_majority_strict": |
| 231 | + raise ValueError( |
| 232 | + f"Site {idx} has no majority species, the max species is {max_specie} with occupancy {max_val}" |
| 233 | + ) |
| 234 | + if on_disorder == "take_majority_drop": |
| 235 | + continue |
| 236 | + |
| 237 | + # this is the take_max_species case |
| 238 | + site.species = max_specie # set site species in copied structure to max specie |
| 239 | + |
238 | 240 | return structure
|
239 | 241 |
|
240 | 242 |
|
@@ -1525,6 +1527,9 @@ def get_bonded_structure(self, structure: Structure, decorate: bool = False) ->
|
1525 | 1527 | Returns:
|
1526 | 1528 | MoleculeGraph: object from pymatgen.analysis.graphs
|
1527 | 1529 | """
|
| 1530 | + # requires optional dependency which is why it's not a top-level import |
| 1531 | + from pymatgen.analysis.graphs import MoleculeGraph |
| 1532 | + |
1528 | 1533 | if decorate:
|
1529 | 1534 | # Decorate all sites in the underlying structure
|
1530 | 1535 | # with site properties that provides information on the
|
@@ -2508,7 +2513,7 @@ def get_q2(self, thetas=None, phis=None):
|
2508 | 2513 | imag += pre_y_2_2[idx] * self._sin_n_p[2][idx]
|
2509 | 2514 | acc += real * real + imag * imag
|
2510 | 2515 |
|
2511 |
| - return math.sqrt(4 * math.pi * acc / (5 * float(n_nn * n_nn))) |
| 2516 | + return math.sqrt(4 * math.pi * acc / (5 * float(n_nn**2))) |
2512 | 2517 |
|
2513 | 2518 | def get_q4(self, thetas=None, phis=None):
|
2514 | 2519 | """
|
@@ -2617,7 +2622,7 @@ def get_q4(self, thetas=None, phis=None):
|
2617 | 2622 | imag += pre_y_4_4[idx] * self._sin_n_p[4][idx]
|
2618 | 2623 | acc += real * real + imag * imag
|
2619 | 2624 |
|
2620 |
| - return math.sqrt(4 * math.pi * acc / (9 * float(n_nn * n_nn))) |
| 2625 | + return math.sqrt(4 * math.pi * acc / (9 * float(n_nn**2))) |
2621 | 2626 |
|
2622 | 2627 | def get_q6(self, thetas=None, phis=None):
|
2623 | 2628 | """
|
@@ -2788,7 +2793,7 @@ def get_q6(self, thetas=None, phis=None):
|
2788 | 2793 | imag += pre_y_6_6[idx] * self._sin_n_p[6][idx]
|
2789 | 2794 | acc += real * real + imag * imag
|
2790 | 2795 |
|
2791 |
| - return math.sqrt(4 * math.pi * acc / (13 * float(n_nn * n_nn))) |
| 2796 | + return math.sqrt(4 * math.pi * acc / (13 * float(n_nn**2))) |
2792 | 2797 |
|
2793 | 2798 | def get_type(self, index):
|
2794 | 2799 | """Get type of order parameter at the index provided and
|
|
0 commit comments