def calc_expected(self,a,b,c): ada = sum([e*e for e in a]) bdb = sum([e*e for e in b]) if numpy.dot(a,a)*numpy.dot(b,b)==0.0: return util.num_to_floattype(180.0, floattype) else: angle = (180.0/util.num_to_floattype(numpy.pi,floattype)) * numpy.arccos(numpy.dot(a,b)/numpy.sqrt(numpy.dot(a,a)*numpy.dot(b,b))) sign = cmp(numpy.dot(numpy.cross(a,b),c), 0.0) if sign==0: sign=1 return util.num_to_floattype(sign*angle, floattype)
def test_same_plane(self): a=numpy.array([1.0, 0.0, 0.0],floattype) b=numpy.array([0.0, 1.0, 0.0],floattype) c=numpy.array([1.0, 0.0, 0.0],floattype) result = linear_algebra.signed_angle(a,b,c) expected = util.num_to_floattype(0.0, floattype) self.assertAlmostEqual(result,expected)
def test_all_zero_arrays(self): a=numpy.array([0.0, 0.0, 0.0],floattype) b=numpy.array([0.0, 0.0, 0.0],floattype) c=numpy.array([0.0, 0.0, 0.0],floattype) result = linear_algebra.signed_angle(a,b,c) expected = util.num_to_floattype(180.0, floattype) self.assertAlmostEqual(result,expected)
def test_zero(self): a=numpy.array([util.ZERO, 3.0, 0.0],floattype) b=numpy.array([6.0, util.ZERO, 2.0],floattype) c=numpy.array([6.7, 1.0, util.ZERO],floattype) result = linear_algebra.signed_angle(a,b,c) expected = util.num_to_floattype(90.0, floattype) self.assertAlmostEqual(result,expected)
def test_tiny(self): a=numpy.array([util.TINY, 3.0, 0.0],floattype) b=numpy.array([6.0, util.TINY, 2.0],floattype) c=numpy.array([2.0, 3.2, util.TINY],floattype) result = linear_algebra.signed_angle(a,b,c) expected = util.num_to_floattype(90.0, floattype) self.assertAlmostEqual(result,expected)
def test_two_atoms_about_Y_axis(self): #test two atoms rotating about the x axis self.o.setCoor(numpy.array([[[-1.0, 2.0, 3.87],[-5.0, 3.2, 6.0]]],floattype)) axis = 'y' theta = util.num_to_floattype(90.0*numpy.pi/180.0, floattype) frame = 0 # expected_coor = numpy.array([[[3.87, 2.0, 1.0],[6.0, 3.2, 5.0]]],floattype)[frame] print 'expected_coor:\n', expected_coor # self.o.rotate(frame,axis,theta) result_coor = self.o.coor()[frame] print 'result_coor:\n',result_coor # self.assert_list_almost_equal(expected_coor, result_coor,3)
def test_six_atoms_about_X_axis_zero(self): self.o.setCoor(numpy.array([[[1.2, util.ZERO, 3.0],[-2.0, 5.0, 6.0],[7.0, 8.0, 9.0],[1.0, 3.0, 5.0],[2.0, 4.0, 6.0],[0.0, 2.0, 3.0]]],floattype)) axis = 'x' theta = util.num_to_floattype(128.0*numpy.pi/180.0, floattype) frame = 0 # cs=numpy.cos(theta) si=numpy.sin(theta) expected_coor = numpy.array([[[1.2, util.ZERO*cs-3.0*si, util.ZERO*si+3.0*cs],[-2.0, 5.0*cs-6.0*si, 5.0*si+6.0*cs],[7.0, 8.0*cs-9.0*si, 8.0*si+9.0*cs],[1.0, 3.0*cs-5.0*si, 3.0*si+5.0*cs],[2.0, 4.0*cs-6.0*si, 4.0*si+6.0*cs],[0.0, 2.0*cs-3.0*si, 2.0*si+3.0*cs]]],floattype)[frame] print 'expected_coor:\n', expected_coor # self.o.rotate(frame,axis,theta) result_coor = self.o.coor()[frame] print 'result_coor:\n',result_coor # self.assert_list_almost_equal(expected_coor, result_coor,3)
def test_one_atom_about_Z_axis(self): ''' test one atom rotating about the z axis ''' self.o.setCoor(numpy.array([[[1.0, 1.0, 1.0]]],floattype)) axis = 'z' theta = util.num_to_floattype(90.0*numpy.pi/180.0, floattype) frame = 0 # expected_coor = numpy.array([[[-1.0, 1.0, 1.0]]],floattype)[frame] print 'expected_coor:\n', expected_coor # self.o.rotate(frame,axis,theta) result_coor = self.o.coor()[frame] print 'result_coor:\n',result_coor # self.assert_list_almost_equal(expected_coor, result_coor,3)
def test_two_atoms_about_Z_axis(self): ''' test two atoms rotating about the x axis ''' self.o.setCoor(numpy.array([[[-1.0, 2.0, 3.87],[-5.0, 3.2, 6.0]]],floattype)) axis = 'z' theta = util.num_to_floattype(280.0*numpy.pi/180.0, floattype) frame = 0 # #expected_coor = numpy.array([[[-2.0, -1.0, 3.87],[-3.2, -5.0, 6.0]]], floattype)[frame] cs=numpy.cos(theta) si=numpy.sin(theta) expected_coor = numpy.array([[[-1.0*cs-2.0*si, -1.0*si+2.0*cs, 3.87],[-5.0*cs-3.2*si, -5.0*si+3.2*cs, 6.0]]],floattype)[frame] print 'expected_coor:\n', expected_coor # self.o.rotate(frame,axis,theta) result_coor = self.o.coor()[frame] print 'result_coor:\n',result_coor # self.assert_list_almost_equal(expected_coor, result_coor,3)