NuriKit Python API Reference

Project NuriKit: the fundamental software platform for chem- and bio-informatics.

import nuri

Submodules

Top-level Functions

Readers

nuri.readfile(fmt: str, path: PathLike, sanitize: bool = True, skip_on_error: bool = False) MoleculeReader

Read a molecule from a file.

Parameters:
  • fmt – The format of the file.

  • path – The path to the file.

  • sanitize – Whether to sanitize the produced molecule. For formats that is known to produce molecules with insufficient bond information (e.g. PDB), this option will trigger guessing based on the 3D coordinates (nuri.algo.guess_everything()).

  • skip_on_error – Whether to skip a molecule if an error occurs, instead of raising an exception.

Raises:
  • OSError – If any file-related error occurs.

  • ValueError – If the format is unknown or sanitization fails, unless skip_on_error is set.

Return type:

Iterable[Molecule]

nuri.readstring(fmt: str, data: str, sanitize: bool = True, skip_on_error: bool = False) MoleculeReader

Read a molecule from string.

Parameters:
  • fmt – The format of the file.

  • data – The string to read.

  • sanitize – Whether to sanitize the produced molecule. For formats that is known to produce molecules with insufficient bond information (e.g. PDB), this option will trigger guessing based on the 3D coordinates (nuri.algo.guess_everything()).

  • skip_on_error – Whether to skip a molecule if an error occurs, instead of raising an exception.

Raises:

ValueError – If the format is unknown or sanitization fails, unless skip_on_error is set.

Return type:

Iterable[Molecule]

The returned object is an iterable of molecules.

>>> for mol in nuri.readstring("smi", "C"):
...     print(mol[0].atomic_number)
6

Writers

These functions all release the GIL and are thread-safe. Thread-based parallelism is recommended for writing multiple molecules in parallel.

nuri.to_smiles(mol: Molecule) str

Convert a molecule to SMILES string.

Parameters:

mol – The molecule to convert.

Raises:

ValueError – If the conversion fails.

nuri.to_mol2(mol: Molecule, conf: int | None = None, write_sub: bool = True) str

Convert a molecule to Mol2 string.

Parameters:
  • mol – The molecule to convert.

  • conf – The conformation to convert. If not specified, writes all conformations. Ignored if the molecule has no conformations.

  • write_sub – Whether to write the substructures.

Raises:
  • IndexError – If the molecule has any conformations and conf is out of range.

  • ValueError – If the conversion fails.

nuri.to_sdf(mol: Molecule, conf: int | None = None, version: int | None = None) str

Convert a molecule to SDF string.

Parameters:
  • mol – The molecule to convert.

  • conf – The conformation to convert. If not specified, writes all conformations. Ignored if the molecule has no conformations.

  • version – The SDF version to write. If not specified, the version is automatically determined. Only 2000 and 3000 are supported.

Raises:
  • IndexError – If the molecule has any conformations and conf is out of range.

  • ValueError – If the conversion fails, or if the version is invalid.

Top-level Attributes

nuri.periodic_table: PeriodicTable

The singleton instance of core.PeriodicTable class.