Skip to content

Commit a1295b9

Browse files
Merge remote-tracking branch 'upstream/master'
2 parents 63728ff + 51180fc commit a1295b9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+692
-654
lines changed

.coderabbit.yaml

Lines changed: 0 additions & 17 deletions
This file was deleted.

dev_scripts/regen_libxcfunc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,11 @@ def main():
111111
del lines[start + 1 : stop]
112112

113113
# [2] write new py module
114-
with open(xc_funcpy_path, mode="w") as file:
114+
with open(xc_funcpy_path, mode="w", encoding="utf-8") as file:
115115
file.writelines(lines)
116116

117117
print("Files have been regenerated")
118-
print("Remember to update libxc_version in libxcfuncs.py!")
118+
print("Remember to update __version__ in libxcfuncs.py!")
119119

120120
return 0
121121

pymatgen/analysis/elasticity/elastic.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -914,8 +914,7 @@ def find_eq_stress(strains, stresses, tol: float = 1e-10):
914914

915915

916916
def get_strain_state_dict(strains, stresses, eq_stress=None, tol: float = 1e-10, add_eq=True, sort=True):
917-
"""
918-
Creates a dictionary of voigt notation stress-strain sets
917+
"""Create a dictionary of voigt notation stress-strain sets
919918
keyed by "strain state", i. e. a tuple corresponding to
920919
the non-zero entries in ratios to the lowest nonzero value,
921920
e.g. [0, 0.1, 0, 0.2, 0, 0] -> (0,1,0,2,0,0)

pymatgen/analysis/ewald.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -541,17 +541,15 @@ def __init__(self, matrix, m_list, num_to_return=1, algo=ALGO_FAST):
541541
self._minimized_sum = self._output_lists[0][0]
542542

543543
def minimize_matrix(self):
544-
"""
545-
This method finds and returns the permutations that produce the lowest
544+
"""Get the permutations that produce the lowest
546545
Ewald sum calls recursive function to iterate through permutations.
547546
"""
548547
if self._algo in (EwaldMinimizer.ALGO_FAST, EwaldMinimizer.ALGO_BEST_FIRST):
549548
return self._recurse(self._matrix, self._m_list, set(range(len(self._matrix))))
550549
return None
551550

552551
def add_m_list(self, matrix_sum, m_list):
553-
"""
554-
This adds an m_list to the output_lists and updates the current
552+
"""Add an m_list to the output_lists and updates the current
555553
minimum if the list is full.
556554
"""
557555
if self._output_lists is None:
@@ -629,9 +627,7 @@ def get_next_index(cls, matrix, manipulation, indices_left):
629627
return indices[sums.argmax(axis=0)] if f < 1 else indices[sums.argmin(axis=0)]
630628

631629
def _recurse(self, matrix, m_list, indices, output_m_list=None):
632-
"""
633-
This method recursively finds the minimal permutations using a binary
634-
tree search strategy.
630+
"""Find the minimal permutations using a binary tree search strategy.
635631
636632
Args:
637633
matrix: The current matrix (with some permutations already

pymatgen/analysis/ferroelectricity/polarization.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@
7070

7171

7272
def zval_dict_from_potcar(potcar) -> dict[str, float]:
73-
"""
74-
Creates zval_dictionary for calculating the ionic polarization from
73+
"""Create zval_dictionary for calculating the ionic polarization from
7574
Potcar object.
7675
7776
potcar: Potcar object

pymatgen/analysis/magnetism/analyzer.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -604,9 +604,7 @@ def __init__(
604604
truncate_by_symmetry: bool = True,
605605
transformation_kwargs: dict | None = None,
606606
):
607-
"""
608-
This class will try generated different collinear
609-
magnetic orderings for a given input structure.
607+
"""Generate different collinear magnetic orderings for a given input structure.
610608
611609
If the input structure has magnetic moments defined, it
612610
is possible to use these as a hint as to which elements are

pymatgen/analysis/magnetism/heisenberg.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -669,10 +669,8 @@ class HeisenbergScreener:
669669
"""Clean and screen magnetic orderings."""
670670

671671
def __init__(self, structures, energies, screen=False):
672-
"""
673-
This class pre-processes magnetic orderings and energies for
674-
HeisenbergMapper. It prioritizes low-energy orderings with large and
675-
localized magnetic moments.
672+
"""Pre-processes magnetic orderings and energies for HeisenbergMapper.
673+
It prioritizes low-energy orderings with large and localized magnetic moments.
676674
677675
Args:
678676
structures (list): Structure objects with magnetic moments.

pymatgen/analysis/structure_prediction/substitutor.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ class Substitutor(MSONable):
4545
charge_balanced_tol: float = 1e-9
4646

4747
def __init__(self, threshold=1e-3, symprec: float = 0.1, **kwargs):
48-
"""
49-
This substitutor uses the substitution probability class to
50-
find good substitutions for a given chemistry or structure.
48+
"""Use the substitution probability class to find good substitutions for a given chemistry or structure.
5149
5250
Args:
5351
threshold:

pymatgen/analysis/wulff.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -671,8 +671,7 @@ def anisotropy(self) -> float:
671671

672672
@property
673673
def shape_factor(self) -> float:
674-
"""
675-
This is useful for determining the critical nucleus size.
674+
"""Determine the critical nucleus size.
676675
A large shape factor indicates great anisotropy.
677676
See Ballufi, R. W., Allen, S. M. & Carter, W. C. Kinetics
678677
of Materials. (John Wiley & Sons, 2005), p.461.
@@ -685,10 +684,10 @@ def shape_factor(self) -> float:
685684
@property
686685
def effective_radius(self) -> float:
687686
"""
688-
Radius of the WulffShape when the WulffShape is approximated as a sphere.
687+
Radius of the WulffShape (in Angstroms) when the WulffShape is approximated as a sphere.
689688
690689
Returns:
691-
float: radius.
690+
float: radius R_eff
692691
"""
693692
return ((3 / 4) * (self.volume / np.pi)) ** (1 / 3)
694693

pymatgen/core/bonds.py

Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""This class implements definitions for various kinds of bonds. Typically used in
1+
"""This module implements definitions for various kinds of bonds. Typically used in
22
Molecule analysis.
33
"""
44

@@ -17,10 +17,13 @@
1717
from pymatgen.util.typing import SpeciesLike
1818

1919

20-
def _load_bond_length_data():
21-
"""Loads bond length data from json file."""
22-
with open(os.path.join(os.path.dirname(__file__), "bond_lengths.json")) as file:
23-
data = defaultdict(dict)
20+
def _load_bond_length_data() -> dict[tuple[str, ...], dict[float, float]]:
21+
"""Load bond length data from bond_lengths.json file."""
22+
with open(
23+
os.path.join(os.path.dirname(__file__), "bond_lengths.json"),
24+
encoding="utf-8",
25+
) as file:
26+
data: dict[tuple, dict] = defaultdict(dict)
2427
for row in json.load(file):
2528
els = sorted(row["elements"])
2629
data[tuple(els)][row["bond_order"]] = row["length"]
@@ -43,12 +46,19 @@ def __init__(self, site1: Site, site2: Site) -> None:
4346
self.site1 = site1
4447
self.site2 = site2
4548

49+
def __repr__(self) -> str:
50+
return f"Covalent bond between {self.site1} and {self.site2}"
51+
4652
@property
4753
def length(self) -> float:
4854
"""Length of the bond."""
4955
return self.site1.distance(self.site2)
5056

51-
def get_bond_order(self, tol: float = 0.2, default_bl: float | None = None) -> float:
57+
def get_bond_order(
58+
self,
59+
tol: float = 0.2,
60+
default_bl: float | None = None,
61+
) -> float:
5262
"""The bond order according the distance between the two sites.
5363
5464
Args:
@@ -71,8 +81,14 @@ def get_bond_order(self, tol: float = 0.2, default_bl: float | None = None) -> f
7181
return get_bond_order(sp1, sp2, dist, tol, default_bl)
7282

7383
@staticmethod
74-
def is_bonded(site1, site2, tol: float = 0.2, bond_order: float | None = None, default_bl: float | None = None):
75-
"""Test if two sites are bonded, up to a certain limit.
84+
def is_bonded(
85+
site1: Site,
86+
site2: Site,
87+
tol: float = 0.2,
88+
bond_order: float | None = None,
89+
default_bl: float | None = None,
90+
) -> bool:
91+
"""Check if two sites are bonded, up to a certain limit.
7692
7793
Args:
7894
site1 (Site): First site
@@ -87,7 +103,7 @@ def is_bonded(site1, site2, tol: float = 0.2, bond_order: float | None = None, d
87103
bond length. If None, a ValueError will be thrown.
88104
89105
Returns:
90-
Boolean indicating whether two sites are bonded.
106+
bool: whether two sites are bonded.
91107
"""
92108
sp1 = next(iter(site1.species))
93109
sp2 = next(iter(site2.species))
@@ -102,11 +118,12 @@ def is_bonded(site1, site2, tol: float = 0.2, bond_order: float | None = None, d
102118
return dist < (1 + tol) * default_bl
103119
raise ValueError(f"No bond data for elements {syms[0]} - {syms[1]}")
104120

105-
def __repr__(self) -> str:
106-
return f"Covalent bond between {self.site1} and {self.site2}"
107-
108121

109-
def obtain_all_bond_lengths(sp1, sp2, default_bl: float | None = None):
122+
def obtain_all_bond_lengths(
123+
sp1: SpeciesLike,
124+
sp2: SpeciesLike,
125+
default_bl: float | None = None,
126+
) -> dict[float, float]:
110127
"""Obtain bond lengths for all bond orders from bond length database.
111128
112129
Args:
@@ -127,17 +144,23 @@ def obtain_all_bond_lengths(sp1, sp2, default_bl: float | None = None):
127144
if syms in bond_lengths:
128145
return bond_lengths[syms].copy()
129146
if default_bl is not None:
130-
return {1: default_bl}
147+
return {1.0: default_bl}
131148
raise ValueError(f"No bond data for elements {syms[0]} - {syms[1]}")
132149

133150

134-
def get_bond_order(sp1, sp2, dist: float, tol: float = 0.2, default_bl: float | None = None):
151+
def get_bond_order(
152+
sp1: SpeciesLike,
153+
sp2: SpeciesLike,
154+
dist: float,
155+
tol: float = 0.2,
156+
default_bl: float | None = None,
157+
) -> float:
135158
"""Calculate the bond order given the distance of 2 species.
136159
137160
Args:
138161
sp1 (Species): First specie.
139162
sp2 (Species): Second specie.
140-
dist: Their distance in angstrom
163+
dist (float): Distance in angstrom
141164
tol (float): Relative tolerance to test. Basically, the code
142165
checks if the distance between the sites is larger than
143166
(1 + tol) * the longest bond distance or smaller than
@@ -148,8 +171,7 @@ def get_bond_order(sp1, sp2, dist: float, tol: float = 0.2, default_bl: float |
148171
bond length (bond order = 1). If None, a ValueError will be thrown.
149172
150173
Returns:
151-
Float value of bond order. For example, for C-C bond in benzene,
152-
return 1.7.
174+
float: Bond order. For example, 1.7 for C-C bond in benzene.
153175
"""
154176
all_lens = obtain_all_bond_lengths(sp1, sp2, default_bl)
155177
# Transform bond lengths dict to list assuming bond data is successive
@@ -172,7 +194,11 @@ def get_bond_order(sp1, sp2, dist: float, tol: float = 0.2, default_bl: float |
172194
return trial_bond_order - 1
173195

174196

175-
def get_bond_length(sp1: SpeciesLike, sp2: SpeciesLike, bond_order: float = 1) -> float:
197+
def get_bond_length(
198+
sp1: SpeciesLike,
199+
sp2: SpeciesLike,
200+
bond_order: float = 1,
201+
) -> float:
176202
"""Get the bond length between two species.
177203
178204
Args:
@@ -184,8 +210,8 @@ def get_bond_length(sp1: SpeciesLike, sp2: SpeciesLike, bond_order: float = 1) -
184210
C-C bond length, this should be set to 2. Defaults to 1.
185211
186212
Returns:
187-
Bond length in Angstrom. If no data is available, the sum of the atomic
188-
radius is used.
213+
float: Bond length in Angstrom. If no data is available,
214+
the sum of the atomic radius is used.
189215
"""
190216
sp1 = Element(sp1) if isinstance(sp1, str) else sp1
191217
sp2 = Element(sp2) if isinstance(sp2, str) else sp2

0 commit comments

Comments
 (0)