Esempio n. 1
0
    def prepareNative(self, nativePdbInfo=None, resSeqMap=None):
        """do stuff"""

        # Find out how many chains and extract the first if > 1
        if len(nativePdbInfo.models) > 1:
            raise RuntimeError, "More than 1 model."

        # Check if > 1 chain
        chainID = None
        if len(nativePdbInfo.models[0].chains) > 1:

            chainID = nativePdbInfo.models[0].chains[0]

            # Assume native is standardised
            # Extract the chain if > 1
            nativePdbChain = ample_util.filename_append(
                filename=nativePdbInfo.pdb, astr="chain{0}".format(chainID))
            pdb_edit.extract_chain(nativePdbInfo.pdb, nativePdbChain, chainID)
            nativePdb = nativePdbChain
        else:
            nativePdb = nativePdbInfo.pdb

        if not resSeqMap.resSeqMatch():

            # We need to create a copy of the native with numbering matching the model
            nativeRenumber = ample_util.filename_append(filename=nativePdb,
                                                        astr="ren")
            pdb_edit.match_resseq(targetPdb=nativePdb,
                                  outPdb=nativeRenumber,
                                  resMap=resSeqMap)
            nativePdb = nativeRenumber

        return nativePdb
Esempio n. 2
0
    def scoreOrigin(self,
                    origin=None,
                    mrPdbInfo=None,
                    nativePdbInfo=None,
                    resSeqMap=None,
                    workdir=os.getcwd()
                     ):
        
        self.workdir = workdir
        if not resSeqMap.resSeqMatch():
            # We need to create a copy of the placed pdb with numbering matching the native
            mrPdbRes = ample_util.filename_append( filename=mrPdbInfo.pdb, astr="reseq", directory=self.workdir )
            pdb_edit.match_resseq( targetPdb=mrPdbInfo.pdb, sourcePdb=None, outPdb=mrPdbRes, resMap=resSeqMap )
            mrPdb = mrPdbRes
        else:
            mrPdb = mrPdbInfo.pdb
 
        # Make a copy of mrPdb with chains renamed to lower case
        ucChains = mrPdbInfo.models[0].chains
        toChains = [ c.lower() for c in ucChains ]
        mrAaPdb = ample_util.filename_append( filename=mrPdb, astr="ren", directory=self.workdir )
        pdb_edit.rename_chains( inpdb=mrPdb, outpdb=mrAaPdb, fromChain=ucChains, toChain=toChains )

        # The list of chains in the native that we will be checking contacts from
        fromChains = nativePdbInfo.models[0].chains
        
        mrOriginPdb =  mrAaPdb
        if origin != [ 0.0, 0.0, 0.0 ]:
            # Move pdb to new origin
            #ostr="origin{0}".format(i)
            ostr="o{0}".format( origin ).replace(" ","" )
            mrOriginPdb = ample_util.filename_append( filename=mrAaPdb, astr=ostr, directory=self.workdir )
            pdb_edit.translate( inpdb=mrAaPdb, outpdb=mrOriginPdb, ftranslate=origin )
        
        # Concatenate into one file
        joinedPdb = ample_util.filename_append( filename=mrOriginPdb, astr="joined", directory=self.workdir )
        pdb_edit.merge( pdb1=nativePdbInfo.pdb, pdb2=mrOriginPdb, pdbout=joinedPdb )
            
        # Run ncont
        data = RioData()
        data.origin = origin
        data.originPdb = mrOriginPdb
        data.joinedPdb = joinedPdb
        data.fromChains = fromChains
        data.toChains = toChains

        # First get AllAtom score        
        self.calcAllAtom( data )
        
        # Then score RIO
        self.calcRio( data )
        #data.numGood = data.inregister + data.ooregister
        
        # clean up
        os.unlink(mrOriginPdb)
        os.unlink(joinedPdb)
        if os.path.isfile(mrAaPdb): os.unlink(mrAaPdb)
        
        return data
Esempio n. 3
0
    def scoreOrigin(self,
                    origin=None,
                    mrPdbInfo=None,
                    nativePdbInfo=None,
                    resSeqMap=None,
                    workdir=os.getcwd()):

        self.workdir = workdir
        if not resSeqMap.resSeqMatch():
            # We need to create a copy of the placed pdb with numbering matching the native
            mrPdbRes = ample_util.filename_append(filename=mrPdbInfo.pdb,
                                                  astr="reseq",
                                                  directory=self.workdir)
            pdb_edit.match_resseq(targetPdb=mrPdbInfo.pdb,
                                  sourcePdb=None,
                                  outPdb=mrPdbRes,
                                  resMap=resSeqMap)
            mrPdb = mrPdbRes
        else:
            mrPdb = mrPdbInfo.pdb

        # Make a copy of mrPdb with chains renamed to lower case
        ucChains = mrPdbInfo.models[0].chains
        toChains = [c.lower() for c in ucChains]
        mrAaPdb = ample_util.filename_append(filename=mrPdb,
                                             astr="ren",
                                             directory=self.workdir)
        pdb_edit.rename_chains(inpdb=mrPdb,
                               outpdb=mrAaPdb,
                               fromChain=ucChains,
                               toChain=toChains)

        # The list of chains in the native that we will be checking contacts from
        fromChains = nativePdbInfo.models[0].chains

        mrOriginPdb = mrAaPdb
        if origin != [0.0, 0.0, 0.0]:
            # Move pdb to new origin
            #ostr="origin{0}".format(i)
            ostr = "o{0}".format(origin).replace(" ", "")
            mrOriginPdb = ample_util.filename_append(filename=mrAaPdb,
                                                     astr=ostr,
                                                     directory=self.workdir)
            pdb_edit.translate(inpdb=mrAaPdb,
                               outpdb=mrOriginPdb,
                               ftranslate=origin)

        # Concatenate into one file
        joinedPdb = ample_util.filename_append(filename=mrOriginPdb,
                                               astr="joined",
                                               directory=self.workdir)
        pdb_edit.merge(pdb1=nativePdbInfo.pdb,
                       pdb2=mrOriginPdb,
                       pdbout=joinedPdb)

        # Run ncont
        data = RioData()
        data.origin = origin
        data.originPdb = mrOriginPdb
        data.joinedPdb = joinedPdb
        data.fromChains = fromChains
        data.toChains = toChains

        # First get AllAtom score
        self.calcAllAtom(data)

        # Then score RIO
        self.calcRio(data)
        #data.numGood = data.inregister + data.ooregister

        # clean up
        os.unlink(mrOriginPdb)
        os.unlink(joinedPdb)
        if os.path.isfile(mrAaPdb): os.unlink(mrAaPdb)

        return data
Esempio n. 4
0
    def findOrigin(self,
                   nativePdbInfo=None,
                   mrPdbInfo=None,
                   resSeqMap=None,
                   origins=None,
                   allAtom=False,
                   workdir=os.getcwd()):
        """Find the origin using the maximum number of contacts as metric"""

        self.workdir = workdir
        if not resSeqMap.resSeqMatch():
            # We need to create a copy of the placed pdb with numbering matching the native
            mrPdbRes = ample_util.filename_append(filename=mrPdbInfo.pdb,
                                                  astr="reseq",
                                                  directory=self.workdir)
            pdb_edit.match_resseq(targetPdb=mrPdbInfo.pdb,
                                  sourcePdb=None,
                                  outPdb=mrPdbRes,
                                  resMap=resSeqMap)
            mrPdb = mrPdbRes
        else:
            mrPdb = mrPdbInfo.pdb

        # Make a copy of mrPdb with chains renamed to lower case
        ucChains = mrPdbInfo.models[0].chains
        toChains = [c.lower() for c in ucChains]
        placedAaPdb = ample_util.filename_append(filename=mrPdb,
                                                 astr="ren",
                                                 directory=self.workdir)
        pdb_edit.rename_chains(inpdb=mrPdb,
                               outpdb=placedAaPdb,
                               fromChain=ucChains,
                               toChain=toChains)

        # The list of chains in the native that we will be checking contacts from
        fromChains = nativePdbInfo.models[0].chains

        # Loop over origins, move the placed pdb to the new origin and then run ncont
        # Object to hold data on best origin
        self.data = None
        for origin in origins:
            placedOriginPdb = placedAaPdb
            if origin != [0.0, 0.0, 0.0]:
                # Move pdb to new origin
                #ostr="origin{0}".format(i)
                ostr = "o{0}".format(origin).replace(" ", "")
                placedOriginPdb = ample_util.filename_append(
                    filename=placedAaPdb, astr=ostr, directory=self.workdir)
                pdb_edit.translate(inpdb=placedAaPdb,
                                   outpdb=placedOriginPdb,
                                   ftranslate=origin)

            # Concatenate into one file
            joinedPdb = ample_util.filename_append(filename=placedOriginPdb,
                                                   astr="joined",
                                                   directory=self.workdir)
            pdb_edit.merge(pdb1=nativePdbInfo.pdb,
                           pdb2=placedOriginPdb,
                           pdbout=joinedPdb)

            # Set up object to hold data
            data = RioData()
            data.origin = origin
            data.originPdb = placedOriginPdb
            data.joinedPdb = joinedPdb
            data.fromChains = fromChains
            data.toChains = toChains
            data.numGood = 0  # For holding the metric

            # Run ncont
            if allAtom:
                self.calcAllAtom(data)
                data.numGood = data.aaNumContacts
            else:
                self.calcRio(data)
                data.numGood = data.rioInRegister + data.rioOoRegister

            # Save the first origin and only update if we get a better score
            if not self.data or data.numGood > self.data.numGood:
                self.data = data

        # End loop over origins

        # Now need to calculate data for whichever one we didn't calculate
        if allAtom:
            self.calcRio(self.data)
        else:
            self.calcAllAtom(self.data)

        if self.data.numGood > 0:

            # If we got a match run csymmatch so we can see the result
            csym = csymmatch.Csymmatch()
            csymmatchPdb = ample_util.filename_append(
                filename=self.data.originPdb,
                astr="csymmatch_best",
                directory=self.workdir)
            csym.run(refPdb=nativePdbInfo.pdb,
                     inPdb=self.data.originPdb,
                     outPdb=csymmatchPdb,
                     originHand=False)

        return self.data
Esempio n. 5
0
    def findOrigin(self,
                   nativePdbInfo=None,
                   mrPdbInfo=None,
                   resSeqMap=None,
                   origins=None,
                   allAtom=False,
                   workdir=os.getcwd() ):
        """Find the origin using the maximum number of contacts as metric"""
        
        self.workdir = workdir
        if not resSeqMap.resSeqMatch():
            # We need to create a copy of the placed pdb with numbering matching the native
            mrPdbRes = ample_util.filename_append( filename=mrPdbInfo.pdb, astr="reseq", directory=self.workdir )
            pdb_edit.match_resseq( targetPdb=mrPdbInfo.pdb, sourcePdb=None, outPdb=mrPdbRes, resMap=resSeqMap )
            mrPdb = mrPdbRes
        else:
            mrPdb = mrPdbInfo.pdb
 
        # Make a copy of mrPdb with chains renamed to lower case
        ucChains = mrPdbInfo.models[0].chains
        toChains = [ c.lower() for c in ucChains ]
        placedAaPdb = ample_util.filename_append( filename=mrPdb, astr="ren", directory=self.workdir )
        pdb_edit.rename_chains( inpdb=mrPdb, outpdb=placedAaPdb, fromChain=ucChains, toChain=toChains )

        # The list of chains in the native that we will be checking contacts from
        fromChains = nativePdbInfo.models[0].chains
        
        # Loop over origins, move the placed pdb to the new origin and then run ncont
        # Object to hold data on best origin
        self.data = None
        for origin in origins:
            placedOriginPdb =  placedAaPdb
            if origin != [ 0.0, 0.0, 0.0 ]:
                # Move pdb to new origin
                #ostr="origin{0}".format(i)
                ostr="o{0}".format( origin ).replace(" ","" )
                placedOriginPdb = ample_util.filename_append( filename=placedAaPdb, astr=ostr, directory=self.workdir )
                pdb_edit.translate( inpdb=placedAaPdb, outpdb=placedOriginPdb, ftranslate=origin )
            
            # Concatenate into one file
            joinedPdb = ample_util.filename_append( filename=placedOriginPdb, astr="joined", directory=self.workdir )
            pdb_edit.merge( pdb1=nativePdbInfo.pdb, pdb2=placedOriginPdb, pdbout=joinedPdb )
            
            # Set up object to hold data
            data            = RioData()
            data.origin     = origin
            data.originPdb  = placedOriginPdb
            data.joinedPdb  = joinedPdb
            data.fromChains = fromChains
            data.toChains   = toChains
            data.numGood    = 0 # For holding the metric
            
            # Run ncont
            if allAtom:
                self.calcAllAtom( data )
                data.numGood = data.aaNumContacts
            else:
                self.calcRio( data )
                data.numGood = data.rioInRegister + data.rioOoRegister
            
            # Save the first origin and only update if we get a better score
            if not self.data or data.numGood > self.data.numGood:
                self.data = data

        # End loop over origins
        
        # Now need to calculate data for whichever one we didn't calculate
        if allAtom:
            self.calcRio( self.data )
        else:
            self.calcAllAtom( self.data )
        
        if self.data.numGood > 0:
            
            # If we got a match run csymmatch so we can see the result
            csym = csymmatch.Csymmatch()
            csymmatchPdb = ample_util.filename_append( filename=self.data.originPdb,
                                                       astr="csymmatch_best",
                                                       directory=self.workdir )
            csym.run( refPdb=nativePdbInfo.pdb,
                      inPdb=self.data.originPdb,
                      outPdb=csymmatchPdb,
                      originHand=False )
        
        return self.data