I have the following function that takes a dictionary of SMILES strings and converts them to RDKit mol objects.
def smiles_dict_to_mol_list(smiles_dict):
"""smiles dict is a dictionary object containing molecule names
as keys and smiles strings as values.
The return value is a list of RDKit mol objects.
"""
smiles_as_mol = []
for mol_name, smiles_string in smiles_dict.items():
try:
mol = Chem.MolFromSmiles(smiles_string)
mol.SetProp("_Name", mol_name)
smiles_as_mol.append(mol)
except:
print("Error processing:", mol_name)
return smiles_as_mol
This function normally works very well and I can convert any SMILES into a mol object, but when I try to convert the below structure I get an exception. I believe that this is because this compound, and others that also give exceptions, have a coordinated metal ion. In this case platinum. It is also possible that the SMILES string I am using is the problem, but I don't know how I would tell the difference.
N2W: COc1cc(cc(c1O)OC)[C@@H]2c3cc4c(cc3[C@H]([C@@H]5[C@H]2C(=O)OC5)NC(=O)CC[C@@H]6C[NH2][Pt]([NH2]6)Cl)OCO4
So my question is: How can I change my RDKit code so I can work with compounds that have metal atoms?
The problem is the SMILES
not the Pt
.
To get a mol from a bad SMILES set the sanitize
flag to False
.
from rdkit import Chem
from rdkit.Chem.Draw import IPythonConsole
IPythonConsole.molSize = (600,300)
IPythonConsole.drawOptions.addAtomIndices = True
s = 'COc1cc(cc(c1O)OC)[C@@H]2c3cc4c(cc3[C@H]([C@@H]5[C@H]2C(=O)OC5)NC(=O)CC[C@@H]6C[NH2][Pt]([NH2]6)Cl)OCO4'
m = Chem.MolFromSmiles(s, sanitize=False)
m
But now you have a bad molecule.
There a 2 nitrogens with 4 bonds.
problems = Chem.DetectChemistryProblems(m)
for p in problems:
print(p.Message())
Explicit valence for atom # 32 N, 4, is greater than permitted
Explicit valence for atom # 34 N, 4, is greater than permitted
Addition:
In the RDKit Cookbook there a example how to work with dative bonds.
Tried it with your SMILES and it worked
https://www.rdkit.org/docs/Cookbook.html#organometallics-with-dative-bonds