Skip to content

Commit b3ac45a

Browse files
committed
add_oxidation_state_by_guess clarify which guess is used if multiple
fix doc strings with empty return value section
1 parent abd9893 commit b3ac45a

File tree

7 files changed

+34
-40
lines changed

7 files changed

+34
-40
lines changed

pymatgen/analysis/chemenv/connectivity/connected_components.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -371,12 +371,10 @@ def coordination_sequence(self, source_node, path_size=5, coordination="number",
371371
def __len__(self):
372372
return len(self.graph)
373373

374-
def compute_periodicity(self, algorithm="all_simple_paths"):
374+
def compute_periodicity(self, algorithm="all_simple_paths") -> None:
375375
"""
376376
Args:
377377
algorithm ():
378-
379-
Returns:
380378
"""
381379
if algorithm == "all_simple_paths":
382380
self.compute_periodicity_all_simple_paths_algorithm()
@@ -519,6 +517,7 @@ def make_supergraph(self, multiplicity):
519517
multiplicity ():
520518
521519
Returns:
520+
nx.MultiGraph: Super graph of the connected component.
522521
"""
523522
return make_supergraph(self._connected_subgraph, multiplicity, self._periodicity_vectors)
524523

pymatgen/analysis/chemenv/connectivity/structure_connectivity.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ def __init__(
5050
5151
Args:
5252
light_structure_environment: a LightStructureEnvironments object
53-
containing the relevant local environments
54-
for the sites in the structure.
53+
containing the relevant local environments
54+
for the sites in the structure.
5555
connectivity_graph: the networkx MultiGraph if it has already been computed,
56-
e.g. stored in a file or dict and StructureConnectivity
57-
is reconstructed from that file or dict.
56+
e.g. stored in a file or dict and StructureConnectivity
57+
is reconstructed from that file or dict.
5858
environment_subgraphs: the different subgraphs of environments that have
59-
been computed if any (as for connectivity_graph, only
60-
if it is reconstructed from a file or dict).
59+
been computed if any (as for connectivity_graph, only
60+
if it is reconstructed from a file or dict).
6161
"""
6262
self.light_structure_environments = light_structure_environment
6363
if connectivity_graph is None:
@@ -76,6 +76,7 @@ def environment_subgraph(self, environments_symbols=None, only_atoms=None):
7676
only_atoms ():
7777
7878
Returns:
79+
nx.MultiGraph: The subgraph of the structure connectivity graph
7980
"""
8081
if environments_symbols is not None:
8182
self.setup_environment_subgraph(environments_symbols=environments_symbols, only_atoms=only_atoms)
@@ -304,11 +305,12 @@ def from_dict(cls, d):
304305
d ():
305306
306307
Returns:
308+
StructureConnectivity
307309
"""
308310
# Reconstructs the graph with integer as nodes (json's as_dict replaces integer keys with str keys)
309311
cgraph = nx.from_dict_of_dicts(d["connectivity_graph"], create_using=nx.MultiGraph, multigraph_input=True)
310312
cgraph = nx.relabel_nodes(cgraph, int) # Just relabel the nodes using integer casting (maps str->int)
311-
# Relabel multiedges (removes multiedges with str keys and adds them back with int keys)
313+
# Relabel multi-edges (removes multi-edges with str keys and adds them back with int keys)
312314
edges = set(cgraph.edges())
313315
for n1, n2 in edges:
314316
new_edges = {int(iedge): edata for iedge, edata in cgraph[n1][n2].items()}

pymatgen/analysis/molecule_structure_comparator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ def get_13_bonds(priority_bonds):
192192
priority_bonds ():
193193
194194
Returns:
195+
tuple: 13 bonds
195196
"""
196197
all_bond_pairs = list(itertools.combinations(priority_bonds, r=2))
197198
all_2_bond_atoms = [set(b1 + b2) for b1, b2 in all_bond_pairs]
@@ -203,8 +204,7 @@ def get_13_bonds(priority_bonds):
203204
return tuple(sorted(bonds_13))
204205

205206
def _get_bonds(self, mol):
206-
"""
207-
Find all the bond in a molcule.
207+
"""Find all bonds in a molecule.
208208
209209
Args:
210210
mol: the molecule. pymatgen Molecule object

pymatgen/analysis/pourbaix_diagram.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,7 @@ def find_stable_entry(self, pH, V):
809809
V (float): V to find stable entry.
810810
811811
Returns:
812+
PourbaixEntry: stable entry at pH, V
812813
"""
813814
energies_at_conditions = [e.normalized_energy_at_conditions(pH, V) for e in self.stable_entries]
814815
return self.stable_entries[np.argmin(energies_at_conditions)]

pymatgen/command_line/bader_caller.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,8 @@ def get_oxidation_state_decorated_structure(self, nelects: list[int] | None = No
303303
Returns:
304304
Structure: with bader-analysis-based oxidation states.
305305
"""
306-
charges = [self.get_partial_charge(i, None if not nelects else nelects[i]) for i in range(len(self.structure))]
307306
struct = self.structure.copy()
307+
charges = [self.get_partial_charge(idx, None if not nelects else nelects[idx]) for idx in range(len(struct))]
308308
struct.add_oxidation_state_by_site(charges)
309309
return struct
310310

pymatgen/core/structure.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,8 @@ def remove_oxidation_states(self) -> None:
570570

571571
def add_oxidation_state_by_guess(self, **kwargs) -> None:
572572
"""Decorates the structure with oxidation state, guessing
573-
using Composition.oxi_state_guesses().
573+
using Composition.oxi_state_guesses(). If multiple guesses are found
574+
we take the first one.
574575
575576
Args:
576577
**kwargs: parameters to pass into oxi_state_guesses()
@@ -1193,7 +1194,7 @@ def from_magnetic_spacegroup(
11931194
return cls(latt, all_sp, all_coords, site_properties=all_site_properties, labels=all_labels)
11941195

11951196
def unset_charge(self):
1196-
"""Reset the charge to None, i.e., computed dynamically based on oxidation states."""
1197+
"""Reset the charge to None. E.g. to compute it dynamically based on oxidation states."""
11971198
self._charge = None
11981199

11991200
@property
@@ -1222,10 +1223,10 @@ def charge(self) -> float:
12221223
formal_charge = super().charge
12231224
if self._charge is None:
12241225
return super().charge
1225-
if formal_charge != self._charge:
1226+
if abs(formal_charge - self._charge) > 1e-8:
12261227
warnings.warn(
12271228
f"Structure charge ({self._charge}) is set to be not equal to the sum of oxidation states"
1228-
f" ({formal_charge}). Use `unset_charge` if this is not desired."
1229+
f" ({formal_charge}). Use Structure.unset_charge() to reset the charge to None."
12291230
)
12301231
return self._charge
12311232

pymatgen/io/lobster/lobsterenv.py

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ def _evaluate_ce(
685685
additional_condition=0,
686686
perc_strength_ICOHP=0.15,
687687
adapt_extremum_to_add_cond=False,
688-
):
688+
) -> None:
689689
"""
690690
Args:
691691
lowerlimit: lower limit which determines the ICOHPs that are considered for the determination of the
@@ -698,8 +698,6 @@ def _evaluate_ce(
698698
that are still considered for the evaluation
699699
adapt_extremum_to_add_cond: will recalculate the limit based on the bonding type and not on the overall
700700
extremum.
701-
702-
Returns:
703701
"""
704702
# get extremum
705703
if lowerlimit is None and upperlimit is None:
@@ -812,6 +810,7 @@ def _find_environments(self, additional_condition, lowerlimit, upperlimit, only_
812810
only_bonds_to (list): list of str, e.g. ["O"] that will ensure that only bonds to "O" will be considered
813811
814812
Returns:
813+
tuple: list of icohps, list of keys, list of lengths, list of neighisite, list of neighsite, list of coords
815814
"""
816815
# run over structure
817816
list_neighsite = []
@@ -829,12 +828,8 @@ def _find_environments(self, additional_condition, lowerlimit, upperlimit, only_
829828
only_bonds_to=only_bonds_to,
830829
)
831830

832-
(
833-
keys_from_ICOHPs,
834-
lengths_from_ICOHPs,
835-
neighbors_from_ICOHPs,
836-
selected_ICOHPs,
837-
) = self._find_relevant_atoms_additional_condition(idx, icohps, additional_condition)
831+
additional_conds = self._find_relevant_atoms_additional_condition(idx, icohps, additional_condition)
832+
keys_from_ICOHPs, lengths_from_ICOHPs, neighbors_from_ICOHPs, selected_ICOHPs = additional_conds
838833

839834
if len(neighbors_from_ICOHPs) > 0:
840835
centralsite = self.structure[idx]
@@ -927,6 +922,7 @@ def _find_relevant_atoms_additional_condition(self, isite, icohps, additional_co
927922
additional_condition (int): additional condition
928923
929924
Returns:
925+
tuple: keys, lengths and neighbors from selected ICOHPs and selected ICOHPs
930926
"""
931927
neighbors_from_ICOHPs = []
932928
lengths_from_ICOHPs = []
@@ -1048,17 +1044,11 @@ def _find_relevant_atoms_additional_condition(self, isite, icohps, additional_co
10481044
icohps_from_ICOHPs.append(icohp.summed_icohp)
10491045
keys_from_ICOHPs.append(key)
10501046

1051-
return (
1052-
keys_from_ICOHPs,
1053-
lengths_from_ICOHPs,
1054-
neighbors_from_ICOHPs,
1055-
icohps_from_ICOHPs,
1056-
)
1047+
return keys_from_ICOHPs, lengths_from_ICOHPs, neighbors_from_ICOHPs, icohps_from_ICOHPs
10571048

10581049
@staticmethod
10591050
def _get_icohps(icohpcollection, isite, lowerlimit, upperlimit, only_bonds_to):
1060-
"""
1061-
Return icohp dict for certain site.
1051+
"""Return icohp dict for certain site.
10621052
10631053
Args:
10641054
icohpcollection: Icohpcollection object
@@ -1068,6 +1058,7 @@ def _get_icohps(icohpcollection, isite, lowerlimit, upperlimit, only_bonds_to):
10681058
only_bonds_to (list): list of str, e.g. ["O"] that will ensure that only bonds to "O" will be considered
10691059
10701060
Returns:
1061+
dict: of IcohpValues. The keys correspond to the values from the initial list_labels.
10711062
"""
10721063
return icohpcollection.get_icohp_dict_of_site(
10731064
site=isite,
@@ -1091,7 +1082,7 @@ def _get_atomnumber(atomstring) -> int:
10911082
return int(LobsterNeighbors._split_string(atomstring)[1]) - 1
10921083

10931084
@staticmethod
1094-
def _split_string(s):
1085+
def _split_string(s) -> tuple[str, str]:
10951086
"""
10961087
Will split strings such as "Na1" in "Na" and "1" and return "1".
10971088
@@ -1140,7 +1131,7 @@ def _get_limit_from_extremum(
11401131
):
11411132
"""
11421133
Return limits for the evaluation of the icohp values from an icohpcollection
1143-
Return -float('inf'), min(max_icohp*0.15,-0.1). Currently only works for ICOHPs.
1134+
Return -float("inf"), min(max_icohp*0.15,-0.1). Currently only works for ICOHPs.
11441135
11451136
Args:
11461137
icohpcollection: icohpcollection object
@@ -1390,10 +1381,10 @@ class ICOHPNeighborsInfo(NamedTuple):
13901381
total_icohp (float): sum of icohp values of neighbors to the selected sites [given by the id in structure]
13911382
list_icohps (list): list of summed icohp values for all identified interactions with neighbors
13921383
n_bonds (int): number of identified bonds to the selected sites
1393-
labels (list(str)): labels (from ICOHPLIST) for all identified bonds
1394-
atoms (list(list(str)): list of list describing the species present in the identified interactions
1395-
(names from ICOHPLIST), e.g., ['Ag3', 'O5']
1396-
central_isites (list(int)): list of the central isite for each identified interaction.
1384+
labels (list[str]): labels (from ICOHPLIST) for all identified bonds
1385+
atoms (list[list[str]]): list of list describing the species present in the identified interactions
1386+
(names from ICOHPLIST), e.g., ["Ag3", "O5"]
1387+
central_isites (list[int]): list of the central isite for each identified interaction.
13971388
13981389
13991390
"""

0 commit comments

Comments
 (0)