rdtools.conversion.xyz#
Convert XYZ to RDKit Mol and vice versa.
- rdtools.conversion.xyz.add_header_to_xyz(xyz: str, title: str = '') str#
Add header to xyz string.
- Parameters:
xyz (str) – The xyz string to be added header.
title (str, optional) – The title to be added. Defaults to
''.
- Returns:
str – The xyz string with header.
- rdtools.conversion.xyz.mol_from_xyz(xyz: str, backend: Literal['openbabel', 'xyz2mol'] = 'openbabel', header: bool = True, sanitize: bool = True, embed_chiral: bool = False, **kwargs: Any) RWMol#
Convert xyz string to RDKit Chem.RWMol.
- Parameters:
xyz (str) – A XYZ String.
backend (Literal["openbabel", "xyz2mol"], optional) – The backend used to perceive molecule. Defaults to
'openbabel'. Currently, we only support'openbabel'and'xyz2mol'.header (bool, optional) – If lines of the number of atoms and title are included. Defaults to
True.sanitize (bool, optional) – Sanitize the RDKit molecule during conversion. Helpful to set it to
Falsewhen reading in TSs. Defaults toTrue.embed_chiral (bool, optional) –
Trueto embed chiral information. Defaults toTrue.**kwargs (Any) –
Additional arguments to be passed to the function. They will be ignored. Supported arguments for the backend
xyz2mol:charge: The charge of the species. Defaults to
0.allow_charged_fragments:
Truefor charged fragment,Falsefor radical. Defaults toFalse.use_graph:
Trueto use networkx module for accelerate. Defaults toTrue.use_huckel:
Trueto use extended Huckel bond orders to locate bonds. Defaults toFalse.- original: In rare cases, we may hope to use the original
xyz2mol python implementation (with minor modifications), other than the one available in RDKit. Set this argument to
Trueto force use the original xyz2mol implementation in Python.
- Returns:
Chem.RWMol – An RDKit molecule object corresponding to the xyz.
- Raises:
NotImplementedError – If the backend is not supported.
- rdtools.conversion.xyz.mol_to_xyz(mol: Mol, conf_id: int = -1, header: bool = True, comment: str = '') str#
Convert Chem.Mol to a XYZ string.
- Parameters:
mol (Chem.Mol) – A Mol instance to be converted.
conf_id (int, optional) – The index of the conformer to be converted. Defaults to
-1, exporting the XYZ of the first conformer.header (bool, optional) – If lines of the number of atoms and title are included. Defaults to
True.comment (str, optional) – The comment to be added. Defaults to
''.
- Returns:
str – A XYZ string.
- rdtools.conversion.xyz.parse_xyz_by_openbabel(xyz: str, embed_chiral: bool = True, sanitize: bool = True) Mol#
Parse xyz into RDKit Mol utilizing openbabel.
- Parameters:
xyz (str) – The xyz string.
embed_chiral (bool, optional) –
Trueto embed chiral information. Defaults toTrue.sanitize (bool, optional) –
Trueto sanitize the molecule. Defaults toTrue.
- Returns:
Chem.Mol – The RDKit Mol instance.
- Raises:
ImportError – If openbabel is not installed.
- rdtools.conversion.xyz.parse_xyz_by_xyz2mol(xyz: str, charge: int = 0, allow_charged_fragments: bool = False, use_huckel: bool = False, embed_chiral: bool = True, use_atom_maps: bool = False, original: bool = False, sanitize: bool = True, **kwargs: Any) Mol#
Perceive a xyz str using xyz2mol into Mol.
The implementation refers the following blog: https://greglandrum.github.io/rdkit-blog/posts/2022-12-18-introducing-rdDetermineBonds.html
- Parameters:
xyz (str) – The xyz string.
charge (int, optional) – The charge of the species. Defaults to
0.allow_charged_fragments (bool, optional) –
Truefor charged fragment,Falsefor radical. Defaults to False.use_huckel (bool, optional) –
Trueto use extended Huckel bond orders to locate bonds. Defaults to False.embed_chiral (bool, optional) –
Trueto embed chiral information. Defaults to True.use_atom_maps (bool, optional) –
Trueto set atom map numbers to the molecule. Defaults toFalse.original (bool, optional) – Defaults to
False. In rare cases, we may hope to use the original xyz2mol python implementation (with minor modifications), other than the one available in RDKit. Set this argument toTrueto force use the original xyz2mol implementation in Python. The user may have some flexibility to modify this “original” version located at rdtools.conversion.xyz2mol.py.sanitize (bool, optional) – Whether to sanitize the perceived molecule, defaults to
True.**kwargs (Any) – Additional arguments to be passed to the function. They will be ignored.
- Returns:
Chem.Mol – A RDKit Mol corresponding to the xyz.
- rdtools.conversion.xyz.parse_xyz_by_xyz2mol_rdkit_native(xyz: str, charge: int = 0, allow_charged_fragments: bool = False, use_huckel: bool = False, embed_chiral: bool = True, use_atom_maps: bool = False) Mol#
Parse xyz with RDKit’s native implementation of xyz2mol.
- Parameters:
xyz (str) – The xyz string.
charge (int, optional) – The charge of the species. Defaults to
0.allow_charged_fragments (bool, optional) –
Truefor charged fragment,Falsefor radical. Defaults toFalse.use_huckel (bool, optional) –
Truefor Huckel method,Falsefor Gasteiger method. Defaults to False.embed_chiral (bool, optional) –
Truefor chiral molecule,Falsefor non-chiral molecule. Defaults toTrue.use_atom_maps (bool, optional) –
Truefor atom map,Falsefor non-atom map. Defaults toFalse.
- Returns:
Chem.Mol – The RDKit Mol instance.
- Raises:
ValueError – If the xyz string cannot be parsed.
- rdtools.conversion.xyz.xyz_to_coords(xyz: str, header: bool = False) ndarray[tuple[int, ...], dtype[float64]]#
Convert xyz string to coordinates in numpy.
- Parameters:
xyz (str) – A XYZ String.
header (bool, optional) – If lines of the number of atoms and title are included. Defaults to
False.
- Returns:
npt.NDArray[np.float64] – the coordinates of the atoms.