Using mmcif-tools from Python¶
The tools also run from Python, in the same process, and give the same results as on the command line, byte for byte:
import mmciftools
# One tool, with the arguments of its command line: the output comes back as text
text = mmciftools.run('selchain', '-A', '4hhb.cif')
text = mmciftools.run('delentity', '-non-polymer,water', input=text)
# Several tools in a row, the last writing to a file
mmciftools.pipeline('selaltloc', 'delentity -non-polymer,water', 'reres -1',
path='4hhb.cif', output='clean.cif')
# Reports as dictionaries (the --json output of the tool)
info = mmciftools.report('info', '4hhb.cif')
print(info['blocks'][0]['resolution']) # 1.74
check = mmciftools.report('validate', 'clean.cif')
print(check['valid'], check['warnings'])
run(tool, *args, input=None, output=None, cwd=None)returns the output as text, or writes it tooutput. The tool reads the file named inargs, or elseinput: text, or bytes (gzip-compressed or not). Tools are named with or withoutmmcif_.pipeline(*steps, path=None, input=None, output=None)runs steps such as'selchain -A'(or['selchain', '-A']) one after the other, each reading the output of the one before.report(tool, *args, input=None)runsmmcif_info,mmcif_wc,mmcif_validate,mmcif_gap,mmcif_chkensembleormmcif_blockswith--jsonand returns the report as a dictionary.call(...)takes the arguments ofrun()and returns aResult(status,stdout,stderr) whatever the exit status;tools()lists the tools.- A failure raises
mmciftools.ToolError, with the tool'smessageand exitstatus. What a tool prints as a warning comes as ammciftools.ToolWarning(see Python'swarningsmodule). The split tools write their files incwd, the current directory by default. - The calls redirect the standard streams of the process, so they run one at a time (a lock keeps threads from overlapping). To run tools in parallel, run the commands in subprocesses.