scripting: support reading and executing scripts

Both Python and Chimera2 command scripts are supported.

Python scripts are executed inside a sandbox module that has the Chimera2 session available in it. For example, to use the timeit module in a Python script:

import timeit
from chimera.core.comands import sym

m = Chimera2_session.models.list()[0]
t = timeit.timeit(
    "sym.pdb_assemblies(m)",
    "from %s import sym, m" % __name__,
    number=1000
)
print('total time:', t)
open_ch(session, filename, name, *args, **kw)

Execute utf-8 file as Chimera2 commands

This function is invoked via Chimera2’s io open_data() API for files whose names end with .c2cmd.

Parameters:

session : a Chimera2 Session

filename : path to file to open

name : how to identify the file

open_py(session, filename, name, *args, **kw)

Execute Python script in a Chimera2 context

This function is invoked via Chimera2’s io open_data() API for files whose names end with .py, .pyc, or .pyo. Each script is opened in an uniquely named importable sandbox (see timeit example above). And the current Chimera2 session is available as a global variable named Chimera2_session.

Parameters:

session : a Chimera2 Session

filename : path to file to open

name : how to identify the file