def test_unit_arrays_3(self): a=numpy.array([[1.0, 0.0, 0.0]],floattype) b=numpy.array([[1.0, 0.0, 0.0],[0.0, 1.0, 0.0]],floattype).T result = linear_algebra.matrix_multiply(a,b)[1] expected = numpy.array([[1.0, 0.0]],floattype) self.assert_list_almost_equal(result,expected) result_error = linear_algebra.matrix_multiply(a,b)[0] expected_error = [] self.assertEqual(result_error, expected_error)
def test_unit_arrays_3(self): a = numpy.array([[1.0, 0.0, 0.0]], floattype) b = numpy.array([[1.0, 0.0, 0.0], [0.0, 1.0, 0.0]], floattype).T result = linear_algebra.matrix_multiply(a, b)[1] expected = numpy.array([[1.0, 0.0]], floattype) self.assert_list_almost_equal(result, expected) result_error = linear_algebra.matrix_multiply(a, b)[0] expected_error = [] self.assertEqual(result_error, expected_error)
def test_zero(self): a=numpy.array([[util.ZERO, -20.0, 80.0],[2.02, util.ZERO, 20.0]],floattype) b=numpy.array([[1.23, 2.0, 20.0],[10.0, 21.0, util.ZERO]],floattype).T result = linear_algebra.matrix_multiply(a,b)[1] expected = numpy.array([[1560.0, -420.0],[402.4846, 20.2]],floattype) print result self.assert_list_almost_equal(result,expected) result_error = linear_algebra.matrix_multiply(a,b)[0] expected_error = [] self.assertEqual(result_error, expected_error)
def test_nan_inf(self): a=numpy.array([[util.INF, -20.0, 80.0],[2.02, util.NAN, 20.0]],floattype) b=numpy.array([[1.23, 2.0, 20.0],[10.0, 21.0, util.NAN]],floattype).T result = linear_algebra.matrix_multiply(a,b)[1] expected = numpy.array([[util.INF, util.NAN],[util.NAN, util.NAN]],floattype) print result self.assert_list_almost_equal(result,expected) result_error = linear_algebra.matrix_multiply(a,b)[0] expected_error = [] self.assertEqual(result_error, expected_error)
def test_arb_2(self): a=numpy.array([[1.0168308, -1.35572028, -1.35362422],[-0.69958848, 1.66901076, 0.49978462]],floattype) b=numpy.array([-20.69958848, 16.66901076, 20.49978462],floattype) result = linear_algebra.matrix_multiply(a,b)[1] expected = numpy.array([[-71.396],[52.547]],floattype) print result self.assert_list_almost_equal(result,expected,3) result_error = linear_algebra.matrix_multiply(a,b)[0] expected_error = [] self.assertEqual(result_error, expected_error)
def test_arb_1(self): a=numpy.array([[12.0, -20.0, -80.0],[2.02, -901.0, 0.0]],floattype) b=numpy.array([[1.23, 0.03, 20.0],[10.0, 1.0, 3.0]],floattype).T result = linear_algebra.matrix_multiply(a,b)[1] expected = numpy.array([[-1585.84, -140.0],[-24.5454, -880.8]],floattype) print result self.assert_list_almost_equal(result,expected) result_error = linear_algebra.matrix_multiply(a,b)[0] expected_error = [] self.assertEqual(result_error, expected_error)
def test_arb_2(self): a = numpy.array([[1.0168308, -1.35572028, -1.35362422], [-0.69958848, 1.66901076, 0.49978462]], floattype) b = numpy.array([-20.69958848, 16.66901076, 20.49978462], floattype) result = linear_algebra.matrix_multiply(a, b)[1] expected = numpy.array([[-71.396], [52.547]], floattype) print result self.assert_list_almost_equal(result, expected, 3) result_error = linear_algebra.matrix_multiply(a, b)[0] expected_error = [] self.assertEqual(result_error, expected_error)
def test_arb_1(self): a = numpy.array([[12.0, -20.0, -80.0], [2.02, -901.0, 0.0]], floattype) b = numpy.array([[1.23, 0.03, 20.0], [10.0, 1.0, 3.0]], floattype).T result = linear_algebra.matrix_multiply(a, b)[1] expected = numpy.array([[-1585.84, -140.0], [-24.5454, -880.8]], floattype) print result self.assert_list_almost_equal(result, expected) result_error = linear_algebra.matrix_multiply(a, b)[0] expected_error = [] self.assertEqual(result_error, expected_error)
def test_zero(self): a = numpy.array([[util.ZERO, -20.0, 80.0], [2.02, util.ZERO, 20.0]], floattype) b = numpy.array([[1.23, 2.0, 20.0], [10.0, 21.0, util.ZERO]], floattype).T result = linear_algebra.matrix_multiply(a, b)[1] expected = numpy.array([[1560.0, -420.0], [402.4846, 20.2]], floattype) print result self.assert_list_almost_equal(result, expected) result_error = linear_algebra.matrix_multiply(a, b)[0] expected_error = [] self.assertEqual(result_error, expected_error)
def test_nan_inf(self): a = numpy.array([[util.INF, -20.0, 80.0], [2.02, util.NAN, 20.0]], floattype) b = numpy.array([[1.23, 2.0, 20.0], [10.0, 21.0, util.NAN]], floattype).T result = linear_algebra.matrix_multiply(a, b)[1] expected = numpy.array([[util.INF, util.NAN], [util.NAN, util.NAN]], floattype) print result self.assert_list_almost_equal(result, expected) result_error = linear_algebra.matrix_multiply(a, b)[0] expected_error = [] self.assertEqual(result_error, expected_error)
def rotate(self, frame, axis, theta, **kwargs): ''' Simple rotation about the x, y, or z axis. Parameters ---------- frame integer : trajectory frame number to use axis string : 'x', 'y', or 'z' theta float : angle in radians kwargs optional future arguments Returns ------- None updated self._coor Examples ------- >>> import sasmol.system as system ; import math >>> molecule = system.Molecule('hiv1_gag.pdb') >>> frame = 0 ; axis = 'x' ; theta = 45.0 * math.pi / 180.0 >>> molecule.rotate(frame, axis, theta) Note ---------- Calculations are carried out using radians ''' cs = numpy.cos(theta) si = numpy.sin(theta) if(axis == 'x'): mat = numpy.array( [[1.0, 0.0, 0.0], [0.0, cs, -si], [0.0, si, cs]]) elif(axis == 'y'): mat = numpy.array( [[cs, 0.0, si], [0.0, 1.0, 0.0], [-si, 0.0, cs]]) elif(axis == 'z'): mat = numpy.array( [[cs, -si, 0.0], [si, cs, 0.0], [0.0, 0.0, 1.0]]) coordt = self._coor[frame, :].T error, matrix_product = linear_algebra.matrix_multiply(mat, coordt) ncoord = matrix_product.T self._coor[frame, :] = ncoord return
def rotate(self, frame, axis, theta, **kwargs): ''' Simple rotation about the x, y, or z axis. Parameters ---------- frame integer : trajectory frame number to use axis string : 'x', 'y', or 'z' theta float : angle in radians kwargs optional future arguments Returns ------- None updated self._coor Examples ------- >>> import sasmol.system as system ; import math >>> molecule = system.Molecule('hiv1_gag.pdb') >>> frame = 0 ; axis = 'x' ; theta = 45.0 * math.pi / 180.0 >>> molecule.rotate(frame, axis, theta) Note ---------- Calculations are carried out using radians ''' cs = numpy.cos(theta) si = numpy.sin(theta) if (axis == 'x'): mat = numpy.array([[1.0, 0.0, 0.0], [0.0, cs, -si], [0.0, si, cs]]) elif (axis == 'y'): mat = numpy.array([[cs, 0.0, si], [0.0, 1.0, 0.0], [-si, 0.0, cs]]) elif (axis == 'z'): mat = numpy.array([[cs, -si, 0.0], [si, cs, 0.0], [0.0, 0.0, 1.0]]) coordt = self._coor[frame, :].T error, matrix_product = linear_algebra.matrix_multiply(mat, coordt) ncoord = matrix_product.T self._coor[frame, :] = ncoord return
def align(self, other, self_basis, other_basis, **kwargs): ''' Alignment of one object on top of another "self" is aligned onto "other" using the basis of molecule 2 to align onto the basis of molecule 1 and the transformation is then done to all the atoms of molecule 2 self = molecule_2 other = molecule_1 self aligned to other molecule_2 aligned to molecule_1 Parameters ---------- frame integer : trajectory frame number to use other system object : molecule 1 self_basis string : unique description of atoms used for alignment other_basis string : unique description of atoms used for alignment kwargs optional future arguments Returns ------- None updated self._coor Examples ------- >>> import sasmol.system as system >>> molecule_1 = system.Molecule('hiv1_gag.pdb') >>> molecule_2 = system.Molecule('moved_and_rotated_hiv1_gag.pdb') >>> frame = 0 >>> basis_1 = 'name[i] == "CA"' >>> basis_2 = 'name[i] == "CA"' >>> molecule_2.align(molecule_1, basis_1, basis_2) >>> com_sub_2 = molecule_2.calculate_center_of_mass(frame) Note ---- mass_check determines if mass is defined for the object so that center of mass can be calculated ''' frame = 0 ### other = molecule_1 (reference) error, other_mask = other.get_subset_mask(other_basis) subset_other = sasmol.system.Molecule() error = other.copy_molecule_using_mask(subset_other, other_mask, frame) com_subset_other = subset_other.calculate_center_of_mass(frame) subset_other.center(frame) coor_subset_other = subset_other.coor()[frame] ### self = molecule_2 (to be aligned to other / molecule_1) error, self_mask = self.get_subset_mask(self_basis) subset_self = sasmol.system.Molecule() error = self.copy_molecule_using_mask(subset_self, self_mask, frame) com_subset_self = subset_self.calculate_center_of_mass(frame) subset_self.center(frame) coor_subset_self = subset_self.coor()[frame] u = linear_algebra.find_u(coor_subset_self, coor_subset_other) tao = numpy.transpose(self.coor()[frame] - com_subset_other) error, nat2 = linear_algebra.matrix_multiply(u, tao) ncoor = numpy.transpose(nat2) + com_subset_other self._coor[frame, :] = ncoor return