def test_resSeqMap3(self): # See if we can sort out the indexing between the native and model nativePdb = os.path.join(self.testfiles_dir,"2UUI.pdb") modelPdb = os.path.join(self.testfiles_dir,"2UUI_S_00000001.pdb") chainA = "2UUI_A.pdb" pdb_edit.extract_chain( nativePdb, chainA, chainID='A' ) chainAstd = "2UUI_A_std.pdb" pdb_edit.standardise(chainA, chainAstd) resSeqMap = residue_map.residueSequenceMap( chainA, modelPdb ) self.assertEqual( 156, resSeqMap._lenMatch() ) nativeMask = [ False ] * 155 + [ True ] self.assertEqual( resSeqMap.refCAlphaMask, nativeMask) self.assertEqual( resSeqMap.ref2target(10), 16 ) self.assertEqual( resSeqMap.target2ref(155), 149 ) # Check ends match up m1 = resSeqMap.targetResSeq[ resSeqMap.targetOffset ] n1 = resSeqMap.target2ref( m1 ) self.assertEqual( m1, resSeqMap.ref2target(n1) ) re = resSeqMap.refResSeq[ resSeqMap.refOffset + resSeqMap.lenMatch - 1 ] self.assertEqual( resSeqMap.ref2target( re ), resSeqMap.targetResSeq[ resSeqMap.targetOffset + resSeqMap.lenMatch - 1 ] ) os.unlink( chainA ) os.unlink( chainAstd )
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
def test_resSeqMap3(self): # See if we can sort out the indexing between the native and model nativePdb = os.path.join(self.testfiles_dir, "2UUI.pdb") modelPdb = os.path.join(self.testfiles_dir, "2UUI_S_00000001.pdb") chainA = "2UUI_A.pdb" pdb_edit.extract_chain(nativePdb, chainA, chainID='A') chainAstd = "2UUI_A_std.pdb" pdb_edit.standardise(chainA, chainAstd) resSeqMap = residue_map.residueSequenceMap(chainA, modelPdb) self.assertEqual(156, resSeqMap._lenMatch()) nativeMask = [False] * 155 + [True] self.assertEqual(resSeqMap.refCAlphaMask, nativeMask) self.assertEqual(resSeqMap.ref2target(10), 16) self.assertEqual(resSeqMap.target2ref(155), 149) # Check ends match up m1 = resSeqMap.targetResSeq[resSeqMap.targetOffset] n1 = resSeqMap.target2ref(m1) self.assertEqual(m1, resSeqMap.ref2target(n1)) re = resSeqMap.refResSeq[resSeqMap.refOffset + resSeqMap.lenMatch - 1] self.assertEqual( resSeqMap.ref2target(re), resSeqMap.targetResSeq[resSeqMap.targetOffset + resSeqMap.lenMatch - 1] ) os.unlink(chainA) os.unlink(chainAstd)
def getRmsd(self, nativePdbInfo=None, placedPdbInfo=None, refModelPdbInfo=None, workdir=None, cAlphaOnly=True): """For now just save lowest rmsd - can look at collecting more nativeInfo later Currently we assume we are only given one model and that it has already been standardised. """ if workdir: self.workdir = workdir if not self.workdir: self.workdir = os.getcwd() self.cAlphaOnly = cAlphaOnly # Whether to only compare c-alpha atoms # Run a pass to find the # chains native_chains = nativePdbInfo.models[0].chains placed_chains = placedPdbInfo.models[0].chains rmsds = { } # dict of rmsd -> ( chainIDnative, chainIDrefined, reforiginLogfile ) # Match each chain in native against refined and pick the best for nativeChainID in native_chains: if len(native_chains) == 1: # Don't need to do owt as we are just using the native as is nativeChainPdb = nativePdbInfo.pdb else: # Extract the chain from the pdb astr = "chain{0}".format(nativeChainID) nativeChainPdb = ample_util.filename_append( filename=nativePdbInfo.pdb, astr=astr, directory=self.workdir) pdb_edit.extract_chain(nativePdbInfo.pdb, nativeChainPdb, chainID=nativeChainID) # Calculate the RefSeqMap - need to do this before we reduce to c-alphas # The second chain may be a different composition to the first, so we only generate a traceback if we fail # on the first chain. The model only has one chain, so the residueMap has to be the same for all the chains try: resSeqMap = residue_map.residueSequenceMap() resSeqMap.fromInfo( refInfo=nativePdbInfo, refChainID=nativeChainID, targetInfo=refModelPdbInfo, targetChainID='A' # Model only has one chain ) except RuntimeError: if nativeChainID == native_chains[0]: raise Exception else: # Only compare the first chain break for placedChainID in placed_chains: # Prepare the placed PDB placedChainPdb = self.preparePlacedPdb( placedPdb=placedPdbInfo.pdb, placedChainID=placedChainID, nativeChainID=nativeChainID, resSeqMap=resSeqMap) # Now create a PDB with the matching atoms from native that are in refined nativePdbMatch = ample_util.filename_append( filename=nativeChainPdb, astr="matched", directory=self.workdir) pdb_edit.keep_matching(refpdb=placedChainPdb, targetpdb=nativeChainPdb, outpdb=nativePdbMatch, resSeqMap=resSeqMap) # Now get the rmsd astr = "chain{0}_reforigin".format(nativeChainID) reforiginOut = ample_util.filename_append( filename=placedChainPdb, astr=astr, directory=self.workdir) try: rms = self.calculate(refpdb=nativePdbMatch, targetpdb=placedChainPdb, outpdb=reforiginOut) except RuntimeError as e: logger.critical( "GOT REFORIGIN ERROR for {0},{1},{2}\n{3}".format( placedChainPdb, nativeChainPdb, nativeChainID, e)) rms = 99999 rmsds[rms] = (nativeChainID, placedChainID, reforiginOut) # Clean up os.unlink(placedChainPdb) os.unlink(nativePdbMatch) # Now pick the best... rmsd = sorted(rmsds.keys())[0] self.rmsd = rmsd self.bestNativeChain = rmsds[rmsd][0] self.bestPlacedChain = rmsds[rmsd][1] self.bestReforiginPdb = rmsds[rmsd][2] for k in rmsds.keys(): if k != rmsd: try: os.unlink(rmsds[k][2]) except Exception: pass