luna.wrappers.obabel module

convert_molecule(infile, output, infile_format=None, output_format=None, opts=None, openbabel='obabel')[source]

Convert a molecular file to another format using Open Babel.

Parameters
  • infile (str) – The pathname of the molecular file to be converted.

  • output (str) – Save the converted molecule to this file.

  • infile_format (str, optional) – The molecular format of infile. If not provided, the format will be defined by the file extension.

  • output_format (str, optional) – The molecular format of output. If not provided, the format will be defined by the file extension.

  • opts (dict) – A set of convertion options. Check Open Babel to discover which options are available.

  • openbabel (str, optional) – The Open Babel binary location. If not provided, the default binary (‘obabel’) will be used.

Raises

InvalidFileFormat – If the provided molecular formats are not accepted by Open Babel.

Examples

In this example, we will convert the molecule ZINC000007786517 from the format MOL to MOL2 and add hydrogens to it considering a pH of 7 (option “p”).

>>> from luna.util.default_values import LUNA_PATH
>>> from luna.wrappers.obabel import convert_molecule
>>> convert_molecule(infile=f"{LUNA_PATH}/tutorial/inputs/ZINC000007786517.mol",
...                  output="example.mol2",
...                  opts={"p": 7})
mol_to_svg(infile, output, opts=None)[source]

Depict a molecule as SVG using Open Babel.

Parameters
  • infile (str) – The pathname of a molecular file.

  • output (str) – Save the SVG to this file.

  • opts (dict) – A set of depiction options. Check Open Babel to discover which options are available.

Examples

In this example, we will depict the molecule ZINC000007786517 as SVG. The following options will be used:

  • C: do not draw terminal C (and attached H) explicitly;

  • d: do not display the molecule name;

  • P: image size in pixels.

>>> from luna.util.default_values import LUNA_PATH
>>> from luna.wrappers.obabel import mol_to_svg
>>> mol_to_svg(infile=f"{LUNA_PATH}/tutorial/inputs/ZINC000007786517.mol",
...            output="example.svg",
...            opts={"C": None, "d": None, "P": 500})