Hello all, I am trying to create a molecule from geometry (a numpy array n_atoms x 3), symbols (list of atom symbols) and a connectivity map (list of list where each list is [atom_1_idx, atom_2_idx, bond_type]). The information also has all hydrogens. The following code works most of the time:
from rdkit import Chem from rdkit.Geometry.rdGeometry import Point3D _BO_DISPATCH_TABLE = {1: Chem.BondType.SINGLE, 2: Chem.BondType.DOUBLE, 3: Chem.BondType.TRIPLE} conformer = Chem.Conformer(len(symbols)) molecule = Chem.Mol() em = Chem.RWMol(molecule) for i, s in enumerate(symbols): atom = em.AddAtom(Chem.Atom(cmiles.utils._symbols[s])) atom_position = Point3D(geometry[i][0], geometry[i][1], geometry[i][2]) conformer.SetAtomPosition(atom, atom_position) # Add connectivity for bond in connectivity: bond_type = _BO_DISPATCH_TABLE[bond[-1]] em.AddBond(bond[0], bond[1], bond_type) molecule = em.GetMol() Chem.SanitizeMol(molecule) However, if a molecule has a tetravalent nitrogen, the data that I have does not have the explicit formal charge for each atom so I get the following error: ValueError: Sanitization error: Explicit valence for atom # 0 N, 4, is greater than permitted Given that I have all the hydrogen and the total charge of the molecules, I can go in and add the charge to the problematic nitrogen and check that the total charge is still the same. But I am not sure how to capture the offending atom instance. I can get the information from parsing the error message (which is the hack I use now) but I was wondering if there is a better way to do it. Thank you, Chaya
_______________________________________________ Rdkit-discuss mailing list Rdkit-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rdkit-discuss