def _generate_scripts_and_pictures(wf, opt, data, pha=None): blobs = data['blobs'] if data else [] coot_path = coots.find_path() if not blobs: comment('\nUnmodelled blobs not found.') elif opt.img_format: if coot_path: coot_ver = coots.find_version(coot_path) if coot_ver is None: put_error('coot not working(?), no pictures') opt.img_format = None elif 'with python' not in coot_ver: put_error('coot with Python support is needed') opt.img_format = None else: put_error('No coot, no pictures') opt.img_format = None if not utils.syspath('render'): put_error('No Raster3d, no pictures') opt.img_format = None if opt.img_format: if len(blobs) == 1: comment('\nRendering density blob at (%.1f, %.1f, %.1f)' % blobs[0]) else: comment('\nRendering 2 largest blobs: at (%.1f, %.1f, %.1f) ' 'and at (%.1f, %.1f, %.1f)' % (blobs[0] + blobs[1])) com = data and data.get('center') if pha: normal_map = False refl = pha prefix = 'anom-' else: normal_map = True refl = opt.hklout prefix = '' # run-coot.py centers on the biggest blob. It uses relative paths - # it can be run only from the output directory, but is not affected # by moving that directory to different location. # There are blobN-coot.py scripts generated below with absolute paths. # write coot script (apart from pictures) that centers on the biggest blob script_path = os.path.join(wf.output_dir, prefix + 'run-coot.py') script = coots.basic_script(pdb=opt.xyzout, refl=refl, normal_map=normal_map, center=(blobs and blobs[0]), toward=com, white_bg=opt.white_bg) _write_script(script_path, script, executable=True) # blob images, for now for not more than two blobs d = os.path.abspath(wf.output_dir) for n, b in enumerate(blobs[:2]): py_path = os.path.join(wf.output_dir, '%sblob%d-coot.py' % (prefix, n + 1)) content = coots.basic_script(pdb=os.path.join(d, opt.xyzout), refl=os.path.join(d, refl), normal_map=normal_map, center=blobs[n], toward=com, white_bg=opt.white_bg) _write_script(py_path, content) # coot.sh - one-line script for convenience if blobs: coot_sh_text = '{coot} --no-guano {out}/%sblob1-coot.py\n' % prefix else: coot_sh_text = '{coot} --no-guano {out}/final.mtz {out}/final.pdb\n' coot_sh_path = os.path.join(wf.output_dir, prefix + 'coot.sh') _write_script(coot_sh_path, coot_sh_text.format(coot=coot_path or 'coot', out=wf.output_dir), executable=True) if opt.img_format and blobs: script = '' basenames = [] # as a workaround for buggy coot the maps are reloaded for each blob for n, b in enumerate(blobs[:2]): script += coots.basic_script(pdb=opt.xyzout, refl=refl, normal_map=normal_map, center=b, toward=com, white_bg=opt.white_bg) rs, names = coots.r3d_script(center=b, toward=com, blobname='%sblob%s' % (prefix, n + 1)) script += rs basenames += names coot_job = wf.coot_py(script) try: coot_job.run() except workflow.JobError: # check for a possible cause to hint the user # (possible workaround: change $HOME to non-existing directory) if utils.silently_run(coot_job.args, cwd=wf.output_dir)[0] != 0: put_error('coot fails with options: --no-graphics --python', comment='It happens when scripts in .coot or ' '.coot-preferences are not compatible\n' 'with the --no-graphics mode.') raise for n, basename in enumerate(basenames): try: job = wf.render_r3d(basename, img_format=opt.img_format) if n % 3 == 0: job.run() else: # minimal output job.run(show_progress=False, new_line=False) wf.delete_files([basename + '.r3d']) except workflow.JobError as e: # Raster3D may fail saying "increase MAXDET and recompile". # This is not critical, so Dimple doesn't stop. put_error('Rendering failed, no picture', comment=' ' + e.note) return coot_sh_path
def _generate_scripts_and_pictures(wf, opt, data): blobs = data["blobs"] if data else [] if not blobs: comment("\nUnmodelled blobs not found.") elif opt.img_format and _check_picture_tools(): if len(blobs) == 1: comment("\nRendering density blob at (%.1f, %.1f, %.1f)" % blobs[0]) else: comment("\nRendering 2 largest blobs: at (%.1f, %.1f, %.1f) " "and at (%.1f, %.1f, %.1f)" % (blobs[0]+blobs[1])) com = data and data["center"] # run-coot.py centers on the biggest blob. It uses relative paths - # it can be run only from the output directory, but is not affected # by moving that directory to different location. # There are blobN-coot.py scripts generated below with absolute paths. # write coot script (apart from pictures) that centers on the biggest blob script_path = os.path.join(wf.output_dir, "run-coot.py") script = coots.basic_script(pdb=opt.xyzout, mtz=opt.hklout, center=(blobs and blobs[0]), toward=com) _write_script(script_path, script, executable=True) # blob images, for now for not more than two blobs d = os.path.abspath(wf.output_dir) for n, b in enumerate(blobs[:2]): py_path = os.path.join(wf.output_dir, "blob%d-coot.py" % (n+1)) content = coots.basic_script(pdb=os.path.join(d, opt.xyzout), mtz=os.path.join(d, opt.hklout), center=blobs[n], toward=com) _write_script(py_path, content) # coot.sh - one-line script for convenience if blobs: coot_sh_text = '{coot} --no-guano {out}/blob1-coot.py\n' else: coot_sh_text = '{coot} --no-guano {out}/final.mtz {out}/final.pdb\n' coot_sh_path = os.path.join(wf.output_dir, "coot.sh") _write_script(coot_sh_path, coot_sh_text.format(coot=coots.find_path(), out=wf.output_dir), executable=True) if opt.img_format and blobs: script = '' basenames = [] # as a workaround for buggy coot the maps are reloaded for each blob for n, b in enumerate(blobs[:2]): script += coots.basic_script(pdb=opt.xyzout, mtz=opt.hklout, center=b, toward=com) rs, names = coots.r3d_script(b, com, blobname="blob%s"%(n+1)) script += rs basenames += names coot_job = wf.coot_py(script) try: coot_job.run() except workflow.JobError: # check for a possible cause to hint the user # (possible workaround: change $HOME to non-existing directory) if utils.silently_run(coot_job.args, cwd=wf.output_dir)[0] != 0: put_error("coot fails with options: --no-graphics --python", comment="It happens when scripts in .coot or " ".coot-preferences are not compatible\n" "with the --no-graphics mode.") raise for n, basename in enumerate(basenames): job = wf.render_r3d(basename, img_format=opt.img_format) if n % 3 == 0: job.run() else: # minimal output job.run(show_progress=False, new_line=False) wf.delete_files([name+".r3d" for name in basenames]) return coot_sh_path
def _run_mtzdump(hklin, keys): retcode, out, _ = silently_run(['mtzdump', 'HKLIN', hklin], stdin_text="\n".join(keys + ['END'])) if retcode != 0: raise RuntimeError("mtzdump of %s failed" % hklin) return out
def _generate_scripts_and_pictures(wf, opt, data): blobs = data["blobs"] if data else [] coot_path = coots.find_path() if not blobs: comment("\nUnmodelled blobs not found.") elif opt.img_format: if coot_path: coot_ver = coots.find_version(coot_path) if coot_ver is None: put_error("coot not working(?), no pictures") opt.img_format = None elif "with python" not in coot_ver: put_error("coot with Python support is needed") opt.img_format = None else: put_error("No coot, no pictures") opt.img_format = None if not utils.syspath("render"): put_error("No Raster3d, no pictures") opt.img_format = None if opt.img_format: if len(blobs) == 1: comment("\nRendering density blob at (%.1f, %.1f, %.1f)" % blobs[0]) else: comment("\nRendering 2 largest blobs: at (%.1f, %.1f, %.1f) " "and at (%.1f, %.1f, %.1f)" % (blobs[0]+blobs[1])) com = data and data["center"] # run-coot.py centers on the biggest blob. It uses relative paths - # it can be run only from the output directory, but is not affected # by moving that directory to different location. # There are blobN-coot.py scripts generated below with absolute paths. # write coot script (apart from pictures) that centers on the biggest blob script_path = os.path.join(wf.output_dir, "run-coot.py") script = coots.basic_script(pdb=opt.xyzout, mtz=opt.hklout, center=(blobs and blobs[0]), toward=com, white_bg=opt.white_bg) _write_script(script_path, script, executable=True) # blob images, for now for not more than two blobs d = os.path.abspath(wf.output_dir) for n, b in enumerate(blobs[:2]): py_path = os.path.join(wf.output_dir, "blob%d-coot.py" % (n+1)) content = coots.basic_script(pdb=os.path.join(d, opt.xyzout), mtz=os.path.join(d, opt.hklout), center=blobs[n], toward=com, white_bg=opt.white_bg) _write_script(py_path, content) # coot.sh - one-line script for convenience if blobs: coot_sh_text = '{coot} --no-guano {out}/blob1-coot.py\n' else: coot_sh_text = '{coot} --no-guano {out}/final.mtz {out}/final.pdb\n' coot_sh_path = os.path.join(wf.output_dir, "coot.sh") _write_script(coot_sh_path, coot_sh_text.format(coot=coot_path or 'coot', out=wf.output_dir), executable=True) if opt.img_format and blobs: script = '' basenames = [] # as a workaround for buggy coot the maps are reloaded for each blob for n, b in enumerate(blobs[:2]): script += coots.basic_script(pdb=opt.xyzout, mtz=opt.hklout, center=b, toward=com, white_bg=opt.white_bg) rs, names = coots.r3d_script(center=b, toward=com, blobname="blob%s" % (n+1)) script += rs basenames += names coot_job = wf.coot_py(script) try: coot_job.run() except workflow.JobError: # check for a possible cause to hint the user # (possible workaround: change $HOME to non-existing directory) if utils.silently_run(coot_job.args, cwd=wf.output_dir)[0] != 0: put_error("coot fails with options: --no-graphics --python", comment="It happens when scripts in .coot or " ".coot-preferences are not compatible\n" "with the --no-graphics mode.") raise for n, basename in enumerate(basenames): job = wf.render_r3d(basename, img_format=opt.img_format) if n % 3 == 0: job.run() else: # minimal output job.run(show_progress=False, new_line=False) wf.delete_files([name+".r3d" for name in basenames]) return coot_sh_path