def enable_chimera_inline():
"""
Enable IPython magic commands to run some Chimera actions
Currently supported:
- %chimera_export_3D [<model>]:
Depicts the Chimera 3D canvas in a WebGL iframe. Requires
a headless Chimera build and a Notebook instance. SLOW.
- %chimera_run <command>:
Runs Chimera commands meant to be input in the GUI command line
"""
from IPython.display import IFrame
from IPython.core.magic import register_line_magic
import chimera
import Midas
@register_line_magic
def chimera_export_3D(line):
if chimera.viewer.__class__.__name__ == 'NoGuiViewer':
print('This magic requires a headless Chimera build. '
'Check http://www.cgl.ucsf.edu/chimera/download.html#unsupported.',
file=sys.stderr)
return
models = eval(line) if line else []
def html(*models):
if models:
for m in chimera.openModels.list():
m.display = False
chimera.selection.clearCurrent()
for model in models:
model.display = True
chimera.selection.addCurrent(model)
chimera.runCommand('focus sel')
chimera.viewer.windowSize = 800, 600
path = 'chimera_scene_export.html'
Midas.export(filename=path, format='WebGL')
return IFrame(path, *[x + 20 for x in chimera.viewer.windowSize])
return html(*models)
del chimera_export_3D
@register_line_magic
def chimera_run(line):
if not line:
print("Usage: %chimera_run <chimera command>", file=sys.stderr)
return
chimera.runCommand(line)
del chimera_run
评论列表
文章目录