Isomer#

class maize.utilities.chem.chem.Isomer(rd_mol: Mol)[source]#

Bases: object

Thin shim layer for rdkit molecules. Here, an isomer refers to a unique chemical form of a molecule, i.e. a form separated by major energy barriers. Note that SMILES codes do not necessarily map to a single isomer! Some examples of unique isomers:

  • A ring conformer (e.g. for cyclohexane)

  • Cis-trans isomers

  • Chirality

  • Tautomers

  • Different protonation states

Parameters:

rd_mol – RDKit molecule instance

__init__(rd_mol: Mol) None[source]#

Methods

__init__(rd_mol)

add_conformer(conf)

Adds a conformer to the isomer.

addh()

Adds hydrogens to the molecule

atommap(mol)

Finds the atom index mappings based on the MCS.

clear_conformers()

Remove all conformers.

embed([n_conformers])

Generate a 3D embedding of the molecule.

from_rdmols(rd_mols[, sanitize])

Create a molecule from multiple RDKit molecules acting as conformers.

from_sdf(file[, read_conformers])

Create a molecule from an SDF file.

from_sdf_block(sdf)

Create a molecule from an SDF string.

from_smiles(smiles[, sanitize])

Create a molecule from a SMILES string.

generate_stereoisomers([n_max])

Generates possible enantiomers.

get_atomic_tag(idx, tag[, default])

Returns the value for the specified tag of an atom.

get_tag(tag[, default])

Returns the value for the specified tag.

has_atomic_tag(idx, tag)

Returns whether the specified atomic tag is set.

has_tag(tag)

Returns whether the specified tag is set.

remove_conformer(idx)

Remove a conformer.

set_atomic_tag(idx, tag, value)

Sets a tag / property for a single atom.

set_tag(tag, value)

Sets a tag / property for the whole isomer.

to_mol_block()

Generate a MOL block for the isomer.

to_pdb(path)

Writes a molecule to a PDB file.

to_sdf(path[, write_conformers])

Generate an SDF file for the isomer.

to_smiles()

Generate a SMILES code for the isomer

update_conformers_from_mol_block(block[, ...])

Update molecule conformers from a mol block.

update_conformers_from_sdf(sdf[, score_parser])

Update molecule conformers from an SDF file.

Attributes

charge

The charge of the molecule

conformers

Get all stored isomer conformers in an iterable structure

coordinates

Get coordinates of all stored conformers as one NDArray

inchi

Returns the InChI key for the molecule

n_atoms

Number of atoms in the molecule

n_conformers

Number of conformers in the molecule

name

Returns the molecule name

scored

Whether the molecule was scored

scores

The scores of the molecule

tags

Return all tags

classmethod from_rdmols(rd_mols: list[Mol], sanitize: bool = True) Self[source]#

Create a molecule from multiple RDKit molecules acting as conformers.

Parameters:
  • rd_mols – List of RDKit molecule instances

  • sanitize – Whether to sanitize the molecule

Returns:

Molecule instance

Return type:

Molecule

classmethod from_smiles(smiles: str, sanitize: bool = True) Self[source]#

Create a molecule from a SMILES string.

Parameters:
  • smiles – The SMILES string to initialize the molecule with

  • sanitize – Whether to sanitize the molecule

Returns:

Molecule instance

Return type:

Molecule

Raises:

ChemistryException – If there was an error parsing the SMILES code

classmethod from_sdf(file: Path, read_conformers: bool = False) Self[source]#

Create a molecule from an SDF file.

Parameters:
  • file – The SDF file to initialize the molecule with

  • read_conformers – Whether to read all conformers

Returns:

Molecule instance

Return type:

Molecule

Raises:

ChemistryException – If there was an error parsing the SDF

classmethod from_sdf_block(sdf: str) Self[source]#

Create a molecule from an SDF string.

Parameters:

sdf – The SDF string to initialize the molecule with

Returns:

Molecule instance

Return type:

Molecule

Raises:

ChemistryException – If there was an error parsing the SDF

property name: str | None#

Returns the molecule name

property inchi: str#

Returns the InChI key for the molecule

property n_atoms: int#

Number of atoms in the molecule

property n_conformers: int#

Number of conformers in the molecule

property charge: int#

The charge of the molecule

property scores: ndarray[Any, dtype[float32]]#

The scores of the molecule

property scored: bool#

Whether the molecule was scored

property conformers: list[Conformer]#

Get all stored isomer conformers in an iterable structure

property coordinates: ndarray[Any, dtype[float32]]#

Get coordinates of all stored conformers as one NDArray

property tags: dict[str, Any]#

Return all tags

to_sdf(path: Path, write_conformers: bool = False) None[source]#

Generate an SDF file for the isomer.

Parameters:
  • path – Output file path

  • write_conformers – Whether to write all conformers

to_smiles() str[source]#

Generate a SMILES code for the isomer

to_mol_block() str[source]#

Generate a MOL block for the isomer.

addh() None[source]#

Adds hydrogens to the molecule

set_tag(tag: str, value: bool | int | float | str | list[float | int] | ndarray[Any, dtype[float64 | int64]]) None[source]#

Sets a tag / property for the whole isomer.

Parameters:
  • tag – Tag to set

  • value – Corresponding value for all conformers

get_tag(tag: str, default: bool | int | float | str | list[float | int] | ndarray[Any, dtype[float64 | int64]] | None = None) bool | int | float | str | list[float | int] | ndarray[Any, dtype[float64 | int64]][source]#

Returns the value for the specified tag.

Parameters:
  • tag – The tag to lookup

  • default – A default value to return if the key is not found

Returns:

The value of the tag

Return type:

Any

Raises:

KeyError – If the specified tag couldn’t be found

has_tag(tag: str) bool[source]#

Returns whether the specified tag is set.

Parameters:

tag – The tag to lookup

Returns:

Whether the tag is defined

Return type:

bool

set_atomic_tag(idx: int, tag: str, value: bool | int | float | str | list[float | int] | ndarray[Any, dtype[float64 | int64]]) None[source]#

Sets a tag / property for a single atom.

Parameters:
  • idx – Index of the atom

  • tag – Tag to set

  • value – Corresponding value for the atom

get_atomic_tag(idx: int, tag: str, default: Any | None = None) Any[source]#

Returns the value for the specified tag of an atom.

Parameters:
  • idx – Index of the atom

  • tag – The tag to lookup

  • default – A default value to return if the key is not found

Returns:

The value of the tag

Return type:

Any

Raises:

KeyError – If the specified tag couldn’t be found

has_atomic_tag(idx: int, tag: str) bool[source]#

Returns whether the specified atomic tag is set.

Parameters:
  • idx – Index of the atom

  • tag – The tag to lookup

Returns:

Whether the tag is defined

Return type:

bool

add_conformer(conf: Conformer) None[source]#

Adds a conformer to the isomer.

Parameters:

conf – Conformer instance

remove_conformer(idx: int) None[source]#

Remove a conformer.

Parameters:

idx – Index of the conformer to be removed

clear_conformers() None[source]#

Remove all conformers.

update_conformers_from_mol_block(block: str, score_parser: Callable[[dict[str, str]], float] | None = None) None[source]#

Update molecule conformers from a mol block.

Parameters:
  • mol – The mol block

  • score_parser – Function used to parse a score from the mol properties

Raises:

ChemistryException – If there was an error parsing the mol block

update_conformers_from_sdf(sdf: Path, score_parser: Callable[[dict[str, str]], float] | None = None) None[source]#

Update molecule conformers from an SDF file.

Parameters:
  • sdf – The SDF file to initialize the molecule with

  • score_parser – Function used to parse a score from the SDF properties

Raises:

ChemistryException – If there was an error parsing the SDF

atommap(mol: Isomer) list[tuple[int, int]][source]#

Finds the atom index mappings based on the MCS.

Parameters:

mol – Reference Isomer

Returns:

Pairs of atom indices

Return type:

list[tuple[int, int]]

generate_stereoisomers(n_max: int = 32) list[Self][source]#

Generates possible enantiomers.

Parameters:

n_max – Maximum number of stereoisomers to generate

Returns:

List of new molecules representing distinct stereoisomers

Return type:

list[Molecule]

to_pdb(path: Path) None[source]#

Writes a molecule to a PDB file.

Parameters:

path – Path to the PDB file to write

embed(n_conformers: int = 1) None[source]#

Generate a 3D embedding of the molecule.

Parameters:

n_conformers – Number of conformers to generate

Raises:

ChemistryException – If there was an error generating the embeddings