Skip to content
This repository has been archived by the owner on Jun 14, 2018. It is now read-only.

Commit

Permalink
completed geometry unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ferchault committed Jun 10, 2015
1 parent e62002f commit 9b99bd1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/euston/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ def cell_multiply(coord, x, y, z, h_matrix=None, scaling_in=False, scaling_out=F
if i < 1 or int(i) != i:
raise ValueError('Invalid image count.')

# copy input
coord = np.copy(coord)

# prepare data
factor = x * y * z
atoms = coord.shape[0]
Expand All @@ -105,6 +108,7 @@ def cell_multiply(coord, x, y, z, h_matrix=None, scaling_in=False, scaling_out=F
raise TypeError('H matrix has to be given for partially cartesian data.')
coord = cartesian_to_scaled_coordinates(coord, h_matrix)
newcoord[:atoms] = coord

for i_x in range(x):
for i_y in range(y):
for i_z in range(z):
Expand Down
12 changes: 8 additions & 4 deletions tests/data/test_geometry.py → tests/test_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,18 @@ def test_cellmultiply(self):
for system in bravais_lattices:
hmat = geo.abc_to_hmatrix(*system)
result = geo.cell_multiply(base, 1, 1, 2, h_matrix=hmat, scaling_in=sc_in, scaling_out=sc_out)
result2 = geo.cell_multiply(base, 1, 1, 1, h_matrix=hmat, scaling_in=sc_in, scaling_out=True)
result2 *= np.array([1, 1, 0.5])
reference = np.copy(base)
hmat[:, 2] *= 2

# convert to cartesian coordinates
if sc_in:
reference = geo.scaled_to_cartesian_coordinates(reference, hmat)
if sc_out:
result = geo.scaled_to_cartesian_coordinates(result, hmat)
result2 = geo.scaled_to_cartesian_coordinates(result2, hmat)

# single result part of multiplied result
result2 = geo.cell_multiply(base, 1, 1, 1, h_matrix=hmat, scaling_in=sc_in, scaling_out=False)
result2 *= np.array([1, 1, 0.5])
residuals = np.linalg.norm(result - result2[0], axis=1)
# print min(residuals)
#self.assertTrue(min(residuals) < 10e-5)
self.assertTrue(min(residuals) < 10e-5)

0 comments on commit 9b99bd1

Please sign in to comment.