MayaChemTools

    1 #!/bin/env python
    2 #
    3 # File: PyMOLVisualizeElectronDensity.py
    4 # Author: Manish Sud <msud@san.rr.com>
    5 #
    6 # Copyright (C) 2024 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; MayaChemTools v%s; %s): Starting...\n" % (ScriptName, pymol.cmd.get_version()[0], MiscUtil.GetMayaChemToolsVersion(), 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 header for 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 selections 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, Enable = True, IgnoreHydrogens = OptionsInfo["IgnoreHydrogens"])
  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"], Enable = True, IgnoreHydrogens = OptionsInfo["IgnoreHydrogens"])
  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(PyMOLUtil.SetupPMLForDeepColoring(MeshName, Color))
  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(PyMOLUtil.SetupPMLForDeepColoring(SurfaceName, Color))
  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     """Setup 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["IgnoreHydrogens"] = True if re.match("^Yes$", Options["--ignoreHydrogens"], re.I) else False
 1577     
 1578     OptionsInfo["EDMapFiles"] = Options["--EDMapFiles"]
 1579     OptionsInfo["EDMapSuffixes"] = Options["--EDMapSuffixes"]
 1580     ProcessEDMapFilesAndSuffixes()
 1581 
 1582     OptionsInfo["Overwrite"] = Options["--overwrite"]
 1583     OptionsInfo["PMLOut"] = True if re.match("^Yes$", Options["--PMLOut"], re.I) else False
 1584     
 1585     OptionsInfo["Outfile"] = Options["--outfile"]
 1586     FileDir, FileName, FileExt = MiscUtil.ParseFileName(OptionsInfo["Outfile"])
 1587     OptionsInfo["PSEOut"] = False 
 1588     if re.match("^pml$", FileExt, re.I):
 1589         OptionsInfo["PMLOutfile"] = OptionsInfo["Outfile"] 
 1590         OptionsInfo["PMEOutfile"] = re.sub(".pml$", ".pme", OptionsInfo["Outfile"]) 
 1591     elif re.match("^pse$", FileExt, re.I):
 1592         OptionsInfo["PSEOut"] = True 
 1593         OptionsInfo["PSEOutfile"] = OptionsInfo["Outfile"] 
 1594         OptionsInfo["PMLOutfile"] = re.sub(".pse$", ".pml", OptionsInfo["Outfile"]) 
 1595         if os.path.exists(OptionsInfo["PMLOutfile"]) and (not OptionsInfo["Overwrite"]):
 1596             MiscUtil.PrintError("The intermediate output file to be generated, %s, already exist. Use option \"--ov\" or \"--overwrite\" and try again." % OptionsInfo["PMLOutfile"] )
 1597 
 1598     OptionsInfo["LabelFontID"] = int(Options["--labelFontID"])
 1599     
 1600     # Process mesh parameters...
 1601     OptionsInfo["MeshCarveRadius"] = float(Options["--meshCarveRadius"])
 1602     OptionsInfo["MeshComplex"] = True if re.match("^Yes$", Options["--meshComplex"], re.I) else False
 1603     OptionsInfo["MeshChainComplex"] = Options["--meshChainComplex"]
 1604     OptionsInfo["MeshWidth"] = float(Options["--meshWidth"])
 1605     
 1606     OptionsInfo["MeshColorCompositeMap"] = Options["--meshColorCompositeMap"]
 1607     OptionsInfo["MeshLevelCompositeMap"] = float(Options["--meshLevelCompositeMap"])
 1608     OptionsInfo["Mesh1ColorDiffMap"] = Options["--mesh1ColorDiffMap"]
 1609     OptionsInfo["Mesh1LevelDiffMap"] = float(Options["--mesh1LevelDiffMap"])
 1610     OptionsInfo["Mesh2ColorDiffMap"] = Options["--mesh2ColorDiffMap"]
 1611     OptionsInfo["Mesh2LevelDiffMap"] = float(Options["--mesh2LevelDiffMap"])
 1612     
 1613     OptionsInfo["SelectionsChain"] = Options["--selectionsChain"]
 1614     OptionsInfo["SelectionsChainStyle"] = Options["--selectionsChainStyle"]
 1615     ProcessChainSelections()
 1616     
 1617     OptionsInfo["SurfaceComplex"] = True if re.match("^Yes$", Options["--surfaceComplex"], re.I) else False
 1618     OptionsInfo["SurfaceChainComplex"] = Options["--surfaceChainComplex"]
 1619     OptionsInfo["SurfaceTransparency"] = float(Options["--surfaceTransparency"])
 1620     
 1621     OptionsInfo["PocketContactsLigandColor"] = Options["--pocketContactsLigandColor"]
 1622     OptionsInfo["PocketContactsLigandHydrophobicColor"] = Options["--pocketContactsLigandHydrophobicColor"]
 1623     OptionsInfo["PocketContactsSolventColor"] = Options["--pocketContactsSolventColor"]
 1624     OptionsInfo["PocketContactsInorganicColor"] = Options["--pocketContactsInorganicColor"]
 1625     
 1626     OptionsInfo["PocketContactsCutoff"] = float(Options["--pocketContactsCutoff"])
 1627     OptionsInfo["PocketDistanceCutoff"] = float(Options["--pocketDistanceCutoff"])
 1628     
 1629     OptionsInfo["PocketLabelColor"] = Options["--pocketLabelColor"]
 1630     OptionsInfo["PocketSurface"] = True if re.match("^Yes$", Options["--pocketSurface"], re.I) else False
 1631     
 1632     OptionsInfo["VolumeCarveRadius"] = float(Options["--volumeCarveRadius"])
 1633     OptionsInfo["VolumeComplex"] = True if re.match("^Yes$", Options["--volumeComplex"], re.I) else False
 1634     OptionsInfo["VolumeChainComplex"] = Options["--volumeChainComplex"]
 1635     
 1636     OptionsInfo["VolumeColorRampCompositeMap"] = Options["--volumeColorRampCompositeMap"]
 1637     OptionsInfo["VolumeColorRampDiffMap"] = Options["--volumeColorRampDiffMap"]
 1638     
 1639     RetrieveInfilesInfo()
 1640     RetrieveRefFileInfo()
 1641     
 1642     OptionsInfo["ChainIDs"] = Options["--chainIDs"]
 1643     OptionsInfo["LigandIDs"] = Options["--ligandIDs"]
 1644     
 1645     ProcessChainAndLigandIDs()
 1646 
 1647 def RetrieveOptions(): 
 1648     """Retrieve command line arguments and options."""
 1649     
 1650     # Get options...
 1651     global Options
 1652     Options = docopt(_docoptUsage_)
 1653     
 1654     # Set current working directory to the specified directory...
 1655     WorkingDir = Options["--workingdir"]
 1656     if WorkingDir:
 1657         os.chdir(WorkingDir)
 1658     
 1659     # Handle examples option...
 1660     if "--examples" in Options and Options["--examples"]:
 1661         MiscUtil.PrintInfo(MiscUtil.GetExamplesTextFromDocOptText(_docoptUsage_))
 1662         sys.exit(0)
 1663 
 1664 def ValidateOptions():
 1665     """Validate option values."""
 1666     
 1667     MiscUtil.ValidateOptionTextValue("--align", Options["--align"], "yes no")
 1668     MiscUtil.ValidateOptionTextValue("--alignMethod", Options["--alignMethod"], "align cealign super")
 1669     MiscUtil.ValidateOptionTextValue("--alignMode", Options["--alignMode"], "FirstChain Complex")
 1670     
 1671     MiscUtil.ValidateOptionTextValue("--allowEmptyObjects", Options["--allowEmptyObjects"], "yes no")
 1672     
 1673     MiscUtil.ValidateOptionTextValue("--BFactorChainCartoonPutty", Options["--BFactorChainCartoonPutty"], "yes no")
 1674     
 1675     # Expand infiles to handle presence of multiple input files...
 1676     InfileNames = MiscUtil.ExpandFileNames(Options["--infiles"], ",")
 1677     if not len(InfileNames):
 1678         MiscUtil.PrintError("No input files specified for \"-i, --infiles\" option")
 1679 
 1680     # Validate file extensions...
 1681     for Infile in InfileNames:
 1682         MiscUtil.ValidateOptionFilePath("-i, --infiles", Infile)
 1683         MiscUtil.ValidateOptionFileExt("-i, --infiles", Infile, "pdb cif")
 1684         MiscUtil.ValidateOptionsDistinctFileNames("-i, --infiles", Infile, "-o, --outfile", Options["--outfile"])
 1685     Options["--infileNames"] = InfileNames
 1686     
 1687     MiscUtil.ValidateOptionFileExt("-o, --outfile", Options["--outfile"], "pml pse")
 1688     MiscUtil.ValidateOptionsOutputFileOverwrite("-o, --outfile", Options["--outfile"], "--overwrite", Options["--overwrite"])
 1689     
 1690     if re.match("^yes$", Options["--align"], re.I):
 1691         if not re.match("^FirstInputFile$", Options["--alignRefFile"], re.I):
 1692             AlignRefFile = Options["--alignRefFile"]
 1693             MiscUtil.ValidateOptionFilePath("--alignRefFile", AlignRefFile)
 1694             MiscUtil.ValidateOptionFileExt("--alignRefFile", AlignRefFile, "pdb cif")
 1695             MiscUtil.ValidateOptionsDistinctFileNames("--AlignRefFile", AlignRefFile, "-o, --outfile", Options["--outfile"])
 1696     
 1697     MiscUtil.ValidateOptionTextValue("--ignoreHydrogens", Options["--ignoreHydrogens"], "yes no")
 1698     
 1699     MiscUtil.ValidateOptionTextValue("--PMLOut", Options["--PMLOut"], "yes no")
 1700     MiscUtil.ValidateOptionIntegerValue("--labelFontID", Options["--labelFontID"], {})
 1701 
 1702     MiscUtil.ValidateOptionFloatValue("--meshCarveRadius", Options["--meshCarveRadius"], {">": 0.0})
 1703     MiscUtil.ValidateOptionTextValue("--meshComplex", Options["--meshComplex"], "yes no")
 1704     MiscUtil.ValidateOptionTextValue("--meshChainComplex", Options["--meshChainComplex"], "yes no auto")
 1705     MiscUtil.ValidateOptionFloatValue("--meshWidth", Options["--meshWidth"], {">": 0.0})
 1706     
 1707     MiscUtil.ValidateOptionFloatValue("--meshLevelCompositeMap", Options["--meshLevelCompositeMap"], {})
 1708     MiscUtil.ValidateOptionFloatValue("--mesh1LevelDiffMap", Options["--mesh1LevelDiffMap"], {})
 1709     MiscUtil.ValidateOptionFloatValue("--mesh2LevelDiffMap", Options["--mesh2LevelDiffMap"], {})
 1710     
 1711     MiscUtil.ValidateOptionTextValue("--surfaceComplex", Options["--surfaceComplex"], "yes no")
 1712     MiscUtil.ValidateOptionTextValue("--surfaceChainComplex", Options["--surfaceChainComplex"], "yes no auto")
 1713     MiscUtil.ValidateOptionFloatValue("--surfaceTransparency", Options["--surfaceTransparency"], {">=": 0.0, "<=": 1.0})
 1714     
 1715     MiscUtil.ValidateOptionFloatValue("--pocketContactsCutoff", Options["--pocketContactsCutoff"], {">": 0.0})
 1716     MiscUtil.ValidateOptionFloatValue("--pocketDistanceCutoff", Options["--pocketDistanceCutoff"], {">": 0.0})
 1717     if (float(Options["--pocketContactsCutoff"]) > float(Options["--pocketDistanceCutoff"])):
 1718         MiscUtil.PrintError("The value, %s, specified using option \"--pocketContactsCutoff\" must be less than value, %s, specified using \"-pocketDistanceCutoff\" option." % (Options["--pocketContactsCutoff"], Options["--pocketDistanceCutoff"]))
 1719     
 1720     MiscUtil.ValidateOptionTextValue("--pocketSurface", Options["--pocketSurface"], "yes no")
 1721     
 1722     MiscUtil.ValidateOptionFloatValue("--volumeCarveRadius", Options["--volumeCarveRadius"], {">": 0.0})
 1723     MiscUtil.ValidateOptionTextValue("--volumeComplex", Options["--volumeComplex"], "yes no")
 1724     MiscUtil.ValidateOptionTextValue("--volumeChainComplex", Options["--volumeChainComplex"], "yes no auto")
 1725     
 1726 # Setup a usage string for docopt...
 1727 _docoptUsage_ = """
 1728 PyMOLVisualizeElectronDensity.py - Visualize electron density
 1729 
 1730 Usage:
 1731     PyMOLVisualizeElectronDensity.py  [--align <yes or no>] [--alignMethod <align, cealign, super>]
 1732                                      [--alignMode <FirstChain or Complex>] [--alignRefFile <filename>]
 1733                                      [--allowEmptyObjects <yes or no>] [--BFactorChainCartoonPutty <yes or no>]
 1734                                      [--BFactorColorPalette <text> ] [--chainIDs <First, All or ID1,ID2...>]
 1735                                      [--EDMapFiles <file1,file2,...>] [--EDMapSuffixes <CompositeMap,None,...>]
 1736                                      [--ignoreHydrogens <yes or no>] [--ligandIDs <Largest, All or ID1,ID2...>] [--labelFontID <number>]
 1737                                      [--meshCarveRadius <number>] [--meshComplex <yes or no>]
 1738                                      [--meshChainComplex <yes or no>] [--meshColorCompositeMap <text>]
 1739                                      [--meshLevelCompositeMap <number>] [--meshWidth <number>]
 1740                                      [--mesh1ColorDiffMap <text>] [--mesh1LevelDiffMap <number>]
 1741                                      [--mesh2ColorDiffMap <text>] [--mesh2LevelDiffMap <number>]
 1742                                      [--PMLOut <yes or no>] [--pocketContactsLigandColor <text>]
 1743                                      [--pocketContactsLigandHydrophobicColor <text>] [--pocketContactsSolventColor <text>]
 1744                                      [--pocketContactsInorganicColor <text>] [--pocketContactsCutoff <number>]
 1745                                      [--pocketDistanceCutoff <number>] [--pocketLabelColor <text>] [--pocketSurface <yes or no>]
 1746                                      [--selectionsChain <ObjectName,SelectionSpec,...>] [--selectionsChainStyle <DisplayStyle>]
 1747                                      [--surfaceComplex <yes or no> ] [--surfaceChainComplex <yes or no>] [--surfaceTransparency <number>]
 1748                                      [--volumeCarveRadius <number>] [--volumeComplex <yes or no>]
 1749                                      [--volumeChainComplex <yes, no, or auto>] [--volumeColorRampCompositeMap <text>]
 1750                                      [--volumeColorRampDiffMap <text> ] [--overwrite] [-w <dir>] -i <infile1,infile2...> -o <outfile>
 1751     PyMOLVisualizeElectronDensity.py -h | --help | -e | --examples
 1752 
 1753 Description:
 1754     Generate PyMOL visualization files for viewing X-ray electron density around
 1755     chains, ligands, and ligand binding pockets in macromolecules including proteins
 1756     and nucleic acids.
 1757 
 1758     The supported input file formats are: Macromolecule - PDB (.pdb) or CIF(.cif),
 1759     Electron Density - Collaborative Computational Project Number 4 (CCP4) ( .ccp4)
 1760 
 1761     The supported output file formats are: PyMOL script file (.pml), PyMOL session
 1762     file (.pse)
 1763 
 1764     Two types of CCP4 electron density map files may be used for visualizing electron
 1765     density. These file types along with default file names are shown below:
 1766     
 1767         CompositeMap (2Fobs - Fcalc) - <InfileRoot>.ccp4 (required)
 1768         DifferenceMap (Fobs - Fcalc) - <InfileRoot>_diff.ccp4 (optional)
 1769     
 1770     The compsite map file must be present. The difference map file is optional.
 1771     The mesh, volume, and surface PyMOL objects are not generated for missing
 1772     difference map file.
 1773 
 1774     The electron density present in a composite map file is generated by adding two
 1775     difference maps to a calculated map (Fcalc) as shown below:
 1776     
 1777         Fcalc + 2(Fobs - Fcalc) = 2Fobs - Fcalc
 1778     
 1779     The following types of meshes and volumes may be created by default for
 1780     electron density present in composite and difference map files:
 1781     
 1782         CompositeVolume - VolumeColorRamp: 2fofc
 1783         CompositeMesh - ContourLevel: 1; Color: Blue
 1784         DiffVolume - VolumeColorRamp: fofc
 1785         DiffMesh1 - ContourLevel: 3; Color: Green
 1786         DiffMesh2 - ContourLevel: -3; Color: Red
 1787 
 1788     The two meshes created for difference maps correspond to false negative and
 1789     false positive in terms of electron density present in the model. The first mesh
 1790     shown in  green color corresponds to observed electron density missing in the
 1791     model. The second mesh in in red color indicates model electron density not
 1792     observed in the experiment.
 1793     
 1794     A variety of PyMOL groups and objects may be  created for visualization of
 1795     electron density present in map files. These groups and objects correspond to
 1796     maps, volumes, meshes, surfaces,chains, ligands, inorganics, ligand binding
 1797     pockets, polar interactions, and pocket hydrophobic surfaces. A complete
 1798     hierarchy of all possible PyMOL groups and objects is shown below:
 1799     
 1800         <PDBFileRoot>
 1801             .Complex
 1802                 .Complex
 1803                 .2Fo-Fc
 1804                     .Map
 1805                     .Volume
 1806                     .Mesh
 1807                     .Surface
 1808                 .Fo-Fc
 1809                     .Map
 1810                     .Volume
 1811                     .Mesh1
 1812                     .Surface1
 1813                     .Mesh2
 1814                     .Surface2
 1815             .Chain<ID>
 1816                 .Complex
 1817                     .Complex
 1818                     .2Fo-Fc
 1819                         .Volume
 1820                         .Mesh
 1821                         .Surface
 1822                     .Fo-Fc
 1823                         .Volume
 1824                         .Mesh1
 1825                         .Surface1
 1826                         .Mesh2
 1827                         .Surface2
 1828                 .Chain
 1829                     .Chain
 1830                     .BFactor
 1831                     .Selections
 1832                         .<Name1>
 1833                             .Selection
 1834                             .2Fo-Fc
 1835                                 .Volume
 1836                                 .Mesh
 1837                                 .Surface
 1838                             .Fo-Fc
 1839                                 .Volume
 1840                                 .Mesh1
 1841                                 .Surface1
 1842                                 .Mesh2
 1843                                 .Surface2
 1844                         .<Name2>
 1845                             ... ... ..
 1846                 .Solvent
 1847                 .Inorganic
 1848                 .Ligand<ID>
 1849                     .Ligand
 1850                         .Ligand
 1851                         .2Fo-Fc
 1852                             .Volume
 1853                             .Mesh
 1854                             .Surface
 1855                         .Fo-Fc
 1856                             .Volume
 1857                             .Mesh1
 1858                             .Surface1
 1859                             .Mesh2
 1860                             .Surface2
 1861                     .Pocket
 1862                         .Pocket
 1863                         .2Fo-Fc
 1864                             .Volume
 1865                             .Mesh
 1866                             .Surface
 1867                         .Fo-Fc
 1868                             .Volume
 1869                             .Mesh1
 1870                             .Surface1
 1871                             .Mesh2
 1872                             .Surface2
 1873                         .Polar_Contacts
 1874                         .Hydrophobic_Contacts
 1875                         .Surface
 1876                     .Pocket_Solvent
 1877                         .Pocket_Solvent
 1878                         .2Fo-Fc
 1879                             .Volume
 1880                             .Mesh
 1881                             .Surface
 1882                         .Fo-Fc
 1883                             .Volume
 1884                             .Mesh1
 1885                             .Surface1
 1886                             .Mesh2
 1887                             .Surface2
 1888                         .Polar_Contacts
 1889                     .Pocket_Inorganic
 1890                         .Pocket_Inorganic
 1891                         .2Fo-Fc
 1892                             .Volume
 1893                             .Mesh
 1894                             .Surface
 1895                         .Fo-Fc
 1896                             .Volume
 1897                             .Mesh1
 1898                             .Surface1
 1899                             .Mesh2
 1900                             .Surface2
 1901                         .Polar_Contacts
 1902                 .Ligand<ID>
 1903                     .Ligand
 1904                         ... ... ...
 1905                     .Pocket
 1906                         ... ... ...
 1907                     .Pocket_Solvent
 1908                         ... ... ...
 1909                     .Pocket_Inorganic
 1910                         ... ... ...
 1911             .Chain<ID>
 1912                 ... ... ...
 1913                 .Ligand<ID>
 1914                     ... ... ...
 1915                 .Ligand<ID>
 1916                     ... ... ...
 1917             .Chain<ID>
 1918                 ... ... ...
 1919         <PDBFileRoot>
 1920             .Complex
 1921                 ... ... ...
 1922             .Chain<ID>
 1923                 ... ... ...
 1924                 .Ligand<ID>
 1925                     ... ... ...
 1926                 .Ligand<ID>
 1927                     ... ... ...
 1928             .Chain<ID>
 1929                 ... ... ...
 1930     
 1931     The meshes, volumes, and surfaces  are not created for complete complex in
 1932     each input file by default. A word to the wise: The creation of these surface, volume,
 1933     and mesh objects may slow down loading of PML file and generation of PSE file,
 1934     based on the size of input complex and map files. The generation of PSE file
 1935     may also fail.
 1936 
 1937 Options:
 1938     -a, --align <yes or no>  [default: no]
 1939         Align input files to a reference file before visualization along with
 1940         available electron density map files.
 1941     --alignMethod <align, cealign, super>  [default: super]
 1942         Alignment methodology to use for aligning input files to a
 1943         reference file.
 1944     --alignMode <FirstChain or Complex>  [default: FirstChain]
 1945         Portion of input and reference files to use for spatial alignment of
 1946         input files against reference file.  Possible values: FirstChain or
 1947         Complex.
 1948         
 1949         The FirstChain mode allows alignment of the first chain in each input
 1950         file to the first chain in the reference file along with moving the rest
 1951         of the complex to coordinate space of the reference file. The complete
 1952         complex in each input file is aligned to the complete complex in reference
 1953         file for the Complex mode.
 1954     --alignRefFile <filename>  [default: FirstInputFile]
 1955         Reference input file name. The default is to use the first input file
 1956         name specified using '-i, --infiles' option.
 1957     --allowEmptyObjects <yes or no>  [default: no]
 1958         Allow creation of empty PyMOL objects corresponding to solvent and
 1959         inorganic atom selections across chains, ligands, and ligand binding pockets
 1960         in input file(s).
 1961     -c, --chainIDs <First, All or ID1,ID2...>  [default: First]
 1962         List of chain IDs to use for visualizing electron density. Possible values:
 1963         First, All, or a comma delimited list of chain IDs. The default is to use the
 1964         chain ID for the first chain in each input file.
 1965     -b, --BFactorChainCartoonPutty <yes or no>  [default: yes]
 1966         A cartoon putty around individual chains colored by B factors. The minimum
 1967         and maximum values for B factors are automatically detected. These values
 1968         indicate spread of electron density around atoms. The 'blue_white_red' color
 1969         palette is deployed for coloring the cartoon putty.
 1970     --BFactorColorPalette <text>  [default: blue_white_red]
 1971         Color palette for coloring cartoon putty around chains generated using B
 1972         factors. Any valid PyMOL color palette name is allowed. No validation is
 1973         performed. The complete list of valid color palette names is a available
 1974         at: pymolwiki.org/index.php/Spectrum. Examples: blue_white_red,
 1975         blue_white_magenta, blue_red, green_white_red, green_red.
 1976     -e, --examples
 1977         Print examples.
 1978     --EDMapFiles <file1,file1,file3...>  [default: auto]
 1979         Pairwise comma delimited list of composite and difference electron
 1980         density map files corresponding to input files. By default, the names
 1981         of electron density files are automatically generated using a combination
 1982         of input file names and file suffixes '--EDMapSuffixes'.
 1983         
 1984         The first file with in each pairs of filenames correspond to composite
 1985         electron density map. A composite file must be present for each input
 1986         file. The second file corresponds to difference electron density map. The
 1987         difference map file is optional. A value of 'None' must be used to represent
 1988         a missing difference map file. 
 1989         
 1990         The number of specified files must be twice the number of input files.
 1991     --EDMapSuffixes <CompositeMap,None,...>  [default: auto]
 1992         Electron density map file suffixes for generating names of map files from
 1993         the root of input files. It is a pairwise comma delimited list of 'EDMapType'
 1994         and file suffix.
 1995         
 1996         This option is ignored during explicit specification of electron density
 1997         map files using '--EDMapFiles'.
 1998         
 1999         Supported values for 'EDMapType': 'CompositeMap, DifferenceMap'.
 2000         Supported value for file suffix: Any valid string.
 2001         
 2002         Default value: 'CompositeMap,None,DifferenceMap,_diff'
 2003         
 2004         This option is only used for 'Auto' value of '--EDMapFilesMode' option.
 2005         
 2006         The default names of the map files, generated form a combination of
 2007         'InfileRoot' and 'EDSMapType' are shown below:
 2008             
 2009             CompositeMap (2Fobs - Fcalc) - <InfileRoot>.ccp4
 2010             DifferenceMap (Fobs - Fcalc) - <InfileRoot>_diff.ccp4
 2011             
 2012         The composite map files must be present. The difference map files are
 2013         optional.
 2014     -h, --help
 2015         Print this help message.
 2016     -i, --infiles <infile1,infile2,infile3...>
 2017         Input file names.
 2018     --ignoreHydrogens <yes or no>  [default: yes]
 2019         Ignore hydrogens for ligand and pocket views.
 2020     -l, --ligandIDs <Largest, All or ID1,ID2...>  [default: Largest]
 2021         List of ligand IDs present in chains for visualizing electron density across
 2022         ligands and ligand binding pockets. Possible values: Largest, All, or a comma
 2023         delimited list of ligand IDs. The default is to use the largest ligand present
 2024         in all or specified chains in each input file.
 2025         
 2026         Ligands are identified using organic selection operator available in PyMOL.
 2027         It'll also  identify buffer molecules as ligands. The largest ligand contains
 2028         the highest number of heavy atoms.
 2029     --labelFontID <number>  [default: 7]
 2030         Font ID for drawing labels. Default: 7 (Sans Bold). Valid values: 5 to 16.
 2031         The specified value must be a valid PyMOL font ID. No validation is
 2032         performed. The complete lists of valid font IDs is available at:
 2033         pymolwiki.org/index.php/Label_font_id. Examples: 5 - Sans;
 2034         7 - Sans Bold; 9 - Serif; 10 - Serif Bold.
 2035     --meshCarveRadius <number>  [default: 1.6]
 2036         Radius in Angstroms around atoms for including electron density.
 2037     --meshComplex <yes or no>  [default: no]
 2038         Create meshes for complete complex in each input file using corresponding
 2039         composite and difference maps. A total of three meshes, one for composite
 2040         map and two for difference map, are created for the complete complex.
 2041         
 2042         The composite and difference maps are always loaded for the complex.
 2043     --meshChainComplex <yes, no, or auto>  [default: auto]
 2044         Create meshes for individual chain complex in each input file using corresponding
 2045         composite and difference maps. A total of three meshes, one for composite map
 2046         map and two for difference map, are created for each chain complex. By default,
 2047         the meshes are automatically created for chain complexes without any ligands. 
 2048     --meshColorCompositeMap <text>  [default: blue]
 2049         Line color for meshes corresponding to composite maps. The specified value
 2050         must be valid color. No validation is performed.
 2051     --meshLevelCompositeMap <number>  [default: 1.0]
 2052         Contour level in sigma units for generating meshes corresponding to composite
 2053         maps.
 2054     --meshWidth <number>  [default: 0.5]
 2055         Line width for mesh lines corresponding to composite and difference maps.
 2056     --mesh1ColorDiffMap <text>  [default: green]
 2057         Line color for first mesh corresponding to difference maps at contour level
 2058         specified by '--mesh1LevelDiffMap'. The specified value must be valid color.
 2059         No validation is performed.
 2060     --mesh1LevelDiffMap <number>  [default: 3.0]
 2061         Contour level in sigma units for generating first mesh corresponding to 
 2062         to  difference maps.
 2063     --mesh2ColorDiffMap <text>  [default: red]
 2064         Line color for second mesh corresponding to difference maps at contour level
 2065         specified by '--mesh2LevelDiffMap'. The specified value must be valid color.
 2066         No validation is performed.
 2067     --mesh2LevelDiffMap <number>  [default: -3.0]
 2068         Contour level in sigma units for generating second mesh corresponding to
 2069         difference maps.
 2070     -o, --outfile <outfile>
 2071         Output file name.
 2072     -p, --PMLOut <yes or no>  [default: yes]
 2073         Save PML file during generation of PSE file.
 2074     --pocketContactsLigandColor <text>  [default: orange]
 2075         Color for drawing polar contacts between ligand and pocket residues.
 2076         The specified value must be valid color. No validation is performed.
 2077     --pocketContactsLigandHydrophobicColor <text>  [default: purpleblue]
 2078         Color for drawing hydrophobic contacts between ligand and pocket residues.
 2079         The specified value must be valid color. No validation is performed. The
 2080         hydrophobic contacts are shown between pairs of carbon atoms not
 2081         connected to hydrogen bond donor or acceptors atoms as identified
 2082         by PyMOL.
 2083     --pocketContactsSolventColor <text>  [default: marine]
 2084         Color for drawing polar contacts between solvent and pocket residues.
 2085         The specified value must be valid color. No validation is performed.
 2086     --pocketContactsInorganicColor <text>  [default: deepsalmon]
 2087         Color for drawing polar contacts between inorganic and pocket residues.
 2088         The specified value must be valid color. No validation is performed.
 2089     --pocketContactsCutoff <number>  [default: 4.0]
 2090         Distance in Angstroms for identifying polar and hyrdophobic contacts
 2091         between atoms in pocket residues and ligands.
 2092     --pocketDistanceCutoff <number>  [default: 5.0]
 2093         Distance in Angstroms for identifying pocket residues around ligands.
 2094     --pocketLabelColor <text>  [default: magenta]
 2095         Color for drawing residue or atom level labels for a pocket. The specified
 2096         value must be valid color. No validation is performed.
 2097     --pocketSurface <yes or no>  [default: yes]
 2098         Hydrophobic surface around pocket. The pocket surface is colored by
 2099         hydrophobicity. It is only valid for proteins. The color of amino acids is
 2100         set using the Eisenberg hydrophobicity scale. The color varies from red
 2101         to white, red being the most hydrophobic amino acid.
 2102     --selectionsChain <ObjectName,SelectionSpec,...>  [default: None]
 2103         Custom selections for chains. It is a pairwise of list comma delimited values
 2104         corresponding to PyMOL object names and selection specifications.  The
 2105         selection specification must be a valid PyMOL specification. No validation is
 2106         performed.
 2107         
 2108         The PyMOL objects are created for each chain corresponding to the
 2109         specified selections. The display style for PyMOL objects is set using
 2110         value of '--selectionsChainStyle' option.
 2111         
 2112         The specified selection specification is automatically appended to appropriate
 2113         chain specification before creating PyMOL objects.
 2114         
 2115         For example, the following specification for '--selectionsChain' option will
 2116         generate PyMOL objects for chains containing Cysteines and Serines:
 2117             
 2118             Cysteines,resn CYS,Serines,resn SER
 2119             
 2120     --selectionsChainStyle <DisplayStyle>  [default: sticks]
 2121         Display style for PyMOL objects created for '--selectionsChain' option. It
 2122         must be a valid PyMOL display style. No validation is performed.
 2123     --surfaceComplex <yes or no>  [default: no]
 2124         Create surfaces for complete complex 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 the complete complex.
 2127         
 2128         The composite and difference maps are always loaded for the complex.
 2129     --surfaceChainComplex <yes, no or auto>  [default: auto]
 2130         Create surfaces for individual chain complexes in each input file using corresponding
 2131         composite and difference maps. A total of three surfaces, one for composite
 2132         map and two for difference map, are created for each chain complex. By default,
 2133         the surfaces are automatically created for chain complexes without any ligands. 
 2134     --surfaceTransparency <number>  [default: 0.25]
 2135         Surface transparency for molecular and electron density surfaces.
 2136     --volumeCarveRadius <number>  [default: 1.6]
 2137         Radius in Angstroms around atoms for including electron density during
 2138         generation of volume objects.
 2139     --volumeComplex <yes or no>  [default: no]
 2140         Create volumes for complete complex in input file using corresponding
 2141         composite and difference maps. A total of two volumes, one each for
 2142         composite and difference maps, are created for the complete complex.
 2143     --volumeChainComplex <yes, no, or auto>  [default: auto]
 2144         Create volumes for individual chain complex in each input file using corresponding
 2145         composite and difference maps. A total of two volumes, one each for composite
 2146         and difference maps, are created for each chain complex. By default, the
 2147         volumes are automatically created for chain complexes without any ligands.
 2148     --volumeColorRampCompositeMap <text>  [default: 2fofc]
 2149         Name of volume color ramp for composite maps. The specified value must
 2150         be a valid name. No validation is performed. The following volume color ramps
 2151         are currently available in PyMOL: default, 2fofc, fofc, rainbow, and rainbow2.
 2152     --volumeColorRampDiffMap <text>  [default: fofc]
 2153         Name of volume color ramp for difference maps. The specified value must
 2154         be a valid name. No validation is performed. The following volume color ramps
 2155         are currently available in PyMOL: default, 2fofc, fofc, rainbow, and rainbow2.
 2156     --overwrite
 2157         Overwrite existing files.
 2158     -w, --workingdir <dir>
 2159         Location of working directory which defaults to the current directory.
 2160 
 2161 Examples:
 2162     To visualize electron density for the largest ligand in the first chain, and
 2163     ligand binding pockets to highlight ligand interactions with pockect residues,
 2164     solvents and inorganics, in a PDB file by using default map files, and generate a
 2165     PML file, type:
 2166 
 2167         % PyMOLVisualizeElectronDensity.py -i Sample3.pdb -o Sample3.pml
 2168 
 2169     To visualize electron density for the largest ligand in the first chain, cysteine
 2170     and serine residues in the chain, and ligand binding pockets to highlight ligand
 2171     interactions with pockect residues, solvents and inorganics, in a PDB file by
 2172     using default map files, and generate a PML file, type:
 2173 
 2174         % PyMOLVisualizeElectronDensity.py -i Sample3.pdb -o Sample3.pml
 2175           --selectionsChain "Cysteines,resn cys,Serines,resn ser"
 2176 
 2177     To visualize electron density for all ligands in all chains, and ligand binding
 2178     pockets to highlight ligand interactions with pockect residues, solvents
 2179     and inorganics, in a PDB file by using default map files, and generate a
 2180     PML file, type:
 2181 
 2182         % PyMOLVisualizeElectronDensity.py -i Sample3.pdb -o Sample3.pml
 2183           -c All -l All
 2184 
 2185     To visualize electron density for all chains and ligands, along with displaying
 2186     meshes, volumes, and surfaces for complete complex and individual chains,
 2187     in a PDB file by using  default map files, and generate a PML file, type:
 2188 
 2189         % PyMOLVisualizeElectronDensity.py -i Sample3.pdb -o Sample3.pml
 2190           --chainIDs All --ligandIDs All --meshComplex yes --surfaceComplex yes
 2191           --volumeComplex yes --meshChainComplex yes --surfaceChainComplex yes
 2192           --volumeChainComplex yes
 2193 
 2194     To visualize electron density for ligand ADP in chain E along with ligand binding
 2195     pocket, in a PDB file by using  default map files, and generate a PSE file, type:
 2196 
 2197         % PyMOLVisualizeElectronDensity.py -i Sample3.pdb -o Sample3.pse
 2198           --chainIDs E --ligandIDs ADP
 2199 
 2200     To visualize electron density for all igands in all chains along with their binding
 2201     pockets in a PDB file and using explicit file name suffixes for map files, and
 2202     generate a PML file, type:
 2203 
 2204         % PyMOLVisualizeElectronDensity.py -i Sample3.pdb -o Sample3.pml
 2205           --chainIDs All --ligandIDs All --EDMapSuffixes "CompositeMap,None,
 2206           DifferenceMap,_diff"
 2207 
 2208     To visualize electron density for all ligands in all chains along with their binding
 2209     pockets in a PDB file by using explicit file names for map files, and generate
 2210     a PML file, type:
 2211 
 2212         % PyMOLVisualizeElectronDensity.py -i Sample3.pdb -o Sample3.pml
 2213           --chainIDs All --ligandIDs All --EDMapFiles "Sample3.ccp4,
 2214           Sample3_diff.ccp4"
 2215 
 2216     To align and visualize electron density for all ligands in all chains along with their
 2217     binding pockets in PDB files by using explicit file names for map files, and generate
 2218     a PML file, type:
 2219 
 2220         % PyMOLVisualizeElectronDensity.py -a yes -i "Sample3.pdb,Sample4.pdb"
 2221           -o SampleOut.pml --chainIDs All --ligandIDs All --EDMapFiles
 2222          "Sample3.ccp4,Sample3_diff.ccp4,Sample4.ccp4,Sample4_diff.ccp4"
 2223 
 2224 Author:
 2225     Manish Sud(msud@san.rr.com)
 2226 
 2227 See also:
 2228     DownloadPDBFiles.pl, PyMOLVisualizeCavities.py,
 2229     PyMOLVisualizeCryoEMDensity.py, PyMOLVisualizeInterfaces.py,
 2230     PyMOLVisualizeMacromolecules.py, PyMOLVisualizeSurfaceAndBuriedResidues.py
 2231 
 2232 Copyright:
 2233     Copyright (C) 2024 Manish Sud. All rights reserved.
 2234 
 2235     The functionality available in this script is implemented using PyMOL, a
 2236     molecular visualization system on an open source foundation originally
 2237     developed by Warren DeLano.
 2238 
 2239     This file is part of MayaChemTools.
 2240 
 2241     MayaChemTools is free software; you can redistribute it and/or modify it under
 2242     the terms of the GNU Lesser General Public License as published by the Free
 2243     Software Foundation; either version 3 of the License, or (at your option) any
 2244     later version.
 2245 
 2246 """
 2247 
 2248 if __name__ == "__main__":
 2249     main()