Exemplo n.º 1
0
def CalculatePhiPsiAngles():
    """Calculate phi and psi angles for macromolecules containing amino acids."""
    
    SetupOutputFiles()
    WriteColumnLabels()
    
    Infile = OptionsInfo["Infile"]
    MolName = OptionsInfo["InfileRoot"]
    
    MiscUtil.PrintInfo("\nCalculating phi and psi torsion angles for input file %s..." % Infile)
    
    # Load infile
    pymol.cmd.load(Infile, MolName)

    OutDelim = OptionsInfo["OutDelim"]
    Precision = OptionsInfo["Precision"]

    # Go over specified chain IDs..
    for ChainID in OptionsInfo["SpecifiedChainsAndLigandsInfo"]["ChainIDs"]:
        # Write out information for combined file...
        PhiPsiInfo = PyMOLUtil.GetPhiPsiResiduesInfo(MolName, ChainID, Categorize = True)
        OptionsInfo["OutfileResCount"] += len(PhiPsiInfo["ResNums"])
        WritePhiPsiInfo(OptionsInfo["OutFH"], MolName, ChainID, PhiPsiInfo, OutDelim, Precision)

        # Write out information for category fies...
        if OptionsInfo["MultipleOutFiles"]:
            PhiPsiInfoList = []
            GeneralPhiPsiInfo, GlycinePhiPsiInfo, ProlinePhiPsiInfo, PreProlinePhiPsiInfo = PyMOLUtil.GetPhiPsiCategoriesResiduesInfo(MolName, ChainID)
            PhiPsiInfoList.extend([GeneralPhiPsiInfo, GlycinePhiPsiInfo, ProlinePhiPsiInfo, PreProlinePhiPsiInfo])
            
            for Index, Category in enumerate(OptionsInfo["Categories"]):
                OptionsInfo["CategoriesResCount"][Category] += len(PhiPsiInfoList[Index]["ResNums"])
                WritePhiPsiInfo(OptionsInfo["CategoriesOutFHs"][Category], MolName, ChainID, PhiPsiInfoList[Index], OutDelim, Precision)
    
    # Delete MolName object
    pymol.cmd.delete(MolName)

    # Close all files...
    CloseOutputFiles()

    # List number of phi and psi angles in output files...
    MiscUtil.PrintInfo("\nNumber of phi and psi angles in output file %s: %d" % (OptionsInfo["Outfile"],  OptionsInfo["OutfileResCount"]))
    if OptionsInfo["MultipleOutFiles"]:
        MiscUtil.PrintInfo("")
        for Index, Category in enumerate(OptionsInfo["Categories"]):
            MiscUtil.PrintInfo("Number of phi and psi angles in output file %s: %d" % (OptionsInfo["CategoriesOutfiles"][Category], OptionsInfo["CategoriesResCount"][Category]))
def ListPhiPsiAnglesInfo(MolName, ChainIDs):
    """List phi and psi torsion angles for polymer chains with in a molecule."""

    if not (OptionsInfo["All"] or OptionsInfo["PhiPsi"]):
        return

    MiscUtil.PrintInfo("\nListing phi and psi angles information...")

    if not len(ChainIDs):
        MiscUtil.PrintInfo("\nNumber of phi and psi angles: None\n")
        return

    for ChainID in ChainIDs:
        if re.match("^Categories$", OptionsInfo["PhiPsiMode"], re.I):
            # Retrieve phi and psi angles by categories used for Ramachandran plots
            GeneralPhiPsiInfo, GlyPhiPsiInfo, ProPhiPsiInfo, PreProPhiPsiInfo = PyMOLUtil.GetPhiPsiCategoriesResiduesInfo(
                MolName, ChainID)

            SetupAndListPhiPsiResiduesInfo(
                GeneralPhiPsiInfo,
                "General (All residues except glycine, proline, or pre-proline)",
                ChainID)
            SetupAndListPhiPsiResiduesInfo(GlyPhiPsiInfo,
                                           "Glycine (Only glycine residues)",
                                           ChainID)
            SetupAndListPhiPsiResiduesInfo(ProPhiPsiInfo,
                                           "Proline (Only proline residues)",
                                           ChainID)
            SetupAndListPhiPsiResiduesInfo(
                PreProPhiPsiInfo,
                "Pre-Proline (Only residues before proline not including glycine or proline)",
                ChainID)
        else:
            PhiPsiResiduesInfo = PyMOLUtil.GetPhiPsiResiduesInfo(
                MolName, ChainID, Categorize=True)
            SetupAndListPhiPsiResiduesInfo(PhiPsiResiduesInfo, "All", ChainID)