Tool Wrappers (modelarchive.tools)
The modelarchive.tools submodule provides wrappers around external
tools used in ModelArchive workflows, along with convenience functions for
common use cases. Detailed documentation is available for each individual
tool wrapper.
MAXIT (modelarchive.tools.maxit)
MAXIT from RCSB converts coordinate files in PDB legacy format to CIF and CIF files to mmCIF. This module also adds functionality to turn a PDB file into a (minimalist) ModelCIF file. But don’t get too excited - none of the functionality will turn a PDB file into a fully annotated ModelCIF file. It just makes sure the starting point is of valid CIF syntax. Extra data still need to be added…
MAXIT is not bundled with this module. The source code can be downloaded here. Installation instructions are available, and here is a TL;DR how to compile on macOS and most Linux distributions:
# cd into the unpacked source directory first
export RCSBROOT=$(pwd)
make
make binary
# binaries are found in bin/
# RCSBROOT needs to point at data/ when running maxit
This module adds a new tool to the command line, ma-maxit. It simply wraps
around RCSB maxit but extends modes to “CIF/ PDB to ModelCIF”.
- modelarchive.tools.maxit.MAXIT_BINARY = 'maxit'
Path to the maxit binary, defaults to
maxitfrom$PATH.Can be overridden by setting the
MAXIT_BINARYenvironment variable before import.
- modelarchive.tools.maxit.cif2mmcif(infile, outfile)[source]
Convert a CIF file to mmCIF using MAXIT.
Only returns log messages upon failure.
- Parameters:
- Returns:
MAXIT log messages on failure, empty list on success.
- Return type:
- Raises:
RuntimeError – If
RCSBROOTenvironment variable is not set.
- modelarchive.tools.maxit.cif2modelcif(infile, outfile)[source]
Convert a CIF file into a minimalist ModelCIF file.
Sanitizes the input and adds mandatory ModelCIF categories. The input file is expected to be in mmCIF format as produced by MAXIT.
- Parameters:
- Returns:
Path to the output file.
- Return type:
- Raises:
RuntimeError – If reading or writing the CIF file fails.
- modelarchive.tools.maxit.coordfile2modelcif(infile, outfile)[source]
Convert a macromolecular structure file to a minimalist ModelCIF file.
Dispatches to
pdb2modelcif()orcif2modelcif()based on the file extension. Supports.gzcompressed files.- Parameters:
- Returns:
Error log on failure, empty list on success.
- Return type:
- Raises:
RuntimeError – If
RCSBROOTenvironment variable is not set.ValueError – If the file extension is not supported.
- modelarchive.tools.maxit.fixing_pdb2mmcif(pdb_as_string, outfile)[source]
Convert a PDB legacy format string to mmCIF, fixing known issues.
Adds missing chain names if necessary before conversion. Only returns log messages upon failure.
- Parameters:
- Returns:
MAXIT log messages on failure, empty list on success.
- Return type:
- Raises:
RuntimeError – If
RCSBROOTenvironment variable is not set.
- modelarchive.tools.maxit.pdb2cif(infile, outfile)[source]
Convert a PDB legacy format file to CIF using MAXIT.
Only returns log messages upon failure.
- Parameters:
- Returns:
MAXIT log messages on failure, empty list on success.
- Return type:
- Raises:
RuntimeError – If
RCSBROOTenvironment variable is not set.
- modelarchive.tools.maxit.pdb2mmcif(infile, outfile)[source]
Convert a PDB legacy format file to mmCIF using MAXIT.
Runs MAXIT first in PDB to CIF mode, then converts the result to mmCIF. Only returns log messages upon failure.
- Parameters:
- Returns:
- MAXIT log messages on failure, empty list on success.
On failure, the first element indicates which conversion step failed.
- Return type:
- Raises:
RuntimeError – If
RCSBROOTenvironment variable is not set.
- modelarchive.tools.maxit.pdb2modelcif(infile, outfile)[source]
Convert a PDB legacy format file into a minimalist ModelCIF file.
Fixes known issues before conversion. Only returns log messages upon failure.
- Parameters:
- Returns:
Error log on failure, empty list on success.
- Return type:
- Raises:
RuntimeError – If
RCSBROOTenvironment variable is not set.
- modelarchive.tools.maxit.run_maxit(infile, outfile, mode, logfile=None)[source]
Run MAXIT without checks, mode-preselection, or cleanup.
- Parameters:
- Returns:
Result of the MAXIT run.
- Return type:
MolScript (modelarchive.tools.molscript)
Convenience wrapper for MolScript and Raster3D image generation.
MolScript is a tool to create images for molecular structures with the help of Raster3D. While the system creates nice “out-of-the-box” images, the workflow is a bit more involved. So this module exists as a convenience wrapper, producing (opinionated) images from single function or command line calls.
MolScript and Raster3d are not bundled with this module. The source code can be downloaded here and here. Installation instructions are available on the project web pages and/ or in the source code distributions.
This module can also be used on the command line as ma-make-image.
- modelarchive.tools.molscript.MOLAUTO_BINARY = 'molauto'
Path to the molauto binary, defaults to
molautofrom$PATH.Can be overridden by setting the
MOLAUTO_BINARYenvironment variable before import.
- modelarchive.tools.molscript.MOLSCRIPT_BINARY = 'molscript'
Path to the molscript binary, defaults to
molscriptfrom$PATH.Can be overridden by setting the
MOLSCRIPT_BINARYenvironment variable before import.
- modelarchive.tools.molscript.RENDER_BINARY = 'render'
Path to the render (Raster3D) binary, defaults to
renderfrom$PATH.Can be overridden by setting the
RENDER_BINARYenvironment variable before import.
- modelarchive.tools.molscript.coordfile2image(input_file, png_path, colour_scheme=None, img_size=400)[source]
Create a 2D image for a CIF/ PDB file (gzip allowed).
- Parameters:
input_file (Path | str) – Path to the input PDB or mmCIF file. Gzip-compressed files are supported (extensions
.pdb.gz,.pdb.gzip,.cif.gz,.cif.gzip,.mmcif.gz,.mmcif.gzip).colour_scheme (str, optional) – Colour scheme to apply. Currently supported:
"chain". Defaults to None.img_size (int, optional) – Size of the quadratic image in pixels. Defaults to 400.
- Returns:
None
- Raises:
RuntimeError – If image creation fails (PNG missing or too small after rendering) and if the MolScript script is corrupted.
ValueError – If the file extension of
input_fileis not supported.
- modelarchive.tools.molscript.run_molauto(input_pdb, options=None)[source]
Execute molauto without checks or cleanup.
- Parameters:
- Returns:
Result of the MAXIT run.
- Return type:
- Raises:
subprocess.CalledProcessError – If molauto exits with a non-zero return code.
- modelarchive.tools.molscript.run_molscript(script, options=None)[source]
Execute molscript without checks or cleanup.
- Parameters:
- Returns:
Result of the molscript run.
- Return type:
- Raises:
subprocess.CalledProcessError – If molscript exits with a non-zero return code.
- modelarchive.tools.molscript.run_render(script_stdout, png_path, options=None)[source]
Execute render without checks or cleanup.
- Parameters:
- Returns:
Result of the render run.
- Return type:
- Raises:
subprocess.CalledProcessError – If render exits with a non-zero return code.