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.")
def test_radius_indexes(self): cell = numpy.array([ [1.5, 0, 0], [0, 1.5, 0], [0, 0, 1.5], ], float) uc = UnitCell(cell, numpy.array([True, True, True])) self.assert_((uc.get_radius_ranges(3.1) == 3).all()) self.assertEqual(len(uc.get_radius_indexes(3.1)), 81)
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))
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))