Skip to content

Commit bb68c78

Browse files
DanielYang59janosh
andauthored
Improve type annotations and comments for io.cif (#3820)
* remove duplicate warning * type and docstring tweaks * add some types for io.cif * add comments and types * temp save of some formatting * revert functional change * revert unrelated changes * fix unit test * remove update that does nothing * relocate `sub_space_group` and `space_groups` to their usage * add more types * pre-commit auto-fixes * breaking: make parse_magmom/oxi_stats private * remove merge header * fix unit test * add more types * fix mypy errors * add a few spaces * remove if name ==main * simplify "check to see if" in comments * final tweaks * revise docstring * replace deprecated abc.abstractproperty * add missing doc strings and standardize existing * breaking: fix typo in method name orthongonalize_structure * revert accidental change in test_composition.py --------- Co-authored-by: Janosh Riebesell <janosh.riebesell@gmail.com>
1 parent 50043c9 commit bb68c78

33 files changed

+606
-507
lines changed

docs/pymatgen.md

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pymatgen/alchemy/materials.py

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

3131

3232
class TransformedStructure(MSONable):
33-
"""Container object for new structures that include history of
34-
transformations.
33+
"""Container for new structures that include history of transformations.
3534
3635
Each transformed structure is made up of a sequence of structures with
3736
associated transformation history.

pymatgen/analysis/chemenv/coordination_environments/chemenv_strategies.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,7 +1265,7 @@ def from_dict(cls, dct: dict) -> Self:
12651265

12661266

12671267
class NbSetWeight(MSONable, abc.ABC):
1268-
"""Abstract object for neighbors sets weights estimations."""
1268+
"""Abstract base class for neighbor set weight estimations."""
12691269

12701270
@abc.abstractmethod
12711271
def as_dict(self):
@@ -1282,7 +1282,7 @@ def weight(self, nb_set, structure_environments, cn_map=None, additional_info=No
12821282
additional_info: Additional information.
12831283
12841284
Returns:
1285-
Weight of the neighbors set.
1285+
float: Weight of the neighbors set.
12861286
"""
12871287

12881288

@@ -1313,7 +1313,7 @@ def weight(self, nb_set, structure_environments, cn_map=None, additional_info=No
13131313
additional_info: Additional information.
13141314
13151315
Returns:
1316-
Weight of the neighbors set.
1316+
float: Weight of the neighbors set.
13171317
"""
13181318
return self.aw(nb_set=nb_set)
13191319

@@ -1534,7 +1534,7 @@ def weight(self, nb_set, structure_environments, cn_map=None, additional_info=No
15341534
additional_info: Additional information.
15351535
15361536
Returns:
1537-
Weight of the neighbors set.
1537+
float: Weight of the neighbors set.
15381538
"""
15391539
fda_list = self.fda(nb_set=nb_set)
15401540
return self.eval(fda_list=fda_list)
@@ -1680,7 +1680,7 @@ def weight(self, nb_set, structure_environments, cn_map=None, additional_info=No
16801680
additional_info: Additional information.
16811681
16821682
Returns:
1683-
Weight of the neighbors set.
1683+
float: Weight of the neighbors set.
16841684
"""
16851685
effective_csm = get_effective_csm(
16861686
nb_set=nb_set,
@@ -1791,7 +1791,7 @@ def weight(self, nb_set, structure_environments, cn_map=None, additional_info=No
17911791
additional_info: Additional information.
17921792
17931793
Returns:
1794-
Weight of the neighbors set.
1794+
float: Weight of the neighbors set.
17951795
"""
17961796
effcsm = get_effective_csm(
17971797
nb_set=nb_set,
@@ -2006,7 +2006,7 @@ def weight(self, nb_set, structure_environments, cn_map=None, additional_info=No
20062006
additional_info: Additional information.
20072007
20082008
Returns:
2009-
Weight of the neighbors set.
2009+
float: Weight of the neighbors set.
20102010
"""
20112011
return self.cn_weights[len(nb_set)]
20122012

@@ -2186,7 +2186,7 @@ def weight(self, nb_set, structure_environments, cn_map=None, additional_info=No
21862186
additional_info: Additional information.
21872187
21882188
Returns:
2189-
Weight of the neighbors set.
2189+
float: Weight of the neighbors set.
21902190
"""
21912191
return self.area_weight(
21922192
nb_set=nb_set,
@@ -2379,7 +2379,7 @@ def weight(self, nb_set, structure_environments, cn_map=None, additional_info=No
23792379
additional_info: Additional information.
23802380
23812381
Returns:
2382-
Weight of the neighbors set.
2382+
float: Weight of the neighbors set.
23832383
"""
23842384
return self.weight_rf.eval(nb_set.distance_plateau())
23852385

@@ -2446,7 +2446,7 @@ def weight(self, nb_set, structure_environments, cn_map=None, additional_info=No
24462446
additional_info: Additional information.
24472447
24482448
Returns:
2449-
Weight of the neighbors set.
2449+
float: Weight of the neighbors set.
24502450
"""
24512451
return self.weight_rf.eval(nb_set.angle_plateau())
24522452

@@ -2509,7 +2509,7 @@ def weight(self, nb_set, structure_environments, cn_map=None, additional_info=No
25092509
additional_info: Additional information.
25102510
25112511
Returns:
2512-
Weight of the neighbors set.
2512+
float: Weight of the neighbors set.
25132513
"""
25142514
cn = cn_map[0]
25152515
isite = nb_set.isite
@@ -2590,7 +2590,7 @@ def weight(self, nb_set, structure_environments, cn_map=None, additional_info=No
25902590
additional_info: Additional information.
25912591
25922592
Returns:
2593-
Weight of the neighbors set.
2593+
float: Weight of the neighbors set.
25942594
"""
25952595
cn = cn_map[0]
25962596
isite = nb_set.isite

pymatgen/analysis/cost.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def get_entries(self, chemsys):
112112

113113
@singleton
114114
class CostDBElements(CostDBCSV):
115-
"""Singleton object that provides the cost data for elements."""
115+
"""Singleton that provides the cost data for elements."""
116116

117117
def __init__(self):
118118
CostDBCSV.__init__(self, f"{module_dir}/costdb_elements.csv")

pymatgen/analysis/ewald.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ def _recurse(self, matrix, m_list, indices, output_m_list=None):
638638
indices: Set of indices which haven't had a permutation
639639
performed on them.
640640
"""
641-
# check to see if we've found all the solutions that we need
641+
# Check if we've found all the solutions that we need
642642
if self._finished:
643643
return
644644

pymatgen/analysis/fragmenter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def _fragment_one_level(self, old_frag_dict: dict) -> dict:
166166
"""
167167
Perform one step of iterative fragmentation on a list of molecule graphs. Loop through the graphs,
168168
then loop through each graph's edges and attempt to remove that edge in order to obtain two
169-
disconnected subgraphs, aka two new fragments. If successful, check to see if the new fragments
169+
disconnected subgraphs, aka two new fragments. If successful, check if the new fragments
170170
are already present in self.unique_fragments, and append them if not. If unsuccessful, we know
171171
that edge belongs to a ring. If we are opening rings, do so with that bond, and then again
172172
check if the resulting fragment is present in self.unique_fragments and add it if it is not.

pymatgen/analysis/magnetism/analyzer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def __init__(
161161
except ValueError:
162162
warnings.warn(f"Could not assign valences for {structure.reduced_formula}")
163163

164-
# check to see if structure has magnetic moments
164+
# Check if structure has magnetic moments
165165
# on site properties or species spin properties,
166166
# prioritize site properties
167167

pymatgen/analysis/reaction_calculator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737

3838
class BalancedReaction(MSONable):
39-
"""An object representing a complete chemical reaction."""
39+
"""Represent a complete chemical reaction."""
4040

4141
# Tolerance for determining if a particular component fraction is > 0.
4242
TOLERANCE = 1e-6

pymatgen/analysis/thermochemistry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121

2222
class ThermoData:
23-
"""A object container for an experimental Thermochemical Data."""
23+
"""Container for experimental thermo-chemical data."""
2424

2525
def __init__(
2626
self,

pymatgen/core/libxcfunc.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,3 @@ def from_dict(cls, dct: dict) -> Self:
499499
def to_json(self) -> str:
500500
"""Get a json string representation of the LibxcFunc."""
501501
return json.dumps(self.as_dict(), cls=MontyEncoder)
502-
503-
504-
if __name__ == "__main__":
505-
for xc in LibxcFunc:
506-
print(xc)

pymatgen/core/structure.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4056,7 +4056,7 @@ def substitute(self, index: int, func_group: IMolecule | Molecule | str, bond_or
40564056
fgroup = func_group
40574057

40584058
else:
4059-
# Check to see whether the functional group is in database.
4059+
# Check whether the functional group is in database.
40604060
if func_group not in FunctionalGroups:
40614061
raise ValueError(
40624062
f"Can't find functional group {func_group!r} in list. Provide explicit coordinates instead"
@@ -4949,7 +4949,7 @@ def substitute(self, index: int, func_group: IMolecule | Molecule | str, bond_or
49494949
if isinstance(func_group, Molecule):
49504950
functional_group = func_group
49514951
else:
4952-
# Check to see whether the functional group is in database.
4952+
# Check whether the functional group is in database.
49534953
if func_group not in FunctionalGroups:
49544954
raise RuntimeError("Can't find functional group in list. Provide explicit coordinate instead")
49554955
functional_group = FunctionalGroups[func_group]

pymatgen/core/xcfunc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525

2626
class XcFunc(MSONable):
27-
"""This object stores information about the XC correlation functional.
27+
"""Store information about the XC correlation functional.
2828
2929
Client code usually creates the object by calling the class methods:
3030
@@ -162,7 +162,7 @@ def aliases(cls) -> list[str]:
162162

163163
@classmethod
164164
def asxc(cls, obj) -> Self:
165-
"""Convert object into XcFunc."""
165+
"""Convert to XcFunc."""
166166
if isinstance(obj, cls):
167167
return obj
168168
if isinstance(obj, str):

pymatgen/electronic_structure/bandstructure.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -681,9 +681,8 @@ def from_old_dict(cls, dct) -> Self:
681681

682682

683683
class BandStructureSymmLine(BandStructure, MSONable):
684-
r"""This object stores band structures along selected (symmetry) lines in the
685-
Brillouin zone. We call the different symmetry lines (ex: \\Gamma to Z)
686-
"branches".
684+
r"""Store band structures along selected (symmetry) lines in the Brillouin zone.
685+
We call the different symmetry lines (ex: \\Gamma to Z) "branches".
687686
"""
688687

689688
def __init__(

pymatgen/electronic_structure/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ def get_suggested_saxis(magmoms):
355355

356356
@staticmethod
357357
def are_collinear(magmoms) -> bool:
358-
"""Check to see if a set of magnetic moments are collinear with each other.
358+
"""Check if a set of magnetic moments are collinear with each other.
359359
360360
Args:
361361
magmoms: list of magmoms (Magmoms, scalars or vectors).

pymatgen/entries/compatibility.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1354,7 +1354,7 @@ def get_adjustments(self, entry: ComputedEntry) -> list[EnergyAdjustment]:
13541354
# TODO - detection of embedded water molecules is not very sophisticated
13551355
# Should be replaced with some kind of actual structure detection
13561356

1357-
# For any compound except water, check to see if it is a hydrate (contains
1357+
# For any compound except water, check if it is a hydrate (contains
13581358
# H2O in its structure). If so, adjust the energy to remove MU_H2O eV per
13591359
# embedded water molecule.
13601360
# in other words, we assume that the DFT energy of such a compound is really

0 commit comments

Comments
 (0)