RDkit: While converting a *.sdf file to fingerprint, I'm facing several errors

suppl = Chem.SDMolSupplier('1.sdf')
for mol in suppl:
if mol is None: continue
# print(mol.GetNumAtoms())

fps = [Chem.RDKFingerprint(x) for x in supply]


I am facing many errors:

ERROR: Problems encountered parsing Mol data, M  END missing around line 16739
...
ERROR: Explicit valence for atom # 0 O, 3, is greater than permitted
...
ERROR: Could not sanitize molecule ending on line 78558
...
ERROR: Post-condition Violation
RDKit ERROR: Violation occurred on line 91 in file /home/conda/feedstock_root/build_artifacts/rdkit_1593788763912/work/Code/GraphMol/PeriodicTable.h
RDKit ERROR: Failed Expression: anum > -1

...
WARNING: not removing hydrogen atom without neighbors

RDKit WARNING: atom 0 has specified valence (4) smaller than the drawn valence 6.


How can I correct these?

• +1. I think it's our first question so far on rdkit, so I'm not sure how many people here use it. Perhaps help advertise this question on Twitter so that we get more experts that can possibly answer your question. You can tag @StackMatter and we will re-tweet it for you. – Nike Dattani Aug 5 '20 at 23:20
• Done Thank you. – Protima Rani Paul Aug 5 '20 at 23:29

Without seeing the SDF itself it's hard to be specific, but here's what the error messages are telling you, in general:

• the first one normally indicates a badly formed record in the SDF. If you look at around that line in the file you will, hopefully, see a misformed record.
• The next one, "Explicit valence" indicates that the molecule has an atom (in this case an "O") that has the equivalent of three bonds to it. That's not chemically reasonable, so the software complains
• The error about "Alkyl" is self explanatory: there's a molecule in the SDF which has an atom with symbol "Alkyl".

The rest are warnings.

An aside: the best way to get RDKit help is by subscribing to the rdkit-discuss mailing list and posting there. I can't monitor every possible stackexchange and this is a forum which is difficult for occasional users.

• +1. Thanks for coming here and answering this question for our user! A lot of people got tired of subscribing to dozens of mailing lists (basically one for each software), so this StackExchange is where people can ask questions about any computational chemistry or computational physics software in one place. If another user asks here rather than at the mailing list, I'll try to remember to let you know. Also you can subscribe to get emails whenever someone uses the rdkit tag: mattermodeling.meta.stackexchange.com/a/60/5 – Nike Dattani Aug 6 '20 at 3:36
• I appreciate what you're trying to do, and can imagine that it's going to be useful to some people, but I (and the other members of the RDKit community) have limited time and are unable to monitor every possible place people might ask questions. – Greg Landrum Aug 6 '20 at 8:50
• @GregLandrum Thank you for helping us. – Protima Rani Paul Aug 6 '20 at 12:13

As noted by Dr. Landrum, the errors that you are seeing are due to problems in the generation of the original SDF (i.e., improper molecule ending, the atom connectivity, and the use of "Alkyl" as an atom). Generally, RDKit just lets you know that it cannot generate the molecule because of an error in the SDF, and then, instead of producing an RDKit mol object, it produces an instance of None, which is why the example code in the RDKit docs have the if mol is None: continue line of code that you included in your example. If you are happy to skip these molecules when you are generating the RDKit fingerprints, you may do so by first removing any molecules that could not be generated and then calculating the fingerprints, as follows:

# import relevant rdkit objects
from rdkit.Chem import RDKFingerprint, SDMolSupplier

# create instance of sdf reader
suppl = SDMolSupplier('1.sdf')

# read all molecules besides ones with errors into a list
mols = [mol for mol in suppl if mol is not None]

# calculate fingerprints
fps = [RDKFingerprint(mol) for mol in mols]


Note that to actually remove the molecules that are throwing errors, you should not read them directly from SDMolSupplier. As the code is written in your example, it simply will cycle through all of the molecules, see if they are None (i.e., threw an error while being generated), and then move on - it doesn't actually remove the molecules that are None, as the sample code I suggested does. Otherwise, you will run into issues when generating the fingerprints, since RDKFingerprint needs an RDKit mol object to calculate from and will, therefore, throw an error if you try RDKFingerprint(None) (which is what will happen if you forget to remove the None objects between reading the SDF and calculating the fingerprints.

If you cannot skip the problematic molecules in the SDF, you should return to the original file and try to repair the errors inside before calculating fingerprints using RDKit. Here is a useful resource that really breaks down what each mol in an SDF contains: https://chem.libretexts.org/Courses/University_of_Arkansas_Little_Rock/ChemInformatics_(2017)%3A_Chem_4399%2F%2F5399/2.2%3A_Chemical_Representations_on_Computer%3A_Part_II/2.2.2%3A_Anatomy_of_a_MOL_file. It has been helpful to me in combing through to correct similar errors.

Hope this helps!

• Thank you so much, sir, for your valuable suggestion. – Protima Rani Paul Aug 6 '20 at 19:12