Skip to content

Commit 12626a2

Browse files
committed
delete print debugging statements in tests
delete dead code (commended out)
1 parent 1f98fa2 commit 12626a2

18 files changed

+76
-118
lines changed

pymatgen/analysis/adsorption.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def from_bulk_and_miller(
110110
are 10% less coordinated than their bulk counterpart
111111
"""
112112
# TODO: for some reason this works poorly with primitive cells
113-
# may want to switch the coordination algorithm eventually
113+
# may want to switch the coordination algorithm eventually
114114
vnn_bulk = VoronoiNN(tol=0.05)
115115
bulk_coords = [len(vnn_bulk.get_nn(structure, n)) for n in range(len(structure))]
116116
struct = structure.copy(site_properties={"bulk_coordinations": bulk_coords})

pymatgen/analysis/local_env.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -445,8 +445,7 @@ def get_nn_shell_info(self, structure: Structure, site_idx, shell):
445445
all_nn_info = self.get_all_nn_info(structure)
446446
sites = self._get_nn_shell_info(structure, all_nn_info, site_idx, shell)
447447

448-
# Update the site positions
449-
# Did not do this during NN options because that can be slower
448+
# Now update the site positions. Did not do this during NN options because that can be slower.
450449
output = []
451450
for info in sites:
452451
orig_site = structure[info["site_index"]]
@@ -495,8 +494,8 @@ def _get_nn_shell_info(
495494
possible_steps = list(all_nn_info[site_idx])
496495
for i, step in enumerate(possible_steps):
497496
# Update the image information
498-
# Note: We do not update the site position yet, as making a
499-
# PeriodicSite for each intermediate step is too costly
497+
# Note: We do not update the site position yet, as making a PeriodicSite
498+
# for each intermediate step is too costly
500499
step = dict(step)
501500
step["image"] = tuple(np.add(step["image"], _cur_image).tolist())
502501
possible_steps[i] = step
@@ -743,8 +742,7 @@ def get_voronoi_polyhedra(self, structure: Structure, n: int):
743742
- volume - Volume of Voronoi cell for this face
744743
- n_verts - Number of vertices on the facet
745744
"""
746-
# Assemble the list of neighbors used in the tessellation
747-
# Gets all atoms within a certain radius
745+
# Assemble the list of neighbors used in the tessellation. Gets all atoms within a certain radius
748746
targets = structure.elements if self.targets is None else self.targets
749747
center = structure[n]
750748

@@ -814,8 +812,7 @@ def get_all_voronoi_polyhedra(self, structure: Structure):
814812
sites = [x.to_unit_cell() for x in structure]
815813
indices = [(i, 0, 0, 0) for i, _ in enumerate(structure)]
816814

817-
# Get all neighbors within a certain cutoff
818-
# Record both the list of these neighbors, and the site indices
815+
# Get all neighbors within a certain cutoff. Record both the list of these neighbors and the site indices.
819816
all_neighs = structure.get_all_neighbors(self.cutoff, include_index=True, include_image=True)
820817
for neighs in all_neighs:
821818
sites.extend([x[0] for x in neighs])
@@ -1548,8 +1545,7 @@ def get_nn_shell_info(self, structure: Structure, site_idx, shell):
15481545
all_nn_info = self.get_all_nn_info(structure)
15491546
sites = self._get_nn_shell_info(structure, all_nn_info, site_idx, shell)
15501547

1551-
# Update the site positions
1552-
# Did not do this during NN options because that can be slower
1548+
# Now update the site positions. Did not do this during NN options because that can be slower.
15531549
output = []
15541550
for info in sites:
15551551
orig_site = structure[info["site_index"]]
@@ -1694,8 +1690,7 @@ def get_nn_shell_info(self, structure: Structure, site_idx, shell):
16941690
all_nn_info = self.get_all_nn_info(structure)
16951691
sites = self._get_nn_shell_info(structure, all_nn_info, site_idx, shell)
16961692

1697-
# Update the site positions
1698-
# Did not do this during NN options because that can be slower
1693+
# Now update the site positions. Did not do this during NN options because that can be slower.
16991694
output = []
17001695
for info in sites:
17011696
orig_site = structure[info["site_index"]]
@@ -2663,7 +2658,7 @@ def get_q6(self, thetas=None, phis=None):
26632658
real = 0.0
26642659
imag = 0.0
26652660
for idx in nnn_range:
2666-
real += pre_y_6_6[idx] * self._cos_n_p[6][idx] # cos(x) = cos(-x)
2661+
real += pre_y_6_6[idx] * self._cos_n_p[6][idx] # cos(x) = cos(-x)
26672662
imag -= pre_y_6_6[idx] * self._sin_n_p[6][idx] # sin(x) = -sin(-x)
26682663
acc += real * real + imag * imag
26692664

pymatgen/analysis/phase_diagram.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,19 +1722,19 @@ def from_dict(cls, dct):
17221722
elements = [Element.from_dict(elem) for elem in dct["elements"]]
17231723
return cls(entries, elements)
17241724

1725-
# NOTE the following could be inherited unchanged from PhaseDiagram:
1726-
# __repr__,
1727-
# as_dict,
1728-
# all_entries_hulldata,
1729-
# unstable_entries,
1730-
# stable_entries,
1731-
# get_form_energy(),
1732-
# get_form_energy_per_atom(),
1733-
# get_hull_energy(),
1734-
# get_e_above_hull(),
1735-
# get_decomp_and_e_above_hull(),
1736-
# get_decomp_and_phase_separation_energy(),
1737-
# get_phase_separation_energy()
1725+
# NOTE following methods are inherited unchanged from PhaseDiagram:
1726+
# __repr__,
1727+
# as_dict,
1728+
# all_entries_hulldata,
1729+
# unstable_entries,
1730+
# stable_entries,
1731+
# get_form_energy(),
1732+
# get_form_energy_per_atom(),
1733+
# get_hull_energy(),
1734+
# get_e_above_hull(),
1735+
# get_decomp_and_e_above_hull(),
1736+
# get_decomp_and_phase_separation_energy(),
1737+
# get_phase_separation_energy()
17381738

17391739
def get_pd_for_entry(self, entry: Entry | Composition) -> PhaseDiagram:
17401740
"""

pymatgen/analysis/piezo_sensitivity.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,14 @@ def get_rand_BEC(self, max_charge=1):
131131
)
132132
BEC[atom] = temp_tensor
133133
else:
134-
tempfcm = np.zeros([3, 3])
134+
temp_fcm = np.zeros([3, 3])
135135
for op in ops[2]:
136-
tempfcm += op.transform_tensor(BEC[self.BEC_operations[atom][1]])
137-
BEC[ops[0]] = tempfcm
136+
temp_fcm += op.transform_tensor(BEC[self.BEC_operations[atom][1]])
137+
BEC[ops[0]] = temp_fcm
138138
if len(ops[2]) != 0:
139139
BEC[ops[0]] = BEC[ops[0]] / len(ops[2])
140140

141-
# Enforce Acoustic Sum
141+
# Enforce Acoustic Sum
142142
disp_charge = np.einsum("ijk->jk", BEC) / n_atoms
143143
add = np.zeros([n_atoms, 3, 3])
144144

pymatgen/analysis/pourbaix_diagram.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070

7171
# TODO: Revise to more closely reflect PDEntry, invoke from energy/composition
7272
# TODO: PourbaixEntries depend implicitly on having entry energies be
73-
# formation energies, should be a better way to get from raw energies
73+
# formation energies, should be a better way to get from raw energies
7474
# TODO: uncorrected_energy is a bit of a misnomer, but not sure what to rename
7575
class PourbaixEntry(MSONable, Stringify):
7676
"""
@@ -338,7 +338,7 @@ def from_dict(cls, dct):
338338

339339

340340
# TODO: this class isn't particularly useful in its current form, could be
341-
# refactored to include information about the reference solid
341+
# refactored to include information about the reference solid
342342
class IonEntry(PDEntry):
343343
"""
344344
Object similar to PDEntry, but contains an Ion object instead of a
@@ -404,12 +404,11 @@ def ion_or_solid_comp_object(formula):
404404

405405

406406
# TODO: the solids filter breaks some of the functionality of the
407-
# heatmap plotter, because the reference states for decomposition
408-
# don't include oxygen/hydrogen in the OER/HER regions
407+
# heatmap plotter, because the reference states for decomposition
408+
# don't include oxygen/hydrogen in the OER/HER regions
409409

410410

411-
# TODO: create a from_phase_diagram class method for non-formation energy
412-
# invocation
411+
# TODO: create a from_phase_diagram class method for non-formation energy invocation
413412
# TODO: invocation from a MultiEntry entry list could be a bit more robust
414413
# TODO: serialization is still a bit rough around the edges
415414
class PourbaixDiagram(MSONable):

pymatgen/analysis/surface_analysis.py

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,24 +1316,6 @@ def set_all_variables(self, delu_dict, delu_default):
13161316

13171317
return all_delu_dict
13181318

1319-
# def surface_phase_diagram(self, y_param, x_param, miller_index):
1320-
# return
1321-
#
1322-
# def wulff_shape_extrapolated_model(self):
1323-
# return
1324-
#
1325-
# def surface_pourbaix_diagram(self):
1326-
#
1327-
# return
1328-
#
1329-
# def surface_p_vs_t_phase_diagram(self):
1330-
#
1331-
# return
1332-
#
1333-
# def broken_bond_vs_gamma(self):
1334-
#
1335-
# return
1336-
13371319

13381320
def entry_dict_from_list(all_slab_entries):
13391321
"""
@@ -1949,15 +1931,6 @@ def plot_all_stability_map(
19491931

19501932
return plt
19511933

1952-
# class GetChempotRange:
1953-
# def __init__(self, entry):
1954-
# self.entry = entry
1955-
#
1956-
#
1957-
# class SlabEntryGenerator:
1958-
# def __init__(self, entry):
1959-
# self.entry = entry
1960-
19611934

19621935
def sub_chempots(gamma_dict, chempots):
19631936
"""

tests/analysis/test_adsorption.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -144,34 +144,32 @@ def test_generate_substitution_structures(self):
144144
# Test this for a low miller index halite structure
145145
slabs = generate_all_slabs(self.MgO, 1, 10, 10, center_slab=True, max_normal_search=1)
146146
for slab in slabs:
147-
adsgen = AdsorbateSiteFinder(slab)
147+
site_finder = AdsorbateSiteFinder(slab)
148148

149-
ad_slabss = adsgen.generate_substitution_structures("Ni")
149+
sub_structs = site_finder.generate_substitution_structures("Ni")
150150
# There should be 2 configs (sub O and sub
151151
# Mg) for (110) and (100), 1 for (111)
152152
if tuple(slab.miller_index) != (1, 1, 1):
153-
assert len(ad_slabss) == 2
153+
assert len(sub_structs) == 2
154154
else:
155-
assert len(ad_slabss) == 1
155+
assert len(sub_structs) == 1
156156

157157
# Test out whether it can correctly dope both
158158
# sides. Avoid (111) because it is not symmetric
159159
if tuple(slab.miller_index) != (1, 1, 1):
160-
ad_slabss = adsgen.generate_substitution_structures("Ni", sub_both_sides=True, target_species=["Mg"])
160+
sub_structs = site_finder.generate_substitution_structures(
161+
"Ni", sub_both_sides=True, target_species=["Mg"]
162+
)
161163
# Test if default parameters dope the surface site
162-
for i, site in enumerate(ad_slabss[0]):
163-
if adsgen.slab[i].surface_properties == "surface" and site.species_string == "Mg":
164-
print(
165-
ad_slabss[0][i].surface_properties,
166-
adsgen.slab[i].surface_properties,
167-
)
168-
assert ad_slabss[0][i].surface_properties == "substitute"
169-
170-
assert ad_slabss[0].is_symmetric()
164+
for i, site in enumerate(sub_structs[0]):
165+
if site_finder.slab[i].surface_properties == "surface" and site.species_string == "Mg":
166+
assert sub_structs[0][i].surface_properties == "substitute"
167+
168+
assert sub_structs[0].is_symmetric()
171169
# Correctly dope the target species
172-
assert ad_slabss[0].composition.as_dict()["Mg"] == slab.composition.as_dict()["Mg"] - 2
170+
assert sub_structs[0].composition.as_dict()["Mg"] == slab.composition.as_dict()["Mg"] - 2
173171
# There should be one config (sub Mg)
174-
assert len(ad_slabss) == 1
172+
assert len(sub_structs) == 1
175173

176174
def test_functions(self):
177175
slab = self.slab_dict["111"]

tests/analysis/test_eos.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -402,38 +402,38 @@ def test_numerical_eoswrapper(self):
402402
assert_allclose(numerical_eos.eos_params, self.num_eos_fit.eos_params)
403403

404404
def test_numerical_eos_values(self):
405-
np.testing.assert_allclose(self.num_eos_fit.e0, -10.84749, atol=1e-3)
406-
np.testing.assert_allclose(self.num_eos_fit.v0, 40.857201, atol=1e-1)
407-
np.testing.assert_allclose(self.num_eos_fit.b0, 0.55, atol=1e-2)
405+
assert_allclose(self.num_eos_fit.e0, -10.84749, atol=1e-3)
406+
assert_allclose(self.num_eos_fit.v0, 40.857201, atol=1e-1)
407+
assert_allclose(self.num_eos_fit.b0, 0.55, atol=1e-2)
408408
# TODO: why were these tests commented out?
409-
# np.testing.assert_allclose(self.num_eos_fit.b0_GPa, 89.0370727, atol=1e-1)
410-
# np.testing.assert_allclose(self.num_eos_fit.b1, 4.344039, atol=1e-2)
409+
# assert_allclose(self.num_eos_fit.b0_GPa, 89.0370727, atol=1e-1)
410+
# assert_allclose(self.num_eos_fit.b1, 4.344039, atol=1e-2)
411411

412412
def test_eos_func(self):
413413
# list vs np.array arguments
414-
np.testing.assert_allclose(
414+
assert_allclose(
415415
self.num_eos_fit.func([0, 1, 2]),
416416
self.num_eos_fit.func(np.array([0, 1, 2])),
417417
)
418418
# func vs _func
419-
np.testing.assert_allclose(
419+
assert_allclose(
420420
self.num_eos_fit.func(0.0),
421421
self.num_eos_fit._func(0.0, self.num_eos_fit.eos_params),
422422
)
423423
# test the eos function: energy = f(volume)
424424
# numerical eos evaluated at volume=0 == a0 of the fit polynomial
425-
np.testing.assert_allclose(self.num_eos_fit.func(0.0), self.num_eos_fit.eos_params[-1])
425+
assert_allclose(self.num_eos_fit.func(0.0), self.num_eos_fit.eos_params[-1])
426426
birch_eos = EOS(eos_name="birch")
427427
birch_eos_fit = birch_eos.fit(self.volumes, self.energies)
428428
# birch eos evaluated at v0 == e0
429-
np.testing.assert_allclose(birch_eos_fit.func(birch_eos_fit.v0), birch_eos_fit.e0)
429+
assert_allclose(birch_eos_fit.func(birch_eos_fit.v0), birch_eos_fit.e0)
430430

431431
fig = birch_eos_fit.plot_ax(ax=None, show=False, fontsize=8, title="birch eos")
432432
assert hasattr(fig, "savefig")
433433

434434
def test_eos_func_call(self):
435435
# eos_fit_obj.func(volume) == eos_fit_obj(volume)
436-
np.testing.assert_allclose(self.num_eos_fit.func(0.0), self.num_eos_fit(0.0))
436+
assert_allclose(self.num_eos_fit.func(0.0), self.num_eos_fit(0.0))
437437

438438
def test_summary_dict(self):
439439
d = {

tests/analysis/test_interface_reactions.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,7 @@ def name_lst(lst):
435435
def energy_lst(lst):
436436
return lst[0][1], lst[1][1]
437437

438-
result_info = [i.get_no_mixing_energy() for i in self.irs if i.grand]
439-
print(result_info)
438+
result_info = [ir.get_no_mixing_energy() for ir in self.irs if ir.grand]
440439
for i, j in zip(result_info, answer):
441440
err_msg = f"get_no_mixing_energy: names get error, {name_lst(j)} expected but gets {name_lst(i)}"
442441
assert name_lst(i) == name_lst(j), err_msg

tests/analysis/test_quasiharmonic_debye_approx.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import unittest
44

55
import numpy as np
6+
from numpy.testing import assert_allclose
67

78
from pymatgen.analysis.eos import EOS
89
from pymatgen.analysis.quasiharmonic import QuasiharmonicDebyeApprox
@@ -107,34 +108,33 @@ def setUp(self):
107108
def test_bulk_modulus(self):
108109
eos = EOS(self.eos)
109110
eos_fit = eos.fit(self.volumes, self.energies)
110-
print(f"{eos_fit.b0_GPa=!s}")
111111
bulk_modulus = float(str(eos_fit.b0_GPa).split()[0])
112112
bulk_modulus_ans = float(str(self.qhda.bulk_modulus).split()[0])
113-
np.testing.assert_allclose(bulk_modulus, bulk_modulus_ans, atol=1e-3)
113+
assert_allclose(bulk_modulus, bulk_modulus_ans, atol=1e-3)
114114

115115
def test_optimum_volume(self):
116116
opt_vol = self.qhda.optimum_volumes[0]
117-
np.testing.assert_allclose(opt_vol, self.opt_vol, atol=1e-3)
117+
assert_allclose(opt_vol, self.opt_vol, atol=1e-3)
118118

119119
def test_debye_temperature(self):
120120
theta = self.qhda.debye_temperature(self.opt_vol)
121-
np.testing.assert_allclose(theta, 2559.675227, atol=1e-3)
121+
assert_allclose(theta, 2559.675227, atol=1e-3)
122122

123123
def test_gruneisen_parameter(self):
124124
gamma = self.qhda.gruneisen_parameter(self.T, self.opt_vol)
125-
np.testing.assert_allclose(gamma, 1.670486, atol=1e-3)
125+
assert_allclose(gamma, 1.670486, atol=1e-3)
126126

127127
def test_thermal_conductivity(self):
128128
kappa = self.qhda.thermal_conductivity(self.T, self.opt_vol)
129-
np.testing.assert_allclose(kappa, 131.736242, atol=1e-1)
129+
assert_allclose(kappa, 131.736242, atol=1e-1)
130130

131131
def test_vibrational_internal_energy(self):
132132
u = self.qhda.vibrational_internal_energy(self.T, self.opt_vol)
133-
np.testing.assert_allclose(u, 0.50102, atol=1e-3)
133+
assert_allclose(u, 0.50102, atol=1e-3)
134134

135135
def test_vibrational_free_energy(self):
136136
A = self.qhda.vibrational_free_energy(self.T, self.opt_vol)
137-
np.testing.assert_allclose(A, 0.494687, atol=1e-3)
137+
assert_allclose(A, 0.494687, atol=1e-3)
138138

139139

140140
class TestAnharmonicQuasiharmociDebyeApprox(unittest.TestCase):
@@ -185,24 +185,24 @@ def setUp(self):
185185

186186
def test_optimum_volume(self):
187187
opt_vol = self.qhda.optimum_volumes[0]
188-
np.testing.assert_allclose(opt_vol, self.opt_vol, atol=1e-3)
188+
assert_allclose(opt_vol, self.opt_vol, atol=1e-3)
189189

190190
def test_debye_temperature(self):
191191
theta = self.qhda.debye_temperature(self.opt_vol)
192192
np.testing.assert_approx_equal(theta, 601.239096, 4)
193193

194194
def test_gruneisen_parameter(self):
195195
gamma = self.qhda.gruneisen_parameter(0, self.qhda.ev_eos_fit.v0)
196-
np.testing.assert_allclose(gamma, 2.188302, atol=1e-3)
196+
assert_allclose(gamma, 2.188302, atol=1e-3)
197197

198198
def test_thermal_conductivity(self):
199199
kappa = self.qhda.thermal_conductivity(self.T, self.opt_vol)
200-
np.testing.assert_allclose(kappa, 21.810997, atol=1e-1)
200+
assert_allclose(kappa, 21.810997, atol=1e-1)
201201

202202
def test_vibrational_internal_energy(self):
203203
u = self.qhda.vibrational_internal_energy(self.T, self.opt_vol)
204-
np.testing.assert_allclose(u, 0.13845, atol=1e-3)
204+
assert_allclose(u, 0.13845, atol=1e-3)
205205

206206
def test_vibrational_free_energy(self):
207207
A = self.qhda.vibrational_free_energy(self.T, self.opt_vol)
208-
np.testing.assert_allclose(A, -0.014620, atol=1e-3)
208+
assert_allclose(A, -0.014620, atol=1e-3)

0 commit comments

Comments
 (0)