Skip to content

Commit

Permalink
fix doc string indentations and better variable names
Browse files Browse the repository at this point in the history
  • Loading branch information
janosh committed Oct 16, 2023
1 parent f67d6f3 commit ca510d5
Show file tree
Hide file tree
Showing 18 changed files with 147 additions and 170 deletions.
201 changes: 92 additions & 109 deletions pymatgen/analysis/gb/grain.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pymatgen/core/periodic_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -1313,7 +1313,7 @@ def from_str(species_string: str) -> DummySpecies:
m = re.search(r"([A-ZAa-z]*)([0-9.]*)([+\-]*)(.*)", species_string)
if m:
sym = m.group(1)
if m.group(2) == "" and m.group(3) == "":
if m.group(2) == m.group(3) == "":
oxi = 0.0
else:
oxi = 1.0 if m.group(2) == "" else float(m.group(2))
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/core/sites.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def is_ordered(self) -> bool:
occupancy 1.
"""
total_occu = self.species.num_atoms
return total_occu == 1 and len(self.species) == 1
return total_occu == len(self.species) == 1

def __getitem__(self, el):
"""Get the occupancy for element."""
Expand Down
4 changes: 2 additions & 2 deletions pymatgen/core/trajectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ def _combine_site_props(
"""
# special cases

if prop1 is None and prop2 is None:
if prop1 is prop2 is None:
return None

if isinstance(prop1, dict) and prop1 == prop2:
Expand Down Expand Up @@ -608,7 +608,7 @@ def _combine_site_props(
@staticmethod
def _combine_frame_props(prop1: list[dict] | None, prop2: list[dict] | None, len1: int, len2: int) -> list | None:
"""Combine frame properties."""
if prop1 is None and prop2 is None:
if prop1 is prop2 is None:
return None
if prop1 is None:
return [None] * len1 + list(prop2) # type: ignore
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/core/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
"cross_section": {"barn": {"m": 2, 1e-28: 1}, "mbarn": {"m": 2, 1e-31: 1}},
}

ALL_UNITS: dict[str, dict] = {**BASE_UNITS, **DERIVED_UNITS}
ALL_UNITS: dict[str, dict] = BASE_UNITS | DERIVED_UNITS
SUPPORTED_UNIT_NAMES = tuple(i for d in ALL_UNITS.values() for i in d)

# Mapping unit name --> unit type (unit names must be unique).
Expand Down
7 changes: 3 additions & 4 deletions pymatgen/electronic_structure/boltztrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -899,11 +899,10 @@ def check_acc_bzt_bands(sbs_bz, sbs_ref, warn_thr=(0.03, 0.03)):
- "avg_corr": average of correlation coefficient over the 8 bands
- "avg_dist": average of energy distance over the 8 bands
- "nb_list": list of indexes of the 8 compared bands
- "acc_thr": list of two float corresponding to the two warning
thresholds in input
- "acc_thr": list of two float corresponding to the two warning thresholds in input
- "acc_err": list of two bools:
True if the avg_corr > warn_thr[0], and
True if the avg_dist > warn_thr[1]
True if the avg_corr > warn_thr[0], and
True if the avg_dist > warn_thr[1]
See also compare_sym_bands function doc.
"""
if not sbs_ref.is_metal() and not sbs_bz.is_metal():
Expand Down
12 changes: 6 additions & 6 deletions pymatgen/io/lammps/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -874,8 +874,8 @@ def set_charge_atom(self, charges: dict[int, float]) -> None:
Args:
charges: A dictionary with atom indexes as keys and
charges as values, e.g., to set the charge
of the atom with index 3 to -2, use `{3: -2}`.
charges as values, e.g., to set the charge
of the atom with index 3 to -2, use `{3: -2}`.
"""
for iat, q in charges.items():
self.atoms.loc[iat, "q"] = q
Expand All @@ -886,10 +886,10 @@ def set_charge_atom_type(self, charges: dict[str | int, float]) -> None:
Args:
charges: Dict containing the charges for the atom types to set.
The dict should contain atom types as integers or labels and charges.
Example: change the charge of Li atoms to +3:
charges={"Li": 3}
charges={1: 3} if Li atoms are of type 1
The dict should contain atom types as integers or labels and charges.
Example: change the charge of Li atoms to +3:
charges={"Li": 3}
charges={1: 3} if Li atoms are of type 1
"""
for iat, q in charges.items():
if isinstance(iat, str):
Expand Down
4 changes: 2 additions & 2 deletions pymatgen/io/lammps/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class BaseLammpsGenerator(InputGenerator):
calc_type: Human-readable string used to briefly describe the type of computations performed by LAMMPS.
settings: Dictionary containing the values of the parameters to replace in the template.
keep_stages: If True, the string is formatted in a block structure with stage names
and newlines that differentiate commands in the respective stages of the InputFile.
If False, stage names are not printed and all commands appear in a single block.
and newlines that differentiate commands in the respective stages of the InputFile.
If False, stage names are not printed and all commands appear in a single block.
/!\ This InputSet and InputGenerator implementation is based on templates and is not intended to be very flexible.
For instance, pymatgen will not detect whether a given variable should be adapted based on others
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/io/qchem/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def __init__(
Ex:
1. For a single-state calculation with two constraints:
cdft=[[
cdft=[[
{"value": 1.0, "coefficients": [1.0], "first_atoms": [1], "last_atoms": [2], "types": [None]},
{"value": 2.0, "coefficients": [1.0, -1.0], "first_atoms": [1, 17], "last_atoms": [3, 19],
"types": ["s"]}
Expand Down
4 changes: 2 additions & 2 deletions pymatgen/io/vasp/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,8 +622,8 @@ def set_temperature(self, temperature: float):
self.structure.add_site_property("velocities", velocities.tolist())


with open(f"{module_dir}/incar_parameters.json") as incar_params:
incar_params = json.loads(incar_params.read())
with open(f"{module_dir}/incar_parameters.json") as json_file:
incar_params = json.loads(json_file.read())


class BadIncarWarning(UserWarning):
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/phonon/gruneisen.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __init__(
multiplicities: list of multiplicities
structure: The crystal structure (as a pymatgen Structure object) associated with the gruneisen parameters.
lattice: The reciprocal lattice as a pymatgen Lattice object. Pymatgen uses the physics convention of
reciprocal lattice vectors WITH a 2*pi coefficient.
reciprocal lattice vectors WITH a 2*pi coefficient.
"""
self.qpoints = qpoints
self.gruneisen = gruneisen
Expand Down
3 changes: 1 addition & 2 deletions pymatgen/symmetry/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,8 @@ def transform_coords(self, coords: list[list[float]] | np.ndarray) -> list[list[
"""Takes a list of coordinates and transforms them."""
new_coords = []
for x in coords:
x = np.array(x)
Q = np.linalg.inv(self.P)
x_ = np.matmul(Q, (x - self.p))
x_ = np.matmul(Q, (np.array(x) - self.p))
new_coords.append(x_.tolist())
return new_coords

Expand Down
36 changes: 18 additions & 18 deletions tests/analysis/chemenv/coordination_environments/test_voronoi.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def test_voronoi(self):
(6, [5, 5, 6.05]),
]
random.shuffle(order_and_coords)
sorted = np.argsort([oc[0] for oc in order_and_coords]) + 1
arr_sorted = np.argsort([oc[0] for oc in order_and_coords]) + 1
coords.extend([oc[1] for oc in order_and_coords])
fake_structure = Structure(cubic_lattice, species, coords, coords_are_cartesian=True)

Expand Down Expand Up @@ -63,19 +63,19 @@ def test_voronoi(self):
assert len(detailed_voronoi_container.voronoi_list2[0]) == 6
neighbors = detailed_voronoi_container.neighbors(0, 1, 0.5)
assert len(neighbors) == 1
assert neighbors[0]["site"] == fake_structure[sorted[0]]
assert neighbors[0]["site"] == fake_structure[arr_sorted[0]]
neighbors = detailed_voronoi_container.neighbors(0, 1.02, 0.5)
nbs = [nb["site"] for nb in neighbors]
assert len(neighbors) == 3
assert fake_structure[sorted[0]] in nbs
assert fake_structure[sorted[1]] in nbs
assert fake_structure[sorted[2]] in nbs
assert fake_structure[arr_sorted[0]] in nbs
assert fake_structure[arr_sorted[1]] in nbs
assert fake_structure[arr_sorted[2]] in nbs
neighbors = detailed_voronoi_container.neighbors(0, 1.026, 0.5)
nbs = [nb["site"] for nb in neighbors]
assert len(neighbors) == 3
assert fake_structure[sorted[0]] in nbs
assert fake_structure[sorted[1]] in nbs
assert fake_structure[sorted[2]] in nbs
assert fake_structure[arr_sorted[0]] in nbs
assert fake_structure[arr_sorted[1]] in nbs
assert fake_structure[arr_sorted[2]] in nbs
neighbors = detailed_voronoi_container.neighbors(0, 1.5, 0.5)
assert len(neighbors) == 6

Expand All @@ -90,7 +90,7 @@ def test_voronoi(self):
(6, [5, 5, 6.09]),
]
random.shuffle(order_and_coords)
sorted = np.argsort([oc[0] for oc in order_and_coords]) + 1
arr_sorted = np.argsort([oc[0] for oc in order_and_coords]) + 1
coords2.extend([oc[1] for oc in order_and_coords])
fake_structure2 = Structure(cubic_lattice, species, coords2, coords_are_cartesian=True)

Expand All @@ -105,21 +105,21 @@ def test_voronoi(self):
neighbors = detailed_voronoi_container.neighbors(0, 1, 0.5)
nbs = [nb["site"] for nb in neighbors]
assert len(neighbors) == 3
assert fake_structure2[sorted[0]] in nbs
assert fake_structure2[sorted[1]] in nbs
assert fake_structure2[sorted[2]] in nbs
assert fake_structure2[arr_sorted[0]] in nbs
assert fake_structure2[arr_sorted[1]] in nbs
assert fake_structure2[arr_sorted[2]] in nbs
neighbors = detailed_voronoi_container.neighbors(0, 1.02, 0.5)
nbs = [nb["site"] for nb in neighbors]
assert len(neighbors) == 3
assert fake_structure2[sorted[0]] in nbs
assert fake_structure2[sorted[1]] in nbs
assert fake_structure2[sorted[2]] in nbs
assert fake_structure2[arr_sorted[0]] in nbs
assert fake_structure2[arr_sorted[1]] in nbs
assert fake_structure2[arr_sorted[2]] in nbs
neighbors = detailed_voronoi_container.neighbors(0, 1.026, 0.5)
nbs = [nb["site"] for nb in neighbors]
assert len(neighbors) == 3
assert fake_structure2[sorted[0]] in nbs
assert fake_structure2[sorted[1]] in nbs
assert fake_structure2[sorted[2]] in nbs
assert fake_structure2[arr_sorted[0]] in nbs
assert fake_structure2[arr_sorted[1]] in nbs
assert fake_structure2[arr_sorted[2]] in nbs
neighbors = detailed_voronoi_container.neighbors(0, 1.5, 0.5)
assert len(neighbors) == 6

Expand Down
26 changes: 11 additions & 15 deletions tests/analysis/test_surface_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

class TestSlabEntry(PymatgenTest):
def setUp(self):
with open(f"{TEST_DIR}/ucell_entries.txt") as ucell_entries:
ucell_entries = json.loads(ucell_entries.read())
with open(f"{TEST_DIR}/ucell_entries.txt") as file:
ucell_entries = json.loads(file.read())
self.ucell_entries = ucell_entries

# Load objects for O adsorption tests
Expand Down Expand Up @@ -121,8 +121,8 @@ class TestSurfaceEnergyPlotter(PymatgenTest):
def setUp(self):
entry_dict = get_entry_dict(f"{TEST_DIR}/Cu_entries.txt")
self.Cu_entry_dict = entry_dict
with open(f"{TEST_DIR}/ucell_entries.txt") as ucell_entries:
ucell_entries = json.loads(ucell_entries.read())
with open(f"{TEST_DIR}/ucell_entries.txt") as file:
ucell_entries = json.loads(file.read())

self.Cu_ucell_entry = ComputedStructureEntry.from_dict(ucell_entries["Cu"])
self.Cu_analyzer = SurfaceEnergyPlotter(entry_dict, self.Cu_ucell_entry)
Expand All @@ -134,11 +134,7 @@ def setUp(self):
self.Ni_analyzer = SurfaceEnergyPlotter(self.metals_O_entry_dict["Ni"], ucell_entry)
ucell_entry = ComputedStructureEntry.from_dict(ucell_entries["Rh"])
self.Rh_analyzer = SurfaceEnergyPlotter(self.metals_O_entry_dict["Rh"], ucell_entry)
self.Oads_analyzer_dict = {
"Pt": self.Pt_analyzer,
"Ni": self.Ni_analyzer,
"Rh": self.Rh_analyzer,
}
self.Oads_analyzer_dict = {"Pt": self.Pt_analyzer, "Ni": self.Ni_analyzer, "Rh": self.Rh_analyzer}

def test_get_stable_entry_at_u(self):
for plotter in self.Oads_analyzer_dict.values():
Expand Down Expand Up @@ -249,8 +245,8 @@ def test_entry_dict_from_list(self):
all_Pt_slab_entries.append(clean)
all_Pt_slab_entries.extend(Pt_entries[hkl][clean])

a = SurfaceEnergyPlotter(all_Pt_slab_entries, self.Pt_analyzer.ucell_entry)
assert type(a).__name__ == "SurfaceEnergyPlotter"
surf_ene_plotter = SurfaceEnergyPlotter(all_Pt_slab_entries, self.Pt_analyzer.ucell_entry)
assert surf_ene_plotter.list_of_chempots == self.Pt_analyzer.list_of_chempots

# def test_monolayer_vs_BE(self):
# for el in self.Oads_analyzer_dict:
Expand Down Expand Up @@ -389,8 +385,8 @@ def load_O_adsorption():
# Loads the dictionary for clean and O adsorbed Rh, Pt, and Ni entries

# Load the adsorbate as an entry
with open(f"{TEST_DIR}/isolated_O_entry.txt") as isolated_O_entry:
isolated_O_entry = json.loads(isolated_O_entry.read())
with open(f"{TEST_DIR}/isolated_O_entry.txt") as file:
isolated_O_entry = json.loads(file.read())
O_entry = ComputedStructureEntry.from_dict(isolated_O_entry)

# entry_dict for the adsorption case, O adsorption on Ni, Rh and Pt
Expand All @@ -416,8 +412,8 @@ def load_O_adsorption():
clean = SlabEntry(entry.structure, entry.energy, (1, 0, 0), label=key + "_clean")
metals_O_entry_dict[el][(1, 0, 0)][clean] = []

with open(f"{TEST_DIR}/cs_entries_o_ads.json") as entries:
entries = json.loads(entries.read())
with open(f"{TEST_DIR}/cs_entries_o_ads.json") as file:
entries = json.loads(file.read())
for key in entries:
entry = ComputedStructureEntry.from_dict(entries[key])
for el, val in metals_O_entry_dict.items():
Expand Down
4 changes: 2 additions & 2 deletions tests/core/test_sites.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ def test_distance(self):
assert ord_site.distance(self.disordered_site) == 0

def test_pickle(self):
o = pickle.dumps(self.propertied_site)
assert pickle.loads(o) == self.propertied_site
dump = pickle.dumps(self.propertied_site)
assert pickle.loads(dump) == self.propertied_site

def test_setters(self):
self.disordered_site.species = "Cu"
Expand Down
2 changes: 1 addition & 1 deletion tests/core/test_surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ def test_get_slab(self):
assert len(slab_non_prim) == len(slab) * 4

# Some randomized testing of cell vectors
for i in range(1, 231):
for _ in range(1, 231):
i = random.randint(1, 230)
sg = SpaceGroup.from_int_number(i)
if sg.crystal_system == "hexagonal" or (
Expand Down
2 changes: 1 addition & 1 deletion tests/files/.pytest-split-durations
Original file line number Diff line number Diff line change
Expand Up @@ -2504,7 +2504,7 @@
"tests/util/test_coord.py::TestCoordUtils::test_lattice_points_in_supercell": 0.00042262504575774074,
"tests/util/test_coord.py::TestCoordUtils::test_pbc_diff": 0.00033979100408032537,
"tests/util/test_coord.py::TestCoordUtils::test_pbc_shortest_vectors": 0.0004611250478774309,
"tests/util/test_coord.py::TestSimplex::test_2dtriangle": 0.0004170419997535646,
"tests/util/test_coord.py::TestSimplex::test_2d_triangle": 0.0004170419997535646,
"tests/util/test_coord.py::TestSimplex::test_bary_coords": 0.00034245802089571953,
"tests/util/test_coord.py::TestSimplex::test_equal": 0.00038299994776025414,
"tests/util/test_coord.py::TestSimplex::test_in_simplex": 0.0003631249419413507,
Expand Down
2 changes: 1 addition & 1 deletion tests/util/test_coord.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def test_in_simplex(self):
coord = np.random.random_sample(size=3) / 3
assert self.simplex.in_simplex(coord)

def test_2dtriangle(self):
def test_2d_triangle(self):
simplex = coord.Simplex([[0, 1], [1, 1], [1, 0]])
assert_allclose(simplex.bary_coords([0.5, 0.5]), [0.5, 0, 0.5])
assert_allclose(simplex.bary_coords([0.5, 1]), [0.5, 0.5, 0])
Expand Down

0 comments on commit ca510d5

Please sign in to comment.