Exemple #1
0
        private byte[] RenderHighlightedObject(IndigoObject mol, IndigoObject query)
        {
            query.aromatize();
            IndigoObject matcher = indigo.substructureMatcher(mol);

            foreach (IndigoObject match in matcher.iterateMatches(query))
            {
                foreach (IndigoObject queryAtom in query.iterateAtoms())
                {
                    IndigoObject atom = match.mapAtom(queryAtom);
                    atom.highlight();

                    foreach (IndigoObject nei in atom.iterateNeighbors())
                    {
                        if (!nei.isPseudoatom() && !nei.isRSite() && nei.atomicNumber() == 1)
                        {
                            nei.highlight();
                            nei.bond().highlight();
                        }
                    }
                }

                foreach (IndigoObject bond in query.iterateBonds())
                {
                    match.mapBond(bond).highlight();
                }
            }

            indigo.setOption("render-coloring", false);
            mol.dearomatize();
            mol.layout();
            return(renderer.renderToBuffer(mol));
        }
Exemple #2
0
        /// <summary>
        /// Returns a depiction of the chemical structure as a bitmap.
        /// </summary>
        /// <param name="width">The desired width in pixels.</param>
        /// <param name="height">The desired height in pixels.</param>
        /// <returns>The bitmap depicting the chemical structure.</returns>
        public Bitmap ToBitmap(int width, int height)
        {
            Bitmap bitmap = null;

            try
            {
                using (Indigo indigo = new Indigo())
                {
                    IndigoRenderer indigoRenderer = new IndigoRenderer(indigo);
                    indigo.setOption("render-coloring", true);
                    indigo.setOption("render-image-size", width, height);
                    indigo.setOption("render-label-mode", "hetero");
                    indigo.setOption("render-margins", 10, 10);
                    indigo.setOption("render-output-format", "png");
                    indigo.setOption("render-relative-thickness", 1.6f);
                    IndigoObject structure = CreateIndigoStructure(indigo);
                    structure.dearomatize();
                    structure.layout();
                    bitmap = indigoRenderer.renderToBitmap(structure);
                    structure.Dispose();
                }
            }
            catch
            {
                bitmap = Properties.Resources.Error;
            }

            return(bitmap);
        }
Exemple #3
0
        public void WriteImageFile(string fname, IndigoObject mol, string format, string comment, float weight)
        {
            switch (format)
            {
            case "png": { indigo.setOption("render-output-format", "png"); break; }

            case "svg": { indigo.setOption("render-output-format", "svg"); break; }

            case "pdf": { indigo.setOption("render-output-format", "pdf"); break; }

            case "emf": { indigo.setOption("render-output-format", "emf"); break; }

            default: throw new Exception("format not handled by Indigo: " + format);
            }

            // http://ggasoftware.com/opensource/indigo/api/options#rendering
            //png, svg, pdf are allowed. On Windows, emf is also allowed.
            indigo.setOption("render-bond-length", "18");

            indigo.setOption("render-relative-thickness", Math.Round(weight, 2).ToString());

            indigo.setOption("render-coloring", true);
            indigo.setOption("render-margins", 1, 1);
            //indigo.setOption("render-atom-ids-visible", true);
            indigo.setOption("render-comment", comment);
            indigo.setOption("render-implicit-hydrogens-visible", false);
            indigo.setOption("render-label-mode", "hetero");
            indigo.setOption("render-comment-font-size", "15");
            indigo.setOption("render-comment-offset", "6");
            mol.layout();
            renderer.renderToFile(mol, fname);

            //indigo.setOption("render-output-format", "svg");
        }
        private void renderMolecule(IndigoObject input)
        {
            IndigoRenderer renderer = new IndigoRenderer(_indigo);

            _indigo.setOption("render-output-format", "emf");
            _indigo.setOption("render-margins", 10, 10);

            if (showBonds == true)
            {
                _indigo.setOption("render-bond-ids-visible", true);
            }
            else
            {
                _indigo.setOption("render-bond-ids-visible", false);
            }
            if (showAtoms == true)
            {
                _indigo.setOption("render-atom-ids-visible", true);
            }
            else
            {
                _indigo.setOption("render-atom-ids-visible", false);
            }
            _indigo.setOption("render-label-mode", "hetero");
            _indigo.setOption("render-stereo-style", "none");
            _indigo.setOption("render-bond-length", 45);

            input.layout();
            MemoryStream ms = new MemoryStream(renderer.renderToBuffer(input));

            pictureBox1.Image = Image.FromStream(ms);
            ms.Close();
        }