MayaChemTools

    1 #!/bin/env python
    2 #
    3 # File: PyMOLVisualizeElectronDensity.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     GenerateElectronDensityVisualization()
   79     
   80     MiscUtil.PrintInfo("\n%s: Done...\n" % ScriptName)
   81     MiscUtil.PrintInfo("Total time: %s" % MiscUtil.GetFormattedElapsedTime(WallClockTime, ProcessorTime))
   82 
   83 def GenerateElectronDensityVisualization():
   84     """Generate electron density 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("mesh_width", %.2f)""" % (OptionsInfo["MeshWidth"]))
  173     PMLCmds.append("""cmd.set("transparency", %.2f, "", 0)""" % (OptionsInfo["SurfaceTransparency"]))
  174     PMLCmds.append("""cmd.set("label_font_id", %s)""" % (OptionsInfo["LabelFontID"]))
  175     PML = "\n".join(PMLCmds)
  176     
  177     OutFH.write("""\n""\n"Setting up PyMOL gobal parameters..."\n""\n""")
  178     OutFH.write("%s\n" % PML)
  179 
  180 def WriteAlignReference(OutFH):
  181     """Setup object for alignment reference """
  182 
  183     RefFileInfo = OptionsInfo["RefFileInfo"]
  184     RefFile = RefFileInfo["RefFileName"]
  185     RefName = RefFileInfo["PyMOLObjectName"]
  186     
  187     PMLCmds = []
  188     PMLCmds.append("""cmd.load("%s", "%s")""" % (RefFile, RefName))
  189     PMLCmds.append("""cmd.hide("everything", "%s")""" % (RefName))
  190     PMLCmds.append("""cmd.disable("%s")""" % (RefName))
  191     PML = "\n".join(PMLCmds)
  192     
  193     OutFH.write("""\n""\n"Loading %s and setting up view for align reference..."\n""\n""" % RefFile)
  194     OutFH.write("%s\n" % PML)
  195     
  196 def WriteAlignComplex(OutFH, FileIndex, PyMOLObjectNames):
  197     """Setup alignment of complex to reference"""
  198 
  199     RefFileInfo = OptionsInfo["RefFileInfo"]
  200     RefName = RefFileInfo["PyMOLObjectName"]
  201     
  202     ComplexName = PyMOLObjectNames["Complex"]
  203     
  204     if re.match("^FirstChain$", OptionsInfo["AlignMode"], re.I):
  205         RefFirstChainID = RefFileInfo["ChainsAndLigandsInfo"]["ChainIDs"][0]
  206         RefAlignSelection = "%s and chain %s" % (RefName, RefFirstChainID)
  207         
  208         ComplexFirstChainID = RetrieveFirstChainID(FileIndex)
  209         ComplexAlignSelection = "%s and chain %s" % (ComplexName, ComplexFirstChainID)
  210     else:
  211         RefAlignSelection = RefName
  212         ComplexAlignSelection = ComplexName
  213 
  214     PML = PyMOLUtil.SetupPMLForAlignment(OptionsInfo["AlignMethod"], RefAlignSelection, ComplexAlignSelection)
  215     OutFH.write("""\n""\n"Aligning %s against reference %s ..."\n""\n""" % (ComplexAlignSelection, RefAlignSelection))
  216     OutFH.write("%s\n" % PML)
  217     
  218 def DeleteAlignReference(OutFH):
  219     """Delete alignment reference object."""
  220     
  221     RefName = OptionsInfo["RefFileInfo"]["PyMOLObjectName"]
  222     OutFH.write("""\n""\n"Deleting alignment reference object %s..."\n""\n""" % RefName)
  223     OutFH.write("""cmd.delete("%s")\n""" % RefName)
  224 
  225 def WriteComplexView(OutFH, FileIndex, PyMOLObjectNames, FirstComplex):
  226     """Write out PML for viewing polymer complex along with electron density."""
  227 
  228     # Setup complex...
  229     Infile = OptionsInfo["InfilesInfo"]["InfilesNames"][FileIndex]
  230     PML = PyMOLUtil.SetupPMLForPolymerComplexView(PyMOLObjectNames["Complex"], Infile, True)
  231     OutFH.write("""\n""\n"Loading %s and setting up view for complex..."\n""\n""" % Infile)
  232     OutFH.write("%s\n" % PML)
  233     
  234     if OptionsInfo["Align"]:
  235         # No need to align complex on to itself...
  236         if not (re.match("^FirstInputFile$", OptionsInfo["AlignRefFile"], re.I) and FirstComplex):
  237             WriteAlignComplex(OutFH, FileIndex, PyMOLObjectNames)
  238 
  239     # Setup electron density maps and meshes...
  240     CompositeEDMapFile = OptionsInfo["CompositeEDMapFiles"][FileIndex]
  241     WriteComplexCompositeElectronDensityMapView(OutFH, PyMOLObjectNames, CompositeEDMapFile)
  242     
  243     if PyMOLObjectNames["SetupDiffEDMapObjects"]:
  244         DifferenceEDMapFile = OptionsInfo["DiffEDMapFiles"][FileIndex]
  245         WriteComplexDifferenceElectronDensityMapView(OutFH, PyMOLObjectNames, DifferenceEDMapFile)
  246 
  247     # Setup complex group...
  248     GenerateAndWritePMLForGroup(OutFH, PyMOLObjectNames["ComplexGroup"], PyMOLObjectNames["ComplexGroupMembers"], False, "close")
  249 
  250 def WriteComplexCompositeElectronDensityMapView(OutFH, PyMOLObjectNames, MapFileName):
  251     """Write out PML for viewing composite maps."""
  252 
  253     # Load composite map (2Fo - Fc) and setup mesh views...
  254     Info = """\
  255 ""
  256 "Loading composite map (2Fo - Fc) %s and setting up mesh view for complex..."
  257 "" """ % MapFileName
  258     OutFH.write("\n%s\n" % Info)
  259 
  260     MapName = PyMOLObjectNames["ComplexCompositeEDMap"]
  261     ComplexName = PyMOLObjectNames["Complex"]
  262     
  263     ContourLevel = OptionsInfo["MeshLevelCompositeMap"]
  264     Color = OptionsInfo["MeshColorCompositeMap"]
  265     
  266     VolumeColorRamp = OptionsInfo["VolumeColorRampCompositeMap"]
  267     
  268     VolumeName = PyMOLObjectNames["ComplexCompositeEDVolume"]
  269     MeshName = PyMOLObjectNames["ComplexCompositeEDMesh"]
  270     SurfaceName = PyMOLObjectNames["ComplexCompositeEDSurface"]
  271     
  272     AlignMapToObjectName = ComplexName if OptionsInfo["Align"] else None
  273     EnableMap = True
  274     PML = SetupPMLForElectronDensityMap(MapFileName, MapName, AlignMapToObjectName, EnableMap)
  275     OutFH.write("%s\n" % PML)
  276 
  277     EnableMesh = OptionsInfo["MeshComplex"]
  278     
  279     EnableVolume = OptionsInfo["VolumeComplex"]
  280     if EnableVolume and EnableMesh:
  281         EnableVolume = False
  282         
  283     EnableSurface = OptionsInfo["SurfaceComplex"]
  284     if EnableSurface and (EnableVolume or EnableMesh):
  285         EnableSurface = False
  286     
  287     if OptionsInfo["VolumeComplex"]:
  288         PML = SetupPMLForElectronDensityVolume(MapName, VolumeName, VolumeColorRamp, Enable = EnableVolume, Selection = ComplexName)
  289         OutFH.write("\n%s\n" % PML)
  290         
  291     if OptionsInfo["MeshComplex"]:
  292         PML = SetupPMLForElectronDensityMesh(MapName, MeshName, ContourLevel, Color, Enable = EnableMesh, Selection = ComplexName)
  293         OutFH.write("\n%s\n" % PML)
  294 
  295     if OptionsInfo["SurfaceComplex"]:
  296         PML = SetupPMLForElectronDensitySurface(MapName, SurfaceName, ContourLevel, Color, Enable = EnableSurface, Selection = ComplexName)
  297         OutFH.write("\n%s\n" % PML)
  298 
  299     GenerateAndWritePMLForGroup(OutFH, PyMOLObjectNames["ComplexCompositeEDGroup"], PyMOLObjectNames["ComplexCompositeEDGroupMembers"], True, "close")
  300     
  301 def WriteComplexDifferenceElectronDensityMapView(OutFH, PyMOLObjectNames, MapFileName):
  302     """Write out PML for viewing difference maps."""
  303 
  304     # Load difference map (Fo - Fc ) and setup mesh views...
  305     Info = """\
  306 ""
  307 "Loading difference map (Fo - Fc ) map %s and setting up mesh views..."
  308 "" """ % MapFileName
  309     OutFH.write("\n%s\n" % Info)
  310 
  311     MapName = PyMOLObjectNames["ComplexDiffEDMap"]
  312     ComplexName = PyMOLObjectNames["Complex"]
  313 
  314     ContourLevel1 = OptionsInfo["Mesh1LevelDiffMap"]
  315     ContourLevel2 = OptionsInfo["Mesh2LevelDiffMap"]
  316     Color1 = OptionsInfo["Mesh1ColorDiffMap"]
  317     Color2 = OptionsInfo["Mesh2ColorDiffMap"]
  318     
  319     VolumeColorRamp = OptionsInfo["VolumeColorRampDiffMap"]
  320     
  321     VolumeName = PyMOLObjectNames["ComplexDiffEDVolume"]
  322     Mesh1Name = PyMOLObjectNames["ComplexDiffEDMesh1"]
  323     Surface1Name = PyMOLObjectNames["ComplexDiffEDSurface1"]
  324     Mesh2Name = PyMOLObjectNames["ComplexDiffEDMesh2"]
  325     Surface2Name = PyMOLObjectNames["ComplexDiffEDSurface2"]
  326     
  327     EnableMesh = OptionsInfo["MeshComplex"]
  328     
  329     EnableVolume = OptionsInfo["VolumeComplex"]
  330     if EnableVolume and EnableMesh:
  331         EnableVolume = False
  332         
  333     EnableSurface = OptionsInfo["SurfaceComplex"]
  334     if EnableSurface and (EnableVolume or EnableMesh):
  335         EnableSurface = False
  336     
  337     AlignMapToObjectName = ComplexName if OptionsInfo["Align"] else None
  338     EnableMap = True
  339     PML = SetupPMLForElectronDensityMap(MapFileName, MapName, AlignMapToObjectName, EnableMap)
  340     OutFH.write("%s\n" % PML)
  341     
  342     if OptionsInfo["VolumeComplex"]:
  343         PML = SetupPMLForElectronDensityVolume(MapName, VolumeName, VolumeColorRamp, Enable = EnableVolume, Selection = ComplexName)
  344         OutFH.write("\n%s\n" % PML)
  345         
  346     if OptionsInfo["MeshComplex"]:
  347         PML = SetupPMLForElectronDensityMesh(MapName, Mesh1Name, ContourLevel1, Color1, Enable = EnableMesh, Selection = ComplexName)
  348         OutFH.write("\n%s\n" % PML)
  349         
  350     if OptionsInfo["SurfaceComplex"]:
  351         PML = SetupPMLForElectronDensitySurface(MapName, Surface1Name, ContourLevel1, Color1, Enable = EnableSurface, Selection = ComplexName)
  352         OutFH.write("\n%s\n" % PML)
  353     
  354     if OptionsInfo["MeshComplex"]:
  355         PML = SetupPMLForElectronDensityMesh(MapName, Mesh2Name, ContourLevel2, Color2, Enable = EnableMesh, Selection = ComplexName)
  356         OutFH.write("\n%s\n" % PML)
  357     
  358     if OptionsInfo["SurfaceComplex"]:
  359         PML = SetupPMLForElectronDensitySurface(MapName, Surface2Name, ContourLevel2, Color2, Enable = EnableSurface, Selection = ComplexName)
  360         OutFH.write("\n%s\n" % PML)
  361     
  362     GenerateAndWritePMLForGroup(OutFH, PyMOLObjectNames["ComplexDiffEDGroup"], PyMOLObjectNames["ComplexDiffEDGroupMembers"], True, "close")
  363 
  364 def WriteChainView(OutFH, FileIndex, PyMOLObjectNames, ChainID):
  365     """Write out PML for viewing chain."""
  366     
  367     OutFH.write("""\n""\n"Setting up views for chain %s..."\n""\n""" % ChainID)
  368     
  369     ChainComplexName = PyMOLObjectNames["Chains"][ChainID]["ChainComplex"]
  370     
  371     # Setup chain complex group view...
  372     WriteChainComplexAndMeshViews(OutFH, FileIndex, PyMOLObjectNames, ChainID)
  373 
  374     # Setup chain view...
  375     WriteChainAloneViews(OutFH, FileIndex, PyMOLObjectNames, ChainID)
  376     
  377     # Setup chain solvent view...
  378     PML = PyMOLUtil.SetupPMLForSolventView(PyMOLObjectNames["Chains"][ChainID]["Solvent"], ChainComplexName, False)
  379     OutFH.write("\n%s\n" % PML)
  380 
  381     # Setup chain inorganic view...
  382     PML = PyMOLUtil.SetupPMLForInorganicView(PyMOLObjectNames["Chains"][ChainID]["Inorganic"], ChainComplexName, False)
  383     OutFH.write("\n%s\n" % PML)
  384 
  385 def WriteChainComplexAndMeshViews(OutFH, FileIndex, PyMOLObjectNames, ChainID):
  386     """Write chain complex and mesh views. """
  387     
  388     # Setup chain complex...
  389     ChainComplexName = PyMOLObjectNames["Chains"][ChainID]["ChainComplex"]
  390     PML = PyMOLUtil.SetupPMLForPolymerChainComplexView(ChainComplexName, PyMOLObjectNames["Complex"], ChainID, True)
  391     OutFH.write("%s\n" % PML)
  392 
  393     SpecifiedChainsAndLigandsInfo = OptionsInfo["InfilesInfo"]["SpecifiedChainsAndLigandsInfo"][FileIndex]
  394     
  395     MeshChainComplex = SpecifiedChainsAndLigandsInfo["MeshChainComplex"][ChainID]
  396     VolumeChainComplex = SpecifiedChainsAndLigandsInfo["VolumeChainComplex"][ChainID]
  397     SurfaceChainComplex = SpecifiedChainsAndLigandsInfo["SurfaceChainComplex"][ChainID]
  398     
  399     EnableVolumeChainComplex = SpecifiedChainsAndLigandsInfo["EnableVolumeChainComplex"][ChainID]
  400     EnableMeshChainComplex = SpecifiedChainsAndLigandsInfo["EnableMeshChainComplex"][ChainID]
  401     EnableSurfaceChainComplex = SpecifiedChainsAndLigandsInfo["EnableSurfaceChainComplex"][ChainID]
  402     
  403     if MeshChainComplex or VolumeChainComplex or SurfaceChainComplex:
  404         # Set up composite mesh and group...
  405         MapName = PyMOLObjectNames["ComplexCompositeEDMap"]
  406         ContourLevel = OptionsInfo["MeshLevelCompositeMap"]
  407         Color = OptionsInfo["MeshColorCompositeMap"]
  408         VolumeColorRamp = OptionsInfo["VolumeColorRampCompositeMap"]
  409         
  410         MeshName = PyMOLObjectNames["Chains"][ChainID]["ChainComplexCompositeEDMesh"]
  411         VolumeName = PyMOLObjectNames["Chains"][ChainID]["ChainComplexCompositeEDVolume"]
  412         SurfaceName = PyMOLObjectNames["Chains"][ChainID]["ChainComplexCompositeEDSurface"]
  413         
  414         if VolumeChainComplex:
  415             PML = SetupPMLForElectronDensityVolume(MapName, VolumeName, VolumeColorRamp, Enable = EnableVolumeChainComplex, Selection = ChainComplexName)
  416             OutFH.write("\n%s\n" % PML)
  417         
  418         if MeshChainComplex:
  419             PML = SetupPMLForElectronDensityMesh(MapName, MeshName, ContourLevel, Color, Enable = EnableMeshChainComplex, Selection = ChainComplexName)
  420             OutFH.write("\n%s\n" % PML)
  421         
  422         if SurfaceChainComplex:
  423             PML = SetupPMLForElectronDensitySurface(MapName, SurfaceName, ContourLevel, Color, Enable = EnableSurfaceChainComplex, Selection = ChainComplexName)
  424             OutFH.write("\n%s\n" % PML)
  425         
  426         GenerateAndWritePMLForGroup(OutFH, PyMOLObjectNames["Chains"][ChainID]["ChainComplexCompositeEDGroup"], PyMOLObjectNames["Chains"][ChainID]["ChainComplexCompositeEDGroupMembers"], True, "close")
  427         if PyMOLObjectNames["SetupDiffEDMapObjects"]:
  428             # Set up difference meshes and group...
  429             MapName = PyMOLObjectNames["ComplexDiffEDMap"]
  430             
  431             ContourLevel1 = OptionsInfo["Mesh1LevelDiffMap"]
  432             ContourLevel2 = OptionsInfo["Mesh2LevelDiffMap"]
  433             Color1 = OptionsInfo["Mesh1ColorDiffMap"]
  434             Color2 = OptionsInfo["Mesh2ColorDiffMap"]
  435             
  436             VolumeColorRamp = OptionsInfo["VolumeColorRampDiffMap"]
  437             VolumeName = PyMOLObjectNames["Chains"][ChainID]["ChainComplexDiffEDVolume"]
  438             
  439             Mesh1Name = PyMOLObjectNames["Chains"][ChainID]["ChainComplexDiffEDMesh1"]
  440             Surface1Name = PyMOLObjectNames["Chains"][ChainID]["ChainComplexDiffEDSurface1"]
  441             Mesh2Name = PyMOLObjectNames["Chains"][ChainID]["ChainComplexDiffEDMesh2"]
  442             Surface2Name = PyMOLObjectNames["Chains"][ChainID]["ChainComplexDiffEDSurface2"]
  443         
  444             if VolumeChainComplex:
  445                 PML = SetupPMLForElectronDensityVolume(MapName, VolumeName, VolumeColorRamp, Enable = EnableVolumeChainComplex, Selection = ChainComplexName)
  446                 OutFH.write("\n%s\n" % PML)
  447             
  448             if MeshChainComplex:
  449                 PML = SetupPMLForElectronDensityMesh(MapName, Mesh1Name, ContourLevel1, Color1, Enable = EnableMeshChainComplex, Selection = ChainComplexName)
  450                 OutFH.write("\n%s\n" % PML)
  451             
  452             if SurfaceChainComplex:
  453                 PML = SetupPMLForElectronDensitySurface(MapName, Surface1Name, ContourLevel1, Color1, Enable = EnableSurfaceChainComplex, Selection = ChainComplexName)
  454                 OutFH.write("\n%s\n" % PML)
  455             
  456             if MeshChainComplex:
  457                 PML = SetupPMLForElectronDensityMesh(MapName, Mesh2Name, ContourLevel2, Color2, Enable = EnableMeshChainComplex, Selection = ChainComplexName)
  458                 OutFH.write("\n%s\n" % PML)
  459             
  460             if SurfaceChainComplex:
  461                 PML = SetupPMLForElectronDensitySurface(MapName, Surface2Name, ContourLevel2, Color2, Enable = EnableSurfaceChainComplex, Selection = ChainComplexName)
  462                 OutFH.write("\n%s\n" % PML)
  463         
  464             GenerateAndWritePMLForGroup(OutFH, PyMOLObjectNames["Chains"][ChainID]["ChainComplexDiffEDGroup"], PyMOLObjectNames["Chains"][ChainID]["ChainComplexDiffEDGroupMembers"], True, "close")
  465     
  466     # Setup chain complex group...
  467     EnableChainComplexGroup = SpecifiedChainsAndLigandsInfo["EnableChainComplexGroup"][ChainID]
  468     GenerateAndWritePMLForGroup(OutFH, PyMOLObjectNames["Chains"][ChainID]["ChainComplexGroup"], PyMOLObjectNames["Chains"][ChainID]["ChainComplexGroupMembers"], EnableChainComplexGroup, "close")
  469     
  470 def WriteChainAloneViews(OutFH, FileIndex, PyMOLObjectNames, ChainID):
  471     """Write individual chain views. """
  472 
  473     ChainComplexName = PyMOLObjectNames["Chains"][ChainID]["ChainComplex"]
  474     
  475     # Setup chain view...
  476     ChainName = PyMOLObjectNames["Chains"][ChainID]["ChainAlone"]
  477     PML = PyMOLUtil.SetupPMLForPolymerChainView(ChainName, ChainComplexName, Enable = True)
  478     OutFH.write("\n%s\n" % PML)
  479 
  480     # Setup chain putty by B-factor view...
  481     if OptionsInfo["BFactorChainCartoonPutty"]:
  482         BFactorPuttyName = PyMOLObjectNames["Chains"][ChainID]["ChainAloneBFactorPutty"]
  483         PML = PyMOLUtil.SetupPMLForBFactorPuttyView(BFactorPuttyName, ChainName, ColorPalette = OptionsInfo["BFactorColorPalette"], Enable = False)
  484         OutFH.write("\n%s\n" % PML)
  485     
  486     # Setup chain selections view...
  487     SetupChainSelectionsView(OutFH, FileIndex, PyMOLObjectNames, ChainID)
  488     
  489     # Setup chain group...
  490     SpecifiedChainsAndLigandsInfo = OptionsInfo["InfilesInfo"]["SpecifiedChainsAndLigandsInfo"][FileIndex]
  491     EnableChainAloneGroup = SpecifiedChainsAndLigandsInfo["EnableChainAloneGroup"][ChainID]
  492     GenerateAndWritePMLForGroup(OutFH, PyMOLObjectNames["Chains"][ChainID]["ChainAloneGroup"], PyMOLObjectNames["Chains"][ChainID]["ChainAloneGroupMembers"], EnableChainAloneGroup, "close")
  493 
  494 def SetupChainSelectionsView(OutFH, FileIndex, PyMOLObjectNames, ChainID):
  495     """Setup chain selectons view. """
  496 
  497     if not OptionsInfo["ChainSelections"]:
  498         return
  499     
  500     ChainName = PyMOLObjectNames["Chains"][ChainID]["ChainAlone"]
  501     SelectionsGroupIDPrefix = "ChainAloneSelections"
  502     
  503     for Index in range(0, len(OptionsInfo["ChainSelectionsInfo"]["Names"])):
  504         SelectionName = OptionsInfo["ChainSelectionsInfo"]["Names"][Index]
  505         SpecifiedSelection = OptionsInfo["ChainSelectionsInfo"]["Selections"][Index]
  506         
  507         SelectionNameGroupID = SelectionName
  508         
  509         # Setup selection object...
  510         SelectionObjectID = "%s%sSelection" % (SelectionsGroupIDPrefix, SelectionNameGroupID)
  511         SelectionObjectName = PyMOLObjectNames["Chains"][ChainID][SelectionObjectID]
  512         SelectionCmd = "(%s and (%s))" % (ChainName, SpecifiedSelection)
  513         PML = PyMOLUtil.SetupPMLForSelectionDisplayView(SelectionObjectName, SelectionCmd, OptionsInfo["SelectionsChainStyle"], Enable = True)
  514         OutFH.write("\n%s\n" % PML)
  515         
  516         # Set up composite mesh and group...
  517         CompositeMeshID = "%s%sCompositeEDMesh" % (SelectionsGroupIDPrefix, SelectionNameGroupID)
  518         CompositeVolumeID = "%s%sCompositeEDVolume" % (SelectionsGroupIDPrefix, SelectionNameGroupID)
  519         CompositeSurfaceID = "%s%sCompositeEDSurface" % (SelectionsGroupIDPrefix, SelectionNameGroupID)
  520         CompositeMeshGroupID = "%s%sCompositeEDGroup" % (SelectionsGroupIDPrefix, SelectionNameGroupID)
  521         CompositeMeshGroupMembersID = "%s%sCompositeEDGroupMembers" % (SelectionsGroupIDPrefix, SelectionNameGroupID)
  522         
  523         CompositeMapName = PyMOLObjectNames["ComplexCompositeEDMap"]
  524         CompositeMeshName = PyMOLObjectNames["Chains"][ChainID][CompositeMeshID]
  525         CompositeVolumeName = PyMOLObjectNames["Chains"][ChainID][CompositeVolumeID]
  526         CompositeSurfaceName = PyMOLObjectNames["Chains"][ChainID][CompositeSurfaceID]
  527         CompositeMeshGroupName = PyMOLObjectNames["Chains"][ChainID][CompositeMeshGroupID]
  528         CompositeMeshGroupMembers = PyMOLObjectNames["Chains"][ChainID][CompositeMeshGroupMembersID]
  529         
  530         PML = SetupPMLForElectronDensityVolume(CompositeMapName, CompositeVolumeName, OptionsInfo["VolumeColorRampCompositeMap"], Enable = False, Selection = SelectionObjectName)
  531         OutFH.write("\n%s\n" % PML)
  532         
  533         PML = SetupPMLForElectronDensityMesh(CompositeMapName, CompositeMeshName, OptionsInfo["MeshLevelCompositeMap"], OptionsInfo["MeshColorCompositeMap"], Enable = True, Selection = SelectionObjectName)
  534         OutFH.write("\n%s\n" % PML)
  535         
  536         PML = SetupPMLForElectronDensitySurface(CompositeMapName, CompositeSurfaceName, OptionsInfo["MeshLevelCompositeMap"], OptionsInfo["MeshColorCompositeMap"], Enable = False, Selection = SelectionObjectName)
  537         OutFH.write("\n%s\n" % PML)
  538         
  539         GenerateAndWritePMLForGroup(OutFH, CompositeMeshGroupName, CompositeMeshGroupMembers, True, "close")
  540         
  541         if PyMOLObjectNames["SetupDiffEDMapObjects"]:
  542             # Set up difference meshes and group...
  543             DiffVolumeID = "%s%sDiffEDVolume" % (SelectionsGroupIDPrefix, SelectionNameGroupID)
  544             DiffMesh1ID = "%s%sDiffEDMesh1" % (SelectionsGroupIDPrefix, SelectionNameGroupID)
  545             DiffSurface1ID = "%s%sDiffEDSurface1" % (SelectionsGroupIDPrefix, SelectionNameGroupID)
  546             DiffMesh2ID = "%s%sDiffEDMesh2" % (SelectionsGroupIDPrefix, SelectionNameGroupID)
  547             DiffSurface2ID = "%s%sDiffEDSurface1" % (SelectionsGroupIDPrefix, SelectionNameGroupID)
  548             DiffMeshGroupID = "%s%sDiffEDGroup" % (SelectionsGroupIDPrefix, SelectionNameGroupID)
  549             DiffMeshGroupMembersID = "%s%sDiffEDGroupMembers" % (SelectionsGroupIDPrefix, SelectionNameGroupID)
  550             
  551             DiffMapName = PyMOLObjectNames["ComplexDiffEDMap"]
  552             DiffVolumeName = PyMOLObjectNames["Chains"][ChainID][DiffVolumeID]
  553             DiffMesh1Name = PyMOLObjectNames["Chains"][ChainID][DiffMesh1ID]
  554             DiffSurface1Name = PyMOLObjectNames["Chains"][ChainID][DiffSurface1ID]
  555             DiffMesh2Name = PyMOLObjectNames["Chains"][ChainID][DiffMesh2ID]
  556             DiffSurface2Name = PyMOLObjectNames["Chains"][ChainID][DiffSurface2ID]
  557             DiffMeshGroupName = PyMOLObjectNames["Chains"][ChainID][DiffMeshGroupID]
  558             DiffMeshGroupMembers = PyMOLObjectNames["Chains"][ChainID][DiffMeshGroupMembersID]
  559             
  560             PML = SetupPMLForElectronDensityVolume(DiffMapName, DiffVolumeName, OptionsInfo["VolumeColorRampDiffMap"], Enable = False, Selection = SelectionObjectName)
  561             OutFH.write("\n%s\n" % PML)
  562             
  563             PML = SetupPMLForElectronDensityMesh(DiffMapName, DiffMesh1Name, OptionsInfo["Mesh1LevelDiffMap"], OptionsInfo["Mesh1ColorDiffMap"],  Enable = True, Selection = SelectionObjectName)
  564             OutFH.write("\n%s\n" % PML)
  565             
  566             PML = SetupPMLForElectronDensitySurface(DiffMapName, DiffSurface1Name, OptionsInfo["Mesh1LevelDiffMap"], OptionsInfo["Mesh1ColorDiffMap"],  Enable = False, Selection = SelectionObjectName)
  567             OutFH.write("\n%s\n" % PML)
  568             
  569             PML = SetupPMLForElectronDensityMesh(DiffMapName, DiffMesh2Name, OptionsInfo["Mesh2LevelDiffMap"], OptionsInfo["Mesh2ColorDiffMap"],  Enable = True, Selection = SelectionObjectName)
  570             OutFH.write("\n%s\n" % PML)
  571             
  572             PML = SetupPMLForElectronDensitySurface(DiffMapName, DiffSurface2Name, OptionsInfo["Mesh2LevelDiffMap"], OptionsInfo["Mesh2ColorDiffMap"],  Enable = False, Selection = SelectionObjectName)
  573             OutFH.write("\n%s\n" % PML)
  574         
  575             GenerateAndWritePMLForGroup(OutFH, DiffMeshGroupName, DiffMeshGroupMembers, True, "close")
  576         
  577         # Setup groups for named selections...
  578         SelectionsNameGroupID = "%s%sGroup" % (SelectionsGroupIDPrefix, SelectionNameGroupID)
  579         SelectionsNameGroupMembersID = "%s%sGroupMembers" % (SelectionsGroupIDPrefix, SelectionNameGroupID)
  580         GenerateAndWritePMLForGroup(OutFH, PyMOLObjectNames["Chains"][ChainID][SelectionsNameGroupID], PyMOLObjectNames["Chains"][ChainID][SelectionsNameGroupMembersID], True, "open")
  581 
  582     # Setup a group for selections...
  583     SelectionsGroupID = "%sGroup" % (SelectionsGroupIDPrefix)
  584     SelectionsGroupMembersID = "%sGroupMembers" % (SelectionsGroupIDPrefix)
  585     GenerateAndWritePMLForGroup(OutFH, PyMOLObjectNames["Chains"][ChainID][SelectionsGroupID], PyMOLObjectNames["Chains"][ChainID][SelectionsGroupMembersID], False, "close")
  586 
  587 def WriteChainLigandView(OutFH, FileIndex, PyMOLObjectNames, ChainID, LigandID):
  588     """Write out PML for viewing ligand in a chain."""
  589     
  590     for GroupID in ["Ligand", "Pocket", "PocketSolvent", "PocketInorganic"]:
  591         ComplexName = PyMOLObjectNames["Chains"][ChainID]["ChainComplex"]
  592         LigandName = PyMOLObjectNames["Ligands"][ChainID][LigandID]["Ligand"]
  593         
  594         # Setup main object...
  595         GroupTypeObjectID = "%s" % (GroupID)
  596         GroupTypeObjectName = PyMOLObjectNames["Ligands"][ChainID][LigandID][GroupTypeObjectID]
  597         
  598         if re.match("^Ligand$", GroupID, re.I):
  599             OutFH.write("""\n""\n"Setting up views for ligand %s in chain %s..."\n""\n""" % (LigandID, ChainID))
  600             PML = PyMOLUtil.SetupPMLForLigandView(GroupTypeObjectName, ComplexName, LigandID, True)
  601             OutFH.write("%s\n" % PML)
  602         elif re.match("^Pocket$", GroupID, re.I):
  603             OutFH.write("""\n""\n"Setting up views for pocket around ligand %s in chain %s..."\n""\n""" % (LigandID, ChainID))
  604             PML = PyMOLUtil.SetupPMLForLigandPocketView(GroupTypeObjectName, ComplexName, LigandName, OptionsInfo["PocketDistanceCutoff"], True)
  605             OutFH.write("%s\n" % PML)
  606             OutFH.write("""cmd.set("label_color", "%s", "%s")\n""" % (OptionsInfo["PocketLabelColor"], GroupTypeObjectName))
  607         elif re.match("^PocketSolvent$", GroupID, re.I):
  608             OutFH.write("""\n""\n"Setting up views for solvent in pockect around ligand %s in chain %s..."\n""\n""" % (LigandID, ChainID))
  609             PML = PyMOLUtil.SetupPMLForLigandPocketSolventView(GroupTypeObjectName, ComplexName, LigandName, OptionsInfo["PocketDistanceCutoff"], Enable = True)
  610             OutFH.write("%s\n" % PML)
  611         elif re.match("^PocketInorganic$", GroupID, re.I):
  612             OutFH.write("""\n""\n"Setting up views for inorganic in pockect around ligand %s in chain %s..."\n""\n""" % (LigandID, ChainID))
  613             PML = PyMOLUtil.SetupPMLForLigandPocketInorganicView(GroupTypeObjectName, ComplexName, LigandName, OptionsInfo["PocketDistanceCutoff"], Enable = True)
  614             OutFH.write("%s\n" % PML)
  615         
  616         # Set up composite mesh and group...
  617         CompositeMeshGroupID = "%sCompositeEDMeshGroup" % (GroupID)
  618         CompositeMeshGroupMembersID = "%sCompositeEDMeshGroupMembers" % (GroupID)
  619         CompositeMeshID = "%sCompositeEDMesh" % (GroupID)
  620         CompositeVolumeID = "%sCompositeEDVolume" % (GroupID)
  621         CompositeSurfaceID = "%sCompositeEDSurface" % (GroupID)
  622 
  623         CompositeMapName = PyMOLObjectNames["ComplexCompositeEDMap"]
  624         CompositeMeshName = PyMOLObjectNames["Ligands"][ChainID][LigandID][CompositeMeshID]
  625         CompositeVolumeName = PyMOLObjectNames["Ligands"][ChainID][LigandID][CompositeVolumeID]
  626         CompositeSurfaceName = PyMOLObjectNames["Ligands"][ChainID][LigandID][CompositeSurfaceID]
  627         CompositeMeshGroupName = PyMOLObjectNames["Ligands"][ChainID][LigandID][CompositeMeshGroupID]
  628         CompositeMeshGroupMembers = PyMOLObjectNames["Ligands"][ChainID][LigandID][CompositeMeshGroupMembersID]
  629         
  630         PML = SetupPMLForElectronDensityVolume(CompositeMapName, CompositeVolumeName, OptionsInfo["VolumeColorRampCompositeMap"], Enable = False, Selection = GroupTypeObjectName)
  631         OutFH.write("\n%s\n" % PML)
  632         
  633         PML = SetupPMLForElectronDensityMesh(CompositeMapName, CompositeMeshName, OptionsInfo["MeshLevelCompositeMap"], OptionsInfo["MeshColorCompositeMap"], Enable = True, Selection = GroupTypeObjectName)
  634         OutFH.write("\n%s\n" % PML)
  635         
  636         PML = SetupPMLForElectronDensitySurface(CompositeMapName, CompositeSurfaceName, OptionsInfo["MeshLevelCompositeMap"], OptionsInfo["MeshColorCompositeMap"], Enable = False, Selection = GroupTypeObjectName)
  637         OutFH.write("\n%s\n" % PML)
  638         
  639         GenerateAndWritePMLForGroup(OutFH, CompositeMeshGroupName, CompositeMeshGroupMembers, True, "close")
  640         
  641         if PyMOLObjectNames["SetupDiffEDMapObjects"]:
  642             # Set up difference meshes and group...
  643             DiffMeshGroupID = "%sDiffEDMeshGroup" % (GroupID)
  644             DiffMeshGroupMembersID = "%sDiffEDMeshGroupMembers" % (GroupID)
  645             DiffVolumeID = "%sDiffEDVolume" % (GroupID)
  646             DiffMesh1ID = "%sDiffEDMesh1" % (GroupID)
  647             DiffSurface1ID = "%sDiffEDSurface1" % (GroupID)
  648             DiffMesh2ID = "%sDiffEDMesh2" % (GroupID)
  649             DiffSurface2ID = "%sDiffEDSurface2" % (GroupID)
  650         
  651             DiffMapName = PyMOLObjectNames["ComplexDiffEDMap"]
  652             DiffVolumeName = PyMOLObjectNames["Ligands"][ChainID][LigandID][DiffVolumeID]
  653             DiffMesh1Name = PyMOLObjectNames["Ligands"][ChainID][LigandID][DiffMesh1ID]
  654             DiffSurface1Name = PyMOLObjectNames["Ligands"][ChainID][LigandID][DiffSurface1ID]
  655             DiffMesh2Name = PyMOLObjectNames["Ligands"][ChainID][LigandID][DiffMesh2ID]
  656             DiffSurface2Name = PyMOLObjectNames["Ligands"][ChainID][LigandID][DiffSurface2ID]
  657             DiffMeshGroupName = PyMOLObjectNames["Ligands"][ChainID][LigandID][DiffMeshGroupID]
  658             DiffMeshGroupMembers = PyMOLObjectNames["Ligands"][ChainID][LigandID][DiffMeshGroupMembersID]
  659             
  660             PML = SetupPMLForElectronDensityVolume(DiffMapName, DiffVolumeName, OptionsInfo["VolumeColorRampDiffMap"], Enable = False, Selection = GroupTypeObjectName)
  661             OutFH.write("\n%s\n" % PML)
  662             
  663             PML = SetupPMLForElectronDensityMesh(DiffMapName, DiffMesh1Name, OptionsInfo["Mesh1LevelDiffMap"], OptionsInfo["Mesh1ColorDiffMap"],  Enable = True, Selection = GroupTypeObjectName)
  664             OutFH.write("\n%s\n" % PML)
  665             
  666             PML = SetupPMLForElectronDensitySurface(DiffMapName, DiffSurface1Name, OptionsInfo["Mesh1LevelDiffMap"], OptionsInfo["Mesh1ColorDiffMap"],  Enable = False, Selection = GroupTypeObjectName)
  667             OutFH.write("\n%s\n" % PML)
  668             
  669             PML = SetupPMLForElectronDensityMesh(DiffMapName, DiffMesh2Name, OptionsInfo["Mesh2LevelDiffMap"], OptionsInfo["Mesh2ColorDiffMap"],  Enable = True, Selection = GroupTypeObjectName)
  670             OutFH.write("\n%s\n" % PML)
  671             
  672             PML = SetupPMLForElectronDensitySurface(DiffMapName, DiffSurface2Name, OptionsInfo["Mesh2LevelDiffMap"], OptionsInfo["Mesh2ColorDiffMap"],  Enable = False, Selection = GroupTypeObjectName)
  673             OutFH.write("\n%s\n" % PML)
  674         
  675             GenerateAndWritePMLForGroup(OutFH, DiffMeshGroupName, DiffMeshGroupMembers, True, "close")
  676         
  677         # Set up polar contacts...
  678         if re.match("^(Pocket|PocketSolvent|PocketInorganic)$", GroupID, re.I):
  679             PolarContactsID = "%sPolarContacts" % (GroupID)
  680             PolarContactsName = PyMOLObjectNames["Ligands"][ChainID][LigandID][PolarContactsID]
  681             
  682             PolarContactsColor = OptionsInfo["PocketContactsLigandColor"]
  683             if re.match("^PocketSolvent$", GroupID, re.I):
  684                 PolarContactsColor = OptionsInfo["PocketContactsSolventColor"]
  685             elif re.match("^PocketInorganic$", GroupID, re.I):
  686                 PolarContactsColor = OptionsInfo["PocketContactsInorganicColor"]
  687             
  688             PML = PyMOLUtil.SetupPMLForPolarContactsView(PolarContactsName, LigandName, GroupTypeObjectName, Enable = False, Color = PolarContactsColor, Cutoff = OptionsInfo["PocketContactsCutoff"])
  689             OutFH.write("\n%s\n" % PML)
  690             
  691             OutFH.write("""cmd.set("label_color", "%s", "%s")\n""" % (PolarContactsColor, PolarContactsName))
  692             
  693         # Set up hydrophobic contacts...
  694         if re.match("^Pocket$", GroupID, re.I):
  695             HydrophobicContactsID = "%sHydrophobicContacts" % (GroupID)
  696             HydrophobicContactsName = PyMOLObjectNames["Ligands"][ChainID][LigandID][HydrophobicContactsID]
  697             HydrophobicContactsColor = OptionsInfo["PocketContactsLigandHydrophobicColor"]
  698             
  699             PML = PyMOLUtil.SetupPMLForHydrophobicContactsView(HydrophobicContactsName, LigandName, GroupTypeObjectName, Enable = False, Color = HydrophobicContactsColor, Cutoff = OptionsInfo["PocketContactsCutoff"])
  700             OutFH.write("\n%s\n" % PML)
  701             OutFH.write("""cmd.set("label_color", "%s", "%s")\n""" % (HydrophobicContactsColor, HydrophobicContactsName))
  702         
  703         # Set up hydrophobic surface...
  704         if re.match("^Pocket$", GroupID, re.I) and OptionsInfo["PocketSurface"]:
  705             HydrophobicSurfaceID = "%sHydrophobicSurface" % (GroupID)
  706             HydrophobicSurfaceName = PyMOLObjectNames["Ligands"][ChainID][LigandID][HydrophobicSurfaceID]
  707             PML = PyMOLUtil.SetupPMLForHydrophobicSurfaceView(HydrophobicSurfaceName, GroupTypeObjectName, ColorPalette = "RedToWhite", Enable = False)
  708             OutFH.write("\n%s\n" % PML)
  709             
  710             OutFH.write("""cmd.set("label_color", "%s", "%s")\n""" % (OptionsInfo["PocketLabelColor"], HydrophobicSurfaceName))
  711         
  712         # Setup group....
  713         GroupNameID = "%sGroup" % (GroupID)
  714         GroupMembersID = "%sGroupMembers" % (GroupID)
  715         GroupName = PyMOLObjectNames["Ligands"][ChainID][LigandID][GroupNameID]
  716         GroupMembers = PyMOLObjectNames["Ligands"][ChainID][LigandID][GroupMembersID]
  717 
  718         Action = "close"
  719         Enable = False
  720         if  re.match("^(Ligand|Pocket)$", GroupID, re.I):
  721             Action = "open"
  722             Enable = True
  723         GenerateAndWritePMLForGroup(OutFH, GroupName, GroupMembers, Enable, Action)
  724 
  725 def GenerateAndWritePMLForGroup(OutFH, GroupName, GroupMembers, Enable = False, Action = "close"):
  726     """Generate and write PML for group. """
  727     
  728     PML = PyMOLUtil.SetupPMLForGroup(GroupName, GroupMembers, Enable, Action)
  729     OutFH.write("""\n""\n"Setting up group %s..."\n""\n""" % GroupName)
  730     OutFH.write("%s\n" % PML)
  731 
  732 def SetupPMLForElectronDensityMap(MapFileName, MapName, AlignMapToObjectName = None, Enable = True):
  733     """Setup PML for loading and viewing electron density map. """
  734 
  735     PMLCmds = []
  736     PMLCmds.append("""cmd.load("%s", "%s")""" % (MapFileName, MapName))
  737     if AlignMapToObjectName is not None:
  738         PMLCmds.append("""cmd.matrix_copy("%s", "%s")""" % (AlignMapToObjectName, MapName))
  739         
  740     PMLCmds.append(PyMOLUtil.SetupPMLForEnableDisable(MapName, Enable))
  741     
  742     PML = "\n".join(PMLCmds)
  743     
  744     return PML
  745     
  746 def SetupPMLForElectronDensityMesh(MapName, MeshName, SigmaLevel, Color, Enable = True, Selection = None):
  747     """Setup PML for electron density mesh. """
  748 
  749     Carve = OptionsInfo["MeshCarveRadius"]
  750     
  751     PMLCmds = []
  752     if Selection is None:
  753         PMLCmds.append("""cmd.isomesh("%s", "%s", %.1f)""" % (MeshName, MapName, SigmaLevel))
  754     else:
  755         PMLCmds.append("""cmd.isomesh("%s", "%s", %.1f, "(%s)", carve = %.1f)""" % (MeshName, MapName, SigmaLevel, Selection, Carve))
  756     PMLCmds.append("""util.color_deep("%s", "%s")""" % (Color, MeshName))
  757     PMLCmds.append(PyMOLUtil.SetupPMLForEnableDisable(MeshName, Enable))
  758     
  759     PML = "\n".join(PMLCmds)
  760     
  761     return PML
  762 
  763 def SetupPMLForElectronDensityVolume(MapName, VolumeName, VolumeColorRamp, Enable = True, Selection = None):
  764     """Setup PML for electron density volume. """
  765 
  766     Carve = OptionsInfo["VolumeCarveRadius"]
  767     
  768     PMLCmds = []
  769     if Selection is None:
  770         PMLCmds.append("""cmd.volume("%s", "%s", "%s")""" % (VolumeName, MapName, VolumeColorRamp))
  771     else:
  772         PMLCmds.append("""cmd.volume("%s", "%s", "%s", "(%s)", carve = %.1f)""" % (VolumeName, MapName, VolumeColorRamp, Selection, Carve))
  773     PMLCmds.append(PyMOLUtil.SetupPMLForEnableDisable(VolumeName, Enable))
  774     
  775     PML = "\n".join(PMLCmds)
  776     
  777     return PML
  778 
  779 def SetupPMLForElectronDensitySurface(MapName, SurfaceName, SigmaLevel, Color, Enable = True, Selection = None):
  780     """Setup PML for electron density surface. """
  781 
  782     Carve = OptionsInfo["MeshCarveRadius"]
  783     
  784     PMLCmds = []
  785     if Selection is None:
  786         PMLCmds.append("""cmd.isosurface("%s", "%s", %.1f)""" % (SurfaceName, MapName, SigmaLevel))
  787     else:
  788         PMLCmds.append("""cmd.isosurface("%s", "%s", %.1f, "(%s)", carve = %.1f)""" % (SurfaceName, MapName, SigmaLevel, Selection, Carve))
  789     PMLCmds.append("""util.color_deep("%s", "%s")""" % (Color, SurfaceName))
  790     PMLCmds.append(PyMOLUtil.SetupPMLForEnableDisable(SurfaceName, Enable))
  791     
  792     PML = "\n".join(PMLCmds)
  793     
  794     return PML
  795 
  796 def GeneratePyMOLSessionFile():
  797     """Generate PME file from PML file. """
  798 
  799     PSEOutfile = OptionsInfo["PSEOutfile"]
  800     PMLOutfile = OptionsInfo["PMLOutfile"]
  801     
  802     MiscUtil.PrintInfo("\nGenerating file %s..." % PSEOutfile)
  803     
  804     PyMOLUtil.ConvertPMLFileToPSEFile(PMLOutfile, PSEOutfile)
  805     
  806     if not os.path.exists(PSEOutfile):
  807         MiscUtil.PrintWarning("Failed to generate PSE file, %s..." % (PSEOutfile))
  808     
  809     if not OptionsInfo["PMLOut"]:
  810         MiscUtil.PrintInfo("Deleting file %s..." % PMLOutfile)
  811         os.remove(PMLOutfile)
  812 
  813 def DeleteEmptyPyMOLObjects(OutFH, FileIndex, PyMOLObjectNames):
  814     """Delete empty PyMOL objects. """
  815     
  816     if OptionsInfo["AllowEmptyObjects"]:
  817         return
  818     
  819     SpecifiedChainsAndLigandsInfo = OptionsInfo["InfilesInfo"]["SpecifiedChainsAndLigandsInfo"][FileIndex]
  820     for ChainID in SpecifiedChainsAndLigandsInfo["ChainIDs"]:
  821         OutFH.write("""\n""\n"Checking and deleting empty objects for chain %s..."\n""\n""" % (ChainID))
  822         
  823         # Delete any chain level objects...
  824         WritePMLToCheckAndDeleteEmptyObjects(OutFH, PyMOLObjectNames["Chains"][ChainID]["Solvent"])
  825         WritePMLToCheckAndDeleteEmptyObjects(OutFH, PyMOLObjectNames["Chains"][ChainID]["Inorganic"])
  826         
  827         for LigandID in SpecifiedChainsAndLigandsInfo["LigandIDs"][ChainID]:
  828             # Delete ligand level objects...
  829             for GroupID in ["Pocket", "PocketSolvent", "PocketInorganic"]:
  830                 GroupNameID = "%sGroup" % (GroupID)
  831                 GroupName = PyMOLObjectNames["Ligands"][ChainID][LigandID][GroupNameID]
  832 
  833                 GroupTypeObjectID = "%s" % (GroupID)
  834                 GroupTypeObjectName = PyMOLObjectNames["Ligands"][ChainID][LigandID][GroupTypeObjectID]
  835                 
  836                 WritePMLToCheckAndDeleteEmptyObjects(OutFH, GroupTypeObjectName, GroupName)
  837 
  838 def WritePMLToCheckAndDeleteEmptyObjects(OutFH, ObjectName, ParentObjectName = None):
  839     """Write PML to check and delete empty PyMOL objects. """
  840     
  841     if ParentObjectName is None:
  842         PML = """CheckAndDeleteEmptyObjects("%s")""" % (ObjectName)
  843     else:
  844         PML = """CheckAndDeleteEmptyObjects("%s", "%s")""" % (ObjectName, ParentObjectName)
  845     
  846     OutFH.write("%s\n" % PML)
  847 
  848 def SetupPyMOLObjectNames(FileIndex):
  849     """Setup hierarchy of PyMOL groups and objects for ligand centric views of
  850     electron density for chains and ligands present in input file.
  851     """
  852 
  853     PyMOLObjectNames = {}
  854     PyMOLObjectNames["Chains"] = {}
  855     PyMOLObjectNames["Ligands"] = {}
  856 
  857     PyMOLObjectNames["SetupDiffEDMapObjects"] = False if OptionsInfo["DiffEDMapFiles"][FileIndex] is None else True
  858 
  859     # Setup groups and objects for complex...
  860     SetupPyMOLObjectNamesForComplex(FileIndex, PyMOLObjectNames)
  861     
  862     # Setup groups and objects for chain...
  863     SpecifiedChainsAndLigandsInfo = OptionsInfo["InfilesInfo"]["SpecifiedChainsAndLigandsInfo"][FileIndex]
  864     for ChainID in SpecifiedChainsAndLigandsInfo["ChainIDs"]:
  865         SetupPyMOLObjectNamesForChain(FileIndex, PyMOLObjectNames, ChainID)
  866         
  867         # Setup groups and objects for ligand...
  868         for LigandID in SpecifiedChainsAndLigandsInfo["LigandIDs"][ChainID]:
  869             SetupPyMOLObjectNamesForLigand(FileIndex, PyMOLObjectNames, ChainID, LigandID)
  870 
  871     return PyMOLObjectNames
  872 
  873 def SetupPyMOLObjectNamesForComplex(FileIndex, PyMOLObjectNames):
  874     """Stetup groups and objects for complex. """
  875     
  876     PDBFileRoot = OptionsInfo["InfilesInfo"]["InfilesRoots"][FileIndex]
  877     
  878     PDBGroupName = "%s" % PDBFileRoot
  879     PyMOLObjectNames["PDBGroup"] = PDBGroupName
  880     PyMOLObjectNames["PDBGroupMembers"] = []
  881 
  882     ComplexGroupName = "%s.Complex" % PyMOLObjectNames["PDBGroup"]
  883     PyMOLObjectNames["ComplexGroup"] = ComplexGroupName
  884     PyMOLObjectNames["PDBGroupMembers"].append(ComplexGroupName)
  885     
  886     PyMOLObjectNames["Complex"] = "%s.Complex" % ComplexGroupName
  887 
  888     CompositeMeshGroupName = "%s.2Fo-Fc" % (ComplexGroupName)
  889     CompositeMapName = "%s.Map" % (CompositeMeshGroupName)
  890     CompositeMeshName = "%s.Mesh" % (CompositeMeshGroupName)
  891     CompositeVolumeName = "%s.Volume" % (CompositeMeshGroupName)
  892     CompositeSurfaceName = "%s.Surface" % (CompositeMeshGroupName)
  893     
  894     PyMOLObjectNames["ComplexCompositeEDGroup"] = CompositeMeshGroupName
  895     PyMOLObjectNames["ComplexCompositeEDMap"] = CompositeMapName
  896     PyMOLObjectNames["ComplexCompositeEDMesh"] = CompositeMeshName
  897     PyMOLObjectNames["ComplexCompositeEDVolume"] = CompositeVolumeName
  898     PyMOLObjectNames["ComplexCompositeEDSurface"] = CompositeSurfaceName
  899 
  900     PyMOLObjectNames["ComplexCompositeEDGroupMembers"] = []
  901     PyMOLObjectNames["ComplexCompositeEDGroupMembers"].append(CompositeMapName)
  902     if OptionsInfo["VolumeComplex"]:
  903         PyMOLObjectNames["ComplexCompositeEDGroupMembers"].append(CompositeVolumeName)
  904     if OptionsInfo["MeshComplex"]:
  905         PyMOLObjectNames["ComplexCompositeEDGroupMembers"].append(CompositeMeshName)
  906     if OptionsInfo["SurfaceComplex"]:
  907         PyMOLObjectNames["ComplexCompositeEDGroupMembers"].append(CompositeSurfaceName)
  908     if PyMOLObjectNames["SetupDiffEDMapObjects"]:
  909         DiffMeshGroupName = "%s.Fo-Fc" % ComplexGroupName
  910         DiffMapName = "%s.Map" % DiffMeshGroupName
  911         DiffVolumeName = "%s.Volume" % DiffMeshGroupName
  912         DiffMesh1Name = "%s.Mesh1" % DiffMeshGroupName
  913         DiffSurface1Name = "%s.Surface1" % DiffMeshGroupName
  914         DiffMesh2Name = "%s.Mesh2" % DiffMeshGroupName
  915         DiffSurface2Name = "%s.Surface2" % DiffMeshGroupName
  916         
  917         PyMOLObjectNames["ComplexDiffEDGroup"] = DiffMeshGroupName
  918         PyMOLObjectNames["ComplexDiffEDMap"] = DiffMapName
  919         PyMOLObjectNames["ComplexDiffEDVolume"] = DiffVolumeName
  920         PyMOLObjectNames["ComplexDiffEDMesh1"] = DiffMesh1Name
  921         PyMOLObjectNames["ComplexDiffEDSurface1"] = DiffSurface1Name
  922         PyMOLObjectNames["ComplexDiffEDMesh2"] = DiffMesh2Name
  923         PyMOLObjectNames["ComplexDiffEDSurface2"] = DiffSurface2Name
  924         
  925         PyMOLObjectNames["ComplexDiffEDGroupMembers"] = []
  926         PyMOLObjectNames["ComplexDiffEDGroupMembers"].append(DiffMapName)
  927         if OptionsInfo["VolumeComplex"]:
  928             PyMOLObjectNames["ComplexDiffEDGroupMembers"].append(DiffVolumeName)
  929         if OptionsInfo["MeshComplex"]:
  930             PyMOLObjectNames["ComplexDiffEDGroupMembers"].append(DiffMesh1Name)
  931         if OptionsInfo["SurfaceComplex"]:
  932             PyMOLObjectNames["ComplexDiffEDGroupMembers"].append(DiffSurface1Name)
  933         if OptionsInfo["MeshComplex"]:
  934             PyMOLObjectNames["ComplexDiffEDGroupMembers"].append(DiffMesh2Name)
  935         if OptionsInfo["SurfaceComplex"]:
  936             PyMOLObjectNames["ComplexDiffEDGroupMembers"].append(DiffSurface2Name)
  937     
  938     PyMOLObjectNames["ComplexGroupMembers"] = []
  939     PyMOLObjectNames["ComplexGroupMembers"].append(PyMOLObjectNames["Complex"])
  940     PyMOLObjectNames["ComplexGroupMembers"].append(PyMOLObjectNames["ComplexCompositeEDGroup"])
  941     if PyMOLObjectNames["SetupDiffEDMapObjects"]:
  942         PyMOLObjectNames["ComplexGroupMembers"].append(PyMOLObjectNames["ComplexDiffEDGroup"])
  943     
  944 def SetupPyMOLObjectNamesForChain(FileIndex, PyMOLObjectNames, ChainID):
  945     """Setup groups and objects for chain."""
  946     
  947     PDBGroupName = PyMOLObjectNames["PDBGroup"]
  948     
  949     SpecifiedChainsAndLigandsInfo = OptionsInfo["InfilesInfo"]["SpecifiedChainsAndLigandsInfo"][FileIndex]
  950     MeshChainComplex = SpecifiedChainsAndLigandsInfo["MeshChainComplex"][ChainID]
  951     VolumeChainComplex = SpecifiedChainsAndLigandsInfo["VolumeChainComplex"][ChainID]
  952     SurfaceChainComplex = SpecifiedChainsAndLigandsInfo["SurfaceChainComplex"][ChainID]
  953     
  954     PyMOLObjectNames["Chains"][ChainID] = {}
  955     PyMOLObjectNames["Ligands"][ChainID] = {}
  956     
  957     # Set up chain group and chain objects...
  958     ChainGroupName = "%s.Chain%s" % (PDBGroupName, ChainID)
  959     PyMOLObjectNames["Chains"][ChainID]["ChainGroup"] = ChainGroupName
  960     PyMOLObjectNames["PDBGroupMembers"].append(ChainGroupName)
  961     PyMOLObjectNames["Chains"][ChainID]["ChainGroupMembers"] = []
  962     
  963     # Setup chain complex group and objects...
  964     ChainComplexGroupName = "%s.Complex" % (ChainGroupName)
  965     PyMOLObjectNames["Chains"][ChainID]["ChainComplexGroup"] = ChainComplexGroupName
  966     PyMOLObjectNames["Chains"][ChainID]["ChainGroupMembers"].append(ChainComplexGroupName)
  967     
  968     PyMOLObjectNames["Chains"][ChainID]["ChainComplex"] = "%s.Complex" % (ChainComplexGroupName)
  969     
  970     CompositeMeshGroupName = "%s.2Fo-Fc" % (ChainComplexGroupName)
  971     CompositeMeshName = "%s.Mesh" % (CompositeMeshGroupName)
  972     CompositeVolumeName = "%s.Volume" % (CompositeMeshGroupName)
  973     CompositeSurfaceName = "%s.Surface" % (CompositeMeshGroupName)
  974     
  975     PyMOLObjectNames["Chains"][ChainID]["ChainComplexCompositeEDGroup"] = CompositeMeshGroupName
  976     PyMOLObjectNames["Chains"][ChainID]["ChainComplexCompositeEDMesh"] = CompositeMeshName
  977     PyMOLObjectNames["Chains"][ChainID]["ChainComplexCompositeEDVolume"] = CompositeVolumeName
  978     PyMOLObjectNames["Chains"][ChainID]["ChainComplexCompositeEDSurface"] = CompositeSurfaceName
  979     
  980     PyMOLObjectNames["Chains"][ChainID]["ChainComplexCompositeEDGroupMembers"] = []
  981     if VolumeChainComplex:
  982         PyMOLObjectNames["Chains"][ChainID]["ChainComplexCompositeEDGroupMembers"].append(CompositeVolumeName)
  983     if MeshChainComplex:
  984         PyMOLObjectNames["Chains"][ChainID]["ChainComplexCompositeEDGroupMembers"].append(CompositeMeshName)
  985     if SurfaceChainComplex:
  986         PyMOLObjectNames["Chains"][ChainID]["ChainComplexCompositeEDGroupMembers"].append(CompositeSurfaceName)
  987     
  988     if PyMOLObjectNames["SetupDiffEDMapObjects"]:
  989         DiffMeshGroupName = "%s.Fo-Fc" % (ChainComplexGroupName)
  990         DiffVolumeName = "%s.Volume" % (DiffMeshGroupName)
  991         DiffMesh1Name = "%s.Mesh1" % (DiffMeshGroupName)
  992         DiffSurface1Name = "%s.Surface1" % (DiffMeshGroupName)
  993         DiffMesh2Name = "%s.Mesh2" % (DiffMeshGroupName)
  994         DiffSurface2Name = "%s.Surface2" % (DiffMeshGroupName)
  995         
  996         PyMOLObjectNames["Chains"][ChainID]["ChainComplexDiffEDGroup"] = DiffMeshGroupName
  997         PyMOLObjectNames["Chains"][ChainID]["ChainComplexDiffEDVolume"] = DiffVolumeName
  998         PyMOLObjectNames["Chains"][ChainID]["ChainComplexDiffEDMesh1"] = DiffMesh1Name
  999         PyMOLObjectNames["Chains"][ChainID]["ChainComplexDiffEDSurface1"] = DiffSurface1Name
 1000         PyMOLObjectNames["Chains"][ChainID]["ChainComplexDiffEDMesh2"] = DiffMesh2Name
 1001         PyMOLObjectNames["Chains"][ChainID]["ChainComplexDiffEDSurface2"] = DiffSurface2Name
 1002         
 1003         PyMOLObjectNames["Chains"][ChainID]["ChainComplexDiffEDGroupMembers"] = []
 1004         if VolumeChainComplex:
 1005             PyMOLObjectNames["Chains"][ChainID]["ChainComplexDiffEDGroupMembers"].append(DiffVolumeName)
 1006         if MeshChainComplex:
 1007             PyMOLObjectNames["Chains"][ChainID]["ChainComplexDiffEDGroupMembers"].append(DiffMesh1Name)
 1008         if SurfaceChainComplex:
 1009             PyMOLObjectNames["Chains"][ChainID]["ChainComplexDiffEDGroupMembers"].append(DiffSurface1Name)
 1010         if MeshChainComplex:
 1011             PyMOLObjectNames["Chains"][ChainID]["ChainComplexDiffEDGroupMembers"].append(DiffMesh2Name)
 1012         if SurfaceChainComplex:
 1013             PyMOLObjectNames["Chains"][ChainID]["ChainComplexDiffEDGroupMembers"].append(DiffSurface2Name)
 1014         
 1015     NameIDs = ["ChainComplex"]
 1016     if MeshChainComplex or VolumeChainComplex or SurfaceChainComplex :
 1017         NameIDs.append("ChainComplexCompositeEDGroup")
 1018         if PyMOLObjectNames["SetupDiffEDMapObjects"]:
 1019             NameIDs.append("ChainComplexDiffEDGroup")
 1020         
 1021     PyMOLObjectNames["Chains"][ChainID]["ChainComplexGroupMembers"] = []
 1022     for NameID in NameIDs:
 1023         Name = PyMOLObjectNames["Chains"][ChainID][NameID]
 1024         PyMOLObjectNames["Chains"][ChainID]["ChainComplexGroupMembers"].append(Name)
 1025 
 1026     # Setup up a group for individual chains...
 1027     ChainAloneGroupName = "%s.Chain" % (ChainGroupName)
 1028     PyMOLObjectNames["Chains"][ChainID]["ChainAloneGroup"] = ChainAloneGroupName
 1029     PyMOLObjectNames["Chains"][ChainID]["ChainGroupMembers"].append(ChainAloneGroupName)
 1030         
 1031     PyMOLObjectNames["Chains"][ChainID]["ChainAloneGroupMembers"] = []
 1032         
 1033     Name = "%s.Chain" % (ChainAloneGroupName)
 1034     PyMOLObjectNames["Chains"][ChainID]["ChainAlone"] = Name
 1035     PyMOLObjectNames["Chains"][ChainID]["ChainAloneGroupMembers"].append(Name)
 1036         
 1037     if OptionsInfo["BFactorChainCartoonPutty"]:
 1038         Name = "%s.BFactor" % (ChainAloneGroupName)
 1039         PyMOLObjectNames["Chains"][ChainID]["ChainAloneBFactorPutty"] = Name
 1040         PyMOLObjectNames["Chains"][ChainID]["ChainAloneGroupMembers"].append(Name)
 1041 
 1042     if OptionsInfo["ChainSelections"]:
 1043         # Setup selections group and its subgroups..
 1044         SelectionsGroupName = "%s.Selections" % (ChainAloneGroupName)
 1045         
 1046         SelectionsGroupIDPrefix = "ChainAloneSelections"
 1047         SelectionsGroupID = "%sGroup" % SelectionsGroupIDPrefix
 1048         
 1049         # Add selections group to chain alone group...
 1050         PyMOLObjectNames["Chains"][ChainID][SelectionsGroupID] = SelectionsGroupName
 1051         PyMOLObjectNames["Chains"][ChainID]["ChainAloneGroupMembers"].append(SelectionsGroupName)
 1052         
 1053         # Initialize selections group members...
 1054         SelectionsGroupMembersID = "%sGroupMembers" % SelectionsGroupIDPrefix
 1055         PyMOLObjectNames["Chains"][ChainID][SelectionsGroupMembersID] = []
 1056         
 1057         # Setup selections name sub group and its members...
 1058         for SelectionName in OptionsInfo["ChainSelectionsInfo"]["Names"]:
 1059             SelectionNameGroupID = SelectionName
 1060             
 1061             SelectionsNameGroupName = "%s.%s" % (SelectionsGroupName, SelectionName)
 1062             SelectionsNameGroupID = "%s%sGroup" % (SelectionsGroupIDPrefix, SelectionNameGroupID)
 1063 
 1064             # Add selections name sub group to selections group...
 1065             PyMOLObjectNames["Chains"][ChainID][SelectionsNameGroupID] = SelectionsNameGroupName
 1066             PyMOLObjectNames["Chains"][ChainID][SelectionsGroupMembersID].append(SelectionsNameGroupName)
 1067             
 1068             # Initialize selections names sub group members...
 1069             SelectionsNameGroupMembersID = "%s%sGroupMembers" % (SelectionsGroupIDPrefix, SelectionNameGroupID)
 1070             PyMOLObjectNames["Chains"][ChainID][SelectionsNameGroupMembersID] = []
 1071 
 1072             # Add selection object to selections name group...
 1073             SelectionObjectName = "%s.Selection" % (SelectionsNameGroupName)
 1074             SelectionObjectID = "%s%sSelection" % (SelectionsGroupIDPrefix, SelectionNameGroupID)
 1075             
 1076             PyMOLObjectNames["Chains"][ChainID][SelectionObjectID] = SelectionObjectName
 1077             PyMOLObjectNames["Chains"][ChainID][SelectionsNameGroupMembersID].append(SelectionObjectName)
 1078 
 1079             # Setup composite mesh group and add it to selections name group...
 1080             CompositeMeshGroupName = "%s.2Fo-Fc" % (SelectionsNameGroupName)
 1081             CompositeMeshGroupID = "%s%sCompositeEDGroup" % (SelectionsGroupIDPrefix, SelectionNameGroupID)
 1082             
 1083             PyMOLObjectNames["Chains"][ChainID][CompositeMeshGroupID] = CompositeMeshGroupName
 1084             PyMOLObjectNames["Chains"][ChainID][SelectionsNameGroupMembersID].append(CompositeMeshGroupName)
 1085             
 1086             # Initialize composite mesh group members...
 1087             CompositeMeshGroupMembersID = "%s%sCompositeEDGroupMembers" % (SelectionsGroupIDPrefix, SelectionNameGroupID)
 1088             PyMOLObjectNames["Chains"][ChainID][CompositeMeshGroupMembersID] = []
 1089 
 1090             # Setup members of composite mesh group...
 1091             CompositeMeshName = "%s.Mesh" % (CompositeMeshGroupName)
 1092             CompositeMeshID = "%s%sCompositeEDMesh" % (SelectionsGroupIDPrefix, SelectionNameGroupID)
 1093             CompositeVolumeName = "%s.Volume" % (CompositeMeshGroupName)
 1094             CompositeVolumeID = "%s%sCompositeEDVolume" % (SelectionsGroupIDPrefix, SelectionNameGroupID)
 1095             CompositeSurfaceName = "%s.Surface" % (CompositeMeshGroupName)
 1096             CompositeSurfaceID = "%s%sCompositeEDSurface" % (SelectionsGroupIDPrefix, SelectionNameGroupID)
 1097     
 1098             PyMOLObjectNames["Chains"][ChainID][CompositeMeshID] = CompositeMeshName
 1099             PyMOLObjectNames["Chains"][ChainID][CompositeVolumeID] = CompositeVolumeName
 1100             PyMOLObjectNames["Chains"][ChainID][CompositeSurfaceID] = CompositeSurfaceName
 1101 
 1102             PyMOLObjectNames["Chains"][ChainID][CompositeMeshGroupMembersID].append(CompositeMeshName)
 1103             PyMOLObjectNames["Chains"][ChainID][CompositeMeshGroupMembersID].append(CompositeVolumeName)
 1104             PyMOLObjectNames["Chains"][ChainID][CompositeMeshGroupMembersID].append(CompositeSurfaceName)
 1105             
 1106             if PyMOLObjectNames["SetupDiffEDMapObjects"]:
 1107                 # Setup diff mesh group and add it to selections name group...
 1108                 DiffMeshGroupName = "%s.Fo-Fc" % (SelectionsNameGroupName)
 1109                 DiffMeshGroupID = "%s%sDiffEDGroup" % (SelectionsGroupIDPrefix, SelectionNameGroupID)
 1110                 
 1111                 PyMOLObjectNames["Chains"][ChainID][DiffMeshGroupID] = DiffMeshGroupName
 1112                 PyMOLObjectNames["Chains"][ChainID][SelectionsNameGroupMembersID].append(DiffMeshGroupName)
 1113                 
 1114                 # Initialize diff mesh group members...
 1115                 DiffMeshGroupMembersID = "%s%sDiffEDGroupMembers" % (SelectionsGroupIDPrefix, SelectionNameGroupID)
 1116                 PyMOLObjectNames["Chains"][ChainID][DiffMeshGroupMembersID] = []
 1117                 
 1118                 # Setup members of diff mesh group...
 1119                 DiffVolumeName = "%s.Volume" % (DiffMeshGroupName)
 1120                 DiffVolumeID = "%s%sDiffEDVolume" % (SelectionsGroupIDPrefix, SelectionNameGroupID)
 1121                 
 1122                 DiffMesh1Name = "%s.Mesh1" % (DiffMeshGroupName)
 1123                 DiffMesh1ID = "%s%sDiffEDMesh1" % (SelectionsGroupIDPrefix, SelectionNameGroupID)
 1124                 DiffSurface1Name = "%s.Surface1" % (DiffMeshGroupName)
 1125                 DiffSurface1ID = "%s%sDiffEDSurface1" % (SelectionsGroupIDPrefix, SelectionNameGroupID)
 1126                 
 1127                 DiffMesh2Name = "%s.Mesh2" % (DiffMeshGroupName)
 1128                 DiffMesh2ID = "%s%sDiffEDMesh2" % (SelectionsGroupIDPrefix, SelectionNameGroupID)
 1129                 DiffSurface2Name = "%s.Surface2" % (DiffMeshGroupName)
 1130                 DiffSurface2ID = "%s%sDiffEDSurface1" % (SelectionsGroupIDPrefix, SelectionNameGroupID)
 1131                 
 1132                 PyMOLObjectNames["Chains"][ChainID][DiffVolumeID] = DiffVolumeName
 1133                 PyMOLObjectNames["Chains"][ChainID][DiffMesh1ID] = DiffMesh1Name
 1134                 PyMOLObjectNames["Chains"][ChainID][DiffSurface1ID] = DiffSurface1Name
 1135                 PyMOLObjectNames["Chains"][ChainID][DiffMesh2ID] = DiffMesh2Name
 1136                 PyMOLObjectNames["Chains"][ChainID][DiffSurface2ID] = DiffSurface2Name
 1137 
 1138                 PyMOLObjectNames["Chains"][ChainID][DiffMeshGroupMembersID] = []
 1139                 PyMOLObjectNames["Chains"][ChainID][DiffMeshGroupMembersID].append(DiffVolumeName)
 1140                 PyMOLObjectNames["Chains"][ChainID][DiffMeshGroupMembersID].append(DiffMesh1Name)
 1141                 PyMOLObjectNames["Chains"][ChainID][DiffMeshGroupMembersID].append(DiffSurface1Name)
 1142                 PyMOLObjectNames["Chains"][ChainID][DiffMeshGroupMembersID].append(DiffMesh2Name)
 1143                 PyMOLObjectNames["Chains"][ChainID][DiffMeshGroupMembersID].append(DiffSurface2Name)
 1144     
 1145     # Setup solvent and inorganic objects for chain...
 1146     for NameID in ["Solvent", "Inorganic"]:
 1147         Name = "%s.%s" % (ChainGroupName, NameID)
 1148         PyMOLObjectNames["Chains"][ChainID][NameID] = Name
 1149         PyMOLObjectNames["Chains"][ChainID]["ChainGroupMembers"].append(Name)
 1150 
 1151 def SetupPyMOLObjectNamesForLigand(FileIndex, PyMOLObjectNames, ChainID, LigandID):
 1152     """Stetup groups and objects for ligand."""
 1153 
 1154     PyMOLObjectNames["Ligands"][ChainID][LigandID] = {}
 1155     
 1156     ChainGroupName = PyMOLObjectNames["Chains"][ChainID]["ChainGroup"]
 1157     
 1158     # Setup a chain level ligand group...
 1159     ChainLigandGroupName = "%s.Ligand%s" % (ChainGroupName, LigandID)
 1160     PyMOLObjectNames["Ligands"][ChainID][LigandID]["ChainLigandGroup"] = ChainLigandGroupName
 1161     PyMOLObjectNames["Chains"][ChainID]["ChainGroupMembers"].append(ChainLigandGroupName)
 1162     
 1163     PyMOLObjectNames["Ligands"][ChainID][LigandID]["ChainLigandGroupMembers"] = []
 1164 
 1165     # Set up groups and objects for a specific ligand group...
 1166     for GroupType in ["Ligand", "Pocket", "Pocket_Solvent", "Pocket_Inorganic"]:
 1167         GroupID = re.sub("_", "", GroupType)
 1168         GroupName = "%s.%s" % (ChainLigandGroupName, GroupType)
 1169                 
 1170         GroupNameID = "%sGroup" % (GroupID)
 1171         GroupMembersID = "%sGroupMembers" % (GroupID)
 1172         
 1173         PyMOLObjectNames["Ligands"][ChainID][LigandID][GroupNameID] = GroupName
 1174         PyMOLObjectNames["Ligands"][ChainID][LigandID]["ChainLigandGroupMembers"].append(GroupName)
 1175         
 1176         GroupTypeObjectName = "%s.%s" % (GroupName, GroupType)
 1177         GroupTypeObjectID = "%s" % (GroupID)
 1178         PyMOLObjectNames["Ligands"][ChainID][LigandID][GroupTypeObjectID] = GroupTypeObjectName
 1179         
 1180         CompositeMeshGroupName = "%s.2Fo-Fc" % (GroupName)
 1181         CompositeMeshName = "%s.Mesh" % (CompositeMeshGroupName)
 1182         CompositeVolumeName = "%s.Volume" % (CompositeMeshGroupName)
 1183         CompositeSurfaceName = "%s.Surface" % (CompositeMeshGroupName)
 1184                 
 1185         CompositeMeshGroupID = "%sCompositeEDMeshGroup" % (GroupID)
 1186         CompositeMeshGroupMembersID = "%sCompositeEDMeshGroupMembers" % (GroupID)
 1187         CompositeMeshID = "%sCompositeEDMesh" % (GroupID)
 1188         CompositeVolumeID = "%sCompositeEDVolume" % (GroupID)
 1189         CompositeSurfaceID = "%sCompositeEDSurface" % (GroupID)
 1190         
 1191         PyMOLObjectNames["Ligands"][ChainID][LigandID][CompositeMeshGroupID] = CompositeMeshGroupName
 1192         PyMOLObjectNames["Ligands"][ChainID][LigandID][CompositeMeshID] = CompositeMeshName
 1193         PyMOLObjectNames["Ligands"][ChainID][LigandID][CompositeVolumeID] = CompositeVolumeName
 1194         PyMOLObjectNames["Ligands"][ChainID][LigandID][CompositeSurfaceID] = CompositeSurfaceName
 1195         PyMOLObjectNames["Ligands"][ChainID][LigandID][CompositeMeshGroupMembersID] = []
 1196         PyMOLObjectNames["Ligands"][ChainID][LigandID][CompositeMeshGroupMembersID].append(CompositeVolumeName)
 1197         PyMOLObjectNames["Ligands"][ChainID][LigandID][CompositeMeshGroupMembersID].append(CompositeMeshName)
 1198         PyMOLObjectNames["Ligands"][ChainID][LigandID][CompositeMeshGroupMembersID].append(CompositeSurfaceName)
 1199                 
 1200         if PyMOLObjectNames["SetupDiffEDMapObjects"]:
 1201             DiffMeshGroupName = "%s.Fo-Fc" % GroupName
 1202             DiffVolumeName = "%s.Volume" % DiffMeshGroupName
 1203             DiffMesh1Name = "%s.Mesh1" % DiffMeshGroupName
 1204             DiffSurface1Name = "%s.Surface1" % DiffMeshGroupName
 1205             DiffMesh2Name = "%s.Mesh2" % DiffMeshGroupName
 1206             DiffSurface2Name = "%s.Surface2" % DiffMeshGroupName
 1207                     
 1208             DiffMeshGroupID = "%sDiffEDMeshGroup" % (GroupID)
 1209             DiffMeshGroupMembersID = "%sDiffEDMeshGroupMembers" % (GroupID)
 1210             DiffVolumeID = "%sDiffEDVolume" % (GroupID)
 1211             DiffMesh1ID = "%sDiffEDMesh1" % (GroupID)
 1212             DiffSurface1ID = "%sDiffEDSurface1" % (GroupID)
 1213             DiffMesh2ID = "%sDiffEDMesh2" % (GroupID)
 1214             DiffSurface2ID = "%sDiffEDSurface2" % (GroupID)
 1215                     
 1216             PyMOLObjectNames["Ligands"][ChainID][LigandID][DiffMeshGroupID] = DiffMeshGroupName
 1217             PyMOLObjectNames["Ligands"][ChainID][LigandID][DiffVolumeID] = DiffVolumeName
 1218             PyMOLObjectNames["Ligands"][ChainID][LigandID][DiffMesh1ID] = DiffMesh1Name
 1219             PyMOLObjectNames["Ligands"][ChainID][LigandID][DiffSurface1ID] = DiffSurface1Name
 1220             PyMOLObjectNames["Ligands"][ChainID][LigandID][DiffMesh2ID] = DiffMesh2Name
 1221             PyMOLObjectNames["Ligands"][ChainID][LigandID][DiffSurface2ID] = DiffSurface2Name
 1222             PyMOLObjectNames["Ligands"][ChainID][LigandID][DiffMeshGroupMembersID] = []
 1223             PyMOLObjectNames["Ligands"][ChainID][LigandID][DiffMeshGroupMembersID].extend([DiffVolumeName, DiffMesh1Name, DiffSurface1Name, DiffMesh2Name,  DiffSurface2Name])
 1224                 
 1225         PyMOLObjectNames["Ligands"][ChainID][LigandID][GroupMembersID] = []
 1226         NameIDs = [GroupTypeObjectID, CompositeMeshGroupID]
 1227         if PyMOLObjectNames["SetupDiffEDMapObjects"]:
 1228             NameIDs.append(DiffMeshGroupID)
 1229         
 1230         for NameID in NameIDs:
 1231             Name = PyMOLObjectNames["Ligands"][ChainID][LigandID][NameID]
 1232             PyMOLObjectNames["Ligands"][ChainID][LigandID][GroupMembersID].append(Name)
 1233         
 1234         if re.match("^Ligand$", GroupType, re.I):
 1235             # No other object needed for Ligand group...
 1236             continue
 1237         
 1238         PolarContactsName = "%s.Polar_Contacts" % (GroupName)
 1239         PolarContactsID = "%sPolarContacts" % (GroupID)
 1240         PyMOLObjectNames["Ligands"][ChainID][LigandID][PolarContactsID] = PolarContactsName
 1241         PyMOLObjectNames["Ligands"][ChainID][LigandID][GroupMembersID].append(PolarContactsName)
 1242                 
 1243         if not re.match("^Pocket$", GroupType, re.I):
 1244             # No other object needed for any other group besides Pocket...
 1245             continue
 1246         
 1247         if not OptionsInfo["PocketSurface"]:
 1248             continue
 1249         
 1250         HydrophobicContactsName = "%s.Hydrophobic_Contacts" % (GroupName)
 1251         HydrophobicContactsID = "%sHydrophobicContacts" % (GroupID)
 1252         PyMOLObjectNames["Ligands"][ChainID][LigandID][HydrophobicContactsID] = HydrophobicContactsName
 1253         PyMOLObjectNames["Ligands"][ChainID][LigandID][GroupMembersID].append(HydrophobicContactsName)
 1254         
 1255         HydrophobicSurfaceName = "%s.Surface" % (GroupName)
 1256         HydrophobicSurfaceID = "%sHydrophobicSurface" % (GroupID)
 1257         PyMOLObjectNames["Ligands"][ChainID][LigandID][HydrophobicSurfaceID] = HydrophobicSurfaceName
 1258         PyMOLObjectNames["Ligands"][ChainID][LigandID][GroupMembersID].append(HydrophobicSurfaceName)
 1259 
 1260 def ProcessEDMapFilesAndSuffixes():
 1261     """Process specified ED map files or suffixes for input files."""
 1262     
 1263     EDMapFiles = OptionsInfo["EDMapFiles"]
 1264     EDMapSuffixes = OptionsInfo["EDMapSuffixes"]
 1265 
 1266     if (not re.match("^auto$", EDMapFiles, re.I)) and (not re.match("^auto$", EDMapSuffixes, re.I)):
 1267             MiscUtil.PrintError("The values, \"%s\" and \"%s\", specified using \"--EDMapFiles\" and \"--EDMapSuffixes\" are not valid. Both of these options can't be specified simultaneously." % (EDMapFiles, EDMapSuffixes))
 1268 
 1269     if not re.match("^auto$", EDMapFiles, re.I):
 1270         ProcessEDMapFiles()
 1271     else:
 1272         ProcessEDMapSuffixes()
 1273         
 1274 def ProcessEDMapFiles():
 1275     """Process specified ED map files"""
 1276 
 1277     EDMapFiles = re.sub(" ", "", OptionsInfo["EDMapFiles"])
 1278     if not EDMapFiles:
 1279         MiscUtil.PrintError("No valid parameter name and value pairs specified using \"--EDMapFiles\" option.")
 1280     
 1281     EDMapFilesWords = EDMapFiles.split(",")
 1282     EDMapFilesWordsCount = len(EDMapFilesWords)
 1283     if EDMapFilesWordsCount % 2:
 1284         MiscUtil.PrintError("The number of comma delimited ED map files, %d, specified using \"--EDMapFiles\" option must be an even number." % (EDMapFilesWordsCount))
 1285 
 1286     InfilesNamesCount = len(OptionsInfo["InfilesNames"])
 1287     if EDMapFilesWordsCount != 2*InfilesNamesCount:
 1288         MiscUtil.PrintError("The number of comma delimited ED map files, %d, specified using \"--EDMapFiles\" must be twice the number of input files, %s, specified using \"-i, --infiles\" option." % (EDMapFilesWordsCount, InfilesNamesCount))
 1289     
 1290     OptionsInfo["CompositeEDMapFiles"] = []
 1291     OptionsInfo["DiffEDMapFiles"] = []
 1292 
 1293     CompositeEDMapFiles = []
 1294     DiffEDMapFiles = []
 1295     for Index in range(0, EDMapFilesWordsCount, 2):
 1296         CompositeEDMapFiles.append(EDMapFilesWords[Index])
 1297         DiffEDMapFiles.append(EDMapFilesWords[Index + 1])
 1298         
 1299     for Index in range(0, InfilesNamesCount):
 1300         Infile = OptionsInfo["InfilesNames"][Index]
 1301         CompositeEDMapFile = CompositeEDMapFiles[Index]
 1302         DiffEDMapFile = DiffEDMapFiles[Index]
 1303 
 1304         if not os.path.exists(CompositeEDMapFile):
 1305             MiscUtil.PrintError("The composite ED map file, %s, specified using option \"--EDMapFiles\", corresponding to input file, %s,  doesn't exist.\n" % (CompositeEDMapFile, Infile))
 1306 
 1307         DiffEDMapFileExists = False
 1308         if not re.match("^None$", DiffEDMapFile, re.I):
 1309             if os.path.exists(DiffEDMapFile):
 1310                 DiffEDMapFileExists = True
 1311             else:
 1312                 MiscUtil.PrintWarning("The difference ED map file, %s, specified using option \"--EDMapFiles\", corresponding to input file, %s,  doesn't exist. PyMOL groups and objectes related to difference maps won't be created.\n" % (DiffEDMapFile, Infile))
 1313         
 1314         OptionsInfo["CompositeEDMapFiles"].append(CompositeEDMapFile)
 1315         if DiffEDMapFileExists:
 1316             OptionsInfo["DiffEDMapFiles"].append(DiffEDMapFile)
 1317         else:
 1318             OptionsInfo["DiffEDMapFiles"].append(None)
 1319             
 1320 def ProcessEDMapSuffixes():
 1321     """Process suffixes for ED map files"""
 1322     
 1323     OptionsInfo["EDMapSuffixesMap"] = {"CompositeMap" : "", "DifferenceMap" : "_diff"}
 1324     
 1325     if re.match("^auto$", OptionsInfo["EDMapSuffixes"], re.I):
 1326         SetupEDMapFileNamesUsingSuffixes()
 1327         return
 1328     
 1329     EDMapSuffixes = re.sub(" ", "", OptionsInfo["EDMapSuffixes"])
 1330     if not EDMapSuffixes:
 1331         MiscUtil.PrintError("No valid parameter name and value pairs specified using \"--EDMapSuffixes\" option.")
 1332     
 1333     EDMapSuffixesWords = EDMapSuffixes.split(",")
 1334     if len(EDMapSuffixesWords) % 2:
 1335         MiscUtil.PrintError("The number of comma delimited ED map types names and suffixes, %d, specified using \"--EDMapSuffixes\" option must be an even number." % (len(EDMapSuffixesWords)))
 1336 
 1337     for Index in range(0, len(EDMapSuffixesWords), 2):
 1338         EDMapType = EDMapSuffixesWords[Index]
 1339         EDMapSuffix = EDMapSuffixesWords[Index + 1]
 1340         
 1341         if re.match("^CompositeMap$", EDMapType, re.I):
 1342             EDMapType = "CompositeMap"
 1343         elif re.match("^DifferenceMap$", EDMapType, re.I):
 1344             EDMapType = "DifferenceMap"
 1345         else:
 1346             MiscUtil.PrintError("The ED map type, %s, specified using \"--EDMapSuffixes\" option is not a valid ED map type. Supported ED map types: CompositeMap, DifferenceMap" % (EDMapType))
 1347             
 1348         if re.match(EDMapSuffix, "None", re.I):
 1349             EDMapSuffix = ""
 1350         
 1351         OptionsInfo["EDMapSuffixesMap"][EDMapType] = EDMapSuffix
 1352     
 1353     SetupEDMapFileNamesUsingSuffixes()
 1354 
 1355 def SetupEDMapFileNamesUsingSuffixes():
 1356     """Set up ED map file names. """
 1357     
 1358     OptionsInfo["CompositeEDMapFiles"] = []
 1359     OptionsInfo["DiffEDMapFiles"] = []
 1360     
 1361     CompositeMapSuffix = OptionsInfo["EDMapSuffixesMap"]["CompositeMap"]
 1362     DiffMapSuffix = OptionsInfo["EDMapSuffixesMap"]["DifferenceMap"]
 1363     InfilesNamesCount = len(OptionsInfo["InfilesNames"])
 1364     
 1365     for Index in range(0, InfilesNamesCount):
 1366         Infile = OptionsInfo["InfilesNames"][Index]
 1367         FileDir, FileName, FileExt = MiscUtil.ParseFileName(Infile)
 1368         InfileRoot = FileName
 1369         
 1370         CompositeEDMapFile = "%s%s.ccp4" % (InfileRoot, CompositeMapSuffix)
 1371         DiffEDMapFile = "%s%s.ccp4" % (InfileRoot, DiffMapSuffix)
 1372         
 1373         if not os.path.exists(CompositeEDMapFile):
 1374             MiscUtil.PrintError("The composite ED map file, %s, for option \"--EDMapSuffixes\", corresponding to input file, %s, doesn't exist.\n" % (CompositeEDMapFile, Infile))
 1375 
 1376         DiffEDMapFileExists = False
 1377         if os.path.exists(DiffEDMapFile):
 1378             DiffEDMapFileExists = True
 1379         else:
 1380             MiscUtil.PrintWarning("The difference ED map file, %s, for option \"--EDMapSuffixes\", corresponding to input file, %s,  doesn't exist. PyMOL groups and objectes related to difference maps won't be created.\n" % (DiffEDMapFile, Infile))
 1381         
 1382         OptionsInfo["CompositeEDMapFiles"].append(CompositeEDMapFile)
 1383         if DiffEDMapFileExists:
 1384             OptionsInfo["DiffEDMapFiles"].append(DiffEDMapFile)
 1385         else:
 1386             OptionsInfo["DiffEDMapFiles"].append(None)
 1387 
 1388 def RetrieveInfilesInfo():
 1389     """Retrieve information for input files."""
 1390 
 1391     InfilesInfo = {}
 1392     
 1393     InfilesInfo["InfilesNames"] = []
 1394     InfilesInfo["InfilesRoots"] = []
 1395     InfilesInfo["ChainsAndLigandsInfo"] = []
 1396     
 1397     for Infile in OptionsInfo["InfilesNames"]:
 1398         FileDir, FileName, FileExt = MiscUtil.ParseFileName(Infile)
 1399         InfileRoot = FileName
 1400         
 1401         ChainsAndLigandInfo = PyMOLUtil.GetChainsAndLigandsInfo(Infile, InfileRoot)
 1402         
 1403         InfilesInfo["InfilesNames"].append(Infile)
 1404         InfilesInfo["InfilesRoots"].append(InfileRoot)
 1405         InfilesInfo["ChainsAndLigandsInfo"].append(ChainsAndLigandInfo)
 1406     
 1407     OptionsInfo["InfilesInfo"] = InfilesInfo
 1408 
 1409 def RetrieveRefFileInfo():
 1410     """Retrieve information for ref file."""
 1411 
 1412     RefFileInfo = {}
 1413     if not OptionsInfo["Align"]:
 1414         OptionsInfo["RefFileInfo"] = RefFileInfo
 1415         return
 1416 
 1417     RefFile = OptionsInfo["RefFileName"]
 1418     
 1419     FileDir, FileName, FileExt = MiscUtil.ParseFileName(RefFile)
 1420     RefFileRoot = FileName
 1421     
 1422     if re.match("^FirstInputFile$", OptionsInfo["AlignRefFile"], re.I):
 1423         ChainsAndLigandInfo = OptionsInfo["InfilesInfo"]["ChainsAndLigandsInfo"][0]
 1424     else:
 1425         MiscUtil.PrintInfo("\nRetrieving chain and ligand information for alignment reference file %s..." % RefFile)
 1426         ChainsAndLigandInfo = PyMOLUtil.GetChainsAndLigandsInfo(RefFile, RefFileRoot)
 1427 
 1428     RefFileInfo["RefFileName"] = RefFile
 1429     RefFileInfo["RefFileRoot"] = RefFileRoot
 1430     RefFileInfo["PyMOLObjectName"] = "AlignRef_%s" % RefFileRoot
 1431     RefFileInfo["ChainsAndLigandsInfo"] = ChainsAndLigandInfo
 1432     
 1433     OptionsInfo["RefFileInfo"] = RefFileInfo
 1434 
 1435 def ProcessChainAndLigandIDs():
 1436     """Process specified chain and ligand IDs for infiles."""
 1437     
 1438     OptionsInfo["InfilesInfo"]["SpecifiedChainsAndLigandsInfo"] = []
 1439     
 1440     for FileIndex in range(0, len(OptionsInfo["InfilesInfo"]["InfilesNames"])):
 1441         MiscUtil.PrintInfo("\nProcessing specified chain and ligand IDs for input file %s..." % OptionsInfo["InfilesInfo"]["InfilesNames"][FileIndex])
 1442         
 1443         ChainsAndLigandsInfo = OptionsInfo["InfilesInfo"]["ChainsAndLigandsInfo"][FileIndex]
 1444         SpecifiedChainsAndLigandsInfo = PyMOLUtil.ProcessChainsAndLigandsOptionsInfo(ChainsAndLigandsInfo, "-c, --chainIDs", OptionsInfo["ChainIDs"], "-l, --ligandIDs", OptionsInfo["LigandIDs"])
 1445         ProcessChainMeshesVolumesAndSurfacesOptions(SpecifiedChainsAndLigandsInfo)
 1446         OptionsInfo["InfilesInfo"]["SpecifiedChainsAndLigandsInfo"].append(SpecifiedChainsAndLigandsInfo)
 1447         
 1448         CheckPresenceOfValidLigandIDs(ChainsAndLigandsInfo, SpecifiedChainsAndLigandsInfo)
 1449         
 1450 def CheckPresenceOfValidLigandIDs(ChainsAndLigandsInfo, SpecifiedChainsAndLigandsInfo):
 1451     """Check presence of valid ligand IDs."""
 1452 
 1453     MiscUtil.PrintInfo("\nSpecified chain IDs: %s" % (", ".join(SpecifiedChainsAndLigandsInfo["ChainIDs"])))
 1454     
 1455     for ChainID in SpecifiedChainsAndLigandsInfo["ChainIDs"]:
 1456         if len (SpecifiedChainsAndLigandsInfo["LigandIDs"][ChainID]):
 1457             MiscUtil.PrintInfo("Chain ID: %s; Specified LigandIDs: %s" % (ChainID, ", ".join(SpecifiedChainsAndLigandsInfo["LigandIDs"][ChainID])))
 1458         else:
 1459             MiscUtil.PrintInfo("Chain IDs: %s; Specified LigandIDs: None" % (ChainID))
 1460             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))
 1461 
 1462 def RetrieveFirstChainID(FileIndex):
 1463     """Get first chain ID."""
 1464     
 1465     ChainsAndLigandsInfo = OptionsInfo["InfilesInfo"]["ChainsAndLigandsInfo"][FileIndex]
 1466     
 1467     FirstChainID = None
 1468     if len(ChainsAndLigandsInfo["ChainIDs"]):
 1469         FirstChainID = ChainsAndLigandsInfo["ChainIDs"][0]
 1470     
 1471     return FirstChainID
 1472 
 1473 def ProcessChainMeshesVolumesAndSurfacesOptions(SpecifiedChainsAndLigandsInfo):
 1474     """Process options to create meshes and surfaces for chains."""
 1475 
 1476     SpecifiedChainsAndLigandsInfo["VolumeChainComplex"] = {}
 1477     SpecifiedChainsAndLigandsInfo["MeshChainComplex"] = {}
 1478     SpecifiedChainsAndLigandsInfo["SurfaceChainComplex"] = {}
 1479 
 1480     SpecifiedChainsAndLigandsInfo["EnableVolumeChainComplex"] = {}
 1481     SpecifiedChainsAndLigandsInfo["EnableMeshChainComplex"] = {}
 1482     SpecifiedChainsAndLigandsInfo["EnableSurfaceChainComplex"] = {}
 1483     
 1484     SpecifiedChainsAndLigandsInfo["EnableChainComplexGroup"] = {}
 1485     SpecifiedChainsAndLigandsInfo["EnableChainAloneGroup"] = {}
 1486     
 1487     for ChainID in SpecifiedChainsAndLigandsInfo["ChainIDs"]:
 1488         LigandsPresent = True if len(SpecifiedChainsAndLigandsInfo["LigandIDs"][ChainID]) else False
 1489 
 1490         # Create and enable mesh  or volume in auto mode...
 1491         if re.match("^auto$", OptionsInfo["MeshChainComplex"], re.I):
 1492             MeshChainComplex = False if LigandsPresent else True
 1493             EnableMeshChainComplex = False if LigandsPresent else True
 1494         else:
 1495             MeshChainComplex = True if re.match("^Yes$", OptionsInfo["MeshChainComplex"], re.I) else False
 1496             EnableMeshChainComplex = True if re.match("^Yes$", OptionsInfo["MeshChainComplex"], re.I) else False
 1497         
 1498         if re.match("^auto$", OptionsInfo["VolumeChainComplex"], re.I):
 1499             VolumeChainComplex = False if LigandsPresent else True
 1500             EnableVolumeChainComplex = False if LigandsPresent else True
 1501         else:
 1502             VolumeChainComplex = True if re.match("^Yes$", OptionsInfo["VolumeChainComplex"], re.I) else False
 1503             EnableVolumeChainComplex = True if re.match("^Yes$", OptionsInfo["VolumeChainComplex"], re.I) else False
 1504         
 1505         if MeshChainComplex and EnableMeshChainComplex:
 1506             EnableVolumeChainComplex = False
 1507         
 1508         # Create and enable surface in auto mode based on the status of mesh and volume...
 1509         if re.match("^auto$", OptionsInfo["SurfaceChainComplex"], re.I):
 1510             SurfaceChainComplex = False if LigandsPresent else True
 1511             EnableSurfaceChainComplex = False if LigandsPresent else True
 1512             
 1513             if MeshChainComplex or VolumeChainComplex:
 1514                 SurfaceChainComplex = False
 1515                 EnableSurfaceChainComplex = False
 1516         else:
 1517             SurfaceChainComplex = True if re.match("^Yes$", OptionsInfo["SurfaceChainComplex"], re.I) else False
 1518             EnableSurfaceChainComplex = True if re.match("^Yes$", OptionsInfo["SurfaceChainComplex"], re.I) else False
 1519         
 1520         if (MeshChainComplex and EnableMeshChainComplex) or (VolumeChainComplex or EnableVolumeChainComplex):
 1521             EnableSurfaceChainComplex = False
 1522             
 1523         if LigandsPresent:
 1524             EnableChainComplexGroup = False
 1525             EnableChainAloneGroup = True
 1526         else:
 1527             EnableChainComplexGroup = True
 1528             EnableChainAloneGroup = False
 1529 
 1530         SpecifiedChainsAndLigandsInfo["VolumeChainComplex"][ChainID] = VolumeChainComplex
 1531         SpecifiedChainsAndLigandsInfo["MeshChainComplex"][ChainID] = MeshChainComplex
 1532         SpecifiedChainsAndLigandsInfo["SurfaceChainComplex"][ChainID] = SurfaceChainComplex
 1533         
 1534         SpecifiedChainsAndLigandsInfo["EnableVolumeChainComplex"][ChainID] = EnableVolumeChainComplex
 1535         SpecifiedChainsAndLigandsInfo["EnableMeshChainComplex"][ChainID] = EnableMeshChainComplex
 1536         SpecifiedChainsAndLigandsInfo["EnableSurfaceChainComplex"][ChainID] = EnableSurfaceChainComplex
 1537         
 1538         SpecifiedChainsAndLigandsInfo["EnableChainComplexGroup"][ChainID] = EnableChainComplexGroup
 1539         SpecifiedChainsAndLigandsInfo["EnableChainAloneGroup"][ChainID] = EnableChainAloneGroup
 1540 
 1541 def ProcessChainSelections():
 1542     """Process custom selections for chains. """
 1543 
 1544     ChainSelectionsInfo = PyMOLUtil.ProcessChainSelectionsOptionsInfo("--selectionsChain", OptionsInfo["SelectionsChain"])
 1545     OptionsInfo["ChainSelectionsInfo"] = ChainSelectionsInfo
 1546     
 1547     ChainSelections = True if len(OptionsInfo["ChainSelectionsInfo"]["Names"]) else False
 1548     OptionsInfo["ChainSelections"] = ChainSelections
 1549     
 1550 def ProcessOptions():
 1551     """Process and validate command line arguments and options"""
 1552     
 1553     MiscUtil.PrintInfo("Processing options...")
 1554     
 1555     # Validate options...
 1556     ValidateOptions()
 1557     
 1558     OptionsInfo["Align"] = True if re.match("^Yes$", Options["--align"], re.I) else False
 1559     OptionsInfo["AlignMethod"] = Options["--alignMethod"].lower()
 1560     OptionsInfo["AlignMode"] = Options["--alignMode"]
 1561     
 1562     OptionsInfo["AllowEmptyObjects"] = True if re.match("^Yes$", Options["--allowEmptyObjects"], re.I) else False
 1563     
 1564     OptionsInfo["BFactorChainCartoonPutty"] = True if re.match("^Yes$", Options["--BFactorChainCartoonPutty"], re.I) else False
 1565     OptionsInfo["BFactorColorPalette"] = Options["--BFactorColorPalette"]
 1566     
 1567     OptionsInfo["Infiles"] = Options["--infiles"]
 1568     OptionsInfo["InfilesNames"] =  Options["--infileNames"]
 1569 
 1570     OptionsInfo["AlignRefFile"] = Options["--alignRefFile"]
 1571     if re.match("^FirstInputFile$", Options["--alignRefFile"], re.I):
 1572         OptionsInfo["RefFileName"] = OptionsInfo["InfilesNames"][0]
 1573     else:
 1574         OptionsInfo["RefFileName"] = Options["--alignRefFile"]
 1575     
 1576     OptionsInfo["EDMapFiles"] = Options["--EDMapFiles"]
 1577     OptionsInfo["EDMapSuffixes"] = Options["--EDMapSuffixes"]
 1578     ProcessEDMapFilesAndSuffixes()
 1579 
 1580     OptionsInfo["Overwrite"] = Options["--overwrite"]
 1581     OptionsInfo["PMLOut"] = True if re.match("^Yes$", Options["--PMLOut"], re.I) else False
 1582     
 1583     OptionsInfo["Outfile"] = Options["--outfile"]
 1584     FileDir, FileName, FileExt = MiscUtil.ParseFileName(OptionsInfo["Outfile"])
 1585     OptionsInfo["PSEOut"] = False 
 1586     if re.match("^pml$", FileExt, re.I):
 1587         OptionsInfo["PMLOutfile"] = OptionsInfo["Outfile"] 
 1588         OptionsInfo["PMEOutfile"] = re.sub(".pml$", ".pme", OptionsInfo["Outfile"]) 
 1589     elif re.match("^pse$", FileExt, re.I):
 1590         OptionsInfo["PSEOut"] = True 
 1591         OptionsInfo["PSEOutfile"] = OptionsInfo["Outfile"] 
 1592         OptionsInfo["PMLOutfile"] = re.sub(".pse$", ".pml", OptionsInfo["Outfile"]) 
 1593         if os.path.exists(OptionsInfo["PMLOutfile"]) and (not OptionsInfo["Overwrite"]):
 1594             MiscUtil.PrintError("The intermediate output file to be generated, %s, already exist. Use option \"--ov\" or \"--overwrite\" and try again." % OptionsInfo["PMLOutfile"] )
 1595 
 1596     OptionsInfo["LabelFontID"] = int(Options["--labelFontID"])
 1597     
 1598     # Process mesh parameters...
 1599     OptionsInfo["MeshCarveRadius"] = float(Options["--meshCarveRadius"])
 1600     OptionsInfo["MeshComplex"] = True if re.match("^Yes$", Options["--meshComplex"], re.I) else False
 1601     OptionsInfo["MeshChainComplex"] = Options["--meshChainComplex"]
 1602     OptionsInfo["MeshWidth"] = float(Options["--meshWidth"])
 1603     
 1604     OptionsInfo["MeshColorCompositeMap"] = Options["--meshColorCompositeMap"]
 1605     OptionsInfo["MeshLevelCompositeMap"] = float(Options["--meshLevelCompositeMap"])
 1606     OptionsInfo["Mesh1ColorDiffMap"] = Options["--mesh1ColorDiffMap"]
 1607     OptionsInfo["Mesh1LevelDiffMap"] = float(Options["--mesh1LevelDiffMap"])
 1608     OptionsInfo["Mesh2ColorDiffMap"] = Options["--mesh2ColorDiffMap"]
 1609     OptionsInfo["Mesh2LevelDiffMap"] = float(Options["--mesh2LevelDiffMap"])
 1610     
 1611     OptionsInfo["SelectionsChain"] = Options["--selectionsChain"]
 1612     OptionsInfo["SelectionsChainStyle"] = Options["--selectionsChainStyle"]
 1613     ProcessChainSelections()
 1614     
 1615     OptionsInfo["SurfaceComplex"] = True if re.match("^Yes$", Options["--surfaceComplex"], re.I) else False
 1616     OptionsInfo["SurfaceChainComplex"] = Options["--surfaceChainComplex"]
 1617     OptionsInfo["SurfaceTransparency"] = float(Options["--surfaceTransparency"])
 1618     
 1619     OptionsInfo["PocketContactsLigandColor"] = Options["--pocketContactsLigandColor"]
 1620     OptionsInfo["PocketContactsLigandHydrophobicColor"] = Options["--pocketContactsLigandHydrophobicColor"]
 1621     OptionsInfo["PocketContactsSolventColor"] = Options["--pocketContactsSolventColor"]
 1622     OptionsInfo["PocketContactsInorganicColor"] = Options["--pocketContactsInorganicColor"]
 1623     
 1624     OptionsInfo["PocketContactsCutoff"] = float(Options["--pocketContactsCutoff"])
 1625     OptionsInfo["PocketDistanceCutoff"] = float(Options["--pocketDistanceCutoff"])
 1626     
 1627     OptionsInfo["PocketLabelColor"] = Options["--pocketLabelColor"]
 1628     OptionsInfo["PocketSurface"] = True if re.match("^Yes$", Options["--pocketSurface"], re.I) else False
 1629     
 1630     OptionsInfo["VolumeCarveRadius"] = float(Options["--volumeCarveRadius"])
 1631     OptionsInfo["VolumeComplex"] = True if re.match("^Yes$", Options["--volumeComplex"], re.I) else False
 1632     OptionsInfo["VolumeChainComplex"] = Options["--volumeChainComplex"]
 1633     
 1634     OptionsInfo["VolumeColorRampCompositeMap"] = Options["--volumeColorRampCompositeMap"]
 1635     OptionsInfo["VolumeColorRampDiffMap"] = Options["--volumeColorRampDiffMap"]
 1636     
 1637     RetrieveInfilesInfo()
 1638     RetrieveRefFileInfo()
 1639     
 1640     OptionsInfo["ChainIDs"] = Options["--chainIDs"]
 1641     OptionsInfo["LigandIDs"] = Options["--ligandIDs"]
 1642     
 1643     ProcessChainAndLigandIDs()
 1644 
 1645 def RetrieveOptions(): 
 1646     """Retrieve command line arguments and options"""
 1647     
 1648     # Get options...
 1649     global Options
 1650     Options = docopt(_docoptUsage_)
 1651     
 1652     # Set current working directory to the specified directory...
 1653     WorkingDir = Options["--workingdir"]
 1654     if WorkingDir:
 1655         os.chdir(WorkingDir)
 1656     
 1657     # Handle examples option...
 1658     if "--examples" in Options and Options["--examples"]:
 1659         MiscUtil.PrintInfo(MiscUtil.GetExamplesTextFromDocOptText(_docoptUsage_))
 1660         sys.exit(0)
 1661 
 1662 def ValidateOptions():
 1663     """Validate option values"""
 1664     
 1665     MiscUtil.ValidateOptionTextValue("--align", Options["--align"], "yes no")
 1666     MiscUtil.ValidateOptionTextValue("--alignMethod", Options["--alignMethod"], "align cealign super")
 1667     MiscUtil.ValidateOptionTextValue("--alignMode", Options["--alignMode"], "FirstChain Complex")
 1668     
 1669     MiscUtil.ValidateOptionTextValue("--allowEmptyObjects", Options["--allowEmptyObjects"], "yes no")
 1670     
 1671     MiscUtil.ValidateOptionTextValue("--BFactorChainCartoonPutty", Options["--BFactorChainCartoonPutty"], "yes no")
 1672     
 1673     # Expand infiles to handle presence of multiple input files...
 1674     InfileNames = MiscUtil.ExpandFileNames(Options["--infiles"], ",")
 1675     if not len(InfileNames):
 1676         MiscUtil.PrintError("No input files specified for \"-i, --infiles\" option")
 1677 
 1678     # Validate file extensions...
 1679     for Infile in InfileNames:
 1680         MiscUtil.ValidateOptionFilePath("-i, --infiles", Infile)
 1681         MiscUtil.ValidateOptionFileExt("-i, --infiles", Infile, "pdb cif")
 1682         MiscUtil.ValidateOptionsDistinctFileNames("-i, --infiles", Infile, "-o, --outfile", Options["--outfile"])
 1683     Options["--infileNames"] = InfileNames
 1684     
 1685     MiscUtil.ValidateOptionFileExt("-o, --outfile", Options["--outfile"], "pml pse")
 1686     MiscUtil.ValidateOptionsOutputFileOverwrite("-o, --outfile", Options["--outfile"], "--overwrite", Options["--overwrite"])
 1687     
 1688     if re.match("^yes$", Options["--align"], re.I):
 1689         if not re.match("^FirstInputFile$", Options["--alignRefFile"], re.I):
 1690             AlignRefFile = Options["--alignRefFile"]
 1691             MiscUtil.ValidateOptionFilePath("--alignRefFile", AlignRefFile)
 1692             MiscUtil.ValidateOptionFileExt("--alignRefFile", AlignRefFile, "pdb cif")
 1693             MiscUtil.ValidateOptionsDistinctFileNames("--AlignRefFile", AlignRefFile, "-o, --outfile", Options["--outfile"])
 1694     
 1695     MiscUtil.ValidateOptionTextValue("--PMLOut", Options["--PMLOut"], "yes no")
 1696     MiscUtil.ValidateOptionIntegerValue("--labelFontID", Options["--labelFontID"], {})
 1697 
 1698     MiscUtil.ValidateOptionFloatValue("--meshCarveRadius", Options["--meshCarveRadius"], {">": 0.0})
 1699     MiscUtil.ValidateOptionTextValue("--meshComplex", Options["--meshComplex"], "yes no")
 1700     MiscUtil.ValidateOptionTextValue("--meshChainComplex", Options["--meshChainComplex"], "yes no auto")
 1701     MiscUtil.ValidateOptionFloatValue("--meshWidth", Options["--meshWidth"], {">": 0.0})
 1702     
 1703     MiscUtil.ValidateOptionFloatValue("--meshLevelCompositeMap", Options["--meshLevelCompositeMap"], {})
 1704     MiscUtil.ValidateOptionFloatValue("--mesh1LevelDiffMap", Options["--mesh1LevelDiffMap"], {})
 1705     MiscUtil.ValidateOptionFloatValue("--mesh2LevelDiffMap", Options["--mesh2LevelDiffMap"], {})
 1706     
 1707     MiscUtil.ValidateOptionTextValue("--surfaceComplex", Options["--surfaceComplex"], "yes no")
 1708     MiscUtil.ValidateOptionTextValue("--surfaceChainComplex", Options["--surfaceChainComplex"], "yes no auto")
 1709     MiscUtil.ValidateOptionFloatValue("--surfaceTransparency", Options["--surfaceTransparency"], {">=": 0.0, "<=": 1.0})
 1710     
 1711     MiscUtil.ValidateOptionFloatValue("--pocketContactsCutoff", Options["--pocketContactsCutoff"], {">": 0.0})
 1712     MiscUtil.ValidateOptionFloatValue("--pocketDistanceCutoff", Options["--pocketDistanceCutoff"], {">": 0.0})
 1713     if (float(Options["--pocketContactsCutoff"]) > float(Options["--pocketDistanceCutoff"])):
 1714         MiscUtil.PrintError("The value, %s, specified using option \"--pocketContactsCutoff\" must be less than value, %s, specified using \"-pocketDistanceCutoff\" option." % (Options["--pocketContactsCutoff"], Options["--pocketDistanceCutoff"]))
 1715     
 1716     MiscUtil.ValidateOptionTextValue("--pocketSurface", Options["--pocketSurface"], "yes no")
 1717     
 1718     MiscUtil.ValidateOptionFloatValue("--volumeCarveRadius", Options["--volumeCarveRadius"], {">": 0.0})
 1719     MiscUtil.ValidateOptionTextValue("--volumeComplex", Options["--volumeComplex"], "yes no")
 1720     MiscUtil.ValidateOptionTextValue("--volumeChainComplex", Options["--volumeChainComplex"], "yes no auto")
 1721     
 1722 # Setup a usage string for docopt...
 1723 _docoptUsage_ = """
 1724 PyMOLVisualizeElectronDensity.py - Visualize electron density
 1725 
 1726 Usage:
 1727     PyMOLVisualizeElectronDensity.py  [--align <yes or no>] [--alignMethod <align, cealign, super>]
 1728                                      [--alignMode <FirstChain or Complex>] [--alignRefFile <filename>]
 1729                                      [--allowEmptyObjects <yes or no>] [--BFactorChainCartoonPutty <yes or no>]
 1730                                      [--BFactorColorPalette <text> ] [--chainIDs <First, All or ID1,ID2...>]
 1731                                      [--EDMapFiles <file1,file2,...>] [--EDMapSuffixes <CompositeMap,None,...>]
 1732                                      [--ligandIDs <Largest, All or ID1,ID2...>] [--labelFontID <number>]
 1733                                      [--meshCarveRadius <number>] [--meshComplex <yes or no>]
 1734                                      [--meshChainComplex <yes or no>] [--meshColorCompositeMap <text>]
 1735                                      [--meshLevelCompositeMap <number>] [--meshWidth <number>]
 1736                                      [--mesh1ColorDiffMap <text>] [--mesh1LevelDiffMap <number>]
 1737                                      [--mesh2ColorDiffMap <text>] [--mesh2LevelDiffMap <number>]
 1738                                      [--PMLOut <yes or no>] [--pocketContactsLigandColor <text>]
 1739                                      [--pocketContactsLigandHydrophobicColor <text>] [--pocketContactsSolventColor <text>]
 1740                                      [--pocketContactsInorganicColor <text>] [--pocketContactsCutoff <number>]
 1741                                      [--pocketDistanceCutoff <number>] [--pocketLabelColor <text>] [--pocketSurface <yes or no>]
 1742                                      [--selectionsChain <ObjectName,SelectionSpec,...>] [--selectionsChainStyle <DisplayStyle>]
 1743                                      [--surfaceComplex <yes or no> ] [--surfaceChainComplex <yes or no>] [--surfaceTransparency <number>]
 1744                                      [--volumeCarveRadius <number>] [--volumeComplex <yes or no>]
 1745                                      [--volumeChainComplex <yes, no, or auto>] [--volumeColorRampCompositeMap <text>]
 1746                                      [--volumeColorRampDiffMap <text> ] [--overwrite] [-w <dir>] -i <infile1,infile2...> -o <outfile>
 1747     PyMOLVisualizeElectronDensity.py -h | --help | -e | --examples
 1748 
 1749 Description:
 1750     Generate PyMOL visualization files for viewing X-ray electron density around
 1751     chains, ligands, and ligand binding pockets in macromolecules including proteins
 1752     and nucleic acids.
 1753 
 1754     The supported input file formats are: Macromolecule - PDB (.pdb) or CIF(.cif),
 1755     Electron Density - Collaborative Computational Project Number 4 (CCP4) ( .ccp4)
 1756 
 1757     The supported output file formats are: PyMOL script file (.pml), PyMOL session
 1758     file (.pse)
 1759 
 1760     Two types of CCP4 electron density map files may be used for visualizing electron
 1761     density. These file types along with default file names are shown below:
 1762     
 1763         CompositeMap (2Fobs - Fcalc) - <InfileRoot>.ccp4 (required)
 1764         DifferenceMap (Fobs - Fcalc) - <InfileRoot>_diff.ccp4 (optional)
 1765     
 1766     The compsite map file must be present. The difference map file is optional.
 1767     The mesh, volume, and surface PyMOL objects are not generated for missing
 1768     difference map file.
 1769 
 1770     The electron density present in composite map file is generated by adding two
 1771     difference maps to a calculated map (Fcalc) as shown below:
 1772     
 1773         Fcalc + 2(Fobs - Fcalc) = 2Fobs - Fcalc
 1774     
 1775     The following types of meshes and volumes may be created by default for
 1776     electron density present in composite and difference map files:
 1777     
 1778         CompositeVolume - VolumeColorRamp: 2fofc
 1779         CompositeMesh - ContourLevel: 1; Color: Blue
 1780         DiffVolume - VolumeColorRamp: fofc
 1781         DiffMesh1 - ContourLevel: 3; Color: Green
 1782         DiffMesh2 - ContourLevel: -3; Color: Red
 1783 
 1784     The two meshes created for difference maps correspond to false negative and
 1785     false positive in terms of electron density present in the model. The first mesh
 1786     shown in  green color corresponds to observed electron density missing in the
 1787     model. The second mesh in in red color indicates model electron density not
 1788     observed in the experiment.
 1789     
 1790     A variety of PyMOL groups and objects may be  created for visualization of
 1791     electron density present in map files. These groups and objects correspond to
 1792     maps, volumes, meshes, surfaces,chains, ligands, inorganics, ligand binding
 1793     pockets, polar interactions, and pocket hydrophobic surfaces. A complete
 1794     hierarchy of all possible PyMOL groups and objects is shown below:
 1795     
 1796         <PDBFileRoot>
 1797             .Complex
 1798                 .Complex
 1799                 .2Fo-Fc
 1800                     .Map
 1801                     .Volume
 1802                     .Mesh
 1803                     .Surface
 1804                 .Fo-Fc
 1805                     .Map
 1806                     .Volume
 1807                     .Mesh1
 1808                     .Surface1
 1809                     .Mesh2
 1810                     .Surface2
 1811             .Chain<ID>
 1812                 .Complex
 1813                     .Complex
 1814                     .2Fo-Fc
 1815                         .Volume
 1816                         .Mesh
 1817                         .Surface
 1818                     .Fo-Fc
 1819                         .Volume
 1820                         .Mesh1
 1821                         .Surface1
 1822                         .Mesh2
 1823                         .Surface2
 1824                 .Chain
 1825                     .Chain
 1826                     .BFactor
 1827                     .Selections
 1828                         .<Name1>
 1829                             .Selection
 1830                             .2Fo-Fc
 1831                                 .Volume
 1832                                 .Mesh
 1833                                 .Surface
 1834                             .Fo-Fc
 1835                                 .Volume
 1836                                 .Mesh1
 1837                                 .Surface1
 1838                                 .Mesh2
 1839                                 .Surface2
 1840                         .<Name2>
 1841                             ... ... ..
 1842                 .Solvent
 1843                 .Inorganic
 1844                 .Ligand<ID>
 1845                     .Ligand
 1846                         .Ligand
 1847                         .2Fo-Fc
 1848                             .Volume
 1849                             .Mesh
 1850                             .Surface
 1851                         .Fo-Fc
 1852                             .Volume
 1853                             .Mesh1
 1854                             .Surface1
 1855                             .Mesh2
 1856                             .Surface2
 1857                     .Pocket
 1858                         .Pocket
 1859                         .2Fo-Fc
 1860                             .Volume
 1861                             .Mesh
 1862                             .Surface
 1863                         .Fo-Fc
 1864                             .Volume
 1865                             .Mesh1
 1866                             .Surface1
 1867                             .Mesh2
 1868                             .Surface2
 1869                         .Polar_Contacts
 1870                         .Hydrophobic_Contacts
 1871                         .Surface
 1872                     .Pocket_Solvent
 1873                         .Pocket_Solvent
 1874                         .2Fo-Fc
 1875                             .Volume
 1876                             .Mesh
 1877                             .Surface
 1878                         .Fo-Fc
 1879                             .Volume
 1880                             .Mesh1
 1881                             .Surface1
 1882                             .Mesh2
 1883                             .Surface2
 1884                         .Polar_Contacts
 1885                     .Pocket_Inorganic
 1886                         .Pocket_Inorganic
 1887                         .2Fo-Fc
 1888                             .Volume
 1889                             .Mesh
 1890                             .Surface
 1891                         .Fo-Fc
 1892                             .Volume
 1893                             .Mesh1
 1894                             .Surface1
 1895                             .Mesh2
 1896                             .Surface2
 1897                         .Polar_Contacts
 1898                 .Ligand<ID>
 1899                     .Ligand
 1900                         ... ... ...
 1901                     .Pocket
 1902                         ... ... ...
 1903                     .Pocket_Solvent
 1904                         ... ... ...
 1905                     .Pocket_Inorganic
 1906                         ... ... ...
 1907             .Chain<ID>
 1908                 ... ... ...
 1909                 .Ligand<ID>
 1910                     ... ... ...
 1911                 .Ligand<ID>
 1912                     ... ... ...
 1913             .Chain<ID>
 1914                 ... ... ...
 1915         <PDBFileRoot>
 1916             .Complex
 1917                 ... ... ...
 1918             .Chain<ID>
 1919                 ... ... ...
 1920                 .Ligand<ID>
 1921                     ... ... ...
 1922                 .Ligand<ID>
 1923                     ... ... ...
 1924             .Chain<ID>
 1925                 ... ... ...
 1926     
 1927     The meshes, volumes, and surfaces  are not created for complete complex in
 1928     each input file by default. A word to the wise: The creation of these surface, volume,
 1929     and mesh objects may slow down loading of PML file and generation of PSE file,
 1930     based on the size of input complex and map files. The generation of PSE file
 1931     may also fail.
 1932 
 1933 Options:
 1934     -a, --align <yes or no>  [default: no]
 1935         Align input files to a reference file before visualization along with
 1936         available electron density map files.
 1937     --alignMethod <align, cealign, super>  [default: super]
 1938         Alignment methodology to use for aligning input files to a
 1939         reference file.
 1940     --alignMode <FirstChain or Complex>  [default: FirstChain]
 1941         Portion of input and reference files to use for spatial alignment of
 1942         input files against reference file.  Possible values: FirstChain or
 1943         Complex.
 1944         
 1945         The FirstChain mode allows alignment of the first chain in each input
 1946         file to the first chain in the reference file along with moving the rest
 1947         of the complex to coordinate space of the reference file. The complete
 1948         complex in each input file is aligned to the complete complex in reference
 1949         file for the Complex mode.
 1950     --alignRefFile <filename>  [default: FirstInputFile]
 1951         Reference input file name. The default is to use the first input file
 1952         name specified using '-i, --infiles' option.
 1953     --allowEmptyObjects <yes or no>  [default: no]
 1954         Allow creation of empty PyMOL objects corresponding to solvent and
 1955         inorganic atom selections across chains, ligands, and ligand binding pockets
 1956         in input file(s).
 1957     -c, --chainIDs <First, All or ID1,ID2...>  [default: First]
 1958         List of chain IDs to use for visualizing electron density. Possible values:
 1959         First, All, or a comma delimited list of chain IDs. The default is to use the
 1960         chain ID for the first chain in each input file.
 1961     -b, --BFactorChainCartoonPutty <yes or no>  [default: yes]
 1962         A cartoon putty around individual chains colored by B factors. The minimum
 1963         and maximum values for B factors are automatically detected. These values
 1964         indicate spread of electron density around atoms. The 'blue_white_red' color
 1965         palette is deployed for coloring the cartoon putty.
 1966     --BFactorColorPalette <text>  [default: blue_white_red]
 1967         Color palette for coloring cartoon putty around chains generated using B
 1968         factors. Any valid PyMOL color palette name is allowed. No validation is
 1969         performed. The complete list of valid color palette names is a available
 1970         at: pymolwiki.org/index.php/Spectrum. Examples: blue_white_red,
 1971         blue_white_magenta, blue_red, green_white_red, green_red.
 1972     -e, --examples
 1973         Print examples.
 1974     --EDMapFiles <file1,file1,file3...>  [default: auto]
 1975         Pairwise comma delimited list of composite and difference electron
 1976         density map files corresponding to input files. By default, the names
 1977         of electron density files are automatically generated using a combination
 1978         of input file names and file suffixes '--EDMapSuffixes'.
 1979         
 1980         The first file with in each pairs of filenames correspond to composite
 1981         electron density map. A composite file must be present for each input
 1982         file. The second file corresponds to difference electron density map. The
 1983         difference map file is optional. A value of 'None' must be used to represent
 1984         a missing difference map file. 
 1985         
 1986         The number of specified files must be twice the number of input files.
 1987     --EDMapSuffixes <CompositeMap,None,...>  [default: auto]
 1988         Electron density map file suffixes for generating names of map files from
 1989         the root of input files. It is a pairwise comma delimited list of 'EDMapType'
 1990         and file suffix.
 1991         
 1992         This option is ignored during explicit specification of electron density
 1993         map files using '--EDMapFiles'.
 1994         
 1995         Supported values for 'EDMapType': 'CompositeMap, DifferenceMap'.
 1996         Supported value for file suffix: Any valid string.
 1997         
 1998         Default value: 'CompositeMap,None,DifferenceMap,_diff'
 1999         
 2000         This option is only used for 'Auto' value of '--EDMapFilesMode' option.
 2001         
 2002         The default names of the map files, generated form a combination of
 2003         'InfileRoot' and 'EDSMapType' are shown below:
 2004             
 2005             CompositeMap (2Fobs - Fcalc) - <InfileRoot>.ccp4
 2006             DifferenceMap (Fobs - Fcalc) - <InfileRoot>_diff.ccp4
 2007             
 2008         The composite map files must be present. The difference map files are
 2009         optional.
 2010     -h, --help
 2011         Print this help message.
 2012     -i, --infiles <infile1,infile2,infile3...>
 2013         Input file names.
 2014     -l, --ligandIDs <Largest, All or ID1,ID2...>  [default: Largest]
 2015         List of ligand IDs present in chains for visualizing electron density across
 2016         ligands and ligand binding pockets. Possible values: Largest, All, or a comma
 2017         delimited list of ligand IDs. The default is to use the largest ligand present
 2018         in all or specified chains in each input file.
 2019         
 2020         Ligands are identified using organic selection operator available in PyMOL.
 2021         It'll also  identify buffer molecules as ligands. The largest ligand contains
 2022         the highest number of heavy atoms.
 2023     --labelFontID <number>  [default: 7]
 2024         Font ID for drawing labels. Default: 7 (Sans Bold). Valid values: 5 to 16.
 2025         The specified value must be a valid PyMOL font ID. No validation is
 2026         performed. The complete lists of valid font IDs is available at:
 2027         pymolwiki.org/index.php/Label_font_id. Examples: 5 - Sans;
 2028         7 - Sans Bold; 9 - Serif; 10 - Serif Bold.
 2029     --meshCarveRadius <number>  [default: 1.6]
 2030         Radius in Angstroms around atoms for including electron density.
 2031     --meshComplex <yes or no>  [default: no]
 2032         Create meshes for complete complex in each input file using corresponding
 2033         composite and difference maps. A total of three meshes, one for composite
 2034         map and two for difference map, are created for the complete complex.
 2035         
 2036         The composite and difference maps are always loaded for the complex.
 2037     --meshChainComplex <yes, no, or auto>  [default: auto]
 2038         Create meshes for individual chain complex in each input file using corresponding
 2039         composite and difference maps. A total of three meshes, one for composite map
 2040         map and two for difference map, are created for each chain complex. By default,
 2041         the meshes are automatically created for chain complexes without any ligands. 
 2042     --meshColorCompositeMap <text>  [default: blue]
 2043         Line color for meshes corresponding to composite maps. The specified value
 2044         must be valid color. No validation is performed.
 2045     --meshLevelCompositeMap <number>  [default: 1.0]
 2046         Contour level in sigma units for generating meshes corresponding to composite
 2047         maps.
 2048     --meshWidth <number>  [default: 0.5]
 2049         Line width for mesh lines corresponding to composite and difference maps.
 2050     --mesh1ColorDiffMap <text>  [default: green]
 2051         Line color for first mesh corresponding to difference maps at contour level
 2052         specified by '--mesh1LevelDiffMap'. The specified value must be valid color.
 2053         No validation is performed.
 2054     --mesh1LevelDiffMap <number>  [default: 3.0]
 2055         Contour level in sigma units for generating first mesh corresponding to 
 2056         to  difference maps.
 2057     --mesh2ColorDiffMap <text>  [default: red]
 2058         Line color for second mesh corresponding to difference maps at contour level
 2059         specified by '--mesh2LevelDiffMap'. The specified value must be valid color.
 2060         No validation is performed.
 2061     --mesh2LevelDiffMap <number>  [default: -3.0]
 2062         Contour level in sigma units for generating second mesh corresponding to
 2063         difference maps.
 2064     -o, --outfile <outfile>
 2065         Output file name.
 2066     -p, --PMLOut <yes or no>  [default: yes]
 2067         Save PML file during generation of PSE file.
 2068     --pocketContactsLigandColor <text>  [default: orange]
 2069         Color for drawing polar contacts between ligand and pocket residues.
 2070         The specified value must be valid color. No validation is performed.
 2071     --pocketContactsLigandHydrophobicColor <text>  [default: purpleblue]
 2072         Color for drawing hydrophobic contacts between ligand and pocket residues.
 2073         The specified value must be valid color. No validation is performed. The
 2074         hydrophobic contacts are shown between pairs of carbon atoms not
 2075         connected to hydrogen bond donor or acceptors atoms as identified
 2076         by PyMOL.
 2077     --pocketContactsSolventColor <text>  [default: marine]
 2078         Color for drawing polar contacts between solvent and pocket residues.
 2079         The specified value must be valid color. No validation is performed.
 2080     --pocketContactsInorganicColor <text>  [default: deepsalmon]
 2081         Color for drawing polar contacts between inorganic and pocket residues.
 2082         The specified value must be valid color. No validation is performed.
 2083     --pocketContactsCutoff <number>  [default: 4.0]
 2084         Distance in Angstroms for identifying polar and hyrdophobic contacts
 2085         between atoms in pocket residues and ligands.
 2086     --pocketDistanceCutoff <number>  [default: 5.0]
 2087         Distance in Angstroms for identifying pocket residues around ligands.
 2088     --pocketLabelColor <text>  [default: magenta]
 2089         Color for drawing residue or atom level labels for a pocket. The specified
 2090         value must be valid color. No validation is performed.
 2091     --pocketSurface <yes or no>  [default: yes]
 2092         Hydrophobic surface around pocket. The pocket surface is colored by
 2093         hydrophobicity. It is only valid for proteins. The color of amino acids is
 2094         set using the Eisenberg hydrophobicity scale. The color varies from red
 2095         to white, red being the most hydrophobic amino acid.
 2096     --selectionsChain <ObjectName,SelectionSpec,...>  [default: None]
 2097         Custom selections for chains. It is a pairwise of list comma delimited values
 2098         corresponding to PyMOL object names and selection specifications.  The
 2099         selection specification must be a valid PyMOL specification. No validation is
 2100         performed.
 2101         
 2102         The PyMOL objects are created for each chain corresponding to the
 2103         specified selections. The display style for PyMOL objects is set using
 2104         value of '--selectionsChainStyle' option.
 2105         
 2106         The specified selection specification is automatically appended to appropriate
 2107         chain specification before creating PyMOL objects.
 2108         
 2109         For example, the following specification for '--selectionsChain' option will
 2110         generate PyMOL objects for chains containing Cysteines and Serines:
 2111             
 2112             Cysteines,resn CYS,Serines,resn SER
 2113             
 2114     --selectionsChainStyle <DisplayStyle>  [default: sticks]
 2115         Display style for PyMOL objects created for '--selectionsChain' option. It
 2116         must be a valid PyMOL display style. No validation is performed.
 2117     --surfaceComplex <yes or no>  [default: no]
 2118         Create surfaces for complete complex in each input file using corresponding
 2119         composite and difference maps. A total of three surfaces, one for composite
 2120         map and two for difference map, are created for the complete complex.
 2121         
 2122         The composite and difference maps are always loaded for the complex.
 2123     --surfaceChainComplex <yes, no or auto>  [default: auto]
 2124         Create surfaces for individual chain complexes in each input file using corresponding
 2125         composite and difference maps. A total of three surfaces, one for composite
 2126         map and two for difference map, are created for each chain complex. By default,
 2127         the surfaces are automatically created for chain complexes without any ligands. 
 2128     --surfaceTransparency <number>  [default: 0.25]
 2129         Surface transparency for molecular and electron density surfaces.
 2130     --volumeCarveRadius <number>  [default: 1.6]
 2131         Radius in Angstroms around atoms for including electron density during
 2132         generation of volume objects.
 2133     --volumeComplex <yes or no>  [default: no]
 2134         Create volumes for complete complex in input file using corresponding
 2135         composite and difference maps. A total of two volumes, one each for
 2136         composite and difference maps, are created for the complete complex.
 2137     --volumeChainComplex <yes, no, or auto>  [default: auto]
 2138         Create volumes for individual chain complex in each input file using corresponding
 2139         composite and difference maps. A total of two volumes, one each for composite
 2140         and difference maps, are created for each chain complex. By default, the
 2141         volumes are automatically created for chain complexes without any ligands.
 2142     --volumeColorRampCompositeMap <text>  [default: 2fofc]
 2143         Name of volume color ramp for composite maps. The specified value must
 2144         be a valid name. No validation is performed. The following volume color ramps
 2145         are currently available in PyMOL: default, 2fofc, fofc, rainbow, and rainbow2.
 2146     --volumeColorRampDiffMap <text>  [default: fofc]
 2147         Name of volume color ramp for difference maps. The specified value must
 2148         be a valid name. No validation is performed. The following volume color ramps
 2149         are currently available in PyMOL: default, 2fofc, fofc, rainbow, and rainbow2.
 2150     --overwrite
 2151         Overwrite existing files.
 2152     -w, --workingdir <dir>
 2153         Location of working directory which defaults to the current directory.
 2154 
 2155 Examples:
 2156     To visualize electron density for the largest ligand in the first chain, and
 2157     ligand binding pockets to highlight ligand interactions with pockect residues,
 2158     solvents and inorganics, in a PDB file by using default map files, and generate a
 2159     PML file, type:
 2160 
 2161         % PyMOLVisualizeElectronDensity.py -i Sample3.pdb -o Sample3.pml
 2162 
 2163     To visualize electron density for the largest ligand in the first chain, cysteine
 2164     and serine residues in the chain, and ligand binding pockets to highlight ligand
 2165     interactions with pockect residues, solvents and inorganics, in a PDB file by
 2166     using default map files, and generate a PML file, type:
 2167 
 2168         % PyMOLVisualizeElectronDensity.py -i Sample3.pdb -o Sample3.pml
 2169           --selectionsChain "Cysteines,resn cys,Serines,resn ser"
 2170 
 2171     To visualize electron density for all ligands in all chains, and ligand binding
 2172     pockets to highlight ligand interactions with pockect residues, solvents
 2173     and inorganics, in a PDB file by using default map files, and generate a
 2174     PML file, type:
 2175 
 2176         % PyMOLVisualizeElectronDensity.py -i Sample3.pdb -o Sample3.pml
 2177           -c All -l All
 2178 
 2179     To visualize electron density for all chains and ligands, along with displaying
 2180     meshes, volumes, and surfaces for complete complex and individual chains,
 2181     in a PDB file by using  default map files, and generate a PML file, type:
 2182 
 2183         % PyMOLVisualizeElectronDensity.py -i Sample3.pdb -o Sample3.pml
 2184           --chainIDs All --ligandIDs All --meshComplex yes --surfaceComplex yes
 2185           --volumeComplex yes --meshChainComplex yes --surfaceChainComplex yes
 2186           --volumeChainComplex yes
 2187 
 2188     To visualize electron density for ligand ADP in chain E along with ligand binding
 2189     pocket, in a PDB file by using  default map files, and generate a PSE file, type:
 2190 
 2191         % PyMOLVisualizeElectronDensity.py -i Sample3.pdb -o Sample3.pse
 2192           --chainIDs E --ligandIDs ADP
 2193 
 2194     To visualize electron density for all igands in all chains along with their binding
 2195     pockets in a PDB file and using explicit file name suffixes for map files, and
 2196     generate a PML file, type:
 2197 
 2198         % PyMOLVisualizeElectronDensity.py -i Sample3.pdb -o Sample3.pml
 2199           --chainIDs All --ligandIDs All --EDMapSuffixes "CompositeMap,None,
 2200           DifferenceMap,_diff"
 2201 
 2202     To visualize electron density for all ligands in all chains along with their binding
 2203     pockets in a PDB file by using explicit file names for map files, and generate
 2204     a PML file, type:
 2205 
 2206         % PyMOLVisualizeElectronDensity.py -i Sample3.pdb -o Sample3.pml
 2207           --chainIDs All --ligandIDs All --EDMapFiles "Sample3.ccp4,
 2208           Sample3_diff.ccp4"
 2209 
 2210     To align and visualize electron density for all ligands in all chains along with their
 2211     binding pockets in PDB files by using explicit file names for map files, and generate
 2212     a PML file, type:
 2213 
 2214         % PyMOLVisualizeElectronDensity.py -a yes -i "Sample3.pdb,Sample4.pdb"
 2215           -o SampleOut.pml --chainIDs All --ligandIDs All --EDMapFiles
 2216          "Sample3.ccp4,Sample3_diff.ccp4,Sample4.ccp4,Sample4_diff.ccp4"
 2217 
 2218 Author:
 2219     Manish Sud(msud@san.rr.com)
 2220 
 2221 See also:
 2222     DownloadPDBFiles.pl, PyMOLVisualizeCavities.py,
 2223     PyMOLVisualizeCryoEMDensity.py, PyMOLVisualizeInterfaces.py,
 2224     PyMOLVisualizeMacromolecules.py, PyMOLVisualizeSurfaceAndBuriedResidues.py
 2225 
 2226 Copyright:
 2227     Copyright (C) 2019 Manish Sud. All rights reserved.
 2228 
 2229     The functionality available in this script is implemented using PyMOL, a
 2230     molecular visualization system on an open source foundation originally
 2231     developed by Warren DeLano.
 2232 
 2233     This file is part of MayaChemTools.
 2234 
 2235     MayaChemTools is free software; you can redistribute it and/or modify it under
 2236     the terms of the GNU Lesser General Public License as published by the Free
 2237     Software Foundation; either version 3 of the License, or (at your option) any
 2238     later version.
 2239 
 2240 """
 2241 
 2242 if __name__ == "__main__":
 2243     main()