Skip to content

Commit d35e1ec

Browse files
authored
Delete variable self assignments (#3196)
* delete self-assignments pymatgen/io/lobster/outputs.py simplify if cond: x = True else x = False to x = cond * del unused w_area_has_intersection_smoothstep strictly speaking breaking but wasn't actually doing anything except call w_area_intersection_specific so recommended fix is to just use that
1 parent f1ac4aa commit d35e1ec

File tree

10 files changed

+32
-82
lines changed

10 files changed

+32
-82
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ci:
88

99
repos:
1010
- repo: https://github.com/astral-sh/ruff-pre-commit
11-
rev: v0.0.279
11+
rev: v0.0.281
1212
hooks:
1313
- id: ruff
1414
args: [--fix]

pymatgen/analysis/chemenv/coordination_environments/chemenv_strategies.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2024,7 +2024,6 @@ def __init__(
20242024
self.area_weight = self.w_area_has_intersection
20252025
elif weight_type == "has_intersection_smoothstep":
20262026
raise NotImplementedError
2027-
# self.area_weight = self.w_area_has_intersection_smoothstep
20282027
else:
20292028
raise ValueError(f'Weight type is {weight_type!r} while it should be "has_intersection"')
20302029
self.surface_definition = surface_definition
@@ -2064,28 +2063,6 @@ def weight(self, nb_set, structure_environments, cn_map=None, additional_info=No
20642063
additional_info=additional_info,
20652064
)
20662065

2067-
def w_area_has_intersection_smoothstep(self, nb_set, structure_environments, cn_map, additional_info):
2068-
"""Get intersection of the neighbors set area with the surface.
2069-
2070-
:param nb_set: Neighbors set.
2071-
:param structure_environments: Structure environments.
2072-
:param cn_map: Mapping index of the neighbors set.
2073-
:param additional_info: Additional information.
2074-
:return: Area intersection between neighbors set and surface.
2075-
"""
2076-
w_area = self.w_area_intersection_specific(
2077-
nb_set=nb_set,
2078-
structure_environments=structure_environments,
2079-
cn_map=cn_map,
2080-
additional_info=additional_info,
2081-
)
2082-
if w_area > 0:
2083-
if self.smoothstep_distance is not None:
2084-
w_area = w_area
2085-
if self.smoothstep_angle is not None:
2086-
w_area = w_area
2087-
return w_area
2088-
20892066
def w_area_has_intersection(self, nb_set, structure_environments, cn_map, additional_info):
20902067
"""Get intersection of the neighbors set area with the surface.
20912068

pymatgen/analysis/wulff.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,6 @@ def get_plot(
462462
ax.set_zlim([-r_range * 1.1, r_range * 1.1]) # pylint: disable=E1101
463463
# add legend
464464
if legend_on:
465-
color_proxy = color_proxy
466465
if show_area:
467466
ax.legend(
468467
color_proxy,

pymatgen/apps/battery/conversion_battery.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ def from_composition_and_pd(cls, comp, pd, working_ion_symbol="Li", allow_unstab
7272
profile.reverse()
7373
if len(profile) < 2:
7474
return None
75-
working_ion_entry = working_ion_entry
7675
working_ion = working_ion_entry.composition.elements[0].symbol
7776
normalization_els = {}
7877
for el, amt in comp.items():
@@ -83,7 +82,7 @@ def from_composition_and_pd(cls, comp, pd, working_ion_symbol="Li", allow_unstab
8382
framework.pop(working_ion)
8483
framework = Composition(framework)
8584

86-
vpairs = [
85+
v_pairs = [
8786
ConversionVoltagePair.from_steps(
8887
profile[i],
8988
profile[i + 1],
@@ -94,7 +93,7 @@ def from_composition_and_pd(cls, comp, pd, working_ion_symbol="Li", allow_unstab
9493
]
9594

9695
return ConversionElectrode( # pylint: disable=E1123
97-
voltage_pairs=vpairs,
96+
voltage_pairs=v_pairs,
9897
working_ion_entry=working_ion_entry,
9998
initial_comp_formula=comp.reduced_formula,
10099
framework_formula=framework.reduced_formula,
@@ -338,26 +337,24 @@ def from_steps(cls, step1, step2, normalization_els, framework_formula):
338337
sum(curr_rxn.all_comp[i].weight * abs(curr_rxn.coeffs[i]) for i in range(len(curr_rxn.all_comp))) / 2
339338
)
340339
mass_charge = prev_mass_dischg
341-
mass_discharge = mass_discharge
342340
vol_discharge = sum(
343341
abs(curr_rxn.get_coeff(e.composition)) * e.structure.volume
344342
for e in step2["entries"]
345343
if e.composition.reduced_formula != working_ion
346344
)
347345

348-
totalcomp = Composition({})
346+
total_comp = Composition({})
349347
for comp in prev_rxn.products:
350348
if comp.reduced_formula != working_ion:
351-
totalcomp += comp * abs(prev_rxn.get_coeff(comp))
352-
frac_charge = totalcomp.get_atomic_fraction(Element(working_ion))
349+
total_comp += comp * abs(prev_rxn.get_coeff(comp))
350+
frac_charge = total_comp.get_atomic_fraction(Element(working_ion))
353351

354-
totalcomp = Composition({})
352+
total_comp = Composition({})
355353
for comp in curr_rxn.products:
356354
if comp.reduced_formula != working_ion:
357-
totalcomp += comp * abs(curr_rxn.get_coeff(comp))
358-
frac_discharge = totalcomp.get_atomic_fraction(Element(working_ion))
355+
total_comp += comp * abs(curr_rxn.get_coeff(comp))
356+
frac_discharge = total_comp.get_atomic_fraction(Element(working_ion))
359357

360-
rxn = rxn
361358
entries_charge = step1["entries"]
362359
entries_discharge = step2["entries"]
363360

pymatgen/command_line/tests/test_gulp_caller.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ def test_run(self):
5656
gin += "buck\n"
5757
gin += "Mg core O shel 946.627 0.31813 0.00000 0.0 10.0\n"
5858
gin += "O shel O shel 22764.000 0.14900 27.87900 0.0 12.0\n"
59-
gin = gin
6059
gc = GulpCaller()
6160

6261
"""Some inherent checks are in the run_gulp function itself.

pymatgen/io/abinit/inputs.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,9 +1087,6 @@ def __init__(self, structure: Structure, pseudos, pseudo_dir="", ndtset=1):
10871087
if isinstance(pseudos, Pseudo):
10881088
pseudos = [pseudos]
10891089

1090-
elif isinstance(pseudos, PseudoTable):
1091-
pseudos = pseudos
1092-
10931090
elif all(isinstance(p, Pseudo) for p in pseudos):
10941091
pseudos = PseudoTable(pseudos)
10951092

pymatgen/io/lobster/lobsterenv.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,9 +1279,7 @@ def from_Lobster(
12791279
Returns: LobsterLightStructureEnvironments
12801280
"""
12811281
strategy = None
1282-
valences = valences
12831282
valences_origin = "user-defined"
1284-
structure = structure
12851283

12861284
coordination_environments = []
12871285

pymatgen/io/lobster/outputs.py

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,8 @@ def __init__(self, are_coops: bool = False, are_cobis: bool = False, filename: s
116116
# Subtract 1 to skip the average
117117
num_bonds = int(parameters[0]) - 1
118118
self.efermi = float(parameters[-1])
119-
if int(parameters[1]) == 2:
120-
spins = [Spin.up, Spin.down]
121-
self.is_spin_polarized = True
122-
else:
123-
spins = [Spin.up]
124-
self.is_spin_polarized = False
119+
self.is_spin_polarized = int(parameters[1]) == 2
120+
spins = [Spin.up, Spin.down] if int(parameters[1]) == 2 else [Spin.up]
125121

126122
# The COHP data start in row num_bonds + 3
127123
data = np.array([np.array(row.split(), dtype=float) for row in contents[num_bonds + 3 :]]).transpose()
@@ -135,22 +131,22 @@ def __init__(self, are_coops: bool = False, are_cobis: bool = False, filename: s
135131

136132
orb_cohp: dict[str, Any] = {}
137133
# present for Lobster versions older than Lobster 2.2.0
138-
veryold = False
134+
very_old = False
139135
# the labeling had to be changed: there are more than one COHP for each atom combination
140136
# this is done to make the labeling consistent with ICOHPLIST.lobster
141-
bondnumber = 0
137+
bond_num = 0
142138
for bond in range(num_bonds):
143139
bond_data = self._get_bond_data(contents[3 + bond])
144140

145-
label = str(bondnumber)
141+
label = str(bond_num)
146142

147143
orbs = bond_data["orbitals"]
148144
cohp = {spin: data[2 * (bond + s * (num_bonds + 1)) + 3] for s, spin in enumerate(spins)}
149145

150146
icohp = {spin: data[2 * (bond + s * (num_bonds + 1)) + 4] for s, spin in enumerate(spins)}
151147
if orbs is None:
152-
bondnumber = bondnumber + 1
153-
label = str(bondnumber)
148+
bond_num = bond_num + 1
149+
label = str(bond_num)
154150
cohp_data[label] = {
155151
"COHP": cohp,
156152
"ICOHP": icohp,
@@ -172,11 +168,11 @@ def __init__(self, are_coops: bool = False, are_cobis: bool = False, filename: s
172168
)
173169
else:
174170
# present for Lobster versions older than Lobster 2.2.0
175-
if bondnumber == 0:
176-
veryold = True
177-
if veryold:
178-
bondnumber += 1
179-
label = str(bondnumber)
171+
if bond_num == 0:
172+
very_old = True
173+
if very_old:
174+
bond_num += 1
175+
label = str(bond_num)
180176

181177
orb_cohp[label] = {
182178
bond_data["orb_label"]: {
@@ -189,7 +185,7 @@ def __init__(self, are_coops: bool = False, are_cobis: bool = False, filename: s
189185
}
190186

191187
# present for lobster older than 2.2.0
192-
if veryold:
188+
if very_old:
193189
for bond_str in orb_cohp:
194190
cohp_data[bond_str] = {
195191
"COHP": None,
@@ -302,18 +298,12 @@ def __init__(self, are_coops: bool = False, are_cobis: bool = False, filename: s
302298

303299
# If the calculation is spin polarized, the line in the middle
304300
# of the file will be another header line.
305-
if "distance" in data[len(data) // 2]:
306-
# TODO: adapt this for orbitalwise stuff
307-
self.is_spin_polarized = True
308-
else:
309-
self.is_spin_polarized = False
301+
# TODO: adapt this for orbitalwise stuff
302+
self.is_spin_polarized = "distance" in data[len(data) // 2]
310303

311304
# check if orbitalwise ICOHPLIST
312305
# include case when there is only one ICOHP!!!
313-
if len(data) > 2 and "_" in data[1].split()[1]:
314-
self.orbitalwise = True
315-
else:
316-
self.orbitalwise = False
306+
self.orbitalwise = len(data) > 2 and "_" in data[1].split()[1]
317307

318308
if self.orbitalwise:
319309
data_without_orbitals = []
@@ -364,7 +354,7 @@ def __init__(self, are_coops: bool = False, are_cobis: bool = False, filename: s
364354
length = float(line[3])
365355
translation = [int(line[4]), int(line[5]), int(line[6])]
366356
icohp[Spin.up] = float(line[7])
367-
num = int(1)
357+
num = 1
368358

369359
if self.is_spin_polarized:
370360
icohp[Spin.down] = float(data_without_orbitals[bond + num_bonds + 1].split()[7])
@@ -1141,10 +1131,7 @@ def __init__(self, filenames=".", vasprun="vasprun.xml", Kpointsfile="KPOINTS"):
11411131
linenumbers.append(iline)
11421132

11431133
if ifilename == 0:
1144-
if len(linenumbers) == 2:
1145-
self.is_spinpolarized = True
1146-
else:
1147-
self.is_spinpolarized = False
1134+
self.is_spinpolarized = len(linenumbers) == 2
11481135

11491136
if ifilename == 0:
11501137
eigenvals = {}

pymatgen/io/nwchem.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -261,25 +261,23 @@ def from_molecule(
261261
example, to perform cosmo calculations with DFT, you'd supply
262262
{'cosmo': "cosmo"}.
263263
"""
264-
title = title if title is not None else "{} {} {}".format(re.sub(r"\s", "", mol.formula), theory, operation)
264+
formula = re.sub(r"\s", "", mol.formula)
265+
title = title if title is not None else f"{formula} {theory} {operation}"
265266

266267
charge = charge if charge is not None else mol.charge
267-
nelectrons = -charge + mol.charge + mol.nelectrons # pylint: disable=E1130
268+
n_electrons = -charge + mol.charge + mol.nelectrons # pylint: disable=E1130
268269
if spin_multiplicity is not None:
269-
spin_multiplicity = spin_multiplicity
270-
if (nelectrons + spin_multiplicity) % 2 != 1:
270+
if (n_electrons + spin_multiplicity) % 2 != 1:
271271
raise ValueError(f"{charge=} and {spin_multiplicity=} is not possible for this molecule")
272272
elif charge == mol.charge:
273273
spin_multiplicity = mol.spin_multiplicity
274274
else:
275-
spin_multiplicity = 1 if nelectrons % 2 == 0 else 2
275+
spin_multiplicity = 1 if n_electrons % 2 == 0 else 2
276276

277277
elements = set(mol.composition.get_el_amt_dict())
278278
if isinstance(basis_set, str):
279279
basis_set = {el: basis_set for el in elements}
280280

281-
basis_set_option = basis_set_option
282-
283281
return NwTask(
284282
charge,
285283
spin_multiplicity,

pymatgen/io/xtb/inputs.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ def constrains_template(molecule, reference_fnm, constraints) -> str:
8181
"""
8282
atoms_to_constrain = constraints["atoms"]
8383
force_constant = constraints["force_constant"]
84-
reference_fnm = reference_fnm
8584
mol = molecule
8685
atoms_for_mtd = [idx for idx in range(1, len(mol) + 1) if idx not in atoms_to_constrain]
8786
# Write as 1-3,5 instead of 1,2,3,5
@@ -91,7 +90,6 @@ def constrains_template(molecule, reference_fnm, constraints) -> str:
9190
interval_list.append(v)
9291
if i != len(atoms_for_mtd) - 1:
9392
interval_list.append(atoms_for_mtd[i + 1])
94-
force_constant = force_constant
9593
allowed_mtd_string = ",".join(
9694
[f"{interval_list[i]}-{interval_list[i + 1]}" for i in range(len(interval_list)) if i % 2 == 0]
9795
)

0 commit comments

Comments
 (0)