In general, RDKit returns None for these cases and can't be handled with try/except. Instead, just check if mol is None, see a similar example here:
https://github.com/rdkit/rdkit/issues/642 Best, Kangway On Mon, Feb 13, 2023 at 7:45 AM RĂ¼diger Lang <r.l...@abcr.com> wrote: > Hello, > > I am trying to edit a large amount of mol files. It happens that the mol > files are not readable. These broken files should simply be skipped and the > program should continue to run. > > With a try / except this does not seem to be solvable in the rdkit: > > > > from rdkit import Chem > > filename = 'C:\\Strukturen\\ProblemMOLs\\99.mol' > > > > try: > > mol = Chem.MolFromMolFile(filename) > > except: > > mol = 'Problem File' > > > > print(mol) > > > > A nonsense MOL file shows a (correct) error message on the console and the > program is interrupted. Here for example:" [16:06:52]None Cannot convert > 'jus' to unsigned int on line 4". > > I don't want an error message on the console but that the program runs > into the except block. I am grateful for any tip. > > > > Thanks, Ruediger Lang > > > > 99.mol: > > This is not a mol-file > > this is not a mol-file > > I am not a mol-file > > just something > > with numbers > > 8879 96874 65-sdf > > > > > _______________________________________________ > Rdkit-discuss mailing list > Rdkit-discuss@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/rdkit-discuss >
_______________________________________________ Rdkit-discuss mailing list Rdkit-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rdkit-discuss