rdmc.external.xyz2mol

Module for generating rdkit molobj/smiles/molecular graph from free atoms

Implementation by Jan H. Jensen based on the following paper and compiled by Xiaorui Dong to make it work with RDKitMol

Yeonjoon Kim and Woo Youn Kim “Universal Structure Conversion Method for Organic Molecules: From Atomic Connectivity to Three-Dimensional Geometry” Bull. Korean Chem. Soc. 2015, Vol. 36, 1769-1777 DOI: 10.1002/bkcs.10334

Last update: 2023/03/02 at commit: f512673

MIT License

Copyright (c) 2018 Jensen Group

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

rdmc.external.xyz2mol.AC2BO(AC, atoms, charge, allow_charged_fragments=True, use_graph=True)

implemenation of algorithm shown in Figure 2

UA: unsaturated atoms

DU: degree of unsaturation (u matrix in Figure)

best_BO: Bcurr in Figure

rdmc.external.xyz2mol.AC2mol(mol, AC, atoms, charge, allow_charged_fragments=True, use_graph=True, use_atom_maps=False)
rdmc.external.xyz2mol.BO2mol(mol, BO_matrix, atoms, atomic_valence_electrons, mol_charge, allow_charged_fragments=True, use_atom_maps=False)

based on code written by Paolo Toscani

From bond order, atoms, valence structure and total charge, generate an rdkit molecule.

Parameters:
  • molecule (mol_charge - total charge of) –

  • molecule

  • symbols (atoms - list of integer atomic) –

  • - (atomic_valence_electrons) –

  • molecule

optional:

allow_charged_fragments - bool - allow charged fragments

returns

mol - updated rdkit molecule with bond connectivity

rdmc.external.xyz2mol.BO_is_OK(BO, AC, charge, DU, atomic_valence_electrons, atoms, valences, allow_charged_fragments=True)

Sanity of bond-orders

Parameters:
  • - (DU) –

  • -

  • -

  • -

optional

allow_charges_fragments -

Returns:

boolean - true of molecule is OK, false if not

rdmc.external.xyz2mol.charge_is_OK(BO, AC, charge, DU, atomic_valence_electrons, atoms, valences, allow_charged_fragments=True)
rdmc.external.xyz2mol.chiral_stereo_check(mol)

Find and embed chiral information into the model based on the coordinates

Parameters:
  • molecule (mol - rdkit) –

  • conformer (with embeded) –

rdmc.external.xyz2mol.clean_charges(mol)

This hack should not be needed anymore, but is kept just in case

rdmc.external.xyz2mol.get_AC(mol, covalent_factor=1.3)

Generate adjacent matrix from atoms and coordinates.

AC is a (num_atoms, num_atoms) matrix with 1 being covalent bond and 0 is not

covalent_factor - 1.3 is an arbitrary factor

Parameters:

conformer (mol - rdkit molobj with 3D) –

optional

covalent_factor - increase covalent bond length threshold with facto

Returns:

AC - adjacent matrix

rdmc.external.xyz2mol.get_BO(AC, UA, DU, valences, UA_pairs, use_graph=True)
rdmc.external.xyz2mol.get_UA(maxValence_list, valence_list)
rdmc.external.xyz2mol.get_UA_pairs(UA, AC, use_graph=True)
rdmc.external.xyz2mol.get_atomic_charge(atom, atomic_valence_electrons, BO_valence)
rdmc.external.xyz2mol.get_bonds(UA, AC)
rdmc.external.xyz2mol.get_proto_mol(atoms)
rdmc.external.xyz2mol.int_atom(atom)

convert str atom to integer atom

rdmc.external.xyz2mol.main()
rdmc.external.xyz2mol.parse_xyz_by_jensen(xyz: str, charge: int = 0, allow_charged_fragments: bool = False, use_graph: bool = True, use_huckel: bool = False, embed_chiral: bool = True, use_atom_maps: bool = False, correct_CO: bool = True, **kwargs) Mol

Perceive a xyz str using xyz2mol by Jensen et al. and generate the corresponding RDKit Mol.

Parameters:
  • charge – The charge of the species. Defaults to 0.

  • allow_charged_fragmentsTrue for charged fragment, False for radical. Defaults to False.

  • use_graphTrue to use networkx module for accelerate. Defaults to True.

  • use_huckelTrue to use extended Huckel bond orders to locate bonds. Defaults to False.

  • embed_chiralTrue to embed chiral information. Defaults to True.

  • use_atom_mapsTrue to set atom map numbers for the molecule. Defaults to False.

  • correctCO (bool, optional) – Defaults to True. In order to get correct RDKit molecule for carbon monoxide ([C-]#[O+]), allow_charged_fragments should be forced to True. This function contains a patch to correct that.

Returns:

A RDKit Mol corresponding to the xyz.

Return type:

Mol

rdmc.external.xyz2mol.read_xyz_file(filename, look_for_charge=True)
rdmc.external.xyz2mol.set_atomic_charges(mol, atoms, atomic_valence_electrons, BO_valences, BO_matrix, mol_charge, use_atom_maps)
rdmc.external.xyz2mol.set_atomic_radicals(mol, atoms, atomic_valence_electrons, BO_valences)

The number of radical electrons = absolute atomic charge

rdmc.external.xyz2mol.str_atom(atom)

convert integer atom to string atom

rdmc.external.xyz2mol.valences_not_too_large(BO, valences)
rdmc.external.xyz2mol.xyz2AC(atoms, xyz, charge, use_huckel=False)

atoms and coordinates to atom connectivity (AC)

Parameters:
  • types (atoms - int atom) –

  • coordinates (xyz -) –

  • charge (charge - molecule) –

optional:

use_huckel - Use Huckel method for atom connecitivty

returns

ac - atom connectivity matrix mol - rdkit molecule

rdmc.external.xyz2mol.xyz2AC_huckel(atomicNumList, xyz, charge)
args

atomicNumList - atom type list xyz - coordinates charge - molecule charge

returns

ac - atom connectivity mol - rdkit molecule

rdmc.external.xyz2mol.xyz2AC_vdW(atoms, xyz)
rdmc.external.xyz2mol.xyz2mol(atoms, coordinates, charge=0, allow_charged_fragments=True, use_graph=True, use_huckel=False, embed_chiral=True, use_atom_maps=False)

Generate a rdkit molobj from atoms, coordinates and a total_charge.

Parameters:
  • types (atoms - list of atom) –

  • coordinates (coordinates - 3xN Cartesian) –

  • (default (charge - total charge of the system) –

optional:

allow_charged_fragments - alternatively radicals are made use_graph - use graph (networkx) use_huckel - Use Huckel method for atom connectivity prediction embed_chiral - embed chiral information to the molecule

Returns:

mols - list of rdkit molobjects