def test_against_mathematica_two_overlap_atoms(self):
     x=numpy.array([[2.920, -2.367, 1.693], [-0.770, -0.827, -0.417]], floattype)
     y=numpy.array([[2.920, -2.367, 1.693], [-0.770, -0.827, -0.417]], floattype)
     result_u = linear_algebra.find_u(x,y)
     expected_u = [[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]];
     for i in range(len(result_u)):
       self.assert_list_almost_equal(list(result_u[i]),expected_u[i])
 def test_against_mathematica_three_arbitary_atoms(self):
     x=numpy.array([[2.920, -2.367, 1.693], [-0.770, -0.827, -0.417], [-2.150, 3.193, -1.277]], floattype)
     y=numpy.array([[1.663, -1.170, 3.567], [-1.197, -1.460, -0.523], [-0.467, 2.630, -3.043]], floattype)
     result_u = linear_algebra.find_u(x,y)
     expected_u = [[0.902737, -0.0539463, 0.426797], [0.23798, 0.8891, -0.390981], [-0.358373, 0.454522, 0.815462]]
     for i in range(len(result_u)):
       self.assert_list_almost_equal(list(result_u[i]),expected_u[i])
 def test_against_mathematica_two_unit_atoms(self):
     x=numpy.array([[1.0, 1.0, 1.0], [2.0, 1.0, 1.0]], floattype)
     y=numpy.array([[1.0, 1.0, 1.0], [1.0, 2.0, 1.0]], floattype)
     result_u = linear_algebra.find_u(x,y); print result_u
     expected_u = [[0.0, 1.0, 0.0], [0.0, 0.0, 1.0], [1.0, 0.0, 0.0]];
     for i in range(len(result_u)):
       self.assert_list_almost_equal(list(result_u[i]),expected_u[i])
 def test_against_mathematica_six_arbitary_atoms(self):
     x=numpy.array([[0.357, -12.123, 2.098], [1.209, 10.209, -50.082], [-1.098, 3.572, 2.982], \
                    [1.231, -1.230, 0.589], [12.398, -30.289, 19.482], [12.123, 0.980, 19.309]], floattype)
     y=numpy.array([[90.380, 12.987, 0.392], [3.219, 83.390, 0.028], [0.002, 10.298, -18.820], \
                    [12.879, -10.298, 0.987], [0.986, 12.984, 0.367], [12.359, -12.402, 1.298]], floattype)
     result_u = linear_algebra.find_u(x,y)
     expected_u = [[0.121253, 0.025345, 0.992298], [-0.992602, 0.00937959, 0.12105], [-0.00623933, -0.999635, 0.0262948]]
     for i in range(len(result_u)):
       self.assert_list_almost_equal(list(result_u[i]),expected_u[i])
 def test_find_u_unit(self):
     x=numpy.array([[0,0,0],[1,0,0]], floattype)
     y=numpy.array([[0,0,0],[0,1,0]], floattype)
     rmx = linear_algebra.find_u(x,y)
     result = numpy.dot(rmx,y.T)
     result = result.T
     self.assertEqual(len(result),len(x))
     for i in range(len(x)):
       self.assert_list_almost_equal(list(result[i]),x[i])
    def test_find_u_rotate_pdb(self):
        m1 = system.Molecule(0)
        m2 = system.Molecule(1)
        m1.read_pdb(PdbPath+"1CRN.pdb")
        m2.read_pdb(modulePdbPath+"1CRN-rot.pdb")

        coor_sub_m1 = m1.coor()[0]
        coor_sub_m2 = m2.coor()[0]

        u = linear_algebra.find_u(coor_sub_m1, coor_sub_m2)
        result = numpy.array((numpy.matrix(u)*(numpy.matrix(coor_sub_m2).T)).T, numpy.float)
        #print numpy.dot(result.reshape(1,-1)[0],coor_sub_m1.reshape(1,-1)[0])/numpy.sqrt(numpy.dot(coor_sub_m1.reshape(1,-1)[0],coor_sub_m1.reshape(1,-1)[0])*numpy.dot(result.reshape(1,-1)[0],result.reshape(1,-1)[0]))
        #m3 = system.Molecule(2)
        #m3.read_pdb('1CRN.pdb')
        #m3._coor[0,:]=result
        #m3.writepdb('1CRN-result.pdb',0,'w')
        self.assertEqual(len(result),len(coor_sub_m1))
        for i in range(len(coor_sub_m1)):
           self.assert_list_almost_equal(list(result[i]),coor_sub_m1[i])
Beispiel #7
0
    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
Beispiel #8
0
    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