Skip to content

Commit 9964c4a

Browse files
authored
Format doc strings (#3790)
* doc string no line break after """\n\s+Get * """\n\s+Set -> """Set * remove __deepcopy__ from io/cp2k/inputs.py Section and SectionList * """\n\s+E -> """E * """\n\s+F -> """F * imperative form: finds->find, initializes->initialize, ... * return if ...: return True; return False -> return ... * deprecate NRANDOM kwarg of coordination_geometry_symmetry_measures_fallback_random snake_case symmop->symm_op * imperative form: Gives->Get, Shows->Show, ... * fix mypy * "Class for ..." -> "..."
1 parent c9292ed commit 9964c4a

File tree

153 files changed

+709
-1062
lines changed

Some content is hidden

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

153 files changed

+709
-1062
lines changed

dev_scripts/chemenv/strategies/multi_weights_strategy_parameters.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ def __init__(self, initial_environment_symbol, expected_final_environment_symbol
5252

5353
@classmethod
5454
def simple_expansion(cls, initial_environment_symbol, expected_final_environment_symbol, neighbors_indices):
55-
"""
56-
Simple expansion of a coordination environment.
55+
"""Simple expansion of a coordination environment.
5756
5857
Args:
5958
initial_environment_symbol (str): The initial coordination environment symbol.

dev_scripts/potcar_scrambler.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ def _read_fortran_str_and_scramble(self, input_str: str, bloat: float = 1.5):
6969
return input_str
7070

7171
def scramble_single_potcar(self, potcar: PotcarSingle) -> str:
72-
"""
73-
Scramble the body of a POTCAR, retain the PSCTR header information.
72+
"""Scramble the body of a POTCAR, retain the PSCTR header information.
7473
7574
To the best of my (ADK) knowledge, in the OUTCAR file,
7675
almost all information from the POTCAR in the "PSCTR" block
@@ -84,8 +83,7 @@ def scramble_single_potcar(self, potcar: PotcarSingle) -> str:
8483
is included. This information is not scrambled below.
8584
"""
8685
scrambled_potcar_str = ""
87-
needs_sha256 = False
88-
scramble_values = False
86+
needs_sha256 = scramble_values = False
8987
og_sha_str = "SHA256 = None\n"
9088
for line in potcar.data.split("\n")[:-1]:
9189
single_line_rows = line.split(";")
@@ -174,8 +172,7 @@ def generate_fake_potcar_libraries() -> None:
174172

175173

176174
def potcar_cleanser() -> None:
177-
"""
178-
Function to replace copyrighted POTCARs used in io.vasp.sets testing
175+
"""Function to replace copyrighted POTCARs used in io.vasp.sets testing
179176
with dummy POTCARs that have scrambled PSP and kinetic energy values
180177
(but retain the original header information which is also found in OUTCARs
181178
and freely shared by VASP)

pymatgen/alchemy/materials.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def __init__(
4343
history: list[AbstractTransformation | dict[str, Any]] | None = None,
4444
other_parameters: dict[str, Any] | None = None,
4545
) -> None:
46-
"""Initializes a transformed structure from a structure.
46+
"""Initialize a transformed structure from a structure.
4747
4848
Args:
4949
structure (Structure): Input structure
@@ -102,7 +102,7 @@ def __len__(self) -> int:
102102
def append_transformation(
103103
self, transformation, return_alternatives: bool = False, clear_redo: bool = True
104104
) -> list[TransformedStructure] | None:
105-
"""Appends a transformation to the TransformedStructure.
105+
"""Append a transformation to the TransformedStructure.
106106
107107
Args:
108108
transformation: Transformation to append
@@ -157,7 +157,7 @@ def append_transformation(
157157
return None
158158

159159
def append_filter(self, structure_filter: AbstractStructureFilter) -> None:
160-
"""Adds a filter.
160+
"""Add a filter.
161161
162162
Args:
163163
structure_filter (StructureFilter): A filter implementing the
@@ -172,7 +172,7 @@ def extend_transformations(
172172
transformations: list[AbstractTransformation],
173173
return_alternatives: bool = False,
174174
) -> None:
175-
"""Extends a sequence of transformations to the TransformedStructure.
175+
"""Extend a sequence of transformations to the TransformedStructure.
176176
177177
Args:
178178
transformations: Sequence of Transformations
@@ -203,7 +203,7 @@ def write_vasp_input(
203203
create_directory: bool = True,
204204
**kwargs,
205205
) -> None:
206-
"""Writes VASP input to an output_dir.
206+
"""Write VASP input to an output_dir.
207207
208208
Args:
209209
vasp_input_set: pymatgen.io.vasp.sets.VaspInputSet like object that creates vasp input files from
@@ -232,7 +232,7 @@ def __str__(self) -> str:
232232
return "\n".join(output)
233233

234234
def set_parameter(self, key: str, value: Any) -> TransformedStructure:
235-
"""Sets a parameter.
235+
"""Set a parameter.
236236
237237
Args:
238238
key (str): The string key.
@@ -270,7 +270,7 @@ def from_cif_str(
270270
primitive: bool = True,
271271
occupancy_tolerance: float = 1.0,
272272
) -> Self:
273-
"""Generates TransformedStructure from a cif string.
273+
"""Generate TransformedStructure from a cif string.
274274
275275
Args:
276276
cif_string (str): Input cif string. Should contain only one
@@ -314,7 +314,7 @@ def from_poscar_str(
314314
poscar_string: str,
315315
transformations: list[AbstractTransformation] | None = None,
316316
) -> Self:
317-
"""Generates TransformedStructure from a poscar string.
317+
"""Generate TransformedStructure from a poscar string.
318318
319319
Args:
320320
poscar_string (str): Input POSCAR string.
@@ -347,7 +347,7 @@ def as_dict(self) -> dict[str, Any]:
347347

348348
@classmethod
349349
def from_dict(cls, dct: dict) -> Self:
350-
"""Creates a TransformedStructure from a dict."""
350+
"""Create a TransformedStructure from a dict."""
351351
struct = Structure.from_dict(dct)
352352
return cls(struct, history=dct["history"], other_parameters=dct.get("other_parameters"))
353353

pymatgen/alchemy/transmuters.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def __init__(
4545
extend_collection: int = 0,
4646
ncores: int | None = None,
4747
) -> None:
48-
"""Initializes a transmuter from an initial list of
48+
"""Initialize a transmuter from an initial list of
4949
pymatgen.alchemy.materials.TransformedStructure.
5050
5151
Args:
@@ -101,7 +101,7 @@ def redo_next_change(self) -> None:
101101
x.redo_next_change()
102102

103103
def append_transformation(self, transformation, extend_collection=False, clear_redo=True):
104-
"""Appends a transformation to all TransformedStructures.
104+
"""Append a transformation to all TransformedStructures.
105105
106106
Args:
107107
transformation: Transformation to append
@@ -134,7 +134,7 @@ def append_transformation(self, transformation, extend_collection=False, clear_r
134134
self.transformed_structures.extend(new_structures)
135135

136136
def extend_transformations(self, transformations):
137-
"""Extends a sequence of transformations to the TransformedStructure.
137+
"""Extend a sequence of transformations to the TransformedStructure.
138138
139139
Args:
140140
transformations: Sequence of Transformations
@@ -143,7 +143,7 @@ def extend_transformations(self, transformations):
143143
self.append_transformation(trafo)
144144

145145
def apply_filter(self, structure_filter):
146-
"""Applies a structure_filter to the list of TransformedStructures
146+
"""Apply a structure_filter to the list of TransformedStructures
147147
in the transmuter.
148148
149149
Args:
@@ -224,12 +224,12 @@ def from_structures(cls, structures, transformations=None, extend_collection=0)
224224

225225

226226
class CifTransmuter(StandardTransmuter):
227-
"""Generates a Transmuter from a cif string, possibly containing multiple
227+
"""Generate a Transmuter from a cif string, possibly containing multiple
228228
structures.
229229
"""
230230

231231
def __init__(self, cif_string, transformations=None, primitive=True, extend_collection=False):
232-
"""Generates a Transmuter from a cif string, possibly
232+
"""Generate a Transmuter from a cif string, possibly
233233
containing multiple structures.
234234
235235
Args:
@@ -259,7 +259,7 @@ def __init__(self, cif_string, transformations=None, primitive=True, extend_coll
259259

260260
@classmethod
261261
def from_filenames(cls, filenames, transformations=None, primitive=True, extend_collection=False) -> Self:
262-
"""Generates a TransformedStructureCollection from a cif, possibly
262+
"""Generate a TransformedStructureCollection from a cif, possibly
263263
containing multiple structures.
264264
265265
Args:
@@ -282,7 +282,7 @@ def from_filenames(cls, filenames, transformations=None, primitive=True, extend_
282282

283283

284284
class PoscarTransmuter(StandardTransmuter):
285-
"""Generates a transmuter from a sequence of POSCARs."""
285+
"""Generate a transmuter from a sequence of POSCARs."""
286286

287287
def __init__(self, poscar_string, transformations=None, extend_collection=False):
288288
"""

pymatgen/analysis/adsorption.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def from_bulk_and_miller(
9393
selective_dynamics=False,
9494
undercoord_threshold=0.09,
9595
) -> Self:
96-
"""This method constructs the adsorbate site finder from a bulk
96+
"""Construct the adsorbate site finder from a bulk
9797
structure and a miller index, which allows the surface sites to be
9898
determined from the difference in bulk and slab coordination, as
9999
opposed to the height threshold.
@@ -150,15 +150,12 @@ def from_bulk_and_miller(
150150
surf_props += ["surface"]
151151
else:
152152
surf_props += ["subsurface"]
153-
new_site_properties = {
154-
"surface_properties": surf_props,
155-
"undercoords": under_coords,
156-
}
153+
new_site_properties = {"surface_properties": surf_props, "undercoords": under_coords}
157154
new_slab = this_slab.copy(site_properties=new_site_properties)
158155
return cls(new_slab, selective_dynamics)
159156

160157
def find_surface_sites_by_height(self, slab: Slab, height=0.9, xy_tol=0.05):
161-
"""This method finds surface sites by determining which sites are
158+
"""Find surface sites by determining which sites are
162159
within a threshold value in height from the topmost site in a list of
163160
sites.
164161
@@ -196,7 +193,7 @@ def find_surface_sites_by_height(self, slab: Slab, height=0.9, xy_tol=0.05):
196193
return surf_sites
197194

198195
def assign_site_properties(self, slab: Slab, height=0.9):
199-
"""Assigns site properties."""
196+
"""Assign site properties."""
200197
if "surface_properties" in slab.site_properties:
201198
return slab
202199

@@ -205,7 +202,7 @@ def assign_site_properties(self, slab: Slab, height=0.9):
205202
return slab.copy(site_properties={"surface_properties": surf_props})
206203

207204
def get_extended_surface_mesh(self, repeat=(5, 5, 1)):
208-
"""Gets an extended surface mesh for to use for adsorption site finding
205+
"""Get an extended surface mesh for to use for adsorption site finding
209206
by constructing supercell of surface sites.
210207
211208
Args:
@@ -233,7 +230,7 @@ def find_adsorption_sites(
233230
positions=("ontop", "bridge", "hollow"),
234231
no_obtuse_hollow=True,
235232
):
236-
"""Finds surface sites according to the above algorithm. Returns a list
233+
"""Find surface sites according to the above algorithm. Returns a list
237234
of corresponding Cartesian coordinates.
238235
239236
Args:
@@ -307,7 +304,7 @@ def find_adsorption_sites(
307304
return ads_sites
308305

309306
def symm_reduce(self, coords_set, threshold=1e-6):
310-
"""Reduces the set of adsorbate sites by finding removing symmetrically
307+
"""Reduce the set of adsorbate sites by finding removing symmetrically
311308
equivalent duplicates.
312309
313310
Args:
@@ -332,7 +329,7 @@ def symm_reduce(self, coords_set, threshold=1e-6):
332329
return [self.slab.lattice.get_cartesian_coords(coords) for coords in unique_coords]
333330

334331
def near_reduce(self, coords_set, threshold=1e-4):
335-
"""Prunes coordinate set for coordinates that are within threshold.
332+
"""Prune coordinate set for coordinates that are within threshold.
336333
337334
Args:
338335
coords_set (Nx3 array-like): list or array of coordinates
@@ -347,7 +344,7 @@ def near_reduce(self, coords_set, threshold=1e-4):
347344

348345
@classmethod
349346
def ensemble_center(cls, site_list, indices, cartesian=True):
350-
"""Finds the center of an ensemble of sites selected from a list of
347+
"""Find the center of an ensemble of sites selected from a list of
351348
sites. Helper method for the find_adsorption_sites algorithm.
352349
353350
Args:
@@ -363,7 +360,7 @@ def ensemble_center(cls, site_list, indices, cartesian=True):
363360
return np.average([site_list[idx].frac_coords for idx in indices], axis=0)
364361

365362
def add_adsorbate(self, molecule: Molecule, ads_coord, repeat=None, translate=True, reorient=True):
366-
"""Adds an adsorbate at a particular coordinate. Adsorbate represented
363+
"""Add an adsorbate at a particular coordinate. Adsorbate represented
367364
by a Molecule object and is translated to (0, 0, 0) if translate is
368365
True, or positioned relative to the input adsorbate coordinate if
369366
translate is False.
@@ -604,7 +601,7 @@ def get_mi_vec(slab):
604601

605602

606603
def get_rot(slab: Slab) -> SymmOp:
607-
"""Gets the transformation to rotate the z axis into the miller index."""
604+
"""Get the transformation to rotate the z axis into the miller index."""
608605
new_z = get_mi_vec(slab)
609606
a, _b, _c = slab.lattice.matrix
610607
new_x = a / np.linalg.norm(a)
@@ -616,13 +613,13 @@ def get_rot(slab: Slab) -> SymmOp:
616613

617614

618615
def put_coord_inside(lattice, cart_coordinate):
619-
"""Converts a Cartesian coordinate such that it is inside the unit cell."""
616+
"""Convert a Cartesian coordinate such that it is inside the unit cell."""
620617
fc = lattice.get_fractional_coords(cart_coordinate)
621618
return lattice.get_cartesian_coords([c - np.floor(c) for c in fc])
622619

623620

624621
def reorient_z(structure):
625-
"""Reorients a structure such that the z axis is concurrent with the normal
622+
"""Reorient a structure such that the z axis is concurrent with the normal
626623
to the A-B plane.
627624
"""
628625
struct = structure.copy()

pymatgen/analysis/bond_dissociation.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import logging
66
import warnings
7+
from typing import cast
78

89
import networkx as nx
910
from monty.json import MSONable
@@ -74,7 +75,8 @@ def __init__(
7475
raise RuntimeError(f"{key=} must be present in all fragment entries! Exiting...")
7576

7677
# Define expected charges
77-
final_charge = int(molecule_entry["final_molecule"]["charge"]) # type: ignore[index]
78+
final_mol = cast(dict, molecule_entry["final_molecule"])
79+
final_charge = int(final_mol["charge"]) # type: ignore[index]
7880
if not allow_additional_charge_separation:
7981
if final_charge == 0:
8082
self.expected_charges = [-1, 0, 1]
@@ -90,9 +92,7 @@ def __init__(
9092
self.expected_charges = [final_charge - 2, final_charge - 1, final_charge, final_charge + 1]
9193

9294
# Build principle molecule graph
93-
self.mol_graph = MoleculeGraph.from_local_env_strategy(
94-
Molecule.from_dict(molecule_entry["final_molecule"]), OpenBabelNN()
95-
)
95+
self.mol_graph = MoleculeGraph.from_local_env_strategy(Molecule.from_dict(final_mol), OpenBabelNN())
9696
# Loop through bonds, aka graph edges, and fragment and process:
9797
for bond in self.mol_graph.graph.edges:
9898
bonds = [(bond[0], bond[1])]
@@ -245,8 +245,7 @@ def fragment_and_process(self, bonds):
245245
n_entries_for_this_frag_pair += 1
246246

247247
def search_fragment_entries(self, frag) -> list:
248-
"""
249-
Search all fragment entries for those isomorphic to the given fragment.
248+
"""Search all fragment entries for those isomorphic to the given fragment.
250249
We distinguish between entries where both initial and final MoleculeGraphs are isomorphic to the
251250
given fragment (entries) vs those where only the initial MoleculeGraph is isomorphic to the given
252251
fragment (initial_entries) vs those where only the final MoleculeGraph is isomorphic (final_entries).
@@ -267,8 +266,7 @@ def search_fragment_entries(self, frag) -> list:
267266
return [entries, initial_entries, final_entries]
268267

269268
def filter_fragment_entries(self, fragment_entries: list) -> None:
270-
"""
271-
Filter the fragment entries.
269+
"""Filter the fragment entries.
272270
273271
Args:
274272
fragment_entries (List): Fragment entries to be filtered.

pymatgen/analysis/bond_valence.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737

3838
def calculate_bv_sum(site, nn_list, scale_factor=1.0):
39-
"""Calculates the BV sum of a site.
39+
"""Calculate the BV sum of a site.
4040
4141
Args:
4242
site (PeriodicSite): The central site to calculate the bond valence
@@ -62,7 +62,7 @@ def calculate_bv_sum(site, nn_list, scale_factor=1.0):
6262

6363

6464
def calculate_bv_sum_unordered(site, nn_list, scale_factor=1):
65-
"""Calculates the BV sum of a site for unordered structures.
65+
"""Calculate the BV sum of a site for unordered structures.
6666
6767
Args:
6868
site (PeriodicSite): The central site to calculate the bond valence
@@ -424,8 +424,7 @@ def _recurse(assigned=None):
424424
raise ValueError("Valences cannot be assigned!")
425425

426426
def get_oxi_state_decorated_structure(self, structure: Structure):
427-
"""
428-
Get an oxidation state decorated structure. This currently works only
427+
"""Get an oxidation state decorated structure. This currently works only
429428
for ordered structures only.
430429
431430
Args:

pymatgen/analysis/chemenv/connectivity/connectivity_finder.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ def __init__(self, multiple_environments_choice=None):
3232
self.setup_parameters(multiple_environments_choice=multiple_environments_choice)
3333

3434
def get_structure_connectivity(self, light_structure_environments):
35-
"""
36-
Get the structure connectivity from the coordination environments provided
35+
"""Get the structure connectivity from the coordination environments provided
3736
as an input.
3837
3938
Args:

0 commit comments

Comments
 (0)