Skip to content

Commit 9a3f714

Browse files
committed
format doc strings
1 parent 28bd5df commit 9a3f714

File tree

16 files changed

+54
-84
lines changed

16 files changed

+54
-84
lines changed

pymatgen/analysis/chemenv/coordination_environments/structure_environments.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2205,11 +2205,7 @@ def add_coord_geom(
22052205
}
22062206

22072207
def __str__(self):
2208-
"""Get a string representation of the ChemicalEnvironments object.
2209-
2210-
Returns:
2211-
String representation of the ChemicalEnvironments object.
2212-
"""
2208+
"""Get a string representation of the ChemicalEnvironments."""
22132209
out = "Chemical environments object :\n"
22142210
if len(self.coord_geoms) == 0:
22152211
out += " => No coordination in it <=\n"

pymatgen/analysis/chemenv/utils/coordination_geometry_utils.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -699,11 +699,7 @@ def init_3points(self, non_zeros, zeros):
699699
self.p3[zeros[1]] = 1.0
700700

701701
def __str__(self):
702-
"""String representation of the Plane object
703-
704-
Returns:
705-
String representation of the Plane object.
706-
"""
702+
"""String representation of the Plane."""
707703
return (
708704
f"Plane object\n => Normal vector : {self.normal_vector}\n => Equation of the plane"
709705
f" ax + by + cz + d = 0\n with a = {self._coefficients[0]}\n "

pymatgen/analysis/cost.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import itertools
1414
import os
1515
from collections import defaultdict
16+
from typing import TYPE_CHECKING
1617

1718
import scipy.constants as const
1819
from monty.design_patterns import singleton
@@ -21,6 +22,9 @@
2122
from pymatgen.core import Composition, Element
2223
from pymatgen.util.provenance import is_valid_bibtex
2324

25+
if TYPE_CHECKING:
26+
from pymatgen.util.typing import CompositionLike
27+
2428
__author__ = "Anubhav Jain"
2529
__copyright__ = "Copyright 2013, The Materials Project"
2630
__version__ = "0.1"
@@ -145,7 +149,7 @@ def get_lowest_decomposition(self, composition):
145149
elements = [e.symbol for e in composition.elements]
146150
for idx in range(len(elements)):
147151
for combi in itertools.combinations(elements, idx + 1):
148-
chemsys = [Element(e) for e in combi]
152+
chemsys = [Element(el) for el in combi]
149153
x = self.costdb.get_entries(chemsys)
150154
entries_list.extend(x)
151155
try:
@@ -154,29 +158,27 @@ def get_lowest_decomposition(self, composition):
154158
except IndexError:
155159
raise ValueError("Error during PD building; most likely, cost data does not exist!")
156160

157-
def get_cost_per_mol(self, comp):
161+
def get_cost_per_mol(self, comp: CompositionLike) -> float:
158162
"""Get best estimate of minimum cost/mol based on known data.
159163
160164
Args:
161-
comp:
162-
Composition as a pymatgen.core.structure.Composition
165+
comp (CompositionLike): chemical formula
163166
164167
Returns:
165-
float of cost/mol
168+
float: energy cost/mol
166169
"""
167-
comp = comp if isinstance(comp, Composition) else Composition(comp)
170+
comp = Composition(comp)
168171
decomp = self.get_lowest_decomposition(comp)
169-
return sum(k.energy_per_atom * v * comp.num_atoms for k, v in decomp.items())
172+
return sum(elem.energy_per_atom * val * comp.num_atoms for elem, val in decomp.items())
170173

171174
def get_cost_per_kg(self, comp):
172175
"""Get best estimate of minimum cost/kg based on known data.
173176
174177
Args:
175-
comp:
176-
Composition as a pymatgen.core.structure.Composition
178+
comp (CompositionLike): chemical formula
177179
178180
Returns:
179-
float of cost/kg
181+
float: energy cost/kg
180182
"""
181183
comp = comp if isinstance(comp, Composition) else Composition(comp)
182184
return self.get_cost_per_mol(comp) / (comp.weight.to("kg") * const.N_A)

pymatgen/command_line/gulp_caller.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ def structure_lines(
278278
written.
279279
280280
Returns:
281-
string containing structure for GULP input
281+
str: containing structure for GULP input
282282
"""
283283
gin = ""
284284
if cell_flg:
@@ -313,8 +313,7 @@ def structure_lines(
313313

314314
@staticmethod
315315
def specie_potential_lines(structure, potential, **kwargs):
316-
"""Generate GULP input specie and potential string for pymatgen
317-
structure.
316+
"""Generate GULP input species and potential string for pymatgen structure.
318317
319318
Args:
320319
structure: pymatgen Structure object
@@ -331,10 +330,9 @@ def specie_potential_lines(structure, potential, **kwargs):
331330
cation_shell_chrg=float
332331
333332
Returns:
334-
string containing specie and potential specification for gulp
335-
input.
333+
str: containing species and potential for GULP input
336334
"""
337-
raise NotImplementedError("gulp_specie_potential not yet implemented.\nUse library_line instead")
335+
raise NotImplementedError("gulp_specie_potential not yet implemented. Use library_line instead")
338336

339337
@staticmethod
340338
def library_line(file_name):

pymatgen/core/bonds.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ def get_bond_order(self, tol: float = 0.2, default_bl: float | None = None) -> f
6363
(bond order = 1). If None, a ValueError will be thrown.
6464
6565
Returns:
66-
Float value of bond order. For example, for C-C bond in
67-
benzene, return 1.7.
66+
float: value of bond order. E.g. 1.7 for C-C bond in benzene.
6867
"""
6968
sp1 = next(iter(self.site1.species))
7069
sp2 = next(iter(self.site2.species))

pymatgen/electronic_structure/cohp.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,7 @@ def icohpvalue(self, spin=Spin.up):
985985

986986
return self._icohp[spin]
987987

988-
def icohpvalue_orbital(self, orbitals, spin=Spin.up):
988+
def icohpvalue_orbital(self, orbitals, spin=Spin.up) -> float:
989989
"""
990990
Args:
991991
orbitals: List of Orbitals or "str(Orbital1)-str(Orbital2)"
@@ -1107,7 +1107,7 @@ def __str__(self) -> str:
11071107
joinstr.append(str(value))
11081108
return "\n".join(joinstr)
11091109

1110-
def get_icohp_by_label(self, label, summed_spin_channels=True, spin=Spin.up, orbitals=None):
1110+
def get_icohp_by_label(self, label, summed_spin_channels=True, spin=Spin.up, orbitals=None) -> float:
11111111
"""Get an icohp value for a certain bond as indicated by the label (bond labels starting by "1" as in
11121112
ICOHPLIST/ICOOPLIST).
11131113
@@ -1118,9 +1118,9 @@ def get_icohp_by_label(self, label, summed_spin_channels=True, spin=Spin.up, orb
11181118
orbitals: List of Orbital or "str(Orbital1)-str(Orbital2)"
11191119
11201120
Returns:
1121-
float describing ICOHP/ICOOP value
1121+
float: ICOHP/ICOOP value
11221122
"""
1123-
icohp_here = self._icohplist[label]
1123+
icohp_here: IcohpValue = self._icohplist[label]
11241124
if orbitals is None:
11251125
if summed_spin_channels:
11261126
return icohp_here.summed_icohp
@@ -1133,7 +1133,7 @@ def get_icohp_by_label(self, label, summed_spin_channels=True, spin=Spin.up, orb
11331133

11341134
return icohp_here.icohpvalue_orbital(spin=spin, orbitals=orbitals)
11351135

1136-
def get_summed_icohp_by_label_list(self, label_list, divisor=1.0, summed_spin_channels=True, spin=Spin.up):
1136+
def get_summed_icohp_by_label_list(self, label_list, divisor=1.0, summed_spin_channels=True, spin=Spin.up) -> float:
11371137
"""Get the sum of several ICOHP values that are indicated by a list of labels
11381138
(labels of the bonds are the same as in ICOHPLIST/ICOOPLIST).
11391139
@@ -1144,7 +1144,7 @@ def get_summed_icohp_by_label_list(self, label_list, divisor=1.0, summed_spin_ch
11441144
spin: if summed_spin_channels is equal to False, this spin indicates which spin channel should be returned
11451145
11461146
Returns:
1147-
float that is a sum of all ICOHPs/ICOOPs as indicated with label_list
1147+
float: sum of all ICOHPs/ICOOPs as indicated with label_list
11481148
"""
11491149
sum_icohp = 0
11501150
for label in label_list:

pymatgen/electronic_structure/dos.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1124,7 +1124,7 @@ def get_dos_fp(
11241124
ValueError: If type is not one of the accepted values {s/p/d/f/}summed_{pdos/tdos}.
11251125
11261126
Returns:
1127-
Fingerprint(namedtuple) : The electronic density of states fingerprint
1127+
NamedTuple: The electronic density of states fingerprint
11281128
of format (energies, densities, type, n_bins)
11291129
"""
11301130
fingerprint = namedtuple("fingerprint", "energies densities type n_bins bin_width")

pymatgen/io/feff/inputs.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ def get_str(self, sort_keys: bool = False, pretty: bool = False) -> str:
584584
pretty: Set to True for pretty aligned output. Defaults to False.
585585
586586
Returns:
587-
String representation of Tags.
587+
str: String representation of the Tags.
588588
"""
589589
keys = list(self)
590590
if sort_keys:
@@ -744,9 +744,9 @@ def diff(self, other):
744744
other: The other PARAMETER dictionary to compare to.
745745
746746
Returns:
747-
Dict of the format {"Same" : parameters_that_are_the_same,
748-
"Different": parameters_that_are_different} Note that the
749-
parameters are return as full dictionaries of values.
747+
dict[str, dict]: has format {"Same" : parameters_that_are_the_same,
748+
"Different": parameters_that_are_different} Note that the
749+
parameters are return as full dictionaries of values.
750750
"""
751751
similar_param = {}
752752
different_param = {}
@@ -874,15 +874,10 @@ def pot_dict_from_str(pot_data):
874874

875875
def __str__(self):
876876
"""Get a string representation of potential parameters to be used in
877-
the feff.inp file,
878-
determined from structure object.
879-
880-
The lines are arranged as follows:
877+
the feff.inp file, determined from structure object.
881878
879+
The lines are arranged as follows:
882880
ipot Z element lmax1 lmax2 stoichiometry spinph
883-
884-
Returns:
885-
String representation of Atomic Coordinate Shells.
886881
"""
887882
central_element = Element(self.absorbing_atom)
888883
ipotrow = [[0, central_element.Z, central_element.symbol, -1, -1, 0.0001, 0]]

pymatgen/io/gaussian.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1292,7 +1292,7 @@ def to_input(
12921292
are the same as GaussianInput class.
12931293
12941294
Returns:
1295-
gaunip (GaussianInput) : the gaussian input object
1295+
GaussianInput: the gaussian input object
12961296
"""
12971297
if not mol:
12981298
mol = self.final_structure

pymatgen/io/icet.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,11 @@ def get_icet_sqs_obj(self, material: Atoms | Structure, cluster_space: _ClusterS
203203
"""Get the SQS objective function.
204204
205205
Args:
206-
material (ase Atoms or pymatgen Structure) : structure to
207-
compute SQS objective function.
208-
Kwargs:
209-
cluster_space (ClusterSpace) : ClusterSpace of the SQS search.
206+
material (pymatgen.Structure | ase.Atoms): structure to compute SQS objective function for.
207+
cluster_space (ClusterSpace): ClusterSpace of the SQS search.
210208
211209
Returns:
212-
float : the SQS objective function
210+
float: the SQS objective function
213211
"""
214212
if isinstance(material, Structure):
215213
material = AseAtomsAdaptor.get_atoms(material)
@@ -228,11 +226,11 @@ def enumerate_sqs_structures(self, cluster_space: _ClusterSpace | None = None) -
228226
Adapted from icet.tools.structure_generation.generate_sqs_by_enumeration
229227
to accommodate multiprocessing.
230228
231-
Kwargs:
229+
Args:
232230
cluster_space (ClusterSpace) : ClusterSpace of the SQS search.
233231
234232
Returns:
235-
list : a list of dicts of the form: {
233+
list: dicts of the form: {
236234
"structure": SQS structure,
237235
"objective_function": SQS objective function,
238236
}

0 commit comments

Comments
 (0)