Commits

dalke  committed bff0833

atom indices tag is no longer required for complete-sdf output, but
users must specify at least one tag containing MCS data as otherwise
this output format is useless.

Correctly handle output options when there is no MCS

  • Participants
  • Parent commits 11c59b8

Comments (0)

Files changed (1)

 parser.add_argument("--save-counts-tag", metavar="TAG", help=
                     "Save the fragment count, atom count, and bond count to the specified SD tag as "
                     "space separated integers, like '1 9 8'. (The fragment count will not be larger than "
-                    "1 until fmcs supportes disconnected MCSes.)")
-
-parser.add_argument("--save-atom-indices-tag", metavar="TAG", default="mcs-atom-indices", help=
+                    "1 until fmcs supports disconnected MCSes.)")
+
+parser.add_argument("--save-atom-indices-tag", metavar="TAG", help=
                     "If atom classes are specified and the output format is 'complete-sdf' "
                     "then save the MCS fragment atom indices to the tag TAG, in MCS order. "
                     "(Default: mcs-atom-indices)")
                 args.save_atom_class_tag = atom_class_tag
 
     if args.output_format == "complete-sdf":
-        if args.save_atom_indices_tag is None:
-            args.save_atom_indices_tag = "mcs-atom-indices"
-                
+        if (args.save_atom_indices_tag is None and
+            args.save_counts_tag is None and
+            args.save_smiles_tag is None and
+            args.save_smarts_tag is None):
+            parser.error("Using --output-format complete-sdf is useless without at least one "
+                         "of --save-atom-indices-tag, --save-smarts-tag, --save-smiles-tag, "
+                         "or --save-counts-tag")
 
     t1 = time.time()
     structures = []
                 status = "(complete search)"
             else:
                 status = "(timed out)"
-            outfile.write("%s %d atom %d bonds %s\n" % (
+            outfile.write("%s %d atoms %d bonds %s\n" % (
                 mcs.smarts, mcs.num_atoms, mcs.num_bonds, status))
 
     else:
-        # Need to make a structure output
-        pat = Chem.MolFromSmarts(mcs.smarts)
+        if mcs.smarts is None:
+            # There is no MCS. Use something which can't match.
+            pat = Chem.MolFromSmarts("[CN]")
+        else:
+            # Need to make a structure output
+            pat = Chem.MolFromSmarts(mcs.smarts)
         for structure in structures:
             atom_indices = structure.GetSubstructMatch(pat)
             bond_indices = _get_match_bond_indices(pat, structure, atom_indices)