k-ujihara / NCDK

The Chemistry Development Kit ported to .NET
https://kazuyaujihara.github.io/NCDK/
GNU Lesser General Public License v2.1
35 stars 11 forks source link

Stereo Information is lost during StructureDiagramGenerator.GenerateCoordinates() #21

Closed MikeWilliams-UK closed 4 years ago

MikeWilliams-UK commented 4 years ago

Reproduction Steps replace input.mol with the data shown at the end of this issue (which has Wedge and Hatch bonds)

Modify StructureDiagramGenerator_Example.cs as follows

class StructureDiagramGenerator_Example
{
    static void Main(string[] args)
    {
        IAtomContainer someMolecule = null;
        someMolecule = Chem.MolFromFile("./data/input.mol");

        StructureDiagramGenerator sdg = new StructureDiagramGenerator();
        sdg.Molecule = someMolecule;
        sdg.GenerateCoordinates();
        IAtomContainer layedOutMol = sdg.Molecule;

        using (var file = new FileStream("./data/output.mol", FileMode.Create, FileAccess.Write))
        {
            using (var writer = new MDLV2000Writer(file))
            {
                writer.Write(layedOutMol);
            }
        }
    }
}

The resultant molfile is laid out sensibly, but all the wedge and hatch bonds have become "normal" single bonds.

In the following screengrab from our Chem4Word test harness, the source molfile (before zapping coordinates) is shown in on the right with it rotated to match the output of the layout mechanism, which is shown in the left panel. The missing Wedge and Hatch bonds are circled in orange. image

Modified "input.mol"

  Chem4Wrd0513201144

 29 30  0     0  0              0 V2000
    0.0000   0.0000     0.0000 C   0  0  0  0  0  0  0  0  0  0
    0.0000   0.0000     0.0000 N   0  0  0  0  0  0  0  0  0  0
    0.0000   0.0000     0.0000 C   0  0  0  0  0  0  0  0  0  0
    0.0000   0.0000     0.0000 N   0  0  0  0  0  0  0  0  0  0
    0.0000   0.0000     0.0000 C   0  0  0  0  0  0  0  0  0  0
    0.0000   0.0000     0.0000 C   0  0  0  0  0  0  0  0  0  0
    0.0000   0.0000     0.0000 N   0  0  0  0  0  0  0  0  0  0
    0.0000   0.0000     0.0000 C   0  0  0  0  0  0  0  0  0  0
    0.0000   0.0000     0.0000 C   0  0  0  0  0  0  0  0  0  0
    0.0000   0.0000     0.0000 N   0  0  0  0  0  0  0  0  0  0
    0.0000   0.0000     0.0000 C   0  0  0  0  0  0  0  0  0  0
    0.0000   0.0000     0.0000 C   0  0  0  0  0  0  0  0  0  0
    0.0000   0.0000     0.0000 O   0  0  0  0  0  0  0  0  0  0
    0.0000   0.0000     0.0000 C   0  0  0  0  0  0  0  0  0  0
    0.0000   0.0000     0.0000 C   0  0  0  0  0  0  0  0  0  0
    0.0000   0.0000     0.0000 C   0  0  0  0  0  0  0  0  0  0
    0.0000   0.0000     0.0000 O   0  0  0  0  0  0  0  0  0  0
    0.0000   0.0000     0.0000 C   0  0  0  0  0  0  0  0  0  0
    0.0000   0.0000     0.0000 O   0  0  0  0  0  0  0  0  0  0
    0.0000   0.0000     0.0000 C   0  0  0  0  0  0  0  0  0  0
    0.0000   0.0000     0.0000 C   0  0  0  0  0  0  0  0  0  0
    0.0000   0.0000     0.0000 C   0  0  0  0  0  0  0  0  0  0
    0.0000   0.0000     0.0000 C   0  0  0  0  0  0  0  0  0  0
    0.0000   0.0000     0.0000 C   0  0  0  0  0  0  0  0  0  0
    0.0000   0.0000     0.0000 C   0  0  0  0  0  0  0  0  0  0
    0.0000   0.0000     0.0000 C   0  0  0  0  0  0  0  0  0  0
    0.0000   0.0000     0.0000 C   0  0  0  0  0  0  0  0  0  0
    0.0000   0.0000     0.0000 C   0  0  0  0  0  0  0  0  0  0
    0.0000   0.0000     0.0000 C   0  0  0  0  0  0  0  0  0  0
  1  2  1  0     0  0
  1  3  1  0     0  0
  3  4  1  0     0  0
  4  5  1  0     0  0
  5  6  1  0     0  0
  6  7  1  6     0  0
  7  8  1  0     0  0
  8  9  1  0     0  0
  9 10  1  0     0  0
 10 11  1  0     0  0
  9 12  1  1     0  0
  8 13  2  0     0  0
  6 14  1  0     0  0
 14 15  1  0     0  0
 14 16  1  0     0  0
  5 17  2  0     0  0
  3 18  1  1     0  0
  1 19  2  0     0  0
  2 20  1  0     0  0
 20 21  1  0     0  0
 21 22  2  0     0  0
 22 23  1  0     0  0
 23 24  2  0     0  0
 24 25  1  0     0  0
 25 20  2  0     0  0
 21 26  1  0     0  0
 26 27  2  0     0  0
 27 28  1  0     0  0
 28 29  2  0     0  0
 29 22  1  0     0  0
M  END
$$$$
MikeWilliams-UK commented 4 years ago

Correction to the previous message. I have now integrated this into our test harness and I can confirm that Wedge and Hatch bonds are preserved. Maybe I messed up the file when I zapped the co-ordinates by hand.

Left is loaded from the file, right is after Layout. image

deadlyvices commented 4 years ago

Cool. If that's the case we now have a redraw function