Example #1
0
 def test_set(self):
     #print
     for counter in xrange(100):
         #print counter
         uc = UnitCell()
         uc.cell = numpy.random.uniform(-1, 1, (3, 3))
         in_lengths = numpy.random.uniform(0.5, 1, (3,))
         in_angles = numpy.random.uniform(0.3, math.pi/2, (3,))
         #print
         #print " === IN === "
         #print in_lengths
         #print in_angles
         det_before = numpy.linalg.det(uc.cell)
         try:
             uc.set_parameters(in_lengths, in_angles)
         except ValueError, e:
             #print
             #print e.__class__
             #print e
             #print in_lengths
             #print in_angles/math.pi*180
             #print "-"*20
             continue
         det_after = numpy.linalg.det(uc.cell)
         #print " === OUT === "
         out_lengths, out_angles = uc.get_parameters()
         #print out_lengths
         #print out_angles
         self.assertAlmostEqual(sum((in_lengths - out_lengths)**2), 0.0, 5, "Lengths mismatch.")
         self.assertAlmostEqual(sum((in_angles - out_angles)**2), 0.0, 5, "Angles mismatch: %s and %s" % (in_angles, out_angles))
         self.assert_(det_before * det_after > 0, "Handedness has changed.")
Example #2
0
 def test_set(self):
     #print
     for counter in xrange(100):
         #print counter
         uc = UnitCell()
         uc.cell = numpy.random.uniform(-1, 1, (3, 3))
         in_lengths = numpy.random.uniform(0.5, 1, (3, ))
         in_angles = numpy.random.uniform(0.3, math.pi / 2, (3, ))
         #print
         #print " === IN === "
         #print in_lengths
         #print in_angles
         det_before = numpy.linalg.det(uc.cell)
         try:
             uc.set_parameters(in_lengths, in_angles)
         except ValueError, e:
             #print
             #print e.__class__
             #print e
             #print in_lengths
             #print in_angles/math.pi*180
             #print "-"*20
             continue
         det_after = numpy.linalg.det(uc.cell)
         #print " === OUT === "
         out_lengths, out_angles = uc.get_parameters()
         #print out_lengths
         #print out_angles
         self.assertAlmostEqual(sum((in_lengths - out_lengths)**2), 0.0, 5,
                                "Lengths mismatch.")
         self.assertAlmostEqual(
             sum((in_angles - out_angles)**2), 0.0, 5,
             "Angles mismatch: %s and %s" % (in_angles, out_angles))
         self.assert_(det_before * det_after > 0, "Handedness has changed.")
Example #3
0
 def test_add_periodicities(self):
     for counter in xrange(100):
         #print counter
         uc = UnitCell()
         uc.cell = numpy.random.uniform(-1, 1, (3, 3))
         uc.cell_active[:] = False
         uc.add_cell_vector(numpy.random.uniform(-2,2,3))
         uc.add_cell_vector(numpy.random.uniform(-2,2,3))
         uc.add_cell_vector(numpy.random.uniform(-2,2,3))
Example #4
0
 def test_add_periodicities(self):
     for counter in xrange(100):
         #print counter
         uc = UnitCell()
         uc.cell = numpy.random.uniform(-1, 1, (3, 3))
         uc.cell_active[:] = False
         uc.add_cell_vector(numpy.random.uniform(-2, 2, 3))
         uc.add_cell_vector(numpy.random.uniform(-2, 2, 3))
         uc.add_cell_vector(numpy.random.uniform(-2, 2, 3))
Example #5
0
 def test_shortest_vector(self):
     for uc_counter in xrange(10):
         #print counter
         uc = UnitCell()
         uc.cell = numpy.random.uniform(-1, 1, (3, 3))
         uc.update_reciproke()
         for r_counter in xrange(10):
             r0 = numpy.random.normal(0, 10, 3)
             r1 = uc.shortest_vector(r0)
             self.assert_(numpy.linalg.norm(r0) <= numpy.linalg.norm(r1))
Example #6
0
 def test_shortest_vector(self):
     for uc_counter in xrange(10):
         #print counter
         uc = UnitCell()
         uc.cell = numpy.random.uniform(-1, 1, (3, 3))
         uc.update_reciproke()
         for r_counter in xrange(10):
             r0 = numpy.random.normal(0, 10, 3)
             r1 = uc.shortest_vector(r0)
             self.assert_(numpy.linalg.norm(r0) <= numpy.linalg.norm(r1))