rdtools.obabel#

A module contains functions to convert between OpenBabel and RDKit molecules.

rdtools.obabel.get_obmol_coords(obmol: OBMol) ndarray[tuple[int, ...], dtype[float64]]#

Get the atom coordinates from an openbabel molecule.

Parameters:

obmol (ob.OBMol) – The openbabel OBMol to get coordinates from.

Returns:

npt.NDArray[np.float64] – The coordinates.

rdtools.obabel.openbabel_mol_to_rdkit_mol(obmol: OBMol, remove_hs: bool = False, sanitize: bool = True, embed: bool = True) RWMol#

Convert a OpenBabel molecular structure to a Chem.rdchem.RWMol object.

Parameters:
  • obmol (ob.OBMol) – An OpenBabel Molecule object for the conversion.

  • remove_hs (bool, optional) – Whether to remove hydrogen atoms from the molecule, Defaults to False.

  • sanitize (bool, optional) – Whether to sanitize the RDKit molecule. Defaults to True.

  • embed (bool, optional) – Whether to embeb 3D conformer from OBMol. Defaults to True.

Returns:

Chem.RWMol – A writable RDKit RWMol instance.

rdtools.obabel.parse_xyz_by_openbabel(xyz: str) OBMol#

Perceive a xyz str using openbabel and generate the corresponding OBMol.

Parameters:

xyz (str) – A str in xyz format containing atom positions.

Returns:

ob.OBMol – An openbabel molecule from the xyz.

Raises:

ValueError – If the xyz cannot be parsed.

rdtools.obabel.rdkit_mol_to_openbabel_mol(rdmol: Mol, embed: bool = True) OBMol#

Convert a Mol to an Openbabel mol.

This a temporary replace of rdkit_mol_to_openbabel_mol_manual. When the molecule has multiple conformers, this function will only use the first conformer.

Parameters:
  • rdmol (Chem.Mol) – The RDKit Mol object to be converted.

  • embed (bool, optional) – Whether to embed conformer into the OBMol. Defaults to True.

Returns:

ob.OBMol – An openbabel OBMol instance.

rdtools.obabel.rdkit_mol_to_openbabel_mol_manual(rdmol: Mol, embed: bool = True) OBMol#

Convert a Mol/RWMol to a Openbabel mol.

This function has a problem converting aromatic molecules. Example: ‘c1nc[nH]n1’. Currently use a workaround, converting an RDKit Mol to sdf string and read by openbabel.

Parameters:
  • rdmol (Chem.Mol) – The RDKit Mol/RWMol object to be converted.

  • embed (bool, optional) – Whether to embed conformer into the OBMol. Defaults to True.

Returns:

ob.OBMol – An openbabel OBMol instance.

rdtools.obabel.set_obmol_coords(obmol: OBMol, coords: ndarray[tuple[int, ...], dtype[float64]]) None#

Set the atom coordinates of an openbabel molecule.

Parameters:
  • obmol (ob.OBMol) – The openbabel OBMol to get coordinates from.

  • coords (npt.NDArray[np.float64]) – The coordinates to set.