Пример #1
0
        public void Main()
        {
            Depiction depiction = null;

            #region EnsureSuffix
            depiction.WriteTo(Depiction.SvgFormatKey, "~/chemical"); // create a file "~/chemical.svg"
            #endregion
        }
Пример #2
0
/// <summary>
/// Get the SVG for a molecule within a specified size rectangle (units important, eg. px, mm
/// </summary>
/// <param name="width"></param>
/// <param name="height"></param>
/// <param name="units"></param>
/// <param name="dp"></param>
/// <returns></returns>

        public string GetMoleculeSvg(
            int width             = -1,
            int height            = -1,
            string units          = Depiction.UnitsPixel,
            DisplayPreferences dp = null)
        {
            string svg = null;

            UpdateNativeMolecule();

            if (NativeMol == null || NativeMol.Atoms.Count == 0)
            {
                return(null);
            }

            //width = height = -1; // debug
            //units = null;

            //NativeMol.setProperty(CDKConstants.TITLE, "caffeine"); // title already set from input!

            // Use size and units if specified. If not defined then a mm size box just containing the structure will be defined in generated svg

            DepictionGenerator dptgen = new DepictionGenerator();

            if (width > 0 && height > 0)
            {
                dptgen.Size      = new System.Windows.Size(width, height);
                dptgen.FillToFit = true;
            }

            Depiction d = dptgen.Depict(NativeMol);

            if (Lex.IsDefined(units))
            {
                if (units != Depiction.UnitsPixel && units != Depiction.UnitsMM)
                {
                    throw new Exception("Invalid Depiction units: " + units);
                }

                svg = d.ToSvgString(units);                 // get SVG setting desired units in the XML
            }

            else
            {
                svg = d.ToSvgString();
            }

            return(svg);
        }
Пример #3
0
        private void UpdateVisual()
        {
            switch (_ChemObject)
            {
            case IAtomContainer mol:
                depiction = Generator.Depict(mol, MakeHighlightDictionary(mol));
                break;

            case IReaction rxn:
                depiction = Generator.Depict(rxn, MakeHighlightDictionary(ReactionManipulator.ToMolecule(rxn)));
                break;

            default:
                depiction = null;
                break;
            }

            this.InvalidateVisual();
        }
Пример #4
0
        /// <summary>
        /// Render molecule into bitmap of specified size.
        /// </summary>
        /// <param name="bitmapWidth"></param>
        /// <param name="bitmapHeight"></param>
        /// <param name="dp"></param>
        /// <returns></returns>

        public Bitmap GetMoleculeBitmap(
            int bitmapWidth,
            int bitmapHeight,
            DisplayPreferences dp = null)
        {
            byte[]     ba;
            FileStream fs;
            float      top, bottom, left, right, height, width, strBottom, hCenter, drop, stdBndLen, scale, fontSize, bondThickness;
            int        txtLen;
            Bitmap     bm;

            UpdateNativeMolecule();

            if (NativeMol == null || NativeMol.Atoms.Count == 0)
            {
                return(null);
            }

            //NativeMol.setProperty(CDKConstants.TITLE, "caffeine"); // title already set from input!

            DepictionGenerator dptgen = new DepictionGenerator();

            dptgen.Size = new System.Windows.Size(bitmapWidth, bitmapHeight);

            Depiction d = dptgen.Depict(NativeMol);

            dptgen.Size      = new System.Windows.Size(bitmapWidth, bitmapHeight);
            dptgen.FillToFit = true;

            //string svg = d.ToSvgString();
            //bm = SvgUtil.GetBitmapFromSvgXml(svg, bitmapWidth);

            //System.Windows.Media.Imaging.RenderTargetBitmap rtBm = d.ToBitmap();

            string path = TempFile.GetTempFileName(ClientDirs.TempDir, "jpg", true);

            d.WriteTo("jpg", path);
            bm = new Bitmap(path);

            return(bm);
        }
        public void Generate(string text, string filename)
        {
            Depiction depict = null;

            if (IsReactionSmilees(text))
            {
                var rxn = parser.ParseReactionSmiles(text);
                ReactionManipulator.PerceiveDativeBonds(rxn);
                ReactionManipulator.PerceiveRadicals(rxn);
                depict = PictureGenerator.Depict(rxn);
            }
            else
            {
                var mol = NCDKExcel.Utility.Parse(text);
                AtomContainerManipulator.PerceiveDativeBonds(mol);
                AtomContainerManipulator.PerceiveRadicals(mol);
                depict = PictureGenerator.Depict(mol);
            }
            depict.WriteTo(filename);

            if (!filename.EndsWith(".svg"))
            {
                return;
            }

            string svg;

            using (var r = new StreamReader(filename))
            {
                svg = r.ReadToEnd();
            }
            using (var r = new StreamWriter(filename))
            {
                r.Write(_rect_transparent.Replace(svg, ""));
            }
        }
Пример #6
0
        private void UpdateVisual()
        {
            switch (_ChemObject)
            {
            case IAtomContainer mol:
                var sss = new Dictionary <IChemObject, Color>();
                foreach (var o in SplitHighlightinhObjects(mol, this.HighlightingObjects))
                {
                    sss.Add(o, Colors.Aqua);
                }
                depiction = Generator.Depict(mol, sss);
                break;

            case IReaction rxn:
                depiction = Generator.Depict(rxn);
                break;

            default:
                depiction = null;
                break;
            }

            this.InvalidateVisual();
        }
Пример #7
0
        /// <summary>
        /// Render molecule into bitmap of specified size.
        /// </summary>
        /// <param name="bitmapWidth"></param>
        /// <param name="bitmapHeight"></param>
        /// <param name="dp"></param>
        /// <returns></returns>

        public Bitmap GetMoleculeBitmap(
            int bitmapWidth,
            int bitmapHeight,
            DisplayPreferences dp = null)
        {
            byte[]     ba;
            FileStream fs;
            float      top, bottom, left, right, height, width, strBottom, hCenter, drop, stdBndLen, scale, fontSize, bondThickness;
            int        txtLen;
            Bitmap     bm;

            UpdateNativeMolecule();

            if (NativeMol == null || NativeMol.getAtomCount() == 0)
            {
                return(null);
            }

            //NativeMol.setProperty(CDKConstants.TITLE, "caffeine"); // title already set from input!

            sun.awt.Win32FontManager w32Font = new sun.awt.Win32FontManager(); // need this for class to be found

            Environment.SetEnvironmentVariable("CLASSPATH", ".", EnvironmentVariableTarget.Process);
            Environment.SetEnvironmentVariable("JAVA_HOME", @"C:\Mobius_OpenSource\MobiusCommon\CdkMx\bin\Debug", EnvironmentVariableTarget.Process);
            Environment.SetEnvironmentVariable("Path", @"%JAVA_HOME%", EnvironmentVariableTarget.Process);

            /* Need following?
             * CLASSPATH=.; / JAVA_HOME=C:\Program Files\Java\jdk1.6.0_21 / Path=%JAVA_HOME%\bin;
             */

            //DecimalFormatSymbols.getInstance(Local.ENGLISH);

            //Locale.forLanguageTag("en-US")

            DepictionGenerator dptgen = new DepictionGenerator();

            dptgen.withSize(bitmapWidth, bitmapHeight);        // px (raster) or mm (vector)
            //dptgen.withMolTitle();
            //dptgen.withTitleColor(Color.DarkGray); // annotations are red by default
            Depiction d = dptgen.depict(NativeMol);

            /*
             *
             * public const string SVG_FMT = "svg";
             * public const string PS_FMT = "ps";
             * public const string EPS_FMT = "eps";
             * public const string PDF_FMT = "pdf";
             * public const string JPG_FMT = "jpg";
             * public const string PNG_FMT = "png";
             * public const string GIF_FMT = "gif";
             *
             * public const string UNITS_MM = "mm";
             * public const string UNITS_PX = "px";
             */
            java.util.List formats = d.listFormats();
            java.io.File   file    = new java.io.File(@"c:\downloads\test.jpg");
            bool           b       = file.canWrite();
            string         s       = d.toSvgStr();

            d.writeTo("jpg", file);
            //d.writeTo("svg", @"c:\downloads\test.svg");

            //string svg = d.toSvgStr();
            //bm = SvgUtil.GetBitmapFromSvgXml(svg, bitmapWidth);
            bm = new Bitmap(@"c:\downloads\test.jpg");
            return(bm);
        }