Add a PyMOL builder to SCons and generalize PYMOL_PATH setup.
authorW. Trevor King <wking@drexel.edu>
Sat, 14 May 2011 18:42:12 +0000 (14:42 -0400)
committerW. Trevor King <wking@drexel.edu>
Sat, 14 May 2011 18:42:12 +0000 (14:42 -0400)
tex/site_cons/site_tools/pymol.py [new file with mode: 0644]
tex/src/SConscript
tex/src/figures/biotin-streptavidin/SConscript
tex/src/figures/i27/SConscript

diff --git a/tex/site_cons/site_tools/pymol.py b/tex/site_cons/site_tools/pymol.py
new file mode 100644 (file)
index 0000000..871d797
--- /dev/null
@@ -0,0 +1,70 @@
+import os.path
+import re
+import SCons.Action
+import SCons.Scanner
+import SCons.Script
+import SCons.Util
+import doctest
+
+
+load_re = re.compile(r"^load (.*)")
+
+
+def pymol_scan(node, env, path, arg=None):
+    """
+    >>> this_dir = os.path.dirname(__file__)
+    >>> src_dir = os.path.join(this_dir, '..', '..', 'src')
+    >>> class node (object):
+    ...     def __init__(self, path):
+    ...         self.path = path
+    ...         self.abspath = os.path.abspath(self.path)
+    ...         if os.path.isfile(self.path):
+    ...             self.dir = node(os.path.dirname(path))
+    ...     def get_text_contents(self):
+    ...         return open(self.path, 'r').read()
+    ...     def get_contents(self):
+    ...         return self.get_text_contents()
+    ...     def srcnode(self):
+    ...         return self
+    >>> for p in pymol_scan(
+    ...         node(os.path.join(src_dir, 'figures', 'i27', '1TIT.pml')),
+    ...         None, None, None):
+    ...     print p
+    1TIT.pdb
+    """
+    try:
+        contents = node.get_text_contents()
+    except AttributeError:
+        contents = node.get_contents() # for older versions of SCons, fall back on binary read
+    ret = []
+    for string in load_re.findall(contents):
+        p = os.path.join(node.dir.srcnode().abspath, string)
+        if len(string) > 0 and (string not in ret and os.path.exists(p)):
+            ret.append(string)
+    return ret
+
+
+PymolAction = None
+
+def generate(env):
+    """Add Builders and construction variables for Pymol to an Environment."""
+    global PymolAction
+    if PymolAction is None:
+        PymolAction = SCons.Action.Action(
+            '$PYMOLCOM', '$PYMOLCOMSTR')
+
+    env['BUILDERS']['Pymol'] = SCons.Script.Builder(
+        action=PymolAction, suffix='.png', src_suffix = '.pml')
+    env['PYMOL'] = 'pymol'
+    env['PYMOLFLAGS'] = '-cq'
+    env['PYMOLCOM'] = 'cd ${TARGET.dir} && $PYMOL $PYMOLFLAGS ${SOURCE.file}'
+    env.Append(SCANNERS=SCons.Scanner.Base(
+            function=pymol_scan,
+            name='pymol',
+            skeys=['.pml']))
+
+def exists(env):
+    return env.Detect('pymol')
+
+if __name__ == '__main__':
+    doctest.testmod()
index 313493d082838d1f9d45bee047fe0549f49bd51d..b3e814ece00a4455609d60c3266d3d9cc13e7db3 100644 (file)
@@ -1,15 +1,16 @@
+from distutils.sysconfig import get_python_lib
 import os.path
 import SCons.Scanner
 
 from site_cons.site_init import (
      include_child_SConscripts, check_exec, recursive_glob)
-from site_cons.site_tools import asymptote, gnuplot
+from site_cons.site_tools import asymptote, gnuplot, pymol
 
 # Make a new environment.
 env = Environment(ENV={
     'PATH':['/usr/local/bin', '/opt/bin', '/bin', '/usr/bin'],
     'HOME':os.path.expanduser('~'),
-    'PYMOL_PATH':'/usr/lib/python2.6/site-packages/pymol',
+    'PYMOL_PATH':os.path.join(get_python_lib(), 'pymol'),
     'PYMOL_DATA':'/usr/share/pymol/data',
     'PYMOL_SCRIPTS':'/usr/share/pymol/scripts',
     })
@@ -18,6 +19,7 @@ if 'DISPLAY' in os.environ:
 
 asymptote.generate(env)
 gnuplot.generate(env)
+pymol.generate(env)
 
 if not env.GetOption('clean'):
     # Configure the environment since we're not cleaning.
index 5b88d51c83ca2271d3450d1fd24ac39fa8f464d2..a7fdf81f3f60f06ec570b7e3f43596fdf70ff275 100644 (file)
@@ -1,11 +1,8 @@
 # Get the passed in environment.
 Import('env')
 
-swe = env.Command(
-    '1SWE.png',
-    ['1SWE.pml', '1SWE.pdb'],
-    'pymol -cq 1SWE.pml',
-    chdir=True)
+for pml in Glob('*.pml'):
+    env.Pymol(pml)
 
 # Pass back the modified environment.
 Return('env')
index cd1fa486245aff6f5a3d803259da8c1a4677b4cc..a7fdf81f3f60f06ec570b7e3f43596fdf70ff275 100644 (file)
@@ -1,11 +1,8 @@
 # Get the passed in environment.
 Import('env')
 
-tit = env.Command(
-    '1TIT.png',
-    ['1TIT.pml', '1TIT.pdb'],
-    'pymol -cq 1TIT.pml',
-    chdir=True)
+for pml in Glob('*.pml'):
+    env.Pymol(pml)
 
 # Pass back the modified environment.
 Return('env')