From: W. Trevor King Date: Sat, 14 May 2011 18:42:12 +0000 (-0400) Subject: Add a PyMOL builder to SCons and generalize PYMOL_PATH setup. X-Git-Tag: v1.0~356 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=a05d52e33082365502de8f98ec7644cf77d42fe5;p=thesis.git Add a PyMOL builder to SCons and generalize PYMOL_PATH setup. --- diff --git a/tex/site_cons/site_tools/pymol.py b/tex/site_cons/site_tools/pymol.py new file mode 100644 index 0000000..871d797 --- /dev/null +++ b/tex/site_cons/site_tools/pymol.py @@ -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() diff --git a/tex/src/SConscript b/tex/src/SConscript index 313493d..b3e814e 100644 --- a/tex/src/SConscript +++ b/tex/src/SConscript @@ -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. diff --git a/tex/src/figures/biotin-streptavidin/SConscript b/tex/src/figures/biotin-streptavidin/SConscript index 5b88d51..a7fdf81 100644 --- a/tex/src/figures/biotin-streptavidin/SConscript +++ b/tex/src/figures/biotin-streptavidin/SConscript @@ -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') diff --git a/tex/src/figures/i27/SConscript b/tex/src/figures/i27/SConscript index cd1fa48..a7fdf81 100644 --- a/tex/src/figures/i27/SConscript +++ b/tex/src/figures/i27/SConscript @@ -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')