How to reference molecule in current Msketchpane?

User 9d72be7cd4

12-01-2007 22:26:00

We're evaluating using MarvinSketch in an existing java application for sketching and saving molecular structures.





I'm able to get the MSketchPane included on a form in our existing java application, can open, sketch, save and export molecules from the Marvin Menu.





Now, I'm looking at automating a few processes that are necessary if we are to license and use Marvin.





1. Ability to set in a variable - OK: working, using getMol function





2. Ability to load molecule from a variable OK: working, using setMol function (and MOL text string)





3. Ability to take a graphic snapshot of the molecule and record in a variable (in a high-res png format)





CAN TAKE limited, low quality snapshots using getImage() or manual cut and paste = but would like to use the toBinFormat function. How do I reference the Molecule class? Add it as its own bean?





Using:


(bean_73 refers to the MSketchPane)


elements.bean_73.Molecule.toBinFormat("png:w100,h100,#FFF5DE")


returns


The undefined value has no properties calling toBinFormat.





(How to load the molecule class and have it reference the molecule currently open in the sketchpane?)








Using:


fs_productstruct = elements.bean_73.getImage(15)


I actually get a bufferedimage returned, but I don't know how to then use that and call the .toBinformat or something to convert to pnb/jpg/or whatever. Subsequent manual cut/paste will display this image, but I'm not familiar with how to handle this image type or convert to a standard type (jpg, png, etc).





Am I going about this the wrong way? What is the best way to programmatically take a snapshot of a molecule in the Msketchpane bean and output a graphic?





Thanks for any help...so far the chemists who've had a look would LOVE to get this product built into our current java application (ie, in their electronic notebooks).





Also, along the same line of thought, the next step will be to reference and pull information like the mass, formula and such from the displayed molecule into a variable and then save to a database.





Again, will I have to reference the calculation classes OUTSIDE of SketchPane to do this, or as they're already loaded inside the sketchpane is there a way to reference them externally?





Any direction helpful!





NCM


Frontier Scientific








EDIT: Ok, found the setMol and getMol functions and can open and save files via external controls.





So, the only thing left is - how to use some of the image export functions and calculation functions externally with a structure displayed on the sketchpane.





So, very promising...management already likes to "quick" demo I put together of just the above functionality.

ChemAxon 7c2d26e5cf

15-01-2007 15:20:28

If you need the image of the molecule in PNG format, you can do like this:


Code:
MSketchPane sketchpanel = ...


// retrieve structure from the sketcher


Molecule mol = sketchpanel.getMol();


byte[] data = mol.toBinFormat("png:w100,h100,#FFF5DE");



In this case, the returning value is a byte array that represents the molecule in PNG format. If you save it to a file, you can display this PNG file with any image viewer application (or in a web browser).





To get mass and formula about the displayed molecule, retrieve the structure from MSketchPane or MViewPane as Molecule object (like above) then use the Calculator plugin API with this object.


http://www.chemaxon.com/marvin/doc/api/chemaxon/marvin/calculations/ElementalAnalyserPlugin.html