Skip to content

Commit

Permalink
np.allclose(np.array(...), ...) to np.allclose(..., ...)
Browse files Browse the repository at this point in the history
  • Loading branch information
janosh committed Aug 18, 2023
1 parent b12e7eb commit e025ffb
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def draw_network(env_graph, pos, ax, sg=None, periodicity_vectors=None):
color=color,
)
else:
ecolor = color if np.allclose(np.array(delta), np.zeros(3)) else periodic_color
ecolor = color if np.allclose(delta, np.zeros(3)) else periodic_color
e = FancyArrowPatch(
n1center,
n2center,
Expand Down
12 changes: 3 additions & 9 deletions pymatgen/io/lobster/lobsterenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def __init__(
)
else:
self.valences = valences
if np.allclose(np.array(self.valences), np.zeros_like(self.valences)) and additional_condition in [1, 3, 5, 6]:
if np.allclose(self.valences, np.zeros_like(self.valences)) and additional_condition in [1, 3, 5, 6]:
raise ValueError("All valences are equal to 0, additional_conditions 1, 3, 5 and 6 will not work")

if limits is None:
Expand All @@ -204,18 +204,12 @@ def __init__(

@property
def structures_allowed(self):
"""
Boolean property: can this NearNeighbors class be used with Structure
objects?
"""
"""Whether this NearNeighbors class can be used with Structure objects?"""
return True

@property
def molecules_allowed(self):
"""
Boolean property: can this NearNeighbors class be used with Molecule
objects?
"""
"""Whether this NearNeighbors class can be used with Molecule objects?"""
return False

@property
Expand Down
2 changes: 1 addition & 1 deletion tests/analysis/diffraction/test_tem.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def test_get_plot_coeffs(self):
# Test if x * p1 + y * p2 yields p3.
c = TEMCalculator()
coeffs = c.get_plot_coeffs((1, 1, 0), (1, -1, 0), (2, 0, 0))
assert_allclose(np.array([1, 1]), coeffs)
assert_allclose([1, 1], coeffs)

def test_get_positions(self):
c = TEMCalculator()
Expand Down
9 changes: 3 additions & 6 deletions tests/analysis/gb/test_grain.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,11 @@ def test_init(self):
assert self.Cu_GB1.rotation_angle == approx(123.74898859588858)
assert self.Cu_GB1.vacuum_thickness == approx(1.5)
assert self.Cu_GB2.rotation_axis == [1, 2, 3]
assert_allclose(np.array(self.Cu_GB1.ab_shift), np.array([0.0, 0.0]))
assert_allclose(np.array(self.Cu_GB2.ab_shift), np.array([0.2, 0.2]))
assert_allclose(self.Cu_GB1.ab_shift, [0.0, 0.0])
assert_allclose(self.Cu_GB2.ab_shift, [0.2, 0.2])
assert self.Cu_GB1.gb_plane == [1, 3, 1]
assert self.Cu_GB2.gb_plane == [1, 2, 3]
assert_allclose(
np.array(self.Cu_GB1.init_cell.lattice.matrix),
np.array(self.Cu_conv.lattice.matrix),
)
assert_allclose(self.Cu_GB1.init_cell.lattice.matrix, self.Cu_conv.lattice.matrix)

def test_copy(self):
Cu_GB1_copy = self.Cu_GB1.copy()
Expand Down
8 changes: 4 additions & 4 deletions tests/io/vasp/test_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1510,10 +1510,10 @@ def test_hdf5(self):
import h5py

with h5py.File("chgcar_test.hdf5", "r") as f:
assert_allclose(np.array(f["vdata"]["total"]), chgcar.data["total"])
assert_allclose(np.array(f["vdata"]["diff"]), chgcar.data["diff"])
assert_allclose(np.array(f["lattice"]), chgcar.structure.lattice.matrix)
assert_allclose(np.array(f["fcoords"]), chgcar.structure.frac_coords)
assert_allclose(f["vdata"]["total"], chgcar.data["total"])
assert_allclose(f["vdata"]["diff"], chgcar.data["diff"])
assert_allclose(f["lattice"], chgcar.structure.lattice.matrix)
assert_allclose(f["fcoords"], chgcar.structure.frac_coords)
for z in f["Z"]:
assert z in [Element.Ni.Z, Element.O.Z]

Expand Down

0 comments on commit e025ffb

Please sign in to comment.