Skip to content

Commit

Permalink
prefer list literal over verbose coords.append
Browse files Browse the repository at this point in the history
  • Loading branch information
janosh committed Oct 6, 2023
1 parent dcea6b6 commit 5289fe2
Show file tree
Hide file tree
Showing 13 changed files with 170 additions and 238 deletions.
4 changes: 2 additions & 2 deletions pymatgen/analysis/phase_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -1294,10 +1294,10 @@ def get_chempot_range_stability_phase(self, target_comp, open_elt):
min_open = test_open
min_mus = v

elts = [e for e in self.elements if e != open_elt]
elems = [e for e in self.elements if e != open_elt]
res = {}

for i, el in enumerate(elts):
for i, el in enumerate(elems):
res[el] = (min_mus[i] + muref[i], max_mus[i] + muref[i])

res[open_elt] = (min_open, max_open)
Expand Down
4 changes: 2 additions & 2 deletions pymatgen/symmetry/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class SpacegroupAnalyzer:
Uses spglib to perform various symmetry finding operations.
"""

def __init__(self, structure: Structure, symprec: float | None = 0.01, angle_tolerance=5.0):
def __init__(self, structure: Structure, symprec: float | None = 0.01, angle_tolerance: float = 5.0) -> None:
"""
Args:
structure (Structure/IStructure): Structure to find symmetry
Expand Down Expand Up @@ -476,7 +476,7 @@ def get_conventional_to_primitive_transformation_matrix(self, international_mono

@cite_conventional_cell_algo
def get_primitive_standard_structure(self, international_monoclinic=True, keep_site_properties=False):
"""Gives a structure with a primitive cell according to certain standards the
"""Gives a structure with a primitive cell according to certain standards. The
standards are defined in Setyawan, W., & Curtarolo, S. (2010). High-throughput
electronic band structure calculations: Challenges and tools. Computational
Materials Science, 49(2), 299-312. doi:10.1016/j.commatsci.2010.05.010.
Expand Down
6 changes: 3 additions & 3 deletions pymatgen/transformations/advanced_transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ def __init__(
n_jobs (int): Number of parallel jobs used to compute energy criteria. This is used only when the Ewald
or m3gnet or callable sort_criteria is used. Default is -1, which uses all available CPUs.
"""
self.symm_prec = symm_prec
self.sym_prec = symm_prec
self.min_cell_size = min_cell_size
self.max_cell_size = max_cell_size
self.refine_structure = refine_structure
Expand Down Expand Up @@ -362,7 +362,7 @@ def apply_transformation(self, structure: Structure, return_ranked_list: bool |
num_to_return = 1

if self.refine_structure:
finder = SpacegroupAnalyzer(structure, self.symm_prec)
finder = SpacegroupAnalyzer(structure, self.sym_prec)
structure = finder.get_refined_structure()

contains_oxidation_state = all(hasattr(sp, "oxi_state") and sp.oxi_state != 0 for sp in structure.elements)
Expand Down Expand Up @@ -391,7 +391,7 @@ def apply_transformation(self, structure: Structure, return_ranked_list: bool |
structure,
min_cell_size=self.min_cell_size,
max_cell_size=max_cell_size,
symm_prec=self.symm_prec,
symm_prec=self.sym_prec,
refine_structure=False,
enum_precision_parameter=self.enum_precision_parameter,
check_ordered_symmetry=self.check_ordered_symmetry,
Expand Down
4 changes: 1 addition & 3 deletions tests/alchemy/test_materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ def test_append_transformation(self):
self.trans.append_transformation(trafo)
assert self.trans.final_structure.composition.reduced_formula == "NaMnPO4"
assert len(self.trans.structures) == 3
coords = []
coords.append([0, 0, 0])
coords.append([0.75, 0.5, 0.75])
coords = [[0, 0, 0], [0.75, 0.5, 0.75]]
lattice = [
[3.8401979337, 0, 0],
[1.9200989668, 3.3257101909, 0],
Expand Down
39 changes: 20 additions & 19 deletions tests/analysis/test_structure_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,34 +110,35 @@ def test_oxide_type(self):
el_li = Element("Li")
el_o = Element("O")
latt = Lattice([[3.985034, 0, 0], [0, 4.881506, 0], [0, 0, 2.959824]])
elts = [el_li, el_li, el_o, el_o, el_o, el_o]
coords = []
coords.append([0.500000, 0.500000, 0.500000])
coords.append([0, 0, 0])
coords.append([0.632568, 0.085090, 0.500000])
coords.append([0.367432, 0.914910, 0.500000])
coords.append([0.132568, 0.414910, 0.000000])
coords.append([0.867432, 0.585090, 0.000000])
struct = Structure(latt, elts, coords)
elems = [el_li, el_li, el_o, el_o, el_o, el_o]
coords = [
[0.5, 0.5, 0.5],
[0, 0, 0],
[0.632568, 0.085090, 0.5],
[0.367432, 0.914910, 0.5],
[0.132568, 0.414910, 0],
[0.867432, 0.585090, 0],
]
struct = Structure(latt, elems, coords)
assert oxide_type(struct, 1.1) == "superoxide"

el_li = Element("Li")
el_o = Element("O")
elts = [el_li, el_o, el_o, el_o]
elems = [el_li, el_o, el_o, el_o]
latt = Lattice.from_parameters(3.999911, 3.999911, 3.999911, 133.847504, 102.228244, 95.477342)
coords = [
[0.513004, 0.513004, 1.000000],
[0.017616, 0.017616, 0.000000],
[0.649993, 0.874790, 0.775203],
[0.099587, 0.874790, 0.224797],
]
struct = Structure(latt, elts, coords)
struct = Structure(latt, elems, coords)
assert oxide_type(struct, 1.1) == "ozonide"

latt = Lattice.from_parameters(3.159597, 3.159572, 7.685205, 89.999884, 89.999674, 60.000510)
el_li = Element("Li")
el_o = Element("O")
elts = [el_li, el_li, el_li, el_li, el_o, el_o, el_o, el_o]
elems = [el_li, el_li, el_li, el_li, el_o, el_o, el_o, el_o]
coords = [
[0.666656, 0.666705, 0.750001],
[0.333342, 0.333378, 0.250001],
Expand All @@ -148,14 +149,14 @@ def test_oxide_type(self):
[0.666666, 0.666686, 0.350813],
[0.666665, 0.666684, 0.149189],
]
struct = Structure(latt, elts, coords)
struct = Structure(latt, elems, coords)
assert oxide_type(struct, 1.1) == "peroxide"

el_li = Element("Li")
el_o = Element("O")
el_h = Element("H")
latt = Lattice.from_parameters(3.565276, 3.565276, 4.384277, 90.000000, 90.000000, 90.000000)
elts = [el_h, el_h, el_li, el_li, el_o, el_o]
elems = [el_h, el_h, el_li, el_li, el_o, el_o]
coords = [
[0.000000, 0.500000, 0.413969],
[0.500000, 0.000000, 0.586031],
Expand All @@ -164,14 +165,14 @@ def test_oxide_type(self):
[0.000000, 0.500000, 0.192672],
[0.500000, 0.000000, 0.807328],
]
struct = Structure(latt, elts, coords)
struct = Structure(latt, elems, coords)
assert oxide_type(struct, 1.1) == "hydroxide"

el_li = Element("Li")
el_n = Element("N")
el_h = Element("H")
latt = Lattice.from_parameters(3.565276, 3.565276, 4.384277, 90.000000, 90.000000, 90.000000)
elts = [el_h, el_h, el_li, el_li, el_n, el_n]
elems = [el_h, el_h, el_li, el_li, el_n, el_n]
coords = [
[0.000000, 0.500000, 0.413969],
[0.500000, 0.000000, 0.586031],
Expand All @@ -180,12 +181,12 @@ def test_oxide_type(self):
[0.000000, 0.500000, 0.192672],
[0.500000, 0.000000, 0.807328],
]
struct = Structure(latt, elts, coords)
struct = Structure(latt, elems, coords)
assert oxide_type(struct, 1.1) == "None"

el_o = Element("O")
latt = Lattice.from_parameters(4.389828, 5.369789, 5.369789, 70.786622, 69.244828, 69.244828)
elts = [el_o, el_o, el_o, el_o, el_o, el_o, el_o, el_o]
elems = [el_o, el_o, el_o, el_o, el_o, el_o, el_o, el_o]
coords = [
[0.844609, 0.273459, 0.786089],
[0.155391, 0.213911, 0.726541],
Expand All @@ -196,7 +197,7 @@ def test_oxide_type(self):
[0.132641, 0.148222, 0.148222],
[0.867359, 0.851778, 0.851778],
]
struct = Structure(latt, elts, coords)
struct = Structure(latt, elems, coords)
assert oxide_type(struct, 1.1) == "None"

def test_sulfide_type(self):
Expand Down
36 changes: 18 additions & 18 deletions tests/entries/test_compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -1321,15 +1321,15 @@ def test_process_entry_superoxide(self):
el_li = Element("Li")
el_o = Element("O")
latt = Lattice([[3.985034, 0.0, 0.0], [0.0, 4.881506, 0.0], [0.0, 0.0, 2.959824]])
elts = [el_li, el_li, el_o, el_o, el_o, el_o]
elems = [el_li, el_li, el_o, el_o, el_o, el_o]
coords = []
coords.append([0.500000, 0.500000, 0.500000])
coords.append([0.0, 0.0, 0.0])
coords.append([0.632568, 0.085090, 0.500000])
coords.append([0.367432, 0.914910, 0.500000])
coords.append([0.132568, 0.414910, 0.000000])
coords.append([0.867432, 0.585090, 0.000000])
struct = Structure(latt, elts, coords)
struct = Structure(latt, elems, coords)
lio2_entry = ComputedStructureEntry(
struct,
-3,
Expand All @@ -1351,7 +1351,7 @@ def test_process_entry_peroxide(self):
latt = Lattice.from_parameters(3.159597, 3.159572, 7.685205, 89.999884, 89.999674, 60.000510)
el_li = Element("Li")
el_o = Element("O")
elts = [el_li, el_li, el_li, el_li, el_o, el_o, el_o, el_o]
elems = [el_li, el_li, el_li, el_li, el_o, el_o, el_o, el_o]
coords = [
[0.666656, 0.666705, 0.750001],
[0.333342, 0.333378, 0.250001],
Expand All @@ -1362,7 +1362,7 @@ def test_process_entry_peroxide(self):
[0.666666, 0.666686, 0.350813],
[0.666665, 0.666684, 0.149189],
]
struct = Structure(latt, elts, coords)
struct = Structure(latt, elems, coords)
li2o2_entry = ComputedStructureEntry(
struct,
-3,
Expand All @@ -1383,15 +1383,15 @@ def test_process_entry_peroxide(self):
def test_process_entry_ozonide(self):
el_li = Element("Li")
el_o = Element("O")
elts = [el_li, el_o, el_o, el_o]
elems = [el_li, el_o, el_o, el_o]
latt = Lattice.from_parameters(3.999911, 3.999911, 3.999911, 133.847504, 102.228244, 95.477342)
coords = [
[0.513004, 0.513004, 1.000000],
[0.017616, 0.017616, 0.000000],
[0.649993, 0.874790, 0.775203],
[0.099587, 0.874790, 0.224797],
]
struct = Structure(latt, elts, coords)
struct = Structure(latt, elems, coords)
lio3_entry = ComputedStructureEntry(
struct,
-3,
Expand All @@ -1412,10 +1412,10 @@ def test_process_entry_ozonide(self):
def test_process_entry_oxide(self):
el_li = Element("Li")
el_o = Element("O")
elts = [el_li, el_li, el_o]
elems = [el_li, el_li, el_o]
latt = Lattice.from_parameters(3.278, 3.278, 3.278, 60, 60, 60)
coords = [[0.25, 0.25, 0.25], [0.75, 0.75, 0.75], [0.0, 0.0, 0.0]]
struct = Structure(latt, elts, coords)
struct = Structure(latt, elems, coords)
li2o_entry = ComputedStructureEntry(
struct,
-3,
Expand Down Expand Up @@ -1602,10 +1602,10 @@ def setUp(self):
def test_oxide_energy_corr(self):
el_li = Element("Li")
el_o = Element("O")
elts = [el_li, el_li, el_o]
elems = [el_li, el_li, el_o]
latt = Lattice.from_parameters(3.278, 3.278, 3.278, 60, 60, 60)
coords = [[0.25, 0.25, 0.25], [0.75, 0.75, 0.75], [0.0, 0.0, 0.0]]
struct = Structure(latt, elts, coords)
struct = Structure(latt, elems, coords)
li2o_entry = ComputedStructureEntry(
struct,
-3,
Expand All @@ -1627,7 +1627,7 @@ def test_peroxide_energy_corr(self):
latt = Lattice.from_parameters(3.159597, 3.159572, 7.685205, 89.999884, 89.999674, 60.000510)
el_li = Element("Li")
el_o = Element("O")
elts = [el_li, el_li, el_li, el_li, el_o, el_o, el_o, el_o]
elems = [el_li, el_li, el_li, el_li, el_o, el_o, el_o, el_o]
coords = [
[0.666656, 0.666705, 0.750001],
[0.333342, 0.333378, 0.250001],
Expand All @@ -1638,7 +1638,7 @@ def test_peroxide_energy_corr(self):
[0.666666, 0.666686, 0.350813],
[0.666665, 0.666684, 0.149189],
]
struct = Structure(latt, elts, coords)
struct = Structure(latt, elems, coords)
cse_params = {
"is_hubbard": False,
"hubbards": None,
Expand All @@ -1656,15 +1656,15 @@ def test_peroxide_energy_corr(self):
def test_ozonide(self):
el_li = Element("Li")
el_o = Element("O")
elts = [el_li, el_o, el_o, el_o]
elems = [el_li, el_o, el_o, el_o]
latt = Lattice.from_parameters(3.999911, 3.999911, 3.999911, 133.847504, 102.228244, 95.477342)
coords = [
[0.513004, 0.513004, 1.000000],
[0.017616, 0.017616, 0.000000],
[0.649993, 0.874790, 0.775203],
[0.099587, 0.874790, 0.224797],
]
struct = Structure(latt, elts, coords)
struct = Structure(latt, elems, coords)
lio3_entry = ComputedStructureEntry(
struct,
-3,
Expand Down Expand Up @@ -1867,7 +1867,7 @@ def test_aqueous_compat(self):
el_o = Element("O")
el_h = Element("H")
latt = Lattice.from_parameters(3.565276, 3.565276, 4.384277, 90.000000, 90.000000, 90.000000)
elts = [el_h, el_h, el_li, el_li, el_o, el_o]
elems = [el_h, el_h, el_li, el_li, el_o, el_o]
coords = [
[0.000000, 0.500000, 0.413969],
[0.500000, 0.000000, 0.586031],
Expand All @@ -1876,7 +1876,7 @@ def test_aqueous_compat(self):
[0.000000, 0.500000, 0.192672],
[0.500000, 0.000000, 0.807328],
]
struct = Structure(latt, elts, coords)
struct = Structure(latt, elems, coords)
lioh_entry = ComputedStructureEntry(
struct,
-3,
Expand All @@ -1902,7 +1902,7 @@ def test_potcar_doenst_match_structure(self):
el_o = Element("O")
el_h = Element("H")
latt = Lattice.from_parameters(3.565276, 3.565276, 4.384277, 90.000000, 90.000000, 90.000000)
elts = [el_h, el_h, el_li, el_li, el_o, el_o]
elems = [el_h, el_h, el_li, el_li, el_o, el_o]
coords = [
[0.000000, 0.500000, 0.413969],
[0.500000, 0.000000, 0.586031],
Expand All @@ -1911,7 +1911,7 @@ def test_potcar_doenst_match_structure(self):
[0.000000, 0.500000, 0.192672],
[0.500000, 0.000000, 0.807328],
]
struct = Structure(latt, elts, coords)
struct = Structure(latt, elems, coords)

lioh_entry = ComputedStructureEntry(
struct,
Expand Down
4 changes: 1 addition & 3 deletions tests/io/test_xcrysden.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@

class TestXSF(PymatgenTest):
def test_xsf(self):
coords = []
coords.append([0, 0, 0])
coords.append([0.75, 0.5, 0.75])
coords = [[0, 0, 0], [0.75, 0.5, 0.75]]
lattice = Lattice(
[
[3.8401979337, 0.00, 0.00],
Expand Down
12 changes: 3 additions & 9 deletions tests/io/vasp/test_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,7 @@ def test_cart_scale(self):

def test_significant_figures(self):
si = 14
coords = []
coords.append([0, 0, 0])
coords.append([0.75, 0.5, 0.75])
coords = [[0, 0, 0], [0.75, 0.5, 0.75]]

# Silicon structure for testing.
latt = [
Expand All @@ -215,9 +213,7 @@ def test_significant_figures(self):

def test_str(self):
si = 14
coords = []
coords.append([0, 0, 0])
coords.append([0.75, 0.5, 0.75])
coords = [[0, 0, 0], [0.75, 0.5, 0.75]]

# Silicon structure for testing.
latt = [
Expand Down Expand Up @@ -335,9 +331,7 @@ def test_setattr(self):

def test_velocities(self):
si = 14
coords = []
coords.append([0, 0, 0])
coords.append([0.75, 0.5, 0.75])
coords = [[0, 0, 0], [0.75, 0.5, 0.75]]

# Silicon structure for testing.
latt = [
Expand Down
Loading

0 comments on commit 5289fe2

Please sign in to comment.