1,4-Benzoquinone and the DeduceBondSystemsTool

Once upon a time, there was a DeduceBondSystemsTool, and...

Er, anyway. Further to a patch made on the tool (patch ID : 3040138), there is a failing test for 1,4-benzoquinone:

The tool generates A, and the test wants B. Now, the problem is not that the tool is not trying B as a possibility, but that it generates A first and the final step doesn't remove it or rank it as better than A.

Understanding this requires an understanding of the algorithm. This is (roughly):
  1. For each ring, generate a list of possible positions for all numbers of double bonds.
  2. Generate a set of molecules by combining these positions together.
  3. Remove 'bad' solutions and pick a solution with the least number of 'bad' N/S atoms.
where the definition of 'bad' is based on chemical rules like atom types.

Now, neither A nor B are bad solutions, and they don't contain N or S atoms, so they both have a rank of zero, and the first one generated will be returned. So, there is really no particular reason that the test should pass.

In general, it might be good to separate the generation of possible solutions from the ranking/filtering process. So that the computational or mathematical problem of generation is done by one class, while other classes determine which is the optimal solution (or set of solutions).


If we would know that the O was sp2, then the first solution could be marked as bad. Not sure if that information is available at the DeduceBondSystemTool level...
gilleain said…
It checks for sp2 atoms, but only in the ring...

This is where a separation between generation and chemical rules would make things clearer. Of course, it would be better to constrain and generate, rather than generate and test.

Another architectural issue is that a bond system generation tool might benefit from detecting symmetric atoms. This would mean new module dependencies (eg, on the signature module).