chemaxon.io

This package contains functions for importing and exporting molecules.

GitHub examples: https://github.com/ChemAxon/python-examples/blob/main/jupyter/01_basic_functions.ipynb

@typecheck(Molecule, str)
def export_mol(mol: chemaxon.Molecule, format_opts: str) -> str:

Molecule export

Creates a string representation of the molecule. The format descriptor string can also contain export options. Format and options are separated by a colon, multiple options can be separated by commas. The line separator is '\n'.

The currently supported formats are: smiles, cxsmiles, smarts, MOL V2000, MOL V3000, mrv, cxon, name.

You can find more information about file formats and options on the following link: https://docs.chemaxon.com/display/docs/formats_index.html

Parameters
  • mol: chemaxon.Molecule - Input molecule
  • format_opts: str - This option is to specify the format and options for the export
Returns

str - The exported molecule

@typecheck(str, str)
def open_for_export(file_path: str, format_opts: str) -> chemaxon.io._exporter._MolExporter:

Factory function to create an instance of the molecule exporter with which molecules can be exported into files in the supported formats.

The currently supported formats are: smiles, cxsmiles, smarts, MOL V2000, MOL V3000, mrv, cxon, name.

For more information about file formats and format options, see: https://docs.chemaxon.com/display/docs/formats_index.html.

Parameters
  • file_path: str - The file path, where to export molecule data
  • format_opts: str - This option is to specify the format and options for the export
Returns

An exporter instance. Supported methods: write(Molecule), flush(), close()

@typecheck(str, str)
def import_mol(mol_str: str, format_opts: str = '') -> chemaxon.Molecule:

Molecule import

Reads a molecule from a string. If the string contains multiple molecules (e.g. in the case of an SDF or MRV file), reads only the first one. Processing is single-threaded.

The currently supported formats are: smiles, cxsmiles, smarts, MOL V2000, MOL V3000, mrv, cxon, name.

More info about file formats and options: https://docs.chemaxon.com/display/docs/formats_index.html

Parameters
  • mol_str: str - Input molecule string
  • format_opts: str - This option is to specify the input format and options for the import. If empty string, autodetect will be used. Default is auto-detect.
Returns

chemaxon.Molecule - The imported molecule

@typecheck(str)
def open_for_import( file_path: str, format_opts: str = '') -> chemaxon.io._importer._MolImporter:

Factory function to create a molecule importer for importing molecules from a file.

The currently supported formats are: smiles, cxsmiles, smarts, MOL V2000, MOL V3000, mrv, cxon, name.

More info about file formats and options: https://docs.chemaxon.com/display/docs/formats_index.html

Parameters
  • file_path: the path of the file to be imported.
  • format_opts: This option is to specify the format and options for the import. If empty string, autodetect will be used. Default is auto-detect.
Returns

An instance of the molecule importer. Supported methods: read(), close()

@typecheck(Molecule, list, (str, None), int, str)
def visualize_atom_values( mol: chemaxon.Molecule, values: list, value_attribute: str | None = None, precision: int = 2, format_opts: str = 'headless,nosource,w300') -> str:

Render the molecule as an SVG image with one label per atom.

Draws mol and, for every item in values, places its value next to the corresponding atom. values must be a list of atom-index-keyed NamedTuple results, e.g. chemaxon.calculations.AtomIntValue/AtomDoubleValue, or any other per-atom result NamedTuple such as chemaxon.calculations.ChargeValue/chemaxon.calculations.RefractivityValue.

If the item type has exactly one field besides atom_index, its value is shown automatically. If it has more than one (e.g. ChargeValue.formal_charge/total_charge), value_attribute must name which one to display.

Note: rendering uses an internal copy of the molecule with all atom-level properties cleared first, so only the labels derived from values are shown - any other atom-level properties already on the molecule (e.g. from an SDF import) are not rendered.

Link: https://docs.chemaxon.com/latest/formats_svg.html

Parameters
  • mol: chemaxon.Molecule - Input molecule
  • values: list - Per-atom NamedTuple results with an atom_index field
  • value_attribute: str - Name of the attribute to display, required when the item type has more than one attribute besides atom_index. Optional otherwise.
  • precision: int - Number of decimal places the displayed value is rounded to
  • format_opts: str - Additional SVG export options, appended after the aprop option this function always applies.
Returns

str - SVG representation of the molecule with the given atom labels