Skip to content
This repository has been archived by the owner on Apr 23, 2021. It is now read-only.

Commit

Permalink
Merge pull request #262 from simphony/fix-guess-pc-vectors-261
Browse files Browse the repository at this point in the history
Fix guess_primitive_vectors Error
  • Loading branch information
kitchoi committed Jan 12, 2016
2 parents 627321a + cb64486 commit 38caf80
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
6 changes: 4 additions & 2 deletions simphony/tools/lattice_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,10 @@ def find_jump(arr1d):
nz = points.shape[0] // nx // ny

if nx*ny*nz != points.shape[0]:
message = "Failed to deduce the lattice dimensions"
raise IndexError(message)
message = ("Failed to deduce the lattice dimensions. "
"Guessed nx={0}, ny={1}, nz={2}. This may be caused "
"by missing nodes or defects beyond {3}")
raise ValueError(message.format(nx, ny, nz, tolerance))

# Test if the lattice points spacings are uniform
# Does not test all points, otherwise slow for large data
Expand Down
7 changes: 3 additions & 4 deletions simphony/tools/tests/test_lattice_tools.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import unittest
import random
from collections import defaultdict

import numpy
Expand Down Expand Up @@ -58,7 +57,7 @@ def rotate_permute_flip(vectors):
# rotating vectors
vectors = list(rotate_vectors(vectors, alpha, beta))
# random permutation
random.shuffle(vectors)
numpy.random.shuffle(vectors)
# flipping vectors
p1, p2, p3 = numpy.random.choice((1, -1), (3, 1))*vectors
return (p1, p2, p3)
Expand Down Expand Up @@ -494,7 +493,7 @@ def test_exception_guess_vectors_with_no_first_jump(self):
points = numpy.zeros((20, 3))

# then
with self.assertRaises(IndexError):
with self.assertRaises(ValueError):
lattice_tools.guess_primitive_vectors(points)

def test_exception_guess_vectors_with_no_second_jump(self):
Expand All @@ -503,7 +502,7 @@ def test_exception_guess_vectors_with_no_second_jump(self):
points[1, 0] = 2

# then
with self.assertRaises(IndexError):
with self.assertRaises(ValueError):
lattice_tools.guess_primitive_vectors(points)

def test_exception_guess_vectors_with_wrong_shape_points(self):
Expand Down

0 comments on commit 38caf80

Please sign in to comment.