MayaChemTools

    1 #!/bin/env python
    2 #
    3 # File: PyMOLVisualizeMacromolecules.py
    4 # Author: Manish Sud <msud@san.rr.com>
    5 #
    6 # Copyright (C) 2019 Manish Sud. All rights reserved.
    7 #
    8 # The functionality available in this script is implemented using PyMOL, a
    9 # molecular visualization system on an open source foundation originally
   10 # developed by Warren DeLano.
   11 #
   12 # This file is part of MayaChemTools.
   13 #
   14 # MayaChemTools is free software; you can redistribute it and/or modify it under
   15 # the terms of the GNU Lesser General Public License as published by the Free
   16 # Software Foundation; either version 3 of the License, or (at your option) any
   17 # later version.
   18 #
   19 # MayaChemTools is distributed in the hope that it will be useful, but without
   20 # any warranty; without even the implied warranty of merchantability of fitness
   21 # for a particular purpose.  See the GNU Lesser General Public License for more
   22 # details.
   23 #
   24 # You should have received a copy of the GNU Lesser General Public License
   25 # along with MayaChemTools; if not, see <http://www.gnu.org/licenses/> or
   26 # write to the Free Software Foundation Inc., 59 Temple Place, Suite 330,
   27 # Boston, MA, 02111-1307, USA.
   28 #
   29 
   30 from __future__ import print_function
   31 
   32 # Add local python path to the global path and import standard library modules...
   33 import os
   34 import sys;  sys.path.insert(0, os.path.join(os.path.dirname(sys.argv[0]), "..", "lib", "Python"))
   35 import time
   36 import re
   37 
   38 # PyMOL imports...
   39 try:
   40     import pymol
   41     # Finish launching PyMOL in  a command line mode for batch processing (-c)
   42     # along with the following options:  disable loading of pymolrc and plugins (-k);
   43     # suppress start up messages (-q)
   44     pymol.finish_launching(['pymol', '-ckq'])
   45 except ImportError as ErrMsg:
   46     sys.stderr.write("\nFailed to import PyMOL module/package: %s\n" % ErrMsg)
   47     sys.stderr.write("Check/update your PyMOL environment and try again.\n\n")
   48     sys.exit(1)
   49 
   50 # MayaChemTools imports...
   51 try:
   52     from docopt import docopt
   53     import MiscUtil
   54     import PyMOLUtil
   55 except ImportError as ErrMsg:
   56     sys.stderr.write("\nFailed to import MayaChemTools module/package: %s\n" % ErrMsg)
   57     sys.stderr.write("Check/update your MayaChemTools environment and try again.\n\n")
   58     sys.exit(1)
   59 
   60 ScriptName = os.path.basename(sys.argv[0])
   61 Options = {}
   62 OptionsInfo = {}
   63 
   64 def main():
   65     """Start execution of the script"""
   66     
   67     MiscUtil.PrintInfo("\n%s (PyMOL v%s; %s) Starting...\n" % (ScriptName, pymol.cmd.get_version()[0], time.asctime()))
   68     
   69     (WallClockTime, ProcessorTime) = MiscUtil.GetWallClockAndProcessorTime()
   70     
   71     # Retrieve command line arguments and options...
   72     RetrieveOptions()
   73     
   74     # Process and validate command line arguments and options...
   75     ProcessOptions()
   76 
   77     # Perform actions required by the script...
   78     GenerateMacromolecularVisualization()
   79     
   80     MiscUtil.PrintInfo("\n%s: Done...\n" % ScriptName)
   81     MiscUtil.PrintInfo("Total time: %s" % MiscUtil.GetFormattedElapsedTime(WallClockTime, ProcessorTime))
   82 
   83 def GenerateMacromolecularVisualization():
   84     """Generate macromolecular visualization."""
   85 
   86     Outfile = OptionsInfo["PMLOutfile"]
   87     OutFH = open(Outfile, "w")
   88     if OutFH is None:
   89         MiscUtil.PrintError("Failed to open output fie %s " % Outfile)
   90     
   91     MiscUtil.PrintInfo("\nGenerating file %s..." % Outfile)
   92 
   93     # Setup header...
   94     WritePMLHeader(OutFH, ScriptName)
   95     WritePyMOLParameters(OutFH)
   96     
   97     # Load reffile for alignment..
   98     if OptionsInfo["Align"]:
   99         WriteAlignReference(OutFH)
  100 
  101     # Setup view for each input file...
  102     FirstComplex = True
  103     FirstComplexFirstChainName = None
  104     for FileIndex in range(0, len(OptionsInfo["InfilesInfo"]["InfilesNames"])):
  105         # Setup PyMOL object names...
  106         PyMOLObjectNames = SetupPyMOLObjectNames(FileIndex)
  107 
  108         # Setup complex view...
  109         WriteComplexView(OutFH, FileIndex, PyMOLObjectNames, FirstComplex)
  110         
  111         SpecifiedChainsAndLigandsInfo = OptionsInfo["InfilesInfo"]["SpecifiedChainsAndLigandsInfo"][FileIndex]
  112         FirstChain = True
  113         for ChainID in SpecifiedChainsAndLigandsInfo["ChainIDs"]:
  114             if FirstComplex and FirstChain:
  115                 FirstComplexFirstChainName = PyMOLObjectNames["Chains"][ChainID]["ChainAlone"]
  116                 
  117             WriteChainView(OutFH, FileIndex, PyMOLObjectNames, ChainID)
  118             
  119             # Setup ligand views...
  120             FirstLigand = True
  121             for LigandID in SpecifiedChainsAndLigandsInfo["LigandIDs"][ChainID]:
  122                 WriteChainLigandView(OutFH, FileIndex, PyMOLObjectNames, ChainID, LigandID)
  123                 
  124                 # Set up ligand level group...
  125                 Enable, Action = [False, "close"]
  126                 if FirstLigand:
  127                     FirstLigand = False
  128                     Enable, Action = [True, "open"]
  129                 GenerateAndWritePMLForGroup(OutFH, PyMOLObjectNames["Ligands"][ChainID][LigandID]["ChainLigandGroup"], PyMOLObjectNames["Ligands"][ChainID][LigandID]["ChainLigandGroupMembers"], Enable, Action)
  130             
  131             # Setup Chain level group...
  132             Enable, Action = [False, "close"]
  133             if FirstChain:
  134                 FirstChain = False
  135                 Enable, Action = [True, "open"]
  136             GenerateAndWritePMLForGroup(OutFH, PyMOLObjectNames["Chains"][ChainID]["ChainGroup"], PyMOLObjectNames["Chains"][ChainID]["ChainGroupMembers"], Enable, Action)
  137     
  138         # Set up complex level group...
  139         Enable, Action = [False, "close"]
  140         if FirstComplex:
  141             FirstComplex = False
  142             Enable, Action = [True, "open"]
  143         GenerateAndWritePMLForGroup(OutFH, PyMOLObjectNames["PDBGroup"], PyMOLObjectNames["PDBGroupMembers"], Enable, Action)
  144         
  145         # Delete empty PyMOL objects...
  146         DeleteEmptyPyMOLObjects(OutFH, FileIndex, PyMOLObjectNames)
  147         
  148     if OptionsInfo["Align"]:
  149         DeleteAlignReference(OutFH)
  150 
  151     if FirstComplexFirstChainName is not None:
  152         OutFH.write("""\ncmd.orient("%s", animate = -1)\n""" % FirstComplexFirstChainName)
  153     else:
  154         OutFH.write("""\ncmd.orient("visible", animate = -1)\n""")
  155     
  156     OutFH.close()
  157 
  158     # Generate PSE file as needed...
  159     if OptionsInfo["PSEOut"]:
  160         GeneratePyMOLSessionFile()
  161 
  162 def WritePMLHeader(OutFH, ScriptName):
  163     """Write out PML setting up complex view"""
  164 
  165     HeaderInfo = PyMOLUtil.SetupPMLHeaderInfo(ScriptName)
  166     OutFH.write("%s\n" % HeaderInfo)
  167 
  168 def WritePyMOLParameters(OutFH):
  169     """Write out PyMOL global parameters. """
  170 
  171     PMLCmds = []
  172     PMLCmds.append("""cmd.set("transparency", %.2f, "", 0)""" % (OptionsInfo["SurfaceTransparency"]))
  173     PMLCmds.append("""cmd.set("label_font_id", %s)""" % (OptionsInfo["LabelFontID"]))
  174     PML = "\n".join(PMLCmds)
  175     
  176     OutFH.write("""\n""\n"Setting up PyMOL gobal parameters..."\n""\n""")
  177     OutFH.write("%s\n" % PML)
  178     
  179 def WriteAlignReference(OutFH):
  180     """Setup object for alignment reference """
  181 
  182     RefFileInfo = OptionsInfo["RefFileInfo"]
  183     RefFile = RefFileInfo["RefFileName"]
  184     RefName = RefFileInfo["PyMOLObjectName"]
  185     
  186     PMLCmds = []
  187     PMLCmds.append("""cmd.load("%s", "%s")""" % (RefFile, RefName))
  188     PMLCmds.append("""cmd.hide("everything", "%s")""" % (RefName))
  189     PMLCmds.append("""cmd.disable("%s")""" % (RefName))
  190     PML = "\n".join(PMLCmds)
  191     
  192     OutFH.write("""\n""\n"Loading %s and setting up view for align reference..."\n""\n""" % RefFile)
  193     OutFH.write("%s\n" % PML)
  194     
  195 def WriteAlignComplex(OutFH, FileIndex, PyMOLObjectNames):
  196     """Setup alignment of complex to reference"""
  197 
  198     RefFileInfo = OptionsInfo["RefFileInfo"]
  199     RefName = RefFileInfo["PyMOLObjectName"]
  200     
  201     ComplexName = PyMOLObjectNames["Complex"]
  202     
  203     if re.match("^FirstChain$", OptionsInfo["AlignMode"], re.I):
  204         RefFirstChainID = RefFileInfo["ChainsAndLigandsInfo"]["ChainIDs"][0]
  205         RefAlignSelection = "%s and chain %s" % (RefName, RefFirstChainID)
  206         
  207         ComplexFirstChainID = RetrieveFirstChainID(FileIndex)
  208         ComplexAlignSelection = "%s and chain %s" % (ComplexName, ComplexFirstChainID)
  209     else:
  210         RefAlignSelection = RefName
  211         ComplexAlignSelection = ComplexName
  212 
  213     PML = PyMOLUtil.SetupPMLForAlignment(OptionsInfo["AlignMethod"], RefAlignSelection, ComplexAlignSelection)
  214     OutFH.write("""\n""\n"Aligning %s against reference %s ..."\n""\n""" % (ComplexAlignSelection, RefAlignSelection))
  215     OutFH.write("%s\n" % PML)
  216     
  217 def DeleteAlignReference(OutFH):
  218     """Delete alignment reference object."""
  219     
  220     RefName = OptionsInfo["RefFileInfo"]["PyMOLObjectName"]
  221     OutFH.write("""\n""\n"Deleting alignment reference object %s..."\n""\n""" % RefName)
  222     OutFH.write("""cmd.delete("%s")\n""" % RefName)
  223 
  224 def WriteComplexView(OutFH, FileIndex, PyMOLObjectNames, FirstComplex):
  225     """Write out PML for viewing polymer complex."""
  226 
  227     # Setup complex...
  228     Infile = OptionsInfo["InfilesInfo"]["InfilesNames"][FileIndex]
  229     PML = PyMOLUtil.SetupPMLForPolymerComplexView(PyMOLObjectNames["Complex"], Infile, True)
  230     OutFH.write("""\n""\n"Loading %s and setting up view for complex..."\n""\n""" % Infile)
  231     OutFH.write("%s\n" % PML)
  232 
  233     if OptionsInfo["Align"]:
  234         # No need to align complex on to itself...
  235         if not (re.match("^FirstInputFile$", OptionsInfo["AlignRefFile"], re.I) and FirstComplex):
  236             WriteAlignComplex(OutFH, FileIndex, PyMOLObjectNames)
  237     
  238     if OptionsInfo["SurfaceComplex"]:
  239         # Setup hydrophobic surface...
  240         PML = PyMOLUtil.SetupPMLForHydrophobicSurfaceView(PyMOLObjectNames["ComplexHydrophobicSurface"], PyMOLObjectNames["Complex"], ColorPalette = OptionsInfo["SurfaceColorPalette"], Enable = False)
  241         OutFH.write("\n%s\n" % PML)
  242     
  243     # Setup complex group...
  244     GenerateAndWritePMLForGroup(OutFH, PyMOLObjectNames["ComplexGroup"], PyMOLObjectNames["ComplexGroupMembers"], False, "close")
  245 
  246 def WriteChainView(OutFH, FileIndex, PyMOLObjectNames, ChainID):
  247     """Write out PML for viewing chain."""
  248     
  249     OutFH.write("""\n""\n"Setting up views for chain %s..."\n""\n""" % ChainID)
  250     
  251     ChainComplexName = PyMOLObjectNames["Chains"][ChainID]["ChainComplex"]
  252     
  253     # Setup chain complex group view...
  254     WriteChainComplexViews(OutFH, FileIndex, PyMOLObjectNames, ChainID)
  255 
  256     # Setup chain view...
  257     WriteChainAloneViews(OutFH, FileIndex, PyMOLObjectNames, ChainID)
  258     
  259     # Setup chain solvent view...
  260     PML = PyMOLUtil.SetupPMLForSolventView(PyMOLObjectNames["Chains"][ChainID]["Solvent"], ChainComplexName, False)
  261     OutFH.write("\n%s\n" % PML)
  262 
  263     # Setup chain inorganic view...
  264     PML = PyMOLUtil.SetupPMLForInorganicView(PyMOLObjectNames["Chains"][ChainID]["Inorganic"], ChainComplexName, False)
  265     OutFH.write("\n%s\n" % PML)
  266 
  267 def WriteChainComplexViews(OutFH, FileIndex, PyMOLObjectNames, ChainID):
  268     """Write chain complex views. """
  269     
  270     # Setup chain complex...
  271     ChainComplexName = PyMOLObjectNames["Chains"][ChainID]["ChainComplex"]
  272     PML = PyMOLUtil.SetupPMLForPolymerChainComplexView(ChainComplexName, PyMOLObjectNames["Complex"], ChainID, True)
  273     OutFH.write("%s\n" % PML)
  274 
  275     if OptionsInfo["SurfaceChainComplex"]:
  276         # Setup hydrophobic surface...
  277         PML = PyMOLUtil.SetupPMLForHydrophobicSurfaceView(PyMOLObjectNames["Chains"][ChainID]["ChainComplexHydrophobicSurface"], ChainComplexName, ColorPalette = OptionsInfo["SurfaceColorPalette"], Enable = False)
  278         OutFH.write("\n%s\n" % PML)
  279     
  280     # Setup chain complex group...
  281     GenerateAndWritePMLForGroup(OutFH, PyMOLObjectNames["Chains"][ChainID]["ChainComplexGroup"], PyMOLObjectNames["Chains"][ChainID]["ChainComplexGroupMembers"], False, "close")
  282     
  283 def WriteChainAloneViews(OutFH, FileIndex, PyMOLObjectNames, ChainID):
  284     """Write individual chain views. """
  285 
  286     ChainComplexName = PyMOLObjectNames["Chains"][ChainID]["ChainComplex"]
  287     
  288     # Setup chain view...
  289     ChainName = PyMOLObjectNames["Chains"][ChainID]["ChainAlone"]
  290     PML = PyMOLUtil.SetupPMLForPolymerChainView(ChainName, ChainComplexName, True)
  291     OutFH.write("\n%s\n" % PML)
  292 
  293     WriteChainAloneChainSelectionsView(OutFH,  FileIndex, PyMOLObjectNames, ChainID)
  294     WriteChainAloneResidueTypesView(OutFH,  FileIndex, PyMOLObjectNames, ChainID)
  295         
  296     if GetChainAloneContainsSurfacesStatus(FileIndex, ChainID):
  297         # Setup a generic color surface...
  298         PML = PyMOLUtil.SetupPMLForSurfaceView(PyMOLObjectNames["Chains"][ChainID]["ChainAloneSurface"], ChainName,  Enable = False, Color = OptionsInfo["SurfaceColor"])
  299         OutFH.write("\n%s\n" % PML)
  300         
  301         if GetChainAloneSurfaceChainStatus(FileIndex, ChainID):
  302             # Setup surface colored by hydrophobicity...
  303             PML = PyMOLUtil.SetupPMLForHydrophobicSurfaceView(PyMOLObjectNames["Chains"][ChainID]["ChainAloneHydrophobicSurface"], ChainName, ColorPalette = OptionsInfo["SurfaceColorPalette"], Enable = False)
  304             OutFH.write("\n%s\n" % PML)
  305             
  306             # Setup surface colored by hyrdophobicity and charge...
  307             PML = PyMOLUtil.SetupPMLForHydrophobicAndChargeSurfaceView(PyMOLObjectNames["Chains"][ChainID]["ChainAloneHydrophobicChargeSurface"], ChainName, OptionsInfo["AtomTypesColorNames"]["HydrophobicAtomsColor"], OptionsInfo["AtomTypesColorNames"]["NegativelyChargedAtomsColor"], OptionsInfo["AtomTypesColorNames"]["PositivelyChargedAtomsColor"], OptionsInfo["AtomTypesColorNames"]["OtherAtomsColor"], Enable = False, DisplayAs = None)
  308             OutFH.write("\n%s\n" % PML)
  309         
  310         if GetChainAloneSurfaceChainElectrostaticsStatus(FileIndex, ChainID):
  311             # Setup electrostatics surface...
  312             SelectionObjectName = ChainName
  313             ElectrostaticsGroupName = PyMOLObjectNames["Chains"][ChainID]["ChainAloneElectrostaticsGroup"]
  314             ElectrostaticsGroupMembers = PyMOLObjectNames["Chains"][ChainID]["ChainAloneElectrostaticsGroupMembers"]
  315             WriteSurfaceElectrostaticsView("Surface", OutFH, SelectionObjectName, ElectrostaticsGroupName, ElectrostaticsGroupMembers, DisplayAs = "cartoon")
  316 
  317         # Setup surface group...
  318         GenerateAndWritePMLForGroup(OutFH, PyMOLObjectNames["Chains"][ChainID]["ChainAloneSurfaceGroup"], PyMOLObjectNames["Chains"][ChainID]["ChainAloneSurfaceGroupMembers"], True, "open")
  319 
  320     # Setup chain group...
  321     GenerateAndWritePMLForGroup(OutFH, PyMOLObjectNames["Chains"][ChainID]["ChainAloneGroup"], PyMOLObjectNames["Chains"][ChainID]["ChainAloneGroupMembers"], True, "close")
  322     
  323 def WriteChainLigandView(OutFH, FileIndex, PyMOLObjectNames, ChainID, LigandID):
  324     """Write out PML for viewing ligand in a chain."""
  325     
  326     for GroupID in ["Ligand", "Pocket", "PocketSolvent", "PocketInorganic"]:
  327         ComplexName = PyMOLObjectNames["Chains"][ChainID]["ChainComplex"]
  328         LigandName = PyMOLObjectNames["Ligands"][ChainID][LigandID]["Ligand"]
  329         
  330         # Setup main object...
  331         GroupTypeObjectID = "%s" % (GroupID)
  332         GroupTypeObjectName = PyMOLObjectNames["Ligands"][ChainID][LigandID][GroupTypeObjectID]
  333         
  334         if re.match("^Ligand$", GroupID, re.I):
  335             OutFH.write("""\n""\n"Setting up views for ligand %s in chain %s..."\n""\n""" % (LigandID, ChainID))
  336             PML = PyMOLUtil.SetupPMLForLigandView(GroupTypeObjectName, ComplexName, LigandID, True)
  337             OutFH.write("%s\n" % PML)
  338         elif re.match("^Pocket$", GroupID, re.I):
  339             OutFH.write("""\n""\n"Setting up views for pocket around ligand %s in chain %s..."\n""\n""" % (LigandID, ChainID))
  340             PML = PyMOLUtil.SetupPMLForLigandPocketView(GroupTypeObjectName, ComplexName, LigandName, OptionsInfo["PocketDistanceCutoff"], True)
  341             OutFH.write("%s\n" % PML)
  342             OutFH.write("""cmd.set("label_color", "%s", "%s")\n""" % (OptionsInfo["PocketLabelColor"], GroupTypeObjectName))
  343         elif re.match("^PocketSolvent$", GroupID, re.I):
  344             OutFH.write("""\n""\n"Setting up views for solvent in pockect around ligand %s in chain %s..."\n""\n""" % (LigandID, ChainID))
  345             PML = PyMOLUtil.SetupPMLForLigandPocketSolventView(GroupTypeObjectName, ComplexName, LigandName, OptionsInfo["PocketDistanceCutoff"], Enable = True)
  346             OutFH.write("%s\n" % PML)
  347         elif re.match("^PocketInorganic$", GroupID, re.I):
  348             OutFH.write("""\n""\n"Setting up views for inorganic in pockect around ligand %s in chain %s..."\n""\n""" % (LigandID, ChainID))
  349             PML = PyMOLUtil.SetupPMLForLigandPocketInorganicView(GroupTypeObjectName, ComplexName, LigandName, OptionsInfo["PocketDistanceCutoff"], Enable = True)
  350             OutFH.write("%s\n" % PML)
  351         
  352         # Set up polar contacts...
  353         if re.match("^(Pocket|PocketSolvent|PocketInorganic)$", GroupID, re.I):
  354             PolarContactsID = "%sPolarContacts" % (GroupID)
  355             PolarContactsName = PyMOLObjectNames["Ligands"][ChainID][LigandID][PolarContactsID]
  356             
  357             PolarContactsColor = OptionsInfo["PocketContactsLigandColor"]
  358             if re.match("^PocketSolvent$", GroupID, re.I):
  359                 PolarContactsColor = OptionsInfo["PocketContactsSolventColor"]
  360             elif re.match("^PocketInorganic$", GroupID, re.I):
  361                 PolarContactsColor = OptionsInfo["PocketContactsInorganicColor"]
  362 
  363             PML = PyMOLUtil.SetupPMLForPolarContactsView(PolarContactsName, LigandName, GroupTypeObjectName, Enable = False, Color = PolarContactsColor, Cutoff = OptionsInfo["PocketContactsCutoff"])
  364             OutFH.write("\n%s\n" % PML)
  365             
  366             OutFH.write("""cmd.set("label_color", "%s", "%s")\n""" % (PolarContactsColor, PolarContactsName))
  367             
  368         if re.match("^Pocket$", GroupID, re.I):
  369             # Setup hydrophobic contacts...
  370             HydrophobicContactsID = "%sHydrophobicContacts" % (GroupID)
  371             HydrophobicContactsName = PyMOLObjectNames["Ligands"][ChainID][LigandID][HydrophobicContactsID]
  372             HydrophobicContactsColor = OptionsInfo["PocketContactsLigandHydrophobicColor"]
  373             
  374             PML = PyMOLUtil.SetupPMLForHydrophobicContactsView(HydrophobicContactsName, LigandName, GroupTypeObjectName, Enable = False, Color = HydrophobicContactsColor, Cutoff = OptionsInfo["PocketContactsCutoff"])
  375             OutFH.write("\n%s\n" % PML)
  376             OutFH.write("""cmd.set("label_color", "%s", "%s")\n""" % (HydrophobicContactsColor, HydrophobicContactsName))
  377 
  378             # Setup pocket residues...
  379             WritePocketResidueTypesView(OutFH,  FileIndex, PyMOLObjectNames, ChainID, LigandID, GroupTypeObjectID)
  380             WritePocketSurfacesTypesView(OutFH,  FileIndex, PyMOLObjectNames, ChainID, LigandID, GroupTypeObjectID)
  381         
  382         if re.match("^Ligand$", GroupID, re.I):
  383             # Setup ball and stick view...
  384             BallAndStickNameID = "%sBallAndStick" % (GroupID)
  385             BallAndStickName = PyMOLObjectNames["Ligands"][ChainID][LigandID][BallAndStickNameID]
  386             PML = PyMOLUtil.SetupPMLForBallAndStickView(BallAndStickName, GroupTypeObjectName, Enable = False)
  387             OutFH.write("\n%s\n" % PML)
  388             
  389         # Setup group...
  390         GroupNameID = "%sGroup" % (GroupID)
  391         GroupMembersID = "%sGroupMembers" % (GroupID)
  392         GroupName = PyMOLObjectNames["Ligands"][ChainID][LigandID][GroupNameID]
  393         GroupMembers = PyMOLObjectNames["Ligands"][ChainID][LigandID][GroupMembersID]
  394 
  395         Action = "close"
  396         Enable = False
  397         if  re.match("^(Ligand|Pocket)$", GroupID, re.I):
  398             Action = "open"
  399             Enable = True
  400         GenerateAndWritePMLForGroup(OutFH, GroupName, GroupMembers, Enable, Action)
  401 
  402 def WritePocketSurfacesTypesView(OutFH,  FileIndex, PyMOLObjectNames, ChainID, LigandID, PocketObjectID):
  403     """Write out PML for viewing surfaces for a ligand pocket."""
  404 
  405     if not GetPocketContainsSurfaceStatus(FileIndex, ChainID, LigandID):
  406         return
  407     
  408     PocketObjectName = PyMOLObjectNames["Ligands"][ChainID][LigandID][PocketObjectID]
  409     
  410     SurfacesGroupID = "%sSurfacesGroup" % (PocketObjectID)
  411     SurfacesGroupMembersID = "%sSurfacesGroupMembers" % (PocketObjectID)
  412 
  413     # Cavity modes: 1 or 2.  1: Cavity surfaces; 2: Culled cavity surfaces...
  414     CavityMode = 2
  415     
  416     # Setup surfaces subgroup and its members...
  417     for SubGroupType in ["Surface", "Cavity"]:
  418         ProcessingCavity = True if re.match("^Cavity$", SubGroupType, re.I) else False
  419         
  420         SubGroupID = re.sub("_", "", SubGroupType)
  421         SurfacesSubGroupID = "%s%sGroup" % (SurfacesGroupID, SubGroupID)
  422         SurfacesSubGroupMembersID = "%sMembers" % (SurfacesSubGroupID)
  423 
  424         # Turn off lines display for cavity surfaces...
  425         DisplayStyle = None if ProcessingCavity else "lines"
  426 
  427         # Setup a generic color surface...
  428         SurfaceID = "%sSurface" % (SurfacesSubGroupID)
  429         SurfaceName = PyMOLObjectNames["Ligands"][ChainID][LigandID][SurfaceID]
  430         PML = PyMOLUtil.SetupPMLForSurfaceView(SurfaceName, PocketObjectName, Enable = False, Color = OptionsInfo["SurfaceColor"], DisplayAs = DisplayStyle)
  431         OutFH.write("\n%s\n" % PML)
  432         
  433         if ProcessingCavity:
  434             OutFH.write("""cmd.set("surface_cavity_mode", %d, "%s")\n""" % (CavityMode, SurfaceName))
  435         
  436         OutFH.write("""cmd.set("label_color", "%s", "%s")\n""" % (OptionsInfo["PocketLabelColor"], SurfaceName))
  437         
  438         if GetPocketSurfaceChainStatus(FileIndex, ChainID, LigandID):
  439             # Setup a surface colored by hydrphobicity...
  440             HydrophobicSurfaceID = "%sHydrophobicSurface" % (SurfacesSubGroupID)
  441             HydrophobicSurfaceName = PyMOLObjectNames["Ligands"][ChainID][LigandID][HydrophobicSurfaceID]
  442             PML = PyMOLUtil.SetupPMLForHydrophobicSurfaceView(HydrophobicSurfaceName, PocketObjectName, ColorPalette = OptionsInfo["SurfaceColorPalette"], Enable = False, DisplayAs = DisplayStyle)
  443             OutFH.write("\n%s\n" % PML)
  444             
  445             if ProcessingCavity:
  446                 OutFH.write("""cmd.set("surface_cavity_mode", %d, "%s")\n""" % (CavityMode, HydrophobicSurfaceName))
  447             
  448             OutFH.write("""cmd.set("label_color", "%s", "%s")\n""" % (OptionsInfo["PocketLabelColor"], HydrophobicSurfaceName))
  449             
  450             # Setup a surface colored by hydrphobicity and charge...
  451             HydrophobicChargeSurfaceID = "%sHydrophobicChargeSurface" % (SurfacesSubGroupID)
  452             HydrophobicChargeSurfaceName = PyMOLObjectNames["Ligands"][ChainID][LigandID][HydrophobicChargeSurfaceID]
  453             PML = PyMOLUtil.SetupPMLForHydrophobicAndChargeSurfaceView(HydrophobicChargeSurfaceName, PocketObjectName,  OptionsInfo["AtomTypesColorNames"]["HydrophobicAtomsColor"], OptionsInfo["AtomTypesColorNames"]["NegativelyChargedAtomsColor"], OptionsInfo["AtomTypesColorNames"]["PositivelyChargedAtomsColor"], OptionsInfo["AtomTypesColorNames"]["OtherAtomsColor"], Enable = False, DisplayAs = DisplayStyle)
  454             OutFH.write("\n%s\n" % PML)
  455             
  456             if ProcessingCavity:
  457                 OutFH.write("""cmd.set("surface_cavity_mode", %d, "%s")\n""" % (CavityMode, HydrophobicChargeSurfaceName))
  458             
  459             OutFH.write("""cmd.set("label_color", "%s", "%s")\n""" % (OptionsInfo["PocketLabelColor"], HydrophobicChargeSurfaceName))
  460             
  461             if GetPocketSurfaceChainElectrostaticsStatus(FileIndex, ChainID, LigandID):
  462                 # Set up a electrostatics surface...
  463                 ElectrostaticsGroupID = "%sElectrostaticsGroup" % (SurfacesSubGroupID)
  464                 ElectrostaticsGroupMembersID = "%sElectrostaticsGroupMembers" % (SurfacesSubGroupID)
  465                 ElectrostaticsGroupName = PyMOLObjectNames["Ligands"][ChainID][LigandID][ElectrostaticsGroupID]
  466                 ElectrostaticsGroupMembers = PyMOLObjectNames["Ligands"][ChainID][LigandID][ElectrostaticsGroupMembersID]
  467                 WriteSurfaceElectrostaticsView(SubGroupType, OutFH, PocketObjectName, ElectrostaticsGroupName, ElectrostaticsGroupMembers, DisplayAs = DisplayStyle, SurfaceCavityMode = CavityMode)
  468                 
  469             # Setup surfaces sub group...
  470             GenerateAndWritePMLForGroup(OutFH, PyMOLObjectNames["Ligands"][ChainID][LigandID][SurfacesSubGroupID], PyMOLObjectNames["Ligands"][ChainID][LigandID][SurfacesSubGroupMembersID], True, "open")
  471         
  472     # Setup surface group...
  473     GenerateAndWritePMLForGroup(OutFH, PyMOLObjectNames["Ligands"][ChainID][LigandID][SurfacesGroupID], PyMOLObjectNames["Ligands"][ChainID][LigandID][SurfacesGroupMembersID], True, "open")
  474     
  475     
  476 def WritePocketResidueTypesView(OutFH,  FileIndex, PyMOLObjectNames, ChainID, LigandID, PocketObjectID):
  477     """Write out PML for viewing residue types for a ligand pocket."""
  478     
  479     if not GetPocketResidueTypesStatus(FileIndex, ChainID, LigandID):
  480         return
  481 
  482     PocketObjectName = PyMOLObjectNames["Ligands"][ChainID][LigandID][PocketObjectID]
  483     
  484     ResiduesGroupID = "%sResiduesGroup" % (PocketObjectID)
  485     ResiduesGroupMembersID = "%sMembers" % (ResiduesGroupID)
  486     
  487     # Setup residue types objects...
  488     for SubGroupType in ["Aromatic", "Hydrophobic", "Polar", "Positively_Charged", "Negatively_Charged", "Other"]:
  489         SubGroupID = re.sub("_", "", SubGroupType)
  490         
  491         ResiduesSubGroupID = "%s%sGroup" % (ResiduesGroupID, SubGroupID)
  492         ResiduesSubMembersGroupID = "%sMembers" % (ResiduesSubGroupID)
  493     
  494         SubGroupMemberID = "%sResidues" % (ResiduesSubGroupID)
  495         ResiduesObjectName = PyMOLObjectNames["Ligands"][ChainID][LigandID][SubGroupMemberID]
  496 
  497         SubGroupMemberID = "%sSurface" % (ResiduesSubGroupID)
  498         ResiduesSurfaceObjectName = PyMOLObjectNames["Ligands"][ChainID][LigandID][SubGroupMemberID]
  499 
  500         ResiduesColor = OptionsInfo["ResidueTypesParams"][SubGroupType]["Color"] 
  501         ResiduesNames = OptionsInfo["ResidueTypesParams"][SubGroupType]["Residues"]
  502 
  503         NegateResidueNames = True if re.match("^Other$", SubGroupType, re.I) else False
  504         WriteResidueTypesResiduesAndSurfaceView(OutFH, PocketObjectName, ResiduesObjectName, ResiduesSurfaceObjectName, ResiduesColor, ResiduesNames, NegateResidueNames)
  505         
  506         # Setup residue type sub groups...
  507         GenerateAndWritePMLForGroup(OutFH, PyMOLObjectNames["Ligands"][ChainID][LigandID][ResiduesSubGroupID], PyMOLObjectNames["Ligands"][ChainID][LigandID][ResiduesSubMembersGroupID], True, "close")
  508     
  509     # Setup residue types group...
  510     GenerateAndWritePMLForGroup(OutFH, PyMOLObjectNames["Ligands"][ChainID][LigandID][ResiduesGroupID], PyMOLObjectNames["Ligands"][ChainID][LigandID][ResiduesGroupMembersID], False, "close")
  511 
  512 def WriteChainAloneChainSelectionsView(OutFH,  FileIndex, PyMOLObjectNames, ChainID):
  513     """Write out PML for viewing selections for a chain. """
  514 
  515     if not GetChainAloneContainsSelectionsStatus(FileIndex, ChainID):
  516         return
  517     
  518     ChainName = PyMOLObjectNames["Chains"][ChainID]["ChainAlone"]
  519     SelectionsGroupIDPrefix = "ChainAloneSelections"
  520     
  521     for Index in range(0, len(OptionsInfo["ChainSelectionsInfo"]["Names"])):
  522         SelectionName = OptionsInfo["ChainSelectionsInfo"]["Names"][Index]
  523         Selection = OptionsInfo["ChainSelectionsInfo"]["Selections"][Index]
  524         
  525         SelectionNameGroupID = SelectionName
  526         
  527         # Setup a selection object...
  528         SelectionObjectID = "%s%sSelection" % (SelectionsGroupIDPrefix, SelectionNameGroupID)
  529         SelectionObjectName = PyMOLObjectNames["Chains"][ChainID][SelectionObjectID]
  530         SelectionCmd = "(%s and (%s))" % (ChainName, Selection)
  531         PML = PyMOLUtil.SetupPMLForSelectionDisplayView(SelectionObjectName, SelectionCmd, OptionsInfo["SelectionsChainStyle"], Enable = True)
  532         OutFH.write("\n%s\n" % PML)
  533         
  534         if GetChainAloneContainsChainSelectionSurfacesStatus(FileIndex, ChainID):
  535             # Display style for selection objects in surfaces...
  536             DisplayStyle = "lines"
  537             
  538             # Setup a generic color surface...
  539             SurfaceID = "%s%s%sSurface" % (SelectionsGroupIDPrefix, SelectionNameGroupID, "Surface")
  540             SurfaceName = PyMOLObjectNames["Chains"][ChainID][SurfaceID]
  541             PML = PyMOLUtil.SetupPMLForSurfaceView(SurfaceName, SelectionObjectName, Enable = False, Color = OptionsInfo["SurfaceColor"], DisplayAs = DisplayStyle)
  542             OutFH.write("\n%s\n" % PML)
  543             
  544             if GetChainAloneSurfaceChainSelectionStatus(FileIndex, ChainID):
  545                 # Setup a surface colored by hydrphobicity...
  546                 HydrophobicSurfaceID = "%s%sSurfaceHydrophobicity" % (SelectionsGroupIDPrefix, SelectionNameGroupID)
  547                 HydrophobicSurfaceName = PyMOLObjectNames["Chains"][ChainID][HydrophobicSurfaceID]
  548                 PML = PyMOLUtil.SetupPMLForHydrophobicSurfaceView(HydrophobicSurfaceName, SelectionObjectName, ColorPalette = OptionsInfo["SurfaceColorPalette"], Enable = False, DisplayAs = DisplayStyle)
  549                 OutFH.write("\n%s\n" % PML)
  550                 
  551                 # Setup a surface colored by hydrphobicity and charge...
  552                 HydrophobicChargeSurfaceID = "%s%sSurfaceHydrophobicityCharge" % (SelectionsGroupIDPrefix, SelectionNameGroupID)
  553                 HydrophobicChargeSurfaceName = PyMOLObjectNames["Chains"][ChainID][HydrophobicChargeSurfaceID]
  554                 PML = PyMOLUtil.SetupPMLForHydrophobicAndChargeSurfaceView(HydrophobicChargeSurfaceName, SelectionObjectName,  OptionsInfo["AtomTypesColorNames"]["HydrophobicAtomsColor"], OptionsInfo["AtomTypesColorNames"]["NegativelyChargedAtomsColor"], OptionsInfo["AtomTypesColorNames"]["PositivelyChargedAtomsColor"], OptionsInfo["AtomTypesColorNames"]["OtherAtomsColor"], Enable = False, DisplayAs = DisplayStyle)
  555                 OutFH.write("\n%s\n" % PML)
  556 
  557             # Setup group for surfaces...
  558             SurfaceGroupID = "%s%sSurfaceGroup" % (SelectionsGroupIDPrefix, SelectionNameGroupID)
  559             SurfaceGroupMembersID = "%s%sSurfaceGroupMembers" % (SelectionsGroupIDPrefix, SelectionNameGroupID)
  560             GenerateAndWritePMLForGroup(OutFH, PyMOLObjectNames["Chains"][ChainID][SurfaceGroupID], PyMOLObjectNames["Chains"][ChainID][SurfaceGroupMembersID], True, "close")
  561 
  562         # Setup groups for named selections...
  563         SelectionsNameGroupID = "%s%sGroup" % (SelectionsGroupIDPrefix, SelectionNameGroupID)
  564         SelectionsNameGroupMembersID = "%s%sGroupMembers" % (SelectionsGroupIDPrefix, SelectionNameGroupID)
  565         GenerateAndWritePMLForGroup(OutFH, PyMOLObjectNames["Chains"][ChainID][SelectionsNameGroupID], PyMOLObjectNames["Chains"][ChainID][SelectionsNameGroupMembersID], True, "open")
  566 
  567     # Setup a group for selections...
  568     SelectionsGroupID = "%sGroup" % (SelectionsGroupIDPrefix)
  569     SelectionsGroupMembersID = "%sGroupMembers" % (SelectionsGroupIDPrefix)
  570     GenerateAndWritePMLForGroup(OutFH, PyMOLObjectNames["Chains"][ChainID][SelectionsGroupID], PyMOLObjectNames["Chains"][ChainID][SelectionsGroupMembersID], False, "close")
  571     
  572 def WriteChainAloneResidueTypesView(OutFH,  FileIndex, PyMOLObjectNames, ChainID):
  573     """Write out PML for viewing residue types for a chain. """
  574 
  575     if not GetChainAloneResidueTypesStatus(FileIndex, ChainID):
  576         return
  577     
  578     ChainName = PyMOLObjectNames["Chains"][ChainID]["ChainAlone"]
  579     
  580     # Setup residue types objects...
  581     ResiduesGroupIDPrefix = "ChainAloneResidues"
  582     for SubGroupType in ["Aromatic", "Hydrophobic", "Polar", "Positively_Charged", "Negatively_Charged", "Other"]:
  583         SubGroupID = re.sub("_", "", SubGroupType)
  584 
  585         ResiduesObjectID = "%s%sResidues" % (ResiduesGroupIDPrefix, SubGroupID)
  586         ResiduesObjectName = PyMOLObjectNames["Chains"][ChainID][ResiduesObjectID]
  587 
  588         ResiduesSurfaceObjectID = "%s%sSurface" % (ResiduesGroupIDPrefix, SubGroupID)
  589         ResiduesSurfaceObjectName = PyMOLObjectNames["Chains"][ChainID][ResiduesSurfaceObjectID]
  590 
  591         ResiduesColor = OptionsInfo["ResidueTypesParams"][SubGroupType]["Color"] 
  592         ResiduesNames = OptionsInfo["ResidueTypesParams"][SubGroupType]["Residues"]
  593 
  594         NegateResidueNames = True if re.match("^Other$", SubGroupType, re.I) else False
  595         WriteResidueTypesResiduesAndSurfaceView(OutFH, ChainName, ResiduesObjectName, ResiduesSurfaceObjectName, ResiduesColor, ResiduesNames, NegateResidueNames)
  596 
  597         # Setup sub groups for residue types..
  598         ResiduesSubGroupID = "%s%sGroup" % (ResiduesGroupIDPrefix, SubGroupID)
  599         ResiduesSubGroupMembersID = "%s%sGroupMembers" % (ResiduesGroupIDPrefix, SubGroupID)
  600 
  601         # Setup residue type sub groups...
  602         GenerateAndWritePMLForGroup(OutFH, PyMOLObjectNames["Chains"][ChainID][ResiduesSubGroupID], PyMOLObjectNames["Chains"][ChainID][ResiduesSubGroupMembersID], True, "close")
  603         
  604     # Setup residue types group...
  605     GenerateAndWritePMLForGroup(OutFH, PyMOLObjectNames["Chains"][ChainID]["ChainAloneResiduesGroup"], PyMOLObjectNames["Chains"][ChainID]["ChainAloneResiduesGroupMembers"], False, "close")
  606 
  607 def WriteResidueTypesResiduesAndSurfaceView(OutFH, SelectionObjectName, Name, SurfaceName, ResiduesColor, ResiduesNames, NegateResidueNames):
  608     """Write residue types residues and surface view. """
  609 
  610     ResidueNamesSelection = "+".join(ResiduesNames)
  611     if NegateResidueNames:
  612         Selection = "%s and (not resn %s)" % (SelectionObjectName, ResidueNamesSelection)
  613     else:
  614         Selection = "%s and (resn %s)" % (SelectionObjectName, ResidueNamesSelection)
  615 
  616     # Setup residues...
  617     PML = PyMOLUtil.SetupPMLForSelectionDisplayView(Name, Selection, "lines", ResiduesColor, True)
  618     OutFH.write("\n%s\n" % PML)
  619 
  620     # Setup surface...
  621     PML = PyMOLUtil.SetupPMLForSelectionDisplayView(SurfaceName, Selection, "surface", ResiduesColor, True)
  622     OutFH.write("\n%s\n" % PML)
  623     
  624 def WriteSurfaceElectrostaticsView(Mode, OutFH, SelectionObjectName, ElectrostaticsGroupName, ElectrostaticsGroupMembers, DisplayAs = None, SurfaceCavityMode = 2):
  625     """Write out PML for viewing surface electrostatics. """
  626 
  627     if len(ElectrostaticsGroupMembers) == 5:
  628         Name, ContactPotentialName, MapName, LegendName, VolumeName = ElectrostaticsGroupMembers
  629     else:
  630         Name, ContactPotentialName, MapName, LegendName = ElectrostaticsGroupMembers
  631         VolumeName = None
  632 
  633     PMLCmds = []
  634 
  635     # Setup chain...
  636     PMLCmds.append("""cmd.create("%s", "(%s)")""" % (Name, SelectionObjectName))
  637 
  638     # Setup vacuum electrostatics surface along with associated objects...
  639     PMLCmds.append("""util.protein_vacuum_esp("%s", mode=2, quiet=0, _self=cmd)""" % (Name))
  640     PMLCmds.append("""cmd.set_name("%s_e_chg", "%s")""" % (Name, ContactPotentialName))
  641     
  642     if DisplayAs is not None:
  643         PMLCmds.append("""cmd.show("%s", "(%s)")""" % (DisplayAs, ContactPotentialName))
  644 
  645     if re.match("^Cavity$", Mode, re.I):
  646         if SurfaceCavityMode is not None:
  647             PMLCmds.append("""cmd.set("surface_cavity_mode", %d, "%s")\n""" % (SurfaceCavityMode, ContactPotentialName))
  648         
  649     PMLCmds.append(PyMOLUtil.SetupPMLForEnableDisable(ContactPotentialName, Enable = True))
  650     
  651     PMLCmds.append("""cmd.set_name("%s_e_map", "%s")""" % (Name, MapName))
  652     PMLCmds.append(PyMOLUtil.SetupPMLForEnableDisable(MapName, Enable = False))
  653     
  654     PMLCmds.append("""cmd.set_name("%s_e_pot", "%s")""" % (Name, LegendName))
  655     PMLCmds.append(PyMOLUtil.SetupPMLForEnableDisable(LegendName, Enable = False))
  656 
  657     if VolumeName is not None:
  658         PMLCmds.append("""cmd.volume("%s", "%s", "%s", "(%s)")""" % (VolumeName, MapName, "esp", Name))
  659         PMLCmds.append(PyMOLUtil.SetupPMLForEnableDisable(VolumeName, Enable = False))
  660     
  661     # Delete name and take it out from the group membership. It is
  662     # is already part of ContactPotential object.
  663     PMLCmds.append("""cmd.delete("%s")""" % (Name))
  664     ElectrostaticsGroupMembers.pop(0)
  665     
  666     PML = "\n".join(PMLCmds)
  667     
  668     OutFH.write("\n%s\n" % PML)
  669     
  670     # Setup group...
  671     GenerateAndWritePMLForGroup(OutFH, ElectrostaticsGroupName, ElectrostaticsGroupMembers, False, "close")
  672 
  673 def GenerateAndWritePMLForGroup(OutFH, GroupName, GroupMembers, Enable = False, Action = "close"):
  674     """Generate and write PML for group. """
  675     
  676     PML = PyMOLUtil.SetupPMLForGroup(GroupName, GroupMembers, Enable, Action)
  677     OutFH.write("""\n""\n"Setting up group %s..."\n""\n""" % GroupName)
  678     OutFH.write("%s\n" % PML)
  679 
  680 def GeneratePyMOLSessionFile():
  681     """Generate PME file from PML file. """
  682 
  683     PSEOutfile = OptionsInfo["PSEOutfile"]
  684     PMLOutfile = OptionsInfo["PMLOutfile"]
  685     
  686     MiscUtil.PrintInfo("\nGenerating file %s..." % PSEOutfile)
  687     
  688     PyMOLUtil.ConvertPMLFileToPSEFile(PMLOutfile, PSEOutfile)
  689     
  690     if not os.path.exists(PSEOutfile):
  691         MiscUtil.PrintWarning("Failed to generate PSE file, %s..." % (PSEOutfile))
  692     
  693     if not OptionsInfo["PMLOut"]:
  694         MiscUtil.PrintInfo("Deleting file %s..." % PMLOutfile)
  695         os.remove(PMLOutfile)
  696 
  697 def DeleteEmptyPyMOLObjects(OutFH, FileIndex, PyMOLObjectNames):
  698     """Delete empty PyMOL objects. """
  699     
  700     if OptionsInfo["AllowEmptyObjects"]:
  701         return
  702     
  703     SpecifiedChainsAndLigandsInfo = OptionsInfo["InfilesInfo"]["SpecifiedChainsAndLigandsInfo"][FileIndex]
  704     for ChainID in SpecifiedChainsAndLigandsInfo["ChainIDs"]:
  705         OutFH.write("""\n""\n"Checking and deleting empty objects for chain %s..."\n""\n""" % (ChainID))
  706         
  707         # Delete any chain level objects...
  708         WritePMLToCheckAndDeleteEmptyObjects(OutFH, PyMOLObjectNames["Chains"][ChainID]["Solvent"])
  709         WritePMLToCheckAndDeleteEmptyObjects(OutFH, PyMOLObjectNames["Chains"][ChainID]["Inorganic"])
  710 
  711         # Delete chain selection objects...
  712         DeleteEmptyChainSelectionsObjects(OutFH, FileIndex, PyMOLObjectNames, ChainID)
  713         
  714         # Delete residue type objects...
  715         DeleteEmptyChainResidueTypesObjects(OutFH, FileIndex, PyMOLObjectNames, ChainID)
  716         
  717         for LigandID in SpecifiedChainsAndLigandsInfo["LigandIDs"][ChainID]:
  718             # Delete ligand level objects...
  719             for GroupID in ["Pocket", "PocketSolvent", "PocketInorganic"]:
  720                 GroupNameID = "%sGroup" % (GroupID)
  721                 GroupName = PyMOLObjectNames["Ligands"][ChainID][LigandID][GroupNameID]
  722 
  723                 GroupTypeObjectID = "%s" % (GroupID)
  724                 GroupTypeObjectName = PyMOLObjectNames["Ligands"][ChainID][LigandID][GroupTypeObjectID]
  725                 
  726                 WritePMLToCheckAndDeleteEmptyObjects(OutFH, GroupTypeObjectName, GroupName)
  727                 
  728                 if re.match("^Pocket$", GroupID, re.I):
  729                     DeleteEmptyPocketResidueTypesObjects(OutFH, FileIndex, PyMOLObjectNames, ChainID, LigandID, GroupTypeObjectID)
  730 
  731 def DeleteEmptyChainSelectionsObjects(OutFH, FileIndex, PyMOLObjectNames, ChainID):
  732     """Delete empty chain selection objects. """
  733 
  734     if not GetChainAloneContainsSelectionsStatus(FileIndex, ChainID):
  735         return
  736     
  737     SelectionsGroupIDPrefix = "ChainAloneSelections"
  738 
  739     for SelectionName in OptionsInfo["ChainSelectionsInfo"]["Names"]:
  740         SelectionNameGroupID = SelectionName
  741         
  742         # Delete surface objects and surface group...
  743         SurfaceGroupID = "%s%sSurfaceGroup" % (SelectionsGroupIDPrefix, SelectionNameGroupID)
  744         SurfaceGroupMembersID = "%s%sSurfaceGroupMembers" % (SelectionsGroupIDPrefix, SelectionNameGroupID)
  745         WritePMLToCheckAndDeleteEmptyObjects(OutFH, ",".join(PyMOLObjectNames["Chains"][ChainID][SurfaceGroupMembersID]), PyMOLObjectNames["Chains"][ChainID][SurfaceGroupID])
  746         
  747         # Delete Selection object and selection name group...
  748         SelectionObjectID = "%s%sSelection" % (SelectionsGroupIDPrefix, SelectionNameGroupID)
  749         SelectionsGroupID = "%s%sGroup" % (SelectionsGroupIDPrefix, SelectionNameGroupID)
  750         WritePMLToCheckAndDeleteEmptyObjects(OutFH, PyMOLObjectNames["Chains"][ChainID][SelectionObjectID], PyMOLObjectNames["Chains"][ChainID][SelectionsGroupID])
  751 
  752 def DeleteEmptyChainResidueTypesObjects(OutFH, FileIndex, PyMOLObjectNames, ChainID):
  753     """Delete empty chain residue objects. """
  754     
  755     if not GetChainAloneResidueTypesStatus(FileIndex, ChainID):
  756         return
  757     
  758     ResiduesGroupIDPrefix = "ChainAloneResidues"
  759     for GroupType in ["Aromatic", "Hydrophobic", "Polar", "Positively_Charged", "Negatively_Charged", "Other"]:
  760         GroupID = re.sub("_", "", GroupType)
  761         
  762         ResiduesGroupID = "%s%sGroup" % (ResiduesGroupIDPrefix, GroupID)
  763         GroupName = PyMOLObjectNames["Chains"][ChainID][ResiduesGroupID]
  764         
  765         GroupObjectNamesList = []
  766         
  767         ResiduesObjectID = "%s%sResidues" % (ResiduesGroupIDPrefix, GroupID)
  768         ResiduesObjectName = PyMOLObjectNames["Chains"][ChainID][ResiduesObjectID]
  769         GroupObjectNamesList.append(ResiduesObjectName)
  770         
  771         ResiduesSurfaceObjectID = "%s%sSurface" % (ResiduesGroupIDPrefix, GroupID)
  772         ResiduesSurfaceObjectName = PyMOLObjectNames["Chains"][ChainID][ResiduesSurfaceObjectID]
  773         GroupObjectNamesList.append(ResiduesSurfaceObjectName)
  774         
  775         GroupObjectNames = ",".join(GroupObjectNamesList)
  776         WritePMLToCheckAndDeleteEmptyObjects(OutFH, GroupObjectNames, GroupName)
  777 
  778 def DeleteEmptyPocketResidueTypesObjects(OutFH, FileIndex, PyMOLObjectNames, ChainID, LigandID, PocketObjectID):
  779     """Delete empty chain residue objects. """
  780     
  781     if not GetPocketResidueTypesStatus(FileIndex, ChainID, LigandID):
  782         return
  783     
  784     ResiduesGroupID = "%sResiduesGroup" % (PocketObjectID)
  785     ResiduesGroupMembersID = "%sMembers" % (ResiduesGroupID)
  786     
  787     for SubGroupType in ["Aromatic", "Hydrophobic", "Polar", "Positively_Charged", "Negatively_Charged", "Other"]:
  788         SubGroupID = re.sub("_", "", SubGroupType)
  789         
  790         ResiduesSubGroupID = "%s%sGroup" % (ResiduesGroupID, SubGroupID)
  791         ResiduesSubMembersGroupID = "%sMembers" % (ResiduesSubGroupID)
  792 
  793         SubGroupName = PyMOLObjectNames["Ligands"][ChainID][LigandID][ResiduesSubGroupID]
  794         SubGroupObjectNames = ",".join(PyMOLObjectNames["Ligands"][ChainID][LigandID][ResiduesSubMembersGroupID])
  795         
  796         WritePMLToCheckAndDeleteEmptyObjects(OutFH, SubGroupObjectNames, SubGroupName)
  797 
  798 def WritePMLToCheckAndDeleteEmptyObjects(OutFH, ObjectName, ParentObjectName = None):
  799     """Write PML to check and delete empty PyMOL objects. """
  800     
  801     if ParentObjectName is None:
  802         PML = """CheckAndDeleteEmptyObjects("%s")""" % (ObjectName)
  803     else:
  804         PML = """CheckAndDeleteEmptyObjects("%s", "%s")""" % (ObjectName, ParentObjectName)
  805     
  806     OutFH.write("%s\n" % PML)
  807     
  808 def SetupPyMOLObjectNames(FileIndex):
  809     """Setup hierarchy of PyMOL groups and objects for ligand centric views of
  810     chains and ligands present in input file.
  811     """
  812 
  813     PyMOLObjectNames = {}
  814     PyMOLObjectNames["Chains"] = {}
  815     PyMOLObjectNames["Ligands"] = {}
  816 
  817     # Setup groups and objects for complex...
  818     SetupPyMOLObjectNamesForComplex(FileIndex, PyMOLObjectNames)
  819     
  820     # Setup groups and objects for chain...
  821     SpecifiedChainsAndLigandsInfo = OptionsInfo["InfilesInfo"]["SpecifiedChainsAndLigandsInfo"][FileIndex]
  822     for ChainID in SpecifiedChainsAndLigandsInfo["ChainIDs"]:
  823         SetupPyMOLObjectNamesForChain(FileIndex, PyMOLObjectNames, ChainID)
  824         
  825         # Setup groups and objects for ligand...
  826         for LigandID in SpecifiedChainsAndLigandsInfo["LigandIDs"][ChainID]:
  827             SetupPyMOLObjectNamesForLigand(FileIndex, PyMOLObjectNames, ChainID, LigandID)
  828 
  829     return PyMOLObjectNames
  830 
  831 def SetupPyMOLObjectNamesForComplex(FileIndex, PyMOLObjectNames):
  832     """Setup groups and objects for complex. """
  833     
  834     PDBFileRoot = OptionsInfo["InfilesInfo"]["InfilesRoots"][FileIndex]
  835     
  836     PDBGroupName = "%s" % PDBFileRoot
  837     PyMOLObjectNames["PDBGroup"] = PDBGroupName
  838     PyMOLObjectNames["PDBGroupMembers"] = []
  839 
  840     ComplexGroupName = "%s.Complex" % PyMOLObjectNames["PDBGroup"]
  841     PyMOLObjectNames["ComplexGroup"] = ComplexGroupName
  842     PyMOLObjectNames["PDBGroupMembers"].append(ComplexGroupName)
  843     
  844     PyMOLObjectNames["Complex"] = "%s.Complex" % ComplexGroupName
  845     if OptionsInfo["SurfaceComplex"]:
  846         PyMOLObjectNames["ComplexHydrophobicSurface"] = "%s.Surface" % ComplexGroupName
  847 
  848     PyMOLObjectNames["ComplexGroupMembers"] = []
  849     PyMOLObjectNames["ComplexGroupMembers"].append(PyMOLObjectNames["Complex"])
  850     if OptionsInfo["SurfaceComplex"]:
  851         PyMOLObjectNames["ComplexGroupMembers"].append(PyMOLObjectNames["ComplexHydrophobicSurface"])
  852     
  853 def SetupPyMOLObjectNamesForChain(FileIndex, PyMOLObjectNames, ChainID):
  854     """Setup groups and objects for chain."""
  855     
  856     PDBGroupName = PyMOLObjectNames["PDBGroup"]
  857     
  858     PyMOLObjectNames["Chains"][ChainID] = {}
  859     PyMOLObjectNames["Ligands"][ChainID] = {}
  860     
  861     # Set up chain group and chain objects...
  862     ChainGroupName = "%s.Chain%s" % (PDBGroupName, ChainID)
  863     PyMOLObjectNames["Chains"][ChainID]["ChainGroup"] = ChainGroupName
  864     PyMOLObjectNames["PDBGroupMembers"].append(ChainGroupName)
  865     PyMOLObjectNames["Chains"][ChainID]["ChainGroupMembers"] = []
  866     
  867     # Setup chain complex group and objects...
  868     ChainComplexGroupName = "%s.Complex" % (ChainGroupName)
  869     PyMOLObjectNames["Chains"][ChainID]["ChainComplexGroup"] = ChainComplexGroupName
  870     PyMOLObjectNames["Chains"][ChainID]["ChainGroupMembers"].append(ChainComplexGroupName)
  871 
  872     PyMOLObjectNames["Chains"][ChainID]["ChainComplexGroupMembers"] = []
  873     
  874     Name = "%s.Complex" % (ChainComplexGroupName)
  875     PyMOLObjectNames["Chains"][ChainID]["ChainComplex"] = Name
  876     PyMOLObjectNames["Chains"][ChainID]["ChainComplexGroupMembers"].append(Name)
  877     
  878     if OptionsInfo["SurfaceChainComplex"]:
  879         Name = "%s.Surface" % (ChainComplexGroupName)
  880         PyMOLObjectNames["Chains"][ChainID]["ChainComplexHydrophobicSurface"] = Name
  881         PyMOLObjectNames["Chains"][ChainID]["ChainComplexGroupMembers"].append(Name)
  882 
  883     # Setup up a group for individual chains...
  884     ChainAloneGroupName = "%s.Chain" % (ChainGroupName)
  885     PyMOLObjectNames["Chains"][ChainID]["ChainAloneGroup"] = ChainAloneGroupName
  886     PyMOLObjectNames["Chains"][ChainID]["ChainGroupMembers"].append(ChainAloneGroupName)
  887         
  888     PyMOLObjectNames["Chains"][ChainID]["ChainAloneGroupMembers"] = []
  889         
  890     Name = "%s.Chain" % (ChainAloneGroupName)
  891     PyMOLObjectNames["Chains"][ChainID]["ChainAlone"] = Name
  892     PyMOLObjectNames["Chains"][ChainID]["ChainAloneGroupMembers"].append(Name)
  893 
  894     if GetChainAloneContainsSelectionsStatus(FileIndex, ChainID):
  895         # Setup selections group and its subgroups..
  896         SelectionsGroupName = "%s.Selections" % (ChainAloneGroupName)
  897         
  898         SelectionsGroupIDPrefix = "ChainAloneSelections"
  899         SelectionsGroupID = "%sGroup" % SelectionsGroupIDPrefix
  900         
  901         # Add selections group to chain alone group...
  902         PyMOLObjectNames["Chains"][ChainID][SelectionsGroupID] = SelectionsGroupName
  903         PyMOLObjectNames["Chains"][ChainID]["ChainAloneGroupMembers"].append(SelectionsGroupName)
  904         
  905         # Initialize selections group members...
  906         SelectionsGroupMembersID = "%sGroupMembers" % SelectionsGroupIDPrefix
  907         PyMOLObjectNames["Chains"][ChainID][SelectionsGroupMembersID] = []
  908 
  909         # Setup selections name sub group and its members...
  910         for SelectionName in OptionsInfo["ChainSelectionsInfo"]["Names"]:
  911             SelectionNameGroupID = SelectionName
  912             
  913             SelectionsNameGroupName = "%s.%s" % (SelectionsGroupName, SelectionName)
  914             SelectionsNameGroupID = "%s%sGroup" % (SelectionsGroupIDPrefix, SelectionNameGroupID)
  915 
  916             # Add selections name sub group to selections group...
  917             PyMOLObjectNames["Chains"][ChainID][SelectionsNameGroupID] = SelectionsNameGroupName
  918             PyMOLObjectNames["Chains"][ChainID][SelectionsGroupMembersID].append(SelectionsNameGroupName)
  919             
  920             # Initialize selections names sub group members...
  921             SelectionsNameGroupMembersID = "%s%sGroupMembers" % (SelectionsGroupIDPrefix, SelectionNameGroupID)
  922             PyMOLObjectNames["Chains"][ChainID][SelectionsNameGroupMembersID] = []
  923 
  924             # Add selection member to selections name group...
  925             SubGroupMemberName = "%s.Selection" % (SelectionsNameGroupName)
  926             SubGroupMemberID = "%s%sSelection" % (SelectionsGroupIDPrefix, SelectionNameGroupID)
  927             
  928             PyMOLObjectNames["Chains"][ChainID][SubGroupMemberID] = SubGroupMemberName
  929             PyMOLObjectNames["Chains"][ChainID][SelectionsNameGroupMembersID].append(SubGroupMemberName)
  930             
  931             if GetChainAloneContainsChainSelectionSurfacesStatus(FileIndex, ChainID):
  932                 # Setup a surface sub group and add it to selections name group...
  933                 
  934                 SelectionsNameSurfaceGroupName = "%s.Surface" % (SelectionsNameGroupName)
  935                 SelectionsNameSurfaceGroupID = "%s%sSurfaceGroup" % (SelectionsGroupIDPrefix, SelectionNameGroupID)
  936 
  937                 # Add selection surface group to selectio name group...
  938                 PyMOLObjectNames["Chains"][ChainID][SelectionsNameSurfaceGroupID] = SelectionsNameSurfaceGroupName
  939                 PyMOLObjectNames["Chains"][ChainID][SelectionsNameGroupMembersID].append(SelectionsNameSurfaceGroupName)
  940 
  941                 # Initialize surface names sub group members...
  942                 SelectionsNameSurfaceGroupMembersID = "%s%sSurfaceGroupMembers" % (SelectionsGroupIDPrefix, SelectionNameGroupID)
  943                 PyMOLObjectNames["Chains"][ChainID][SelectionsNameSurfaceGroupMembersID] = []
  944                 
  945                 # Setup a generic color surface...
  946                 SubGroupMemberName = "%s.Surface" % (SelectionsNameSurfaceGroupName)
  947                 SubGroupMemberID = "%s%s%sSurface" % (SelectionsGroupIDPrefix, SelectionNameGroupID, "Surface")
  948                 PyMOLObjectNames["Chains"][ChainID][SubGroupMemberID] = SubGroupMemberName
  949                 PyMOLObjectNames["Chains"][ChainID][SelectionsNameSurfaceGroupMembersID].append(SubGroupMemberName)
  950                 
  951                 if GetChainAloneSurfaceChainSelectionStatus(FileIndex, ChainID):
  952                     # Setup surfaces...
  953                     for MemberType in ["Hydrophobicity", "Hydrophobicity_Charge"]:
  954                         MemberID = re.sub("_", "", MemberType)
  955                         
  956                         SubGroupMemberName = "%s.%s" % (SelectionsNameSurfaceGroupName, MemberType)
  957                         SubGroupMemberID = "%s%s%s%s" % (SelectionsGroupIDPrefix, SelectionNameGroupID, "Surface", MemberID)
  958                         
  959                         PyMOLObjectNames["Chains"][ChainID][SubGroupMemberID] = SubGroupMemberName
  960                         PyMOLObjectNames["Chains"][ChainID][SelectionsNameSurfaceGroupMembersID].append(SubGroupMemberName)
  961 
  962     if GetChainAloneResidueTypesStatus(FileIndex, ChainID):
  963         # Setup residue type group and its subgroups...
  964         ResiduesGroupName = "%s.Residues" % (ChainAloneGroupName)
  965         
  966         ResiduesGroupIDPrefix = "ChainAloneResidues"
  967         ResiduesGroupID = "%sGroup" % ResiduesGroupIDPrefix
  968 
  969         # Add residue group to chain alone group...
  970         PyMOLObjectNames["Chains"][ChainID][ResiduesGroupID] = ResiduesGroupName
  971         PyMOLObjectNames["Chains"][ChainID]["ChainAloneGroupMembers"].append(ResiduesGroupName)
  972         
  973         # Initialize residue group members...
  974         ResiduesGroupMembersID = "%sGroupMembers" % ResiduesGroupIDPrefix
  975         PyMOLObjectNames["Chains"][ChainID][ResiduesGroupMembersID] = []
  976 
  977         # Setup residues sub groups and its members...
  978         for SubGroupType in ["Aromatic", "Hydrophobic", "Polar", "Positively_Charged", "Negatively_Charged", "Other"]:
  979             SubGroupID = re.sub("_", "", SubGroupType)
  980 
  981             ResiduesSubGroupName = "%s.%s" % (ResiduesGroupName, SubGroupType)
  982             ResiduesSubGroupID = "%s%sGroup" % (ResiduesGroupIDPrefix, SubGroupID)
  983 
  984             # Add sub group to residues group...
  985             PyMOLObjectNames["Chains"][ChainID][ResiduesSubGroupID] = ResiduesSubGroupName
  986             PyMOLObjectNames["Chains"][ChainID][ResiduesGroupMembersID].append(ResiduesSubGroupName)
  987 
  988             # Initialize sub group members...
  989             ResiduesSubGroupMembersID = "%s%sGroupMembers" % (ResiduesGroupIDPrefix, SubGroupID)
  990             PyMOLObjectNames["Chains"][ChainID][ResiduesSubGroupMembersID] = []
  991             
  992             # Add sub group members to subgroup...
  993             for MemberType in ["Residues", "Surface"]:
  994                 MemberID = re.sub("_", "", MemberType)
  995 
  996                 SubGroupMemberName = "%s.%s" % (ResiduesSubGroupName, MemberType)
  997                 SubGroupMemberID = "%s%s%s" % (ResiduesGroupIDPrefix, SubGroupID, MemberID)
  998                 
  999                 PyMOLObjectNames["Chains"][ChainID][SubGroupMemberID] = SubGroupMemberName
 1000                 PyMOLObjectNames["Chains"][ChainID][ResiduesSubGroupMembersID].append(SubGroupMemberName)
 1001 
 1002     if GetChainAloneContainsSurfacesStatus(FileIndex, ChainID):
 1003         # Setup a surface group and add it to chain alone group...
 1004         SurfaceGroupName = "%s.Surface" % (ChainAloneGroupName)
 1005         PyMOLObjectNames["Chains"][ChainID]["ChainAloneSurfaceGroup"] = SurfaceGroupName
 1006         PyMOLObjectNames["Chains"][ChainID]["ChainAloneGroupMembers"].append(SurfaceGroupName)
 1007         
 1008         PyMOLObjectNames["Chains"][ChainID]["ChainAloneSurfaceGroupMembers"] = []
 1009 
 1010         # Setup a generic color surface...
 1011         Name = "%s.Surface" % (SurfaceGroupName)
 1012         PyMOLObjectNames["Chains"][ChainID]["ChainAloneSurface"] = Name
 1013         PyMOLObjectNames["Chains"][ChainID]["ChainAloneSurfaceGroupMembers"].append(Name)
 1014         
 1015         if GetChainAloneSurfaceChainStatus(FileIndex, ChainID):
 1016             # Setup hydrophobicity surface...
 1017             Name = "%s.Hydrophobicity" % (SurfaceGroupName)
 1018             PyMOLObjectNames["Chains"][ChainID]["ChainAloneHydrophobicSurface"] = Name
 1019             PyMOLObjectNames["Chains"][ChainID]["ChainAloneSurfaceGroupMembers"].append(Name)
 1020             
 1021             # Setup hydrophobicity and charge surface...
 1022             Name = "%s.Hydrophobicity_Charge" % (SurfaceGroupName)
 1023             PyMOLObjectNames["Chains"][ChainID]["ChainAloneHydrophobicChargeSurface"] = Name
 1024             PyMOLObjectNames["Chains"][ChainID]["ChainAloneSurfaceGroupMembers"].append(Name)
 1025     
 1026         if GetChainAloneSurfaceChainElectrostaticsStatus(FileIndex, ChainID):
 1027             # Setup electrostatics group...
 1028             GroupName = "%s.Vacuum_Electrostatics" % (SurfaceGroupName)
 1029             PyMOLObjectNames["Chains"][ChainID]["ChainAloneElectrostaticsGroup"] = GroupName
 1030             PyMOLObjectNames["Chains"][ChainID]["ChainAloneSurfaceGroupMembers"].append(GroupName)
 1031             
 1032             # Setup electrostatics group members...
 1033             PyMOLObjectNames["Chains"][ChainID]["ChainAloneElectrostaticsGroupMembers"] = []
 1034             
 1035             for MemberType in ["Chain", "Contact_Potential", "Map", "Legend", "Volume"]:
 1036                 MemberID = re.sub("_", "", MemberType)
 1037                 
 1038                 Name = "%s.%s" % (GroupName, MemberType)
 1039                 NameID = "ChainAloneElectrostaticsSurface%s" % MemberID
 1040                 
 1041                 PyMOLObjectNames["Chains"][ChainID][NameID] = Name
 1042                 PyMOLObjectNames["Chains"][ChainID]["ChainAloneElectrostaticsGroupMembers"].append(Name)
 1043             
 1044     # Setup solvent and inorganic objects for chain...
 1045     for NameID in ["Solvent", "Inorganic"]:
 1046         Name = "%s.%s" % (ChainGroupName, NameID)
 1047         PyMOLObjectNames["Chains"][ChainID][NameID] = Name
 1048         PyMOLObjectNames["Chains"][ChainID]["ChainGroupMembers"].append(Name)
 1049 
 1050 def SetupPyMOLObjectNamesForLigand(FileIndex, PyMOLObjectNames, ChainID, LigandID):
 1051     """Stetup groups and objects for ligand."""
 1052 
 1053     PyMOLObjectNames["Ligands"][ChainID][LigandID] = {}
 1054     
 1055     ChainGroupName = PyMOLObjectNames["Chains"][ChainID]["ChainGroup"]
 1056     
 1057     # Setup a chain level ligand group...
 1058     ChainLigandGroupName = "%s.Ligand%s" % (ChainGroupName, LigandID)
 1059     PyMOLObjectNames["Ligands"][ChainID][LigandID]["ChainLigandGroup"] = ChainLigandGroupName
 1060     PyMOLObjectNames["Chains"][ChainID]["ChainGroupMembers"].append(ChainLigandGroupName)
 1061     
 1062     PyMOLObjectNames["Ligands"][ChainID][LigandID]["ChainLigandGroupMembers"] = []
 1063 
 1064     # Set up groups and objects for a specific ligand group...
 1065     for GroupType in ["Ligand", "Pocket", "Pocket_Solvent", "Pocket_Inorganic"]:
 1066         GroupID = re.sub("_", "", GroupType)
 1067         GroupName = "%s.%s" % (ChainLigandGroupName, GroupType)
 1068                 
 1069         GroupNameID = "%sGroup" % (GroupID)
 1070         GroupMembersID = "%sGroupMembers" % (GroupID)
 1071         
 1072         PyMOLObjectNames["Ligands"][ChainID][LigandID][GroupNameID] = GroupName
 1073         PyMOLObjectNames["Ligands"][ChainID][LigandID]["ChainLigandGroupMembers"].append(GroupName)
 1074         
 1075         GroupTypeObjectName = "%s.%s" % (GroupName, GroupType)
 1076         GroupTypeObjectID = "%s" % (GroupID)
 1077         PyMOLObjectNames["Ligands"][ChainID][LigandID][GroupTypeObjectID] = GroupTypeObjectName
 1078         
 1079         PyMOLObjectNames["Ligands"][ChainID][LigandID][GroupMembersID] = []
 1080         PyMOLObjectNames["Ligands"][ChainID][LigandID][GroupMembersID].append(GroupTypeObjectName)
 1081         
 1082         if re.match("^Ligand$", GroupType, re.I):
 1083             # Only need to add ball and stick...
 1084             BallAndStickName = "%s.BallAndStick" % (GroupName)
 1085             BallAndStickID = "%sBallAndStick" % (GroupID)
 1086             PyMOLObjectNames["Ligands"][ChainID][LigandID][BallAndStickID] = BallAndStickName
 1087             PyMOLObjectNames["Ligands"][ChainID][LigandID][GroupMembersID].append(BallAndStickName)
 1088         
 1089         if re.match("^(Pocket|Pocket_Solvent|Pocket_Inorganic)$", GroupType, re.I):
 1090             PolarContactsName = "%s.Polar_Contacts" % (GroupName)
 1091             PolarContactsID = "%sPolarContacts" % (GroupID)
 1092             PyMOLObjectNames["Ligands"][ChainID][LigandID][PolarContactsID] = PolarContactsName
 1093             PyMOLObjectNames["Ligands"][ChainID][LigandID][GroupMembersID].append(PolarContactsName)
 1094                 
 1095         if re.match("^Pocket$", GroupType, re.I):
 1096             HydrophobicContactsName = "%s.Hydrophobic_Contacts" % (GroupName)
 1097             HydrophobicContactsID = "%sHydrophobicContacts" % (GroupID)
 1098             PyMOLObjectNames["Ligands"][ChainID][LigandID][HydrophobicContactsID] = HydrophobicContactsName
 1099             PyMOLObjectNames["Ligands"][ChainID][LigandID][GroupMembersID].append(HydrophobicContactsName)
 1100             
 1101             if GetPocketResidueTypesStatus(FileIndex, ChainID, LigandID):
 1102                 # Setup residue type group and add to pocket group...
 1103                 ResiduesGroupName = "%s.Residues" % (GroupName)
 1104                 ResiduesGroupID = "%sResiduesGroup" % (GroupID)
 1105                 ResiduesGroupMembersID = "%sMembers" % (ResiduesGroupID)
 1106 
 1107                 PyMOLObjectNames["Ligands"][ChainID][LigandID][ResiduesGroupID] = ResiduesGroupName
 1108                 PyMOLObjectNames["Ligands"][ChainID][LigandID][GroupMembersID].append(ResiduesGroupName)
 1109                 PyMOLObjectNames["Ligands"][ChainID][LigandID][ResiduesGroupMembersID] = []
 1110                 
 1111                 # Setup residue group subgroup and its members...
 1112                 for SubGroupType in ["Aromatic", "Hydrophobic", "Polar", "Positively_Charged", "Negatively_Charged", "Other"]:
 1113                     SubGroupID = re.sub("_", "", SubGroupType)
 1114                     ResiduesSubGroupName = "%s.%s" % (ResiduesGroupName, SubGroupType)
 1115                     ResiduesSubGroupID = "%s%sGroup" % (ResiduesGroupID, SubGroupID)
 1116                     ResiduesSubMembersGroupID = "%sMembers" % (ResiduesSubGroupID)
 1117                     
 1118                     # Add sub group to residues group...
 1119                     PyMOLObjectNames["Ligands"][ChainID][LigandID][ResiduesSubGroupID] = ResiduesSubGroupName
 1120                     PyMOLObjectNames["Ligands"][ChainID][LigandID][ResiduesGroupMembersID].append(ResiduesSubGroupName)
 1121                     PyMOLObjectNames["Ligands"][ChainID][LigandID][ResiduesSubMembersGroupID] = []
 1122                     
 1123                     # Add sub group members to subgroup...
 1124                     for MemberType in ["Residues", "Surface"]:
 1125                         MemberID = re.sub("_", "", MemberType)
 1126                         SubGroupMemberName = "%s.%s" % (ResiduesSubGroupName, MemberType)
 1127                         SubGroupMemberID = "%s%s" % (ResiduesSubGroupID, MemberID)
 1128                         
 1129                         PyMOLObjectNames["Ligands"][ChainID][LigandID][SubGroupMemberID] = SubGroupMemberName
 1130                         PyMOLObjectNames["Ligands"][ChainID][LigandID][ResiduesSubMembersGroupID].append(SubGroupMemberName)
 1131 
 1132             if GetPocketContainsSurfaceStatus(FileIndex, ChainID, LigandID):
 1133                 # Setup a surfaces group and add it to pocket group...
 1134                 SurfacesGroupName = "%s.Surfaces" % (GroupName)
 1135                 SurfacesGroupID = "%sSurfacesGroup" % (GroupID)
 1136                 SurfacesGroupMembersID = "%sMembers" % (SurfacesGroupID)
 1137 
 1138                 PyMOLObjectNames["Ligands"][ChainID][LigandID][SurfacesGroupID] = SurfacesGroupName
 1139                 PyMOLObjectNames["Ligands"][ChainID][LigandID][GroupMembersID].append(SurfacesGroupName)
 1140                 PyMOLObjectNames["Ligands"][ChainID][LigandID][SurfacesGroupMembersID] = []
 1141 
 1142                 # Setup surfaces subgroup and its members...
 1143                 for SubGroupType in ["Surface", "Cavity"]:
 1144                     SubGroupID = re.sub("_", "", SubGroupType)
 1145                     SurfacesSubGroupName = "%s.%s" % (SurfacesGroupName, SubGroupType)
 1146                     SurfacesSubGroupID = "%s%sGroup" % (SurfacesGroupID, SubGroupID)
 1147                     SurfacesSubGroupMembersID = "%sMembers" % (SurfacesSubGroupID)
 1148                     
 1149                     # Add sub group to surfaces group...
 1150                     PyMOLObjectNames["Ligands"][ChainID][LigandID][SurfacesSubGroupID] = SurfacesSubGroupName
 1151                     PyMOLObjectNames["Ligands"][ChainID][LigandID][SurfacesGroupMembersID].append(SurfacesSubGroupName)
 1152                     PyMOLObjectNames["Ligands"][ChainID][LigandID][SurfacesSubGroupMembersID] = []
 1153                     
 1154                     # Setup a generic color surface...
 1155                     SurfaceName = "%s.Surface" % (SurfacesSubGroupName)
 1156                     SurfaceID = "%sSurface" % (SurfacesSubGroupID)
 1157                     PyMOLObjectNames["Ligands"][ChainID][LigandID][SurfaceID] = SurfaceName
 1158                     PyMOLObjectNames["Ligands"][ChainID][LigandID][SurfacesSubGroupMembersID].append(SurfaceName)
 1159                     
 1160                     if GetPocketSurfaceChainStatus(FileIndex, ChainID, LigandID):
 1161                         # Surface colored by hydrophobicity...
 1162                         HydrophobicSurfaceName = "%s.Hydrophobicity" % (SurfacesSubGroupName)
 1163                         HydrophobicSurfaceID = "%sHydrophobicSurface" % (SurfacesSubGroupID)
 1164                         PyMOLObjectNames["Ligands"][ChainID][LigandID][HydrophobicSurfaceID] = HydrophobicSurfaceName
 1165                         PyMOLObjectNames["Ligands"][ChainID][LigandID][SurfacesSubGroupMembersID].append(HydrophobicSurfaceName)
 1166                         
 1167                         # Surface colored by hydrophobicity and charge...
 1168                         HydrophobicChargeSurfaceName = "%s.Hydrophobicity_Charge" % (SurfacesSubGroupName)
 1169                         HydrophobicChargeSurfaceID = "%sHydrophobicChargeSurface" % (SurfacesSubGroupID)
 1170                         PyMOLObjectNames["Ligands"][ChainID][LigandID][HydrophobicChargeSurfaceID] = HydrophobicChargeSurfaceName
 1171                         PyMOLObjectNames["Ligands"][ChainID][LigandID][SurfacesSubGroupMembersID].append(HydrophobicChargeSurfaceName)
 1172                 
 1173                     if GetPocketSurfaceChainElectrostaticsStatus(FileIndex, ChainID, LigandID):
 1174                         ElectrostaticsGroupName = "%s.Vacuum_Electrostatics" % (SurfacesSubGroupName)
 1175                         ElectrostaticsGroupID = "%sElectrostaticsGroup" % (SurfacesSubGroupID)
 1176                         ElectrostaticsGroupMembersID = "%sElectrostaticsGroupMembers" % (SurfacesSubGroupID)
 1177                         
 1178                         PyMOLObjectNames["Ligands"][ChainID][LigandID][ElectrostaticsGroupID] = ElectrostaticsGroupName
 1179                         PyMOLObjectNames["Ligands"][ChainID][LigandID][SurfacesSubGroupMembersID].append(ElectrostaticsGroupName)
 1180                         
 1181                         # Setup electrostatics group members without the volume object...
 1182                         PyMOLObjectNames["Ligands"][ChainID][LigandID][ElectrostaticsGroupMembersID] = []
 1183                         
 1184                         for MemberType in ["Pocket", "Contact_Potential", "Map", "Legend"]:
 1185                             MemberID = re.sub("_", "", MemberType)
 1186                             
 1187                             Name = "%s.%s" % (ElectrostaticsGroupName, MemberType)
 1188                             NameID = "%s%s" % (ElectrostaticsGroupID, MemberID)
 1189                             
 1190                             PyMOLObjectNames["Ligands"][ChainID][LigandID][NameID] = Name
 1191                             PyMOLObjectNames["Ligands"][ChainID][LigandID][ElectrostaticsGroupMembersID].append(Name)
 1192     
 1193 def RetrieveInfilesInfo():
 1194     """Retrieve information for input files."""
 1195 
 1196     InfilesInfo = {}
 1197     
 1198     InfilesInfo["InfilesNames"] = []
 1199     InfilesInfo["InfilesRoots"] = []
 1200     InfilesInfo["ChainsAndLigandsInfo"] = []
 1201     
 1202     for Infile in OptionsInfo["InfilesNames"]:
 1203         FileDir, FileName, FileExt = MiscUtil.ParseFileName(Infile)
 1204         InfileRoot = FileName
 1205         
 1206         ChainsAndLigandInfo = PyMOLUtil.GetChainsAndLigandsInfo(Infile, InfileRoot)
 1207         
 1208         InfilesInfo["InfilesNames"].append(Infile)
 1209         InfilesInfo["InfilesRoots"].append(InfileRoot)
 1210         InfilesInfo["ChainsAndLigandsInfo"].append(ChainsAndLigandInfo)
 1211     
 1212     OptionsInfo["InfilesInfo"] = InfilesInfo
 1213 
 1214 def RetrieveRefFileInfo():
 1215     """Retrieve information for ref file."""
 1216 
 1217     RefFileInfo = {}
 1218     if not OptionsInfo["Align"]:
 1219         OptionsInfo["RefFileInfo"] = RefFileInfo
 1220         return
 1221 
 1222     RefFile = OptionsInfo["RefFileName"]
 1223     
 1224     FileDir, FileName, FileExt = MiscUtil.ParseFileName(RefFile)
 1225     RefFileRoot = FileName
 1226     
 1227     if re.match("^FirstInputFile$", OptionsInfo["AlignRefFile"], re.I):
 1228         ChainsAndLigandInfo = OptionsInfo["InfilesInfo"]["ChainsAndLigandsInfo"][0]
 1229     else:
 1230         MiscUtil.PrintInfo("\nRetrieving chain and ligand information for alignment reference file %s..." % RefFile)
 1231         ChainsAndLigandInfo = PyMOLUtil.GetChainsAndLigandsInfo(RefFile, RefFileRoot)
 1232 
 1233     RefFileInfo["RefFileName"] = RefFile
 1234     RefFileInfo["RefFileRoot"] = RefFileRoot
 1235     RefFileInfo["PyMOLObjectName"] = "AlignRef_%s" % RefFileRoot
 1236     RefFileInfo["ChainsAndLigandsInfo"] = ChainsAndLigandInfo
 1237     
 1238     OptionsInfo["RefFileInfo"] = RefFileInfo
 1239 
 1240 def ProcessChainAndLigandIDs():
 1241     """Process specified chain and ligand IDs for infiles."""
 1242     
 1243     OptionsInfo["InfilesInfo"]["SpecifiedChainsAndLigandsInfo"] = []
 1244     
 1245     for FileIndex in range(0, len(OptionsInfo["InfilesInfo"]["InfilesNames"])):
 1246         MiscUtil.PrintInfo("\nProcessing specified chain and ligand IDs for input file %s..." % OptionsInfo["InfilesInfo"]["InfilesNames"][FileIndex])
 1247         
 1248         ChainsAndLigandsInfo = OptionsInfo["InfilesInfo"]["ChainsAndLigandsInfo"][FileIndex]
 1249         SpecifiedChainsAndLigandsInfo = PyMOLUtil.ProcessChainsAndLigandsOptionsInfo(ChainsAndLigandsInfo, "-c, --chainIDs", OptionsInfo["ChainIDs"], "-l, --ligandIDs", OptionsInfo["LigandIDs"])
 1250         ProcessResidueTypesAndSurfaceAndChainSelectionsOptions(FileIndex, SpecifiedChainsAndLigandsInfo)
 1251         
 1252         OptionsInfo["InfilesInfo"]["SpecifiedChainsAndLigandsInfo"].append(SpecifiedChainsAndLigandsInfo)
 1253         
 1254         CheckPresenceOfValidLigandIDs(ChainsAndLigandsInfo, SpecifiedChainsAndLigandsInfo)
 1255         
 1256 def ProcessResidueTypesAndSurfaceAndChainSelectionsOptions(FileIndex, SpecifiedChainsAndLigandsInfo):
 1257     """Process residue types, surface, and chian selections options for chains and pockets."""
 1258 
 1259     SpecifiedChainsAndLigandsInfo["ChainSurfaces"] = {}
 1260     SpecifiedChainsAndLigandsInfo["SurfaceChain"] = {}
 1261     SpecifiedChainsAndLigandsInfo["SurfaceChainElectrostatics"] = {}
 1262     
 1263     SpecifiedChainsAndLigandsInfo["PocketSurfaces"] = {}
 1264     SpecifiedChainsAndLigandsInfo["SurfacePocket"] = {}
 1265     SpecifiedChainsAndLigandsInfo["SurfacePocketElectrostatics"] = {}
 1266     
 1267     SpecifiedChainsAndLigandsInfo["ResidueTypesChain"] = {}
 1268     SpecifiedChainsAndLigandsInfo["ResidueTypesPocket"] = {}
 1269 
 1270     SpecifiedChainsAndLigandsInfo["ChainSelections"] = {}
 1271     SpecifiedChainsAndLigandsInfo["ChainSelectionsSurfaces"] = {}
 1272     SpecifiedChainsAndLigandsInfo["SurfaceChainSelections"] = {}
 1273     
 1274     # Load infile...
 1275     Infile = OptionsInfo["InfilesInfo"]["InfilesNames"][FileIndex]
 1276     MolName = OptionsInfo["InfilesInfo"]["InfilesRoots"][FileIndex]
 1277     pymol.cmd.load(Infile, MolName)
 1278     
 1279     for ChainID in SpecifiedChainsAndLigandsInfo["ChainIDs"]:
 1280         AminoAcidsPresent = PyMOLUtil.AreAminoAcidResiduesPresent(MolName, ChainID)
 1281 
 1282         # Process surfaces for chains...
 1283         if re.match("^auto$", OptionsInfo["SurfaceChain"], re.I):
 1284             SurfaceChain = True if AminoAcidsPresent else False
 1285         else:
 1286             SurfaceChain = True if re.match("^yes$", OptionsInfo["SurfaceChain"], re.I) else False
 1287         SpecifiedChainsAndLigandsInfo["SurfaceChain"][ChainID] = SurfaceChain
 1288 
 1289         if re.match("^auto$", OptionsInfo["SurfaceChainElectrostatics"], re.I):
 1290             SurfaceChainElectrostatics = True if AminoAcidsPresent else False
 1291         else:
 1292             SurfaceChainElectrostatics = True if re.match("^yes$", OptionsInfo["SurfaceChainElectrostatics"], re.I) else False
 1293         SpecifiedChainsAndLigandsInfo["SurfaceChainElectrostatics"][ChainID] = SurfaceChainElectrostatics
 1294 
 1295         # A generic color surafce is always created...
 1296         ChainSurfaces = True
 1297         SpecifiedChainsAndLigandsInfo["ChainSurfaces"][ChainID] = ChainSurfaces
 1298         
 1299         # Process residue types for chains...
 1300         if re.match("^auto$", OptionsInfo["ResidueTypesChain"], re.I):
 1301             ResidueTypesChain = True if AminoAcidsPresent else False
 1302         else:
 1303             ResidueTypesChain = True if re.match("^yes$", OptionsInfo["ResidueTypesChain"], re.I) else False
 1304         SpecifiedChainsAndLigandsInfo["ResidueTypesChain"][ChainID] = ResidueTypesChain
 1305 
 1306         # Process chain selections...
 1307         ChainSelections = True if len(OptionsInfo["ChainSelectionsInfo"]["Names"]) else False
 1308         SpecifiedChainsAndLigandsInfo["ChainSelections"][ChainID] = ChainSelections
 1309         
 1310         # Process surfaces for chain selections...
 1311         if re.match("^auto$", OptionsInfo["SelectionsChainSurface"], re.I):
 1312             SurfaceChainSelections = True if AminoAcidsPresent else False
 1313         else:
 1314             SurfaceChainSelections = True if re.match("^yes$", OptionsInfo["SelectionsChainSurface"], re.I) else False
 1315         SpecifiedChainsAndLigandsInfo["SurfaceChainSelections"][ChainID] = SurfaceChainSelections
 1316         
 1317         # A generic color surafce is always created...
 1318         ChainSelectionsSurfaces = True
 1319         SpecifiedChainsAndLigandsInfo["ChainSelectionsSurfaces"][ChainID] = ChainSelectionsSurfaces
 1320         
 1321         # Process residue types and surfaces for pockets...
 1322         SpecifiedChainsAndLigandsInfo["PocketSurfaces"][ChainID] = {}
 1323         SpecifiedChainsAndLigandsInfo["SurfacePocket"][ChainID] = {}
 1324         SpecifiedChainsAndLigandsInfo["SurfacePocketElectrostatics"][ChainID] = {}
 1325         
 1326         SpecifiedChainsAndLigandsInfo["ResidueTypesPocket"][ChainID] = {}
 1327         
 1328         for LigandID in SpecifiedChainsAndLigandsInfo["LigandIDs"][ChainID]:
 1329             if re.match("^auto$", OptionsInfo["PocketSurface"], re.I):
 1330                 PocketSurface = True if AminoAcidsPresent else False
 1331             else:
 1332                 PocketSurface = True if re.match("^yes$", OptionsInfo["PocketSurface"], re.I) else False
 1333             SpecifiedChainsAndLigandsInfo["SurfacePocket"][ChainID][LigandID] = PocketSurface
 1334             
 1335             if re.match("^auto$", OptionsInfo["PocketSurfaceElectrostatics"], re.I):
 1336                 PocketSurfaceElectrostatics = True if AminoAcidsPresent else False
 1337             else:
 1338                 PocketSurfaceElectrostatics = True if re.match("^yes$", OptionsInfo["PocketSurfaceElectrostatics"], re.I) else False
 1339             SpecifiedChainsAndLigandsInfo["SurfacePocketElectrostatics"][ChainID][LigandID] = PocketSurfaceElectrostatics
 1340 
 1341             # A generic color surafce is always displayed...
 1342             PocketSurfaces = True
 1343             SpecifiedChainsAndLigandsInfo["PocketSurfaces"][ChainID][LigandID] = PocketSurfaces
 1344         
 1345             if re.match("^auto$", OptionsInfo["PocketResidueTypes"], re.I):
 1346                 PocketResidueTypes = True if AminoAcidsPresent else False
 1347             else:
 1348                 PocketResidueTypes = True if re.match("^yes$", OptionsInfo["PocketResidueTypes"], re.I) else False
 1349             SpecifiedChainsAndLigandsInfo["ResidueTypesPocket"][ChainID][LigandID] = PocketResidueTypes
 1350     
 1351     # Delete loaded object...
 1352     pymol.cmd.delete(MolName)
 1353 
 1354 def GetChainAloneResidueTypesStatus(FileIndex, ChainID):
 1355     """Get status of residue types for chain alone object."""
 1356 
 1357     Status = OptionsInfo["InfilesInfo"]["SpecifiedChainsAndLigandsInfo"][FileIndex]["ResidueTypesChain"][ChainID]
 1358     
 1359     return Status
 1360 
 1361 def GetPocketResidueTypesStatus(FileIndex, ChainID, LigandID):
 1362     """Get status of residue types for a pocket."""
 1363 
 1364     return OptionsInfo["InfilesInfo"]["SpecifiedChainsAndLigandsInfo"][FileIndex]["ResidueTypesPocket"][ChainID][LigandID]
 1365 
 1366 def GetChainAloneContainsSurfacesStatus(FileIndex, ChainID):
 1367     """Get status of surfaces present in chain alone object."""
 1368 
 1369     return OptionsInfo["InfilesInfo"]["SpecifiedChainsAndLigandsInfo"][FileIndex]["ChainSurfaces"][ChainID]
 1370 
 1371 def GetPocketContainsSurfaceStatus(FileIndex, ChainID, LigandID):
 1372     """Get status of surfaces present in a pocket."""
 1373 
 1374     return OptionsInfo["InfilesInfo"]["SpecifiedChainsAndLigandsInfo"][FileIndex]["PocketSurfaces"][ChainID][LigandID]
 1375 
 1376 def GetChainAloneSurfaceChainStatus(FileIndex, ChainID):
 1377     """Get status of hydrophobic surfaces for chain alone object."""
 1378 
 1379     return OptionsInfo["InfilesInfo"]["SpecifiedChainsAndLigandsInfo"][FileIndex]["SurfaceChain"][ChainID]
 1380 
 1381 def GetChainAloneSurfaceChainElectrostaticsStatus(FileIndex, ChainID):
 1382     """Get status of electrostatics surfaces for chain alone object."""
 1383 
 1384     return OptionsInfo["InfilesInfo"]["SpecifiedChainsAndLigandsInfo"][FileIndex]["SurfaceChainElectrostatics"][ChainID]
 1385 
 1386 def GetPocketSurfaceChainStatus(FileIndex, ChainID, LigandID):
 1387     """Get status of hydrophobic surfaces for a pocket."""
 1388 
 1389     return OptionsInfo["InfilesInfo"]["SpecifiedChainsAndLigandsInfo"][FileIndex]["SurfacePocket"][ChainID][LigandID]
 1390 
 1391 def GetPocketSurfaceChainElectrostaticsStatus(FileIndex, ChainID, LigandID):
 1392     """Get status of hydrophobic surfaces for a pocket."""
 1393 
 1394     return OptionsInfo["InfilesInfo"]["SpecifiedChainsAndLigandsInfo"][FileIndex]["SurfacePocketElectrostatics"][ChainID][LigandID]
 1395 
 1396 def GetChainAloneContainsSelectionsStatus(FileIndex, ChainID):
 1397     """Get status of selections present in chain alone object."""
 1398     return OptionsInfo["InfilesInfo"]["SpecifiedChainsAndLigandsInfo"][FileIndex]["ChainSelections"][ChainID]
 1399 
 1400 def GetChainAloneContainsChainSelectionSurfacesStatus(FileIndex, ChainID):
 1401     """Get status of chain selections surfaces present in chain alone object."""
 1402     return OptionsInfo["InfilesInfo"]["SpecifiedChainsAndLigandsInfo"][FileIndex]["ChainSelectionsSurfaces"][ChainID]
 1403 
 1404 def GetChainAloneSurfaceChainSelectionStatus(FileIndex, ChainID):
 1405     """Get status of hydrophobic surfaces for chain alone object."""
 1406     return OptionsInfo["InfilesInfo"]["SpecifiedChainsAndLigandsInfo"][FileIndex]["SurfaceChainSelections"][ChainID]
 1407 
 1408 def CheckPresenceOfValidLigandIDs(ChainsAndLigandsInfo, SpecifiedChainsAndLigandsInfo):
 1409     """Check presence of valid ligand IDs."""
 1410 
 1411     MiscUtil.PrintInfo("\nSpecified chain IDs: %s" % (", ".join(SpecifiedChainsAndLigandsInfo["ChainIDs"])))
 1412     
 1413     for ChainID in SpecifiedChainsAndLigandsInfo["ChainIDs"]:
 1414         if len (SpecifiedChainsAndLigandsInfo["LigandIDs"][ChainID]):
 1415             MiscUtil.PrintInfo("Chain ID: %s; Specified LigandIDs: %s" % (ChainID, ", ".join(SpecifiedChainsAndLigandsInfo["LigandIDs"][ChainID])))
 1416         else:
 1417             MiscUtil.PrintInfo("Chain IDs: %s; Specified LigandIDs: None" % (ChainID))
 1418             MiscUtil.PrintWarning("No valid ligand IDs found for chain ID, %s. PyMOL groups and objects related to ligand and binding pockect won't be created." % (ChainID))
 1419 
 1420 def RetrieveFirstChainID(FileIndex):
 1421     """Get first chain ID."""
 1422     
 1423     ChainsAndLigandsInfo = OptionsInfo["InfilesInfo"]["ChainsAndLigandsInfo"][FileIndex]
 1424     
 1425     FirstChainID = None
 1426     if len(ChainsAndLigandsInfo["ChainIDs"]):
 1427         FirstChainID = ChainsAndLigandsInfo["ChainIDs"][0]
 1428     
 1429     return FirstChainID
 1430 
 1431 def ProcessResidueTypes():
 1432     """Process residue types. """
 1433 
 1434     ResidueTypesNamesInfo, ResidueTypesParamsInfo = PyMOLUtil.ProcessResidueTypesOptionsInfo("-r, --residueTypes", OptionsInfo["ResidueTypes"])
 1435     OptionsInfo["ResidueTypesNames"] = ResidueTypesNamesInfo
 1436     OptionsInfo["ResidueTypesParams"] = ResidueTypesParamsInfo
 1437     
 1438 def ProcessSurfaceAtomTypesColors():
 1439     """Process surface atom types colors. """
 1440 
 1441     AtomTypesColorNamesInfo = PyMOLUtil.ProcessSurfaceAtomTypesColorsOptionsInfo("--surfaceAtomTypesColors", OptionsInfo["SurfaceAtomTypesColors"])
 1442     OptionsInfo["AtomTypesColorNames"] = AtomTypesColorNamesInfo
 1443 
 1444 def ProcessChainSelections():
 1445     """Process custom selections for chains. """
 1446 
 1447     ChainSelectionsInfo = PyMOLUtil.ProcessChainSelectionsOptionsInfo("--selectionsChain", OptionsInfo["SelectionsChain"])
 1448     OptionsInfo["ChainSelectionsInfo"] = ChainSelectionsInfo
 1449 
 1450 def ProcessOptions():
 1451     """Process and validate command line arguments and options"""
 1452 
 1453     MiscUtil.PrintInfo("Processing options...")
 1454     
 1455     # Validate options...
 1456     ValidateOptions()
 1457     
 1458     OptionsInfo["Align"] = True if re.match("^Yes$", Options["--align"], re.I) else False
 1459     OptionsInfo["AlignMethod"] = Options["--alignMethod"].lower()
 1460     OptionsInfo["AlignMode"] = Options["--alignMode"]
 1461     
 1462     OptionsInfo["AllowEmptyObjects"] = True if re.match("^Yes$", Options["--allowEmptyObjects"], re.I) else False
 1463 
 1464     OptionsInfo["Infiles"] = Options["--infiles"]
 1465     OptionsInfo["InfilesNames"] =  Options["--infileNames"]
 1466 
 1467     OptionsInfo["AlignRefFile"] = Options["--alignRefFile"]
 1468     if re.match("^FirstInputFile$", Options["--alignRefFile"], re.I):
 1469         OptionsInfo["RefFileName"] = OptionsInfo["InfilesNames"][0]
 1470     else:
 1471         OptionsInfo["RefFileName"] = Options["--alignRefFile"]
 1472     
 1473     OptionsInfo["Overwrite"] = Options["--overwrite"]
 1474     OptionsInfo["PMLOut"] = True if re.match("^Yes$", Options["--PMLOut"], re.I) else False
 1475     
 1476     OptionsInfo["Outfile"] = Options["--outfile"]
 1477     FileDir, FileName, FileExt = MiscUtil.ParseFileName(OptionsInfo["Outfile"])
 1478     OptionsInfo["PSEOut"] = False 
 1479     if re.match("^pml$", FileExt, re.I):
 1480         OptionsInfo["PMLOutfile"] = OptionsInfo["Outfile"] 
 1481         OptionsInfo["PMEOutfile"] = re.sub(".pml$", ".pme", OptionsInfo["Outfile"]) 
 1482     elif re.match("^pse$", FileExt, re.I):
 1483         OptionsInfo["PSEOut"] = True 
 1484         OptionsInfo["PSEOutfile"] = OptionsInfo["Outfile"] 
 1485         OptionsInfo["PMLOutfile"] = re.sub(".pse$", ".pml", OptionsInfo["Outfile"]) 
 1486         if os.path.exists(OptionsInfo["PMLOutfile"]) and (not OptionsInfo["Overwrite"]):
 1487             MiscUtil.PrintError("The intermediate output file to be generated, %s, already exist. Use option \"--ov\" or \"--overwrite\" and try again." % OptionsInfo["PMLOutfile"] )
 1488 
 1489     OptionsInfo["LabelFontID"] = int(Options["--labelFontID"])
 1490     
 1491     OptionsInfo["PocketContactsLigandColor"] = Options["--pocketContactsLigandColor"]
 1492     OptionsInfo["PocketContactsLigandHydrophobicColor"] = Options["--pocketContactsLigandHydrophobicColor"]
 1493     OptionsInfo["PocketContactsSolventColor"] = Options["--pocketContactsSolventColor"]
 1494     OptionsInfo["PocketContactsInorganicColor"] = Options["--pocketContactsInorganicColor"]
 1495 
 1496     OptionsInfo["PocketContactsCutoff"] = float(Options["--pocketContactsCutoff"])
 1497     OptionsInfo["PocketDistanceCutoff"] = float(Options["--pocketDistanceCutoff"])
 1498     
 1499     OptionsInfo["PocketLabelColor"] = Options["--pocketLabelColor"]
 1500     
 1501     OptionsInfo["PocketResidueTypes"] = Options["--pocketResidueTypes"]
 1502     OptionsInfo["PocketSurface"] = Options["--pocketSurface"]
 1503     OptionsInfo["PocketSurfaceElectrostatics"] = Options["--pocketSurfaceElectrostatics"]
 1504     
 1505     OptionsInfo["ResidueTypesChain"] = Options["--residueTypesChain"]
 1506     OptionsInfo["ResidueTypes"] = Options["--residueTypes"]
 1507     ProcessResidueTypes()
 1508 
 1509     OptionsInfo["SelectionsChain"] = Options["--selectionsChain"]
 1510     OptionsInfo["SelectionsChainSurface"] = Options["--selectionsChainSurface"]
 1511     OptionsInfo["SelectionsChainStyle"] = Options["--selectionsChainStyle"]
 1512     ProcessChainSelections()
 1513     
 1514     OptionsInfo["SurfaceChain"] = Options["--surfaceChain"]
 1515     OptionsInfo["SurfaceChainElectrostatics"] = Options["--surfaceChainElectrostatics"]
 1516     
 1517     OptionsInfo["SurfaceChainComplex"] = True if re.match("^Yes$", Options["--surfaceChainComplex"], re.I) else False
 1518     OptionsInfo["SurfaceComplex"] = True if re.match("^Yes$", Options["--surfaceComplex"], re.I) else False
 1519     
 1520     OptionsInfo["SurfaceColor"] = Options["--surfaceColor"]
 1521     OptionsInfo["SurfaceColorPalette"] = Options["--surfaceColorPalette"]
 1522     OptionsInfo["SurfaceAtomTypesColors"] = Options["--surfaceAtomTypesColors"]
 1523     ProcessSurfaceAtomTypesColors()
 1524     
 1525     OptionsInfo["SurfaceTransparency"] = float(Options["--surfaceTransparency"])
 1526     
 1527     RetrieveInfilesInfo()
 1528     RetrieveRefFileInfo()
 1529     
 1530     OptionsInfo["ChainIDs"] = Options["--chainIDs"]
 1531     OptionsInfo["LigandIDs"] = Options["--ligandIDs"]
 1532     
 1533     ProcessChainAndLigandIDs()
 1534 
 1535 def RetrieveOptions(): 
 1536     """Retrieve command line arguments and options"""
 1537     
 1538     # Get options...
 1539     global Options
 1540     Options = docopt(_docoptUsage_)
 1541 
 1542     # Set current working directory to the specified directory...
 1543     WorkingDir = Options["--workingdir"]
 1544     if WorkingDir:
 1545         os.chdir(WorkingDir)
 1546     
 1547     # Handle examples option...
 1548     if "--examples" in Options and Options["--examples"]:
 1549         MiscUtil.PrintInfo(MiscUtil.GetExamplesTextFromDocOptText(_docoptUsage_))
 1550         sys.exit(0)
 1551 
 1552 def ValidateOptions():
 1553     """Validate option values"""
 1554     
 1555     MiscUtil.ValidateOptionTextValue("--align", Options["--align"], "yes no")
 1556     MiscUtil.ValidateOptionTextValue("--alignMethod", Options["--alignMethod"], "align cealign super")
 1557     MiscUtil.ValidateOptionTextValue("--alignMode", Options["--alignMode"], "FirstChain Complex")
 1558     
 1559     MiscUtil.ValidateOptionTextValue("--allowEmptyObjects", Options["--allowEmptyObjects"], "yes no")
 1560 
 1561     # Expand infiles to handle presence of multiple input files...
 1562     InfileNames = MiscUtil.ExpandFileNames(Options["--infiles"], ",")
 1563     if not len(InfileNames):
 1564         MiscUtil.PrintError("No input files specified for \"-i, --infiles\" option")
 1565 
 1566     # Validate file extensions...
 1567     for Infile in InfileNames:
 1568         MiscUtil.ValidateOptionFilePath("-i, --infiles", Infile)
 1569         MiscUtil.ValidateOptionFileExt("-i, --infiles", Infile, "pdb cif")
 1570         MiscUtil.ValidateOptionsDistinctFileNames("-i, --infiles", Infile, "-o, --outfile", Options["--outfile"])
 1571     Options["--infileNames"] = InfileNames
 1572     
 1573     MiscUtil.ValidateOptionFileExt("-o, --outfile", Options["--outfile"], "pml pse")
 1574     MiscUtil.ValidateOptionsOutputFileOverwrite("-o, --outfile", Options["--outfile"], "--overwrite", Options["--overwrite"])
 1575 
 1576     if re.match("^yes$", Options["--align"], re.I):
 1577         if not re.match("^FirstInputFile$", Options["--alignRefFile"], re.I):
 1578             AlignRefFile = Options["--alignRefFile"]
 1579             MiscUtil.ValidateOptionFilePath("--alignRefFile", AlignRefFile)
 1580             MiscUtil.ValidateOptionFileExt("--alignRefFile", AlignRefFile, "pdb cif")
 1581             MiscUtil.ValidateOptionsDistinctFileNames("--AlignRefFile", AlignRefFile, "-o, --outfile", Options["--outfile"])
 1582     
 1583     MiscUtil.ValidateOptionTextValue("--PMLOut", Options["--PMLOut"], "yes no")
 1584     MiscUtil.ValidateOptionIntegerValue("--labelFontID", Options["--labelFontID"], {})
 1585 
 1586     MiscUtil.ValidateOptionFloatValue("--pocketContactsCutoff", Options["--pocketContactsCutoff"], {">": 0.0})
 1587     MiscUtil.ValidateOptionFloatValue("--pocketDistanceCutoff", Options["--pocketDistanceCutoff"], {">": 0.0})
 1588     if (float(Options["--pocketContactsCutoff"]) > float(Options["--pocketDistanceCutoff"])):
 1589         MiscUtil.PrintError("The value, %s, specified using option \"--pocketContactsCutoff\" must be less than value, %s, specified using \"-pocketDistanceCutoff\" option." % (Options["--pocketContactsCutoff"], Options["--pocketDistanceCutoff"]))
 1590         
 1591     MiscUtil.ValidateOptionTextValue("--pocketResidueTypes", Options["--pocketResidueTypes"], "yes no auto")
 1592     MiscUtil.ValidateOptionTextValue("--pocketSurface", Options["--pocketSurface"], "yes no auto")
 1593     MiscUtil.ValidateOptionTextValue("--pocketSurfaceElectrostatics", Options["--pocketSurfaceElectrostatics"], "yes no auto")
 1594     
 1595     MiscUtil.ValidateOptionTextValue("--residueTypesChain", Options["--residueTypesChain"], "yes no auto")
 1596     
 1597     MiscUtil.ValidateOptionTextValue("--surfaceComplex", Options["--surfaceComplex"], "yes no")
 1598     MiscUtil.ValidateOptionTextValue("--surfaceChainComplex", Options["--surfaceChainComplex"], "yes no")
 1599     MiscUtil.ValidateOptionTextValue("--surfaceChain", Options["--surfaceChain"], "yes no auto")
 1600     MiscUtil.ValidateOptionTextValue("--surfaceChainElectrostatics", Options["--surfaceChainElectrostatics"], "yes no auto")
 1601     
 1602     MiscUtil.ValidateOptionTextValue("--surfaceColorPalette", Options["--surfaceColorPalette"], "RedToWhite WhiteToGreen")
 1603     MiscUtil.ValidateOptionFloatValue("--surfaceTransparency", Options["--surfaceTransparency"], {">=": 0.0, "<=": 1.0})
 1604     
 1605 # Setup a usage string for docopt...
 1606 _docoptUsage_ = """
 1607 PyMOLVisualizeMacromolecules.py - Visualize macromolecules
 1608 
 1609 Usage:
 1610     PyMOLVisualizeMacromolecules.py [--align <yes or no>] [--alignMethod <align, cealign, super>]
 1611                                     [--alignMode <FirstChain or Complex>] [--alignRefFile <filename>]
 1612                                     [--allowEmptyObjects <yes or no>] [--chainIDs <First, All or ID1,ID2...>]
 1613                                     [--ligandIDs <Largest, All or ID1,ID2...>] [--labelFontID <number>]
 1614                                     [--PMLOut <yes or no>] [--pocketContactsInorganicColor <text>]
 1615                                     [--pocketContactsLigandColor <text>] [--pocketContactsLigandHydrophobicColor <text>]
 1616                                     [--pocketContactsSolventColor <text>] [--pocketContactsCutoff <number>]
 1617                                     [--pocketDistanceCutoff <number>] [--pocketLabelColor <text>] [--pocketResidueTypes <yes or no>]
 1618                                     [--pocketSurface <yes or no>] [--pocketSurfaceElectrostatics <yes or no>]
 1619                                     [--residueTypes <Type,Color,ResNames,...>] [--residueTypesChain <yes or no>]
 1620                                     [--selectionsChain <ObjectName,SelectionSpec,...>] [--selectionsChainSurface <yes or no>]
 1621                                     [--selectionsChainStyle <DisplayStyle>] [--surfaceChain <yes or no>] [--surfaceChainElectrostatics <yes or no>]
 1622                                     [--surfaceChainComplex <yes or no>] [--surfaceComplex <yes or no>]
 1623                                     [--surfaceColor <ColorName>] [--surfaceColorPalette <RedToWhite or WhiteToGreen>]
 1624                                     [--surfaceAtomTypesColors <ColorType,ColorSpec,...>]
 1625                                     [--surfaceTransparency <number>] [--overwrite] [-w <dir>] -i <infile1,infile2,infile3...> -o <outfile>
 1626     PyMOLVisualizeMacromolecules.py -h | --help | -e | --examples
 1627 
 1628 Description:
 1629     Generate PyMOL visualization files for viewing surfaces, chains, ligands, ligand
 1630     binding pockets, and interactions between ligands and binding pockets in
 1631     macromolecules including proteins and nucleic acids.
 1632 
 1633     The supported input file format are: PDB (.pdb), CIF (.cif)
 1634 
 1635     The supported output file formats are: PyMOL script file (.pml), PyMOL session
 1636     file (.pse)
 1637 
 1638     A variety of PyMOL groups and objects may be  created for visualization of
 1639     macromolecules. These groups and objects correspond to complexes, surfaces,
 1640     chains, ligands, inorganics, ligand binding pockets, pocket, polar interactions,
 1641     and pocket hydrophobic surfaces. A complete hierarchy of all possible PyMOL
 1642     groups and objects is shown below:
 1643     
 1644         <PDBFileRoot>
 1645             .Complex
 1646                 .Complex
 1647                 .Surface
 1648             .Chain<ID>
 1649                 .Complex
 1650                     .Complex
 1651                     .Surface
 1652                 .Chain
 1653                     .Chain
 1654                     .Selections
 1655                         .<Name1>
 1656                             .Selection
 1657                             .Surface
 1658                                 .Surface
 1659                                 .Hydrophobicity
 1660                                 .Hydrophobicity_Charge
 1661                         .<Name2>
 1662                             ... ... ..
 1663                     .Residues
 1664                         .Aromatic
 1665                             .Residues
 1666                             .Surface
 1667                         .Hydrophobic
 1668                             .Residues
 1669                             .Surface
 1670                         .Polar
 1671                             .Residues
 1672                             .Surface
 1673                         .Positively_Charged
 1674                             .Residues
 1675                             .Surface
 1676                         .Negatively_Charged
 1677                             .Residues
 1678                             .Surface
 1679                         .Other
 1680                             .Residues
 1681                             .Surface
 1682                     .Surface
 1683                         .Surface
 1684                         .Hydrophobicity
 1685                         .Hydrophobicity_Charge
 1686                         .Vacuum_Electrostatics
 1687                             .Contact_Potentials
 1688                             .Map
 1689                             .Legend
 1690                             .Volume
 1691                 .Solvent
 1692                 .Inorganic
 1693                 .Ligand<ID>
 1694                     .Ligand
 1695                         .Ligand
 1696                         .BallAndStick
 1697                     .Pocket
 1698                         .Pocket
 1699                         .Polar_Contacts
 1700                         .Hydrophobic_Contacts
 1701                         .Residues
 1702                             .Aromatic
 1703                                 .Residues
 1704                                 .Surface
 1705                             .Hydrophobic
 1706                                 .Residues
 1707                                 .Surface
 1708                             .Polar
 1709                                 .Residues
 1710                                 .Surface
 1711                             .Positively_Charged
 1712                                 .Residues
 1713                                 .Surface
 1714                             .Negatively_Charged
 1715                                 .Residues
 1716                                 .Surface
 1717                             .Other
 1718                                 .Residues
 1719                                 .Surface
 1720                         .Surfaces
 1721                             .Surface
 1722                                 .Surface
 1723                                 .Hydrophobicity
 1724                                 .Hydrophobicity_Charge
 1725                                 .Vacuum_Electrostatics
 1726                                     .Contact_Potentials
 1727                                     .Map
 1728                                     .Legend
 1729                             .Cavity
 1730                                 .Surface
 1731                                 .Hydrophobicity
 1732                                 .Hydrophobicity_Charge
 1733                                 .Vacuum_Electrostatics
 1734                                     .Contact_Potentials
 1735                                     .Map
 1736                                     .Legend
 1737                     .Pocket_Solvent
 1738                         .Pocket_Solvent
 1739                         .Polar_Contacts
 1740                     .Pocket_Inorganic
 1741                         .Pocket_Inorganic
 1742                         .Polar_Contacts
 1743                 .Ligand<ID>
 1744                     .Ligand
 1745                         ... ... ...
 1746                     .Pocket
 1747                         ... ... ...
 1748                     .Pocket_Solvent
 1749                         ... ... ...
 1750                     .Pocket_Inorganic
 1751                         ... ... ...
 1752             .Chain<ID>
 1753                 ... ... ...
 1754                 .Ligand<ID>
 1755                     ... ... ...
 1756                 .Ligand<ID>
 1757                     ... ... ...
 1758             .Chain<ID>
 1759                 ... ... ...
 1760         <PDBFileRoot>
 1761             .Complex
 1762                 ... ... ...
 1763             .Chain<ID>
 1764                 ... ... ...
 1765                 .Ligand<ID>
 1766                     ... ... ...
 1767                 .Ligand<ID>
 1768                     ... ... ...
 1769             .Chain<ID>
 1770                 ... ... ...
 1771     
 1772     The hydrophobic and electrostatic surfaces are not created for complete complex
 1773     and chain complex in input file(s) by default. A word to the wise: The creation of
 1774     surface objects may slow down loading of PML file and generation of PSE file, based
 1775     on the size of input complexes. The generation of PSE file may also fail.
 1776 
 1777 Options:
 1778     -a, --align <yes or no>  [default: no]
 1779         Align input files to a reference file before visualization.
 1780     --alignMethod <align, cealign, super>  [default: super]
 1781         Alignment methodology to use for aligning input files to a
 1782         reference file.
 1783     --alignMode <FirstChain or Complex>  [default: FirstChain]
 1784         Portion of input and reference files to use for spatial alignment of
 1785         input files against reference file.  Possible values: FirstChain or
 1786         Complex.
 1787         
 1788         The FirstChain mode allows alignment of the first chain in each input
 1789         file to the first chain in the reference file along with moving the rest
 1790         of the complex to coordinate space of the reference file. The complete
 1791         complex in each input file is aligned to the complete complex in reference
 1792         file for the Complex mode.
 1793     --alignRefFile <filename>  [default: FirstInputFile]
 1794         Reference input file name. The default is to use the first input file
 1795         name specified using '-i, --infiles' option.
 1796     --allowEmptyObjects <yes or no>  [default: no]
 1797         Allow creation of empty PyMOL objects corresponding to solvent and
 1798         inorganic atom selections across chains and ligands in input file(s). By
 1799         default, the empty objects are marked for deletion.
 1800     -c, --chainIDs <First, All or ID1,ID2...>  [default: First]
 1801         List of chain IDs to use for visualizing macromolecules. Possible values:
 1802         First, All, or a comma delimited list of chain IDs. The default is to use the
 1803         chain ID for the first chain in each input file.
 1804     -e, --examples
 1805         Print examples.
 1806     -h, --help
 1807         Print this help message.
 1808     -i, --infiles <infile1,infile2,infile3...>
 1809         Input file names.
 1810     -l, --ligandIDs <Largest, All or ID1,ID2...>  [default: Largest]
 1811         List of ligand IDs present in chains for visualizing macromolecules to
 1812         highlight ligand interactions. Possible values: Largest, All, or a comma
 1813         delimited list of ligand IDs. The default is to use the largest ligand present
 1814         in all or specified chains in each input file.
 1815         
 1816         Ligands are identified using organic selection operator available in PyMOL.
 1817         It'll also  identify buffer molecules as ligands. The largest ligand contains
 1818         the highest number of heavy atoms.
 1819     --labelFontID <number>  [default: 7]
 1820         Font ID for drawing labels. Default: 7 (Sans Bold). Valid values: 5 to 16.
 1821         The specified value must be a valid PyMOL font ID. No validation is
 1822         performed. The complete lists of valid font IDs is available at:
 1823         pymolwiki.org/index.php/Label_font_id. Examples: 5 - Sans;
 1824         7 - Sans Bold; 9 - Serif; 10 - Serif Bold.
 1825     -o, --outfile <outfile>
 1826         Output file name.
 1827     -p, --PMLOut <yes or no>  [default: yes]
 1828         Save PML file during generation of PSE file.
 1829     --pocketContactsInorganicColor <text>  [default: deepsalmon]
 1830         Color for drawing polar contacts between inorganic and pocket residues.
 1831         The specified value must be valid color. No validation is performed.
 1832     --pocketContactsLigandColor <text>  [default: orange]
 1833         Color for drawing polar contacts between ligand and pocket residues.
 1834         The specified value must be valid color. No validation is performed.
 1835     --pocketContactsLigandHydrophobicColor <text>  [default: purpleblue]
 1836         Color for drawing hydrophobic contacts between ligand and pocket residues.
 1837         The specified value must be valid color. No validation is performed. The
 1838         hydrophobic contacts are shown between pairs of carbon atoms not
 1839         connected to hydrogen bond donor or acceptors atoms as identified
 1840         by PyMOL.
 1841     --pocketContactsSolventColor <text>  [default: marine]
 1842         Color for drawing polar contacts between solvent and pocket residues..
 1843         The specified value must be valid color. No validation is performed.
 1844     --pocketContactsCutoff <number>  [default: 4.0]
 1845         Distance in Angstroms for identifying polar and hyrdophobic contacts
 1846         between atoms in pocket residues and ligands.
 1847     --pocketDistanceCutoff <number>  [default: 5.0]
 1848         Distance in Angstroms for identifying pocket residues around ligands.
 1849     --pocketLabelColor <text>  [default: magenta]
 1850         Color for drawing residue or atom level labels for a pocket. The specified
 1851         value must be valid color. No validation is performed.
 1852     --pocketResidueTypes <yes or no>  [default: auto]
 1853         Pocket residue types. The residue groups are generated using residue types,
 1854         colors, and names specified by '--residueTypes' option. It is only valid for
 1855         amino acids.  By default, the residue type groups are automatically created
 1856         for pockets containing amino acids and skipped for chains only containing
 1857         nucleic acids.
 1858     --pocketSurface <yes or no>  [default: auto]
 1859         Surfaces around pocket residues colored by hydrophobicity alone and
 1860         both hydrophobicity and charge. The hydrophobicity surface is colored
 1861         at residue level using Eisenberg hydrophobicity scale for residues and color
 1862         gradient specified by '--surfaceColorPalette' option. The  hydrophobicity and
 1863         charge surface is colored [ REF 140 ] at atom level using colors specified for
 1864         groups of atoms by '--surfaceAtomTypesColors' option. This scheme allows
 1865         simultaneous mapping of hyrophobicity and charge values on the surfaces.
 1866         
 1867         The cavity surfaces around ligands are also generated. These surfaces are
 1868         colored by hydrophobicity along and both hydrophobicity and charge.
 1869         
 1870         This option is only valid for amino acids. By default, both surfaces are
 1871         automatically created for pockets containing amino acids and skipped for
 1872         pockets containing only nucleic acids.
 1873         
 1874         In addition, generic pockect and cavity surfaces colored by '--surfaceColor'
 1875         are always created for pocket residues containing amino acids and nucleic
 1876         acids.
 1877     --pocketSurfaceElectrostatics <yes or no>  [default: auto]
 1878         Vacuum electrostatics contact potential surface around pocket residues.
 1879         A word to the wise from PyMOL documentation: The computed protein
 1880         contact potentials are only qualitatively useful, due to short cutoffs,
 1881         truncation, and lack of solvent "screening".
 1882         
 1883         The cavity surface around ligands is also generated. This surface is
 1884         colored by vacuum electrostatics contact potential.
 1885         
 1886         This option is only valid for amino acids. By default, the electrostatics surface
 1887         is automatically created for chains containing amino acids and skipped for chains
 1888         containing only nucleic acids.
 1889     -r, --residueTypes <Type,Color,ResNames,...>  [default: auto]
 1890         Residue types, colors, and names to generate for residue groups during
 1891         '--pocketResidueTypes' and '--residueTypesChain' option. It is only
 1892         valid for amino acids.
 1893         
 1894         It is a triplet of comma delimited list of amino acid residues type, residues
 1895         color, and a space delimited list three letter residue names. 
 1896         
 1897         The default values for residue type, color, and name triplets  are shown
 1898         below:
 1899             
 1900             Aromatic,brightorange,HIS PHE TRP TYR,
 1901             Hydrophobic,orange,ALA GLY VAL LEU ILE PRO MET,
 1902             Polar,palegreen,ASN GLN SER THR CYS,
 1903             Positively_Charged,marine,ARG LYS,
 1904             Negatively_Charged,red,ASP GLU
 1905             
 1906         The color name must be a valid PyMOL name. No validation is performed.
 1907         An amino acid name may appear across multiple residue types. All other
 1908         residues are grouped under 'Other'.
 1909     --residueTypesChain <yes or no>  [default: auto]
 1910         Chain residue types. The residue groups are generated using residue types,
 1911         colors, and names specified by '--residueTypes' option. It is only valid for
 1912         amino acids.  By default, the residue type groups are automatically created
 1913         for chains containing amino acids and skipped for chains only containing
 1914         nucleic acids.
 1915     --selectionsChain <ObjectName,SelectionSpec,...>  [default: None]
 1916         Custom selections for chains. It is a pairwise list of comma delimited values
 1917         corresponding to PyMOL object names and selection specifications.  The
 1918         selection specification must be a valid PyMOL specification. No validation is
 1919         performed.
 1920         
 1921         The PyMOL objects are created for each chain corresponding to the
 1922         specified selections. The display style for PyMOL objects is set using
 1923         value of '--selectionsChainStyle' option.
 1924         
 1925         The specified selection specification is automatically appended to appropriate
 1926         chain specification before creating PyMOL objects.
 1927         
 1928         For example, the following specification for '--selectionsChain' option will
 1929         generate PyMOL objects for chains containing Cysteines and Serines:
 1930             
 1931             Cysteines,resn CYS,Serines,resn SER
 1932             
 1933     --selectionsChainSurface <yes or no>  [default: auto]
 1934         Surfaces around individual chain selections colored by hydrophobicity alone
 1935         and both hydrophobicity and charge. This option is similar to '--surafceChain'
 1936         options for creating surfaces for chain. Additional details are available in the
 1937         documentation section for '--surfaceChain' options.
 1938     --selectionsChainStyle <DisplayStyle>  [default: sticks]
 1939         Display style for PyMOL objects created for '--selectionsChain' option. It
 1940         must be a valid PyMOL display style. No validation is performed.
 1941     --surfaceChain <yes or no>  [default: auto]
 1942         Surfaces around individual chain colored by hydrophobicity alone and
 1943         both hydrophobicity and charge. The hydrophobicity surface is colored
 1944         at residue level using Eisenberg hydrophobicity scale for residues and color
 1945         gradient specified by '--surfaceColorPalette' option. The  hydrophobicity and
 1946         charge surface is colored [ REF 140 ] at atom level using colors specified for
 1947         groups of atoms by '--surfaceAtomTypesColors' option. This scheme allows
 1948         simultaneous mapping of hyrophobicity and charge values on the surfaces.
 1949         
 1950         This option is only valid for amino acids. By default, both surfaces are
 1951         automatically created for chains containing amino acids and skipped for
 1952         chains containing only nucleic acids.
 1953         
 1954         In addition, generic surfaces colored by '--surfaceColor' are always created
 1955         for chain residues containing amino acids and nucleic acids.
 1956     --surfaceChainElectrostatics <yes or no>  [default: auto]
 1957         Vacuum electrostatics contact potential surface and volume around individual
 1958         chain. A word to the wise from PyMOL documentation: The computed protein
 1959         contact potentials are only qualitatively useful, due to short cutoffs,
 1960         truncation, and lack of solvent "screening".
 1961         
 1962         This option is only valid for amino acids. By default, the electrostatics surface
 1963         and volume are automatically created for chains containing amino acids and
 1964         skipped for chains containing only nucleic acids.
 1965     --surfaceChainComplex <yes or no>  [default: no]
 1966         Hydrophobic surface around chain complex. The  surface is colored by
 1967         hydrophobicity. It is only valid for amino acids.
 1968     --surfaceComplex <yes or no>  [default: no]
 1969         Hydrophobic surface around complete complex. The  surface is colored by
 1970         hydrophobicity. It is only valid for amino acids.
 1971     --surfaceAtomTypesColors <ColorType,ColorSpec,...>  [default: auto]
 1972         Atom colors for generating surfaces colored by hyrophobicity and charge
 1973         around chains and pockets in proteins. It's a pairwise comma delimited list
 1974         of atom color type and color specification for goups of atoms.
 1975         
 1976         The default values for color types [ REF 140 ] along wth color specifications
 1977         are shown below: 
 1978             
 1979             HydrophobicAtomsColor, yellow,
 1980             NegativelyChargedAtomsColor, red,
 1981             PositivelyChargedAtomsColor, blue,
 1982             OtherAtomsColor, gray90
 1983             
 1984         The color names must be valid PyMOL names.
 1985         
 1986         The color values may also be specified as space delimited RGB triplets:
 1987              
 1988             HydrophobicAtomsColor, 0.95 0.78 0.0,
 1989             NegativelyChargedAtomsColor, 1.0 0.4 0.4,
 1990             PositivelyChargedAtomsColor, 0.2 0.5 0.8,
 1991             OtherAtomsColor, 0.95 0.95 0.95
 1992             
 1993     --surfaceColor <ColorName>  [default: lightblue]
 1994         Color name for surfaces around chains and pockets. This color is not used
 1995         for surfaces colored by hydrophobicity and charge. The color name must be
 1996         a valid PyMOL name.
 1997     --surfaceColorPalette <RedToWhite or WhiteToGreen>  [default: RedToWhite]
 1998         Color palette for hydrophobic surfaces around chains and pockets in proteins.
 1999         Possible values: RedToWhite or WhiteToGreen from most hydrophobic amino
 2000         acid to least hydrophobic. The colors values for amino acids are taken from
 2001         color_h script available as part of the Script Library at PyMOL Wiki.
 2002     --surfaceTransparency <number>  [default: 0.25]
 2003         Surface transparency for molecular surfaces.
 2004     --overwrite
 2005         Overwrite existing files.
 2006     -w, --workingdir <dir>
 2007         Location of working directory which defaults to the current directory.
 2008 
 2009 Examples:
 2010     To visualize the first chain, the largest ligand in the first chain, and ligand
 2011     binding pockets to highlight ligand interaction with pocket resiudes, solvents
 2012     and inorganics, in a PDB file, and generate a PML file, type:
 2013 
 2014         % PyMOLVisualizeMacromolecules.py -i Sample4.pdb -o Sample4.pml
 2015 
 2016     To visualize the first chain along with all cysteines and serines, the largest
 2017     ligand in the first chain, and ligand binding pockets to highlight ligand
 2018     interaction with pocket resiudes, solvents and inorganics, in a PDB file,
 2019     and generate a PML file, type:
 2020 
 2021         % PyMOLVisualizeMacromolecules.py -i Sample4.pdb -o Sample4.pml
 2022           --selectionsChain "Cysteines,resn cys,Serines,resn ser"
 2023 
 2024     To visualize all chains, all ligands in all chains, and all ligand binding pockets to
 2025     highlight ligand interaction with pocket resiudes, solvents and inorganics, in a
 2026     PDB file, and generate a PML file, type:
 2027 
 2028         % PyMOLVisualizeMacromolecules.py -c All -l All -i Sample4.pdb -o
 2029           Sample4.pml
 2030 
 2031     To visualize all chains, ligands, and ligand binding pockets along with displaying
 2032     all hydrophibic surfaces and chain electrostatic surface, in a PDB file, and
 2033     generate a PML file, type:
 2034 
 2035         % PyMOLVisualizeMacromolecules.py -c All -l All
 2036           --surfaceChainElectrostatics yes --surfaceChainComplex yes
 2037           --surfaceComplex yes -i Sample4.pdb -o Sample4.pml
 2038 
 2039     To visualize chain E, ligand ADP in chain E, and ligand binding pockets to
 2040     highlight ligand interaction with pocket resiudes, solvents and inorganics,
 2041     in a PDB file, and generate a PML file, type:
 2042 
 2043         % PyMOLVisualizeMacromolecules.py -c E -l ADP -i Sample3.pdb
 2044           -o Sample3.pml
 2045 
 2046     To visualize chain E, ligand ADP in chain E, and ligand binding pockets to
 2047     highlight ligand interaction with pocket resiudes, solvents and inorganics,
 2048     in a PDB file, and generate a PSE file, type:
 2049 
 2050         % PyMOLVisualizeMacromolecules.py -c E -l ADP -i Sample3.pdb
 2051           -o Sample3.pse
 2052 
 2053     To visualize the first chain, the largest ligand in the first chain, and ligand
 2054     binding pockets to highlight ligand interaction with pocket resiudes, solvents
 2055     and inorganics, in PDB files, along with aligning first chain in each input file to
 2056     the first chain in first input file, and generate a PML file, type:
 2057 
 2058         % PyMOLVisualizeMacromolecules.py --align yes -i
 2059           "Sample5.pdb,Sample6.pdb,Sample7.pdb" -o SampleOut.pml
 2060 
 2061     To visualize all chains, all ligands in all chains, and all ligand binding pockets to
 2062     highlight ligand interaction with pocket resiudes, solvents and inorganics, in
 2063     PDB files, along with aligning first chain in each input file to the first chain in
 2064     first input file, and generate a PML file, type:
 2065 
 2066         % PyMOLVisualizeMacromolecules.py --align yes  -c All -l All -i
 2067           "Sample5.pdb,Sample6.pdb,Sample7.pdb" -o SampleOut.pml
 2068 
 2069     To visualize all chains, all ligands in all chains, and all ligand binding pockets to
 2070     highlight ligand interaction with pocket resiudes, solvents and inorganics, in
 2071     PDB files, along with aligning first chain in each input file to the first chain in a
 2072     specified PDB file using a specified alignment method, and generate a PML
 2073     file, type:
 2074 
 2075         % PyMOLVisualizeMacromolecules.py --align yes  --alignMode FirstChain
 2076           --alignRefFile Sample5.pdb --alignMethod super   -c All  -l All -i
 2077           "Sample5.pdb,Sample6.pdb,Sample7.pdb" -o SampleOut.pml
 2078 
 2079 Author:
 2080     Manish Sud(msud@san.rr.com)
 2081 
 2082 See also:
 2083     DownloadPDBFiles.pl, PyMOLVisualizeCavities.py,
 2084     PyMOLVisualizeCryoEMDensity.py, PyMOLVisualizeElectronDensity.py,
 2085     PyMOLVisualizeInterfaces.py, PyMOLVisualizeSurfaceAndBuriedResidues.py
 2086 
 2087 Copyright:
 2088     Copyright (C) 2019 Manish Sud. All rights reserved.
 2089 
 2090     The functionality available in this script is implemented using PyMOL, a
 2091     molecular visualization system on an open source foundation originally
 2092     developed by Warren DeLano.
 2093 
 2094     This file is part of MayaChemTools.
 2095 
 2096     MayaChemTools is free software; you can redistribute it and/or modify it under
 2097     the terms of the GNU Lesser General Public License as published by the Free
 2098     Software Foundation; either version 3 of the License, or (at your option) any
 2099     later version.
 2100 
 2101 """
 2102 
 2103 if __name__ == "__main__":
 2104     main()