Commits

Anonymous committed d349cd2

Better error reporting.
If there's no MCS then report the sizes at "0 0 0" instead of "-1 -1 -1"

Comments (0)

Files changed (1)

benchmark/mcsbench.py

 def rdkit_read_sdf_mols(infile, filename, id_tag):
     for molno, mol in enumerate(Chem.ForwardSDMolSupplier(infile)):
         recno = molno+1
+        if mol is None:
+            raise Error("Unable to parse structure #%r" % (recno,))
         if id_tag is None:
             id = mol.GetProp("_Name").strip()
         else:
     else:
         status = INCOMPLETE
     if mcs.smarts is None:
-        num_atoms = num_bonds = num_fragments = -1
+        num_atoms = num_bonds = num_fragments = 0
         description = "-"
     else:
         num_fragments = 1
             # End of file
             return None
 
-        # Remove terminal newline
-        line = line.rstrip("\n")
-        if line.startswith("#File "):
-            _, _, filename = line.partition(" ")
-            return FileStmt(filename.decode("utf8"))
-        elif line.startswith("#Id-tag "):
-            return IdTagStmt(line[8:].strip())
-        elif line.startswith("# "):
-            return CommentStmt(line[2:])
-        elif line == "#":
-            return CommentStmt("")
-        elif line.startswith("##"):
-            return ProgressStmt(line)
-        elif line.startswith("#"):
-            c = line[1]
-            if not c.isalpha():
-                raise Error("Unsupported statement %r" % (line,))
-            name, _, text = line.partition(" ")
-            name = name[1:]
-            if c == c.upper():
-                return RequiredStmt(name, text)
+        try:
+            # Remove terminal newline
+            line = line.rstrip("\n")
+            if line.startswith("#File "):
+                _, _, filename = line.partition(" ")
+                return FileStmt(filename.decode("utf8"))
+            elif line.startswith("#Id-tag "):
+                return IdTagStmt(line[8:].strip())
+            elif line.startswith("# "):
+                return CommentStmt(line[2:])
+            elif line == "#":
+                return CommentStmt("")
+            elif line.startswith("##"):
+                return ProgressStmt(line)
+            elif line.startswith("#"):
+                c = line[1]
+                if not c.isalpha():
+                    raise Error("Unsupported statement %r" % (line,))
+                name, _, text = line.partition(" ")
+                name = name[1:]
+                if c == c.upper():
+                    return RequiredStmt(name, text)
+                else:
+                    return OptionalStmt(name, text)
             else:
-                return OptionalStmt(name, text)
-        else:
-            # This must be a request for an MCS comparison
-            return parse_mcs_request(line)
-
+                # This must be a request for an MCS comparison
+                return parse_mcs_request(line)
+        except ValueError, err:
+            raise ValueError("%s at line %d" % (err, self.lineno))
+    
 def parse_mcs_request(line):
     # It's in the form:
     #   label id[0] id[1]> ....