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)
def CalculatePhiPsiAngles():
    """Calculate phi and psi angles for scatter plots."""

    Infile = OptionsInfo["Infile"]
    MolName = OptionsInfo["InfileRoot"]

    # Load molecule...
    pymol.cmd.reinitialize()
    pymol.cmd.load(Infile, MolName)

    MiscUtil.PrintInfo(
        "\nCalculating phi and psi torsion angles for input file %s..." %
        Infile)

    # Initialize...
    OptionsInfo["PlotTypesInfo"]["PhiAngles"] = {}
    OptionsInfo["PlotTypesInfo"]["PsiAngles"] = {}
    OptionsInfo["PlotTypesInfo"]["ResCount"] = {}
    for PlotType in OptionsInfo["PlotTypesInfo"]["Types"]:
        OptionsInfo["PlotTypesInfo"]["PhiAngles"][PlotType] = []
        OptionsInfo["PlotTypesInfo"]["PsiAngles"][PlotType] = []
        OptionsInfo["PlotTypesInfo"]["ResCount"][PlotType] = 0

    Precision = OptionsInfo["Precision"]

    TotalResCount = 0
    # Go over specified chain IDs..
    for ChainID in OptionsInfo["SpecifiedChainsAndLigandsInfo"]["ChainIDs"]:
        PhiPsiInfoList = []
        GeneralPhiPsiInfo, GlycinePhiPsiInfo, ProlinePhiPsiInfo, PreProlinePhiPsiInfo = PyMOLUtil.GetPhiPsiCategoriesResiduesInfo(
            MolName, ChainID)
        PhiPsiInfoList.extend([
            GeneralPhiPsiInfo, GlycinePhiPsiInfo, ProlinePhiPsiInfo,
            PreProlinePhiPsiInfo
        ])

        for Index, PlotType in enumerate(
                OptionsInfo["PlotTypesInfo"]["Types"]):
            PhiPsiInfo = PhiPsiInfoList[Index]
            ResCount = len(PhiPsiInfo["ResNums"])
            if not ResCount:
                continue

            TotalResCount += ResCount
            OptionsInfo["PlotTypesInfo"]["ResCount"][PlotType] += ResCount

            PhiAngles, PsiAngles = ProcessPsiInfo(PhiPsiInfo, Precision)
            OptionsInfo["PlotTypesInfo"]["PhiAngles"][PlotType].extend(
                PhiAngles)
            OptionsInfo["PlotTypesInfo"]["PsiAngles"][PlotType].extend(
                PsiAngles)

    # Delete MolName object
    pymol.cmd.delete(MolName)

    MiscUtil.PrintInfo("\nTotal number of phi and psi angles: %d" %
                       TotalResCount)

    MiscUtil.PrintInfo("")
    for PlotType in OptionsInfo["PlotTypesInfo"]["Types"]:
        MiscUtil.PrintInfo(
            "Number of \"%s\" phi and psi angles: %s" %
            (PlotType, OptionsInfo["PlotTypesInfo"]["ResCount"][PlotType]))

    if not TotalResCount:
        MiscUtil.PrintInfo("")
        MiscUtil.PrintWarning(
            "No valid phi and psi angles found in input file. Ramachandran plots will be generated without phi and psi scatter plots..."
        )
Exemple #3
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]))