public void TestDrawMolecule() { var mol = RWMol.MolFromSmiles("c1ccc(C)c(C)c1C"); var drawer = new MolDraw2DCairo(300, 300, -1, -1, true); drawer.drawOptions().addAtomIndices = true; drawer.drawMolecule(mol); drawer.finishDrawing(); var png1 = drawer.getImage().ToArray(); drawer.writeDrawingText("test.png"); byte[] png2 = File.ReadAllBytes("test.png"); Assert.Equal(png1.Length, png2.Length); for (int i = 0; i < png1.Length; i++) { Assert.Equal(png1[i], png2[i]); } File.Delete("test.png"); }
static void MakePicture(string smiles, string filename) { int width = 200; int height = 200; RWMol mol = null; mol = RWMol.MolFromSmiles(smiles); if (mol == null) { mol = RWMol.MolFromSmarts(smiles); } if (mol == null) { throw new Exception($"Cannot recognize: '{smiles}'"); } RDKFuncs.prepareMolForDrawing(mol); if (filename.EndsWith(".svg")) { var view = new MolDraw2DSVG(width, height); view.drawMolecule(mol); view.finishDrawing(); using (var w = new StreamWriter(filename)) { w.Write(view.getDrawingText()); Console.WriteLine($"{filename} is drawn."); } } else if (filename.EndsWith(".png")) { var view = new MolDraw2DCairo(width, height); view.drawMolecule(mol, Path.GetFileNameWithoutExtension(filename)); view.finishDrawing(); view.writeDrawingText(filename); } else { throw new Exception($"Not supported: {filename}"); } }