def SuperpositionMatrix ( self, AllowPerturbations = False, AllowFlip = False ):

          """
          returns rotation between 0th and 1st HierSetOfPoints
          """

          Array1 = self.Content[0]. NonHierarchicalSetOfPoints ( ). Array ( )

          if AllowPerturbations:

             RMSDs = [ ]; Matrices = [ ];


             minRMSD = 1000.0

             Centres1 = self. Content[1] # bo to przeciez ten drugi, blargh
# a wiec ten pierwszy powinien byc zrobiony juz tutaj


             for Perturbation in Perturbations( len ( self.Content [1] ) ):

                 Centres1Perturbation = [ Centres1 [i] for i in Perturbation ]

                 Array2 = Centres1Perturbation. NonHierarchicalSetOfPoints ( ). Array ( )
             
                 Matrices. append ( optimal_superposition ( Array1, Array2 ).T )
                 RMSDs. append ( rmsd (Array1, Array2)  )

                 if AllowFlip:

                    FlippedSet = [ Helix[::-1] for Helix in Centres1Perturbation ]
                    Array2 = FlippedSet. NonHierarchicalSetOfPoints ( ). Array ( )
             
                    Matrices. append ( optimal_superposition ( Array1, Array2 ).T )
                    RMSDs. append ( rmsd (Array1, Array2)  )

             minRMSD = min ( RMSDs ); 

             return Matrices [ RMSDs. index ( minRMSD) ]


          else:

             Array2 = self.Content[1]. NonHierarchicalSetOfPoints ( ). Array ( )

             return optimal_superposition( Array1, Array2 ).T # ok a wiec gdzie jest translacja do zera?
      def RotationMatrix ( self ):

          """
          returns a rotation from 0th vector to 1st vector
          """

          print np.array(self.Content[0]).shape
          print np.array(self.Content[1])

          return optimal_superposition( np.array( [ [ 0.0, 0.0, 0.0  ], self.Content[0] ] ), np.array( [ [ 0.0, 0.0, 0.0  ], self.Content[1] ] ) ).T
Example #3
0
  def testSuperPosition(self):
    "Tests that rmsd=0 works"
    
    for i in xrange(0, 20):
      n = 10
      ref_vecs = [vector3d.RandomVec() for i in xrange(0, n)]
      ref_crds = make_crds(ref_vecs)

      m = vector3d.RandomOriginRotation()
      mov_vecs = [m.transform_vec(r) for r in ref_vecs]
      mov_crds = make_crds(mov_vecs)
      
      matrix = match.optimal_superposition(ref_crds, mov_crds)
      mov_crds[:,:] = numpy.dot(mov_crds, matrix.transpose())
      
      for crd1, crd2 in zip(ref_crds, mov_crds):
        for i in xrange(0,3):
          self.assertAlmostEqual(crd1[i], crd2[i])
      def SuperpositionMatrix ( self, AllowPerturbations = False, AllowFlip = False ):

          """
          returns rotation from 0th SetOfPoints on 1st SetOfPoints
          """

          print self[0][0]

          ciag1 = []

          for i in range ( len ( self [0] ) ):

              for j in range ( len ( self [0][0] ) ):

                  Punkt1 = [ float ( Coord ) for Coord in self[0][i][j] ]

                  ciag1. append ( Punkt1 )


# i powinien chodzic

# ciag 1 jest gotowy
# musze sie doksztalcic z pythona znowu

          if AllowPerturbations:

             RMSDs = [ ]; Matrices = [ ];

             minRMSD = 1000.0;

             Centres1 = self.Content[1]

             for Perturbation in Perturbations( len ( self.Content[1] ) ):

                 Centres1Perturbation = [ Centres1 [i] for i in Perturbation ]

                 ciag2 = [] 

                 for i in range ( len (self[0] ) ):

                     for j in range ( len(self[0][0]) ):

                         el2 = [ float (c) for c in Centres1Perturbation [i][j] ]

                         ciag2. append ( el2 );
             
                 Matrices. append ( optimal_superposition ( np.array(ciag1), np.array(ciag2) ).T )
                 RMSDs. append ( rmsd (np.array(ciag1), np.array(ciag2))  )

                 if AllowFlip:

                    ciag2 = []

                    for i in range ( len (self[0] ) ):

                        for j in range ( len(self[0][0])-1,-1,-1 ):

                            el2 = [ float (c) for c in Centres1Perturbation [i][j] ]

                            ciag2. append ( el2 );
             
                    Matrices. append ( optimal_superposition ( np.array(ciag1), np.array(ciag2) ).T )
                    RMSDs. append ( rmsd (np.array(ciag1), np.array(ciag2))  )

             minRMSD = min ( RMSDs ); 

             return Matrices [ RMSDs. index ( minRMSD) ]


          else:

             ciag2 = [ ]

             for i in range ( len (self[0] ) ):

                 for j in range ( len(self[0][0]) ):

                     el2 = [ float (c) for c in self[1][i][j] ]

                     ciag2. append ( el2 );

          return optimal_superposition( np.array(ciag1), np.array(ciag2) ).T # ok a wiec gdzie jest translacja do zera?
      def SuperpositionMatrix ( self, AllowPerturbations = False, AllowFlip = False ):

          """
          returns rotation matrix from 0th HierSetOfPoints to 1stHierSetOfPoints
          """

          HierarchicalSetOfPointsInstance1, HierarchicalSetOfPointsInstance2  = self. Content

          NonHierarchicalSetOfPointsInstance1 = [ ]

          for SetOfPointsInstance in self. Content [0]:

              NonHierarchicalSetOfPointsInstance1. append ( SetOfPointsInstance )

# pierwszy set jest gotowy

          if AllowPerturbations:

             RMSDs = [ ]; Matrices = [ ];

             minRMSD = 1000.0

             for Perturbation in Perturbations( len ( self. Content[1] ) ):

                 PerturbationInstance = [ self. Content [ 1 ] [i] for i in Perturbation ]

                 NonHierarchicalSetOfPointsInstance2 = [ ]

                 for SetOfPointsInstance in PerturbationInstance:

                     NonHierarchicalSetOfPointsInstance2. append ( SetOfPointsInstance )
             
                 Matrices. append ( optimal_superposition ( np.array(ciag1), np.array(ciag2) ).T )
                 RMSDs. append ( rmsd (np.array(ciag1), np.array(ciag2))  )

                 if AllowFlip:

                    ciag2 = []

                    for i in range ( len (self[0] ) ):

                        for j in range ( len(self[0][0])-1,-1,-1 ):

                            el2 = [ float (c) for c in Centres1Perturbation [i][j] ]

                            ciag2. append ( el2 );
             
                    Matrices. append ( optimal_superposition ( np.array(ciag1), np.array(ciag2) ).T )
                    RMSDs. append ( rmsd (np.array(ciag1), np.array(ciag2))  )

             minRMSD = min ( RMSDs ); 

             return Matrices [ RMSDs. index ( minRMSD) ]


          else:

             ciag2 = [ ]

             for i in range ( len (self[0] ) ):

                 for j in range ( len(self[0][0]) ):

                     el2 = [ float (c) for c in self[1][i][j] ]

                     ciag2. append ( el2 );

          return optimal_superposition( np.array(ciag1), np.array(ciag2) ).T # ok a wiec gdzie jest translacja do zera?