Skip to content

Commit 8b1318a

Browse files
committed
fix TestMVLSlabSet.test_as_from_dict() failing due to float precision
2nd try fix test_valid_magmom_struct() regex on windows fix typos + snake_case variables
1 parent 5409db9 commit 8b1318a

File tree

8 files changed

+51
-66
lines changed

8 files changed

+51
-66
lines changed

pymatgen/analysis/chempot_diagram.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
if TYPE_CHECKING:
4545
from pymatgen.entries.computed_entries import ComputedEntry
4646

47-
with open(os.path.join(os.path.dirname(__file__), "..", "util", "plotly_chempot_layouts.json")) as file:
47+
with open(f"{os.path.dirname(__file__)}/../util/plotly_chempot_layouts.json") as file:
4848
plotly_layouts = json.load(file)
4949

5050

pymatgen/analysis/energy_models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ def __init__(self, real_space_cut=None, recip_space_cut=None, eta=None, acc_fact
5656
Args:
5757
real_space_cut (float): Real space cutoff radius dictating how
5858
many terms are used in the real space sum. Defaults to None,
59-
which means determine automagically using the formula given
59+
which means determine automatically using the formula given
6060
in gulp 3.1 documentation.
6161
recip_space_cut (float): Reciprocal space cutoff radius.
62-
Defaults to None, which means determine automagically using
62+
Defaults to None, which means determine automatically using
6363
the formula given in gulp 3.1 documentation.
6464
eta (float): Screening parameter. Defaults to None, which means
6565
determine automatically.

pymatgen/analysis/fragmenter.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ def open_ring(mol_graph, bond, opt_steps):
299299
self.steps, and then convert the resulting structure back into a molecule graph
300300
to be returned.
301301
"""
302-
obmol = BabelMolAdaptor.from_molecule_graph(mol_graph)
303-
obmol.remove_bond(bond[0][0] + 1, bond[0][1] + 1)
304-
obmol.localopt(steps=opt_steps, forcefield="uff")
305-
return MoleculeGraph.with_local_env_strategy(obmol.pymatgen_mol, OpenBabelNN())
302+
ob_mol = BabelMolAdaptor.from_molecule_graph(mol_graph)
303+
ob_mol.remove_bond(bond[0][0] + 1, bond[0][1] + 1)
304+
ob_mol.localopt(steps=opt_steps, forcefield="uff")
305+
return MoleculeGraph.with_local_env_strategy(ob_mol.pymatgen_mol, OpenBabelNN())

pymatgen/analysis/functional_groups.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,37 +47,37 @@ def __init__(self, molecule, optimize=False):
4747
if isinstance(molecule, str):
4848
try:
4949
if optimize:
50-
obmol = BabelMolAdaptor.from_file(molecule, file_format="mol")
50+
ob_mol = BabelMolAdaptor.from_file(molecule, file_format="mol")
5151
# OBMolecule does not contain pymatgen Molecule information
52-
# So, we need to wrap the obmol in a BabelMolAdapter
53-
obmol.add_hydrogen()
54-
obmol.make3d()
55-
obmol.localopt()
56-
self.molecule = obmol.pymatgen_mol
52+
# So, we need to wrap the ob_mol in a BabelMolAdapter
53+
ob_mol.add_hydrogen()
54+
ob_mol.make3d()
55+
ob_mol.localopt()
56+
self.molecule = ob_mol.pymatgen_mol
5757
else:
5858
self.molecule = Molecule.from_file(molecule)
5959
except OSError:
6060
raise ValueError("Input must be a valid molecule file, a Molecule object, or a MoleculeGraph object.")
6161

6262
elif isinstance(molecule, Molecule):
6363
if optimize:
64-
obmol = BabelMolAdaptor(molecule)
65-
obmol.add_hydrogen()
66-
obmol.make3d()
67-
obmol.localopt()
64+
ob_mol = BabelMolAdaptor(molecule)
65+
ob_mol.add_hydrogen()
66+
ob_mol.make3d()
67+
ob_mol.localopt()
6868

69-
self.molecule = obmol.pymatgen_mol
69+
self.molecule = ob_mol.pymatgen_mol
7070
else:
7171
self.molecule = molecule
7272

7373
elif isinstance(molecule, MoleculeGraph):
7474
if optimize:
75-
obmol = BabelMolAdaptor(molecule.molecule)
76-
obmol.add_hydrogen()
77-
obmol.make3d()
78-
obmol.localopt()
75+
ob_mol = BabelMolAdaptor(molecule.molecule)
76+
ob_mol.add_hydrogen()
77+
ob_mol.make3d()
78+
ob_mol.localopt()
7979

80-
self.molecule = obmol.pymatgen_mol
80+
self.molecule = ob_mol.pymatgen_mol
8181

8282
else:
8383
self.molecule = molecule.molecule

pymatgen/analysis/local_env.py

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,14 +1456,14 @@ def get_nn_info(self, structure: Structure, n: int):
14561456
"""
14571457
from pymatgen.io.babel import BabelMolAdaptor
14581458

1459-
obmol = BabelMolAdaptor(structure).openbabel_mol
1459+
ob_mol = BabelMolAdaptor(structure).openbabel_mol
14601460

14611461
siw = []
14621462

14631463
# Get only the atom of interest
14641464
site_atom = next(
14651465
a
1466-
for i, a in enumerate(openbabel.OBMolAtomDFSIter(obmol))
1466+
for i, a in enumerate(openbabel.OBMolAtomDFSIter(ob_mol))
14671467
if [a.GetX(), a.GetY(), a.GetZ()] == list(structure[n].coords)
14681468
)
14691469

@@ -1475,7 +1475,7 @@ def get_nn_info(self, structure: Structure, n: int):
14751475
bond = site_atom.GetBond(neighbor)
14761476

14771477
if self.order:
1478-
obmol.PerceiveBondOrders()
1478+
ob_mol.PerceiveBondOrders()
14791479
weight = bond.GetBondOrder()
14801480
else:
14811481
weight = bond.GetLength()
@@ -1969,15 +1969,13 @@ def get_okeeffe_params(el_symbol):
19691969
el_symbol (str): element symbol.
19701970
19711971
Returns:
1972-
(dict): atom-size ('r') and electronegativity-related ('c')
1973-
parameter.
1972+
(dict): atom-size ('r') and electronegativity-related ('c') parameter.
19741973
"""
19751974
el = Element(el_symbol)
19761975
if el not in list(BV_PARAMS):
19771976
raise RuntimeError(
19781977
"Could not find O'Keeffe parameters for element"
1979-
f' {el_symbol!r} in "BV_PARAMS"dictionary'
1980-
" provided by pymatgen"
1978+
f' {el_symbol!r} in "BV_PARAMS" dictionary provided by pymatgen'
19811979
)
19821980

19831981
return BV_PARAMS[el]
@@ -2068,14 +2066,7 @@ def site_is_of_motif_type(struct, n, approach="min_dist", delta=0.1, cutoff=10,
20682066
Returns: motif type (str).
20692067
"""
20702068
if thresh is None:
2071-
thresh = {
2072-
"qtet": 0.5,
2073-
"qoct": 0.5,
2074-
"qbcc": 0.5,
2075-
"q6": 0.4,
2076-
"qtribipyr": 0.8,
2077-
"qsqpyr": 0.8,
2078-
}
2069+
thresh = {"qtet": 0.5, "qoct": 0.5, "qbcc": 0.5, "q6": 0.4, "qtribipyr": 0.8, "qsqpyr": 0.8}
20792070

20802071
ops = LocalStructOrderParams(["cn", "tet", "oct", "bcc", "q6", "sq_pyr", "tri_bipyr"])
20812072

@@ -2371,8 +2362,7 @@ def __init__(self, types, parameters=None, cutoff=-10.0):
23712362
def num_ops(self):
23722363
"""
23732364
Returns:
2374-
int: the number of different order parameters that are targeted
2375-
to be calculated.
2365+
int: the number of different order parameters that are targeted to be calculated.
23762366
"""
23772367
return len(self._types)
23782368

@@ -2382,8 +2372,7 @@ def last_nneigh(self):
23822372
Returns:
23832373
int: the number of neighbors encountered during the most
23842374
recent order parameter calculation. A value of -1 indicates
2385-
that no such calculation has yet been performed for this
2386-
instance.
2375+
that no such calculation has yet been performed for this instance.
23872376
"""
23882377
return len(self._last_nneigh)
23892378

tests/core/test_structure.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,11 +1381,7 @@ def test_set_item(self):
13811381

13821382
def test_init_error(self):
13831383
with pytest.raises(StructureError, match="atomic species and fractional coordinates must have same length"):
1384-
Structure(
1385-
Lattice.cubic(3),
1386-
["Si"],
1387-
[[0, 0, 0], [0.5, 0.5, 0.5]],
1388-
)
1384+
Structure(Lattice.cubic(3), ["Si"], [[0, 0, 0], [0.5, 0.5, 0.5]])
13891385

13901386
def test_from_sites(self):
13911387
self.struct.add_site_property("hello", [1, 2])

tests/io/test_babel.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ def setUp(self):
2929

3030
def test_init(self):
3131
adaptor = BabelMolAdaptor(self.mol)
32-
obmol = adaptor.openbabel_mol
32+
ob_mol = adaptor.openbabel_mol
3333
pybel = adaptor.pybel_mol
34-
assert obmol.NumAtoms() == 5
34+
assert ob_mol.NumAtoms() == 5
3535

3636
adaptor = BabelMolAdaptor(adaptor.openbabel_mol)
3737
assert adaptor.pymatgen_mol.formula == "H4 C1"
@@ -55,8 +55,8 @@ def test_from_file_return_all_molecules(self):
5555
def test_from_molecule_graph(self):
5656
graph = MoleculeGraph.with_empty_graph(self.mol)
5757
adaptor = BabelMolAdaptor.from_molecule_graph(graph)
58-
obmol = adaptor.openbabel_mol
59-
assert obmol.NumAtoms() == 5
58+
ob_mol = adaptor.openbabel_mol
59+
assert ob_mol.NumAtoms() == 5
6060
mol = adaptor.pymatgen_mol
6161
assert mol.formula == "H4 C1"
6262

@@ -70,9 +70,9 @@ def test_localopt(self):
7070
self.mol[1] = "H", [0, 0, 1.05]
7171
adaptor = BabelMolAdaptor(self.mol)
7272
adaptor.localopt()
73-
optmol = adaptor.pymatgen_mol
74-
for site in optmol[1:]:
75-
assert site.distance(optmol[0]) == approx(1.09216, abs=1e-1)
73+
opt_mol = adaptor.pymatgen_mol
74+
for site in opt_mol[1:]:
75+
assert site.distance(opt_mol[0]) == approx(1.09216, abs=1e-1)
7676

7777
def test_make3d(self):
7878
mol_0d = pybel.readstring("smi", "CCCC").OBMol
@@ -93,27 +93,27 @@ def test_rotor_search_wrs(self):
9393
adaptor = BabelMolAdaptor(mol)
9494
rotor_args = (250, 50)
9595
adaptor.rotor_conformer(*rotor_args, algo="WeightedRotorSearch")
96-
optmol = adaptor.pymatgen_mol
97-
for site in optmol[1:]:
98-
assert site.distance(optmol[0]) == approx(1.09216, abs=1e-1)
96+
opt_mol = adaptor.pymatgen_mol
97+
for site in opt_mol[1:]:
98+
assert site.distance(opt_mol[0]) == approx(1.09216, abs=1e-1)
9999

100100
def test_rotor_search_srs(self):
101101
mol = copy.deepcopy(self.mol)
102102
mol[1] = "H", [0, 0, 1.05]
103103
adaptor = BabelMolAdaptor(mol)
104104
adaptor.rotor_conformer(200, algo="SystematicRotorSearch")
105-
optmol = adaptor.pymatgen_mol
106-
for site in optmol[1:]:
107-
assert site.distance(optmol[0]) == approx(1.09216, abs=1e-1)
105+
opt_mol = adaptor.pymatgen_mol
106+
for site in opt_mol[1:]:
107+
assert site.distance(opt_mol[0]) == approx(1.09216, abs=1e-1)
108108

109109
def test_rotor_search_rrs(self):
110110
mol = copy.deepcopy(self.mol)
111111
mol[1] = "H", [0, 0, 1.05]
112112
adaptor = BabelMolAdaptor(mol)
113113
adaptor.rotor_conformer(250, 50, algo="RandomRotorSearch")
114-
optmol = adaptor.pymatgen_mol
115-
for site in optmol[1:]:
116-
assert site.distance(optmol[0]) == approx(1.09216, abs=1e-1)
114+
opt_mol = adaptor.pymatgen_mol
115+
for site in opt_mol[1:]:
116+
assert site.distance(opt_mol[0]) == approx(1.09216, abs=1e-1)
117117

118118
def test_confab_conformers(self):
119119
mol = pybel.readstring("smi", "CCCC").OBMol

tests/io/vasp/test_sets.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ def test_valid_magmom_struct(self):
589589
struct.insert(0, "Li", [0, 0, 0])
590590

591591
vis = MPRelaxSet(struct, user_potcar_settings={"Fe": "Fe"}, validate_magmom=False)
592-
with pytest.raises(TypeError, match="argument must be a string or a real number, not 'NoneType'"):
592+
with pytest.raises(TypeError, match="argument must be a string or a real number, not .NoneType."):
593593
print(vis.get_vasp_input())
594594

595595
vis = MPRelaxSet(struct, user_potcar_settings={"Fe": "Fe"}, validate_magmom=True)
@@ -1155,10 +1155,10 @@ def test_kpoints(self):
11551155
# The last kpoint in a slab should always be 1
11561156
assert kpoints_slab[2] == 1
11571157

1158-
def test_as_dict(self):
1158+
def test_as_from_dict(self):
11591159
vis_dict = self.vis.as_dict()
11601160
vis = self.set.from_dict(vis_dict)
1161-
assert vis.as_dict() == vis_dict
1161+
assert {*vis.as_dict()} == {*vis_dict}
11621162

11631163

11641164
class TestMVLElasticSet(PymatgenTest):

0 commit comments

Comments
 (0)