retrieve a reaction as a RxnMolecule from the MSketchPane

User 98a23c34cc

18-10-2013 17:29:20

I want to retrieve the reaction as a RxnMolecule  from the MSketchPane so that I can retrieve the agents ,products and reactants.


(MSketchPane) sketch).getMol();


chemaxon.struc.Molecule cannot be cast to chemaxon.struc.RxnMolecule is being thrown when i used this. 


please guide me to solve this problem.

ChemAxon 5433b8e56b

27-10-2013 13:07:25

Hi Jenny,


sorry for the late reply, I hope my answer find you in time, and helps you solve the problem though.


You can use the RxnMolecule.getReaction(MoleculeGraph) static method to convert the result of MSketchPane.getMol(). If it is a reaction you will get an RxnMolecule, otherwise it will return null.


Technical background details:
The MarvinSketch application works with an RgMolecule inside because that is the most rich representation, and if there is a reaction in the sketcher, then it is in the RgMolecule-s root graph.
This method checks if the MoleculeGraph is an RgMolecule, and if yes then test if its root graph is an RxnMolecule, and returns that if it is, or null if it is not. If the given graph is not an RgMolecule, then it returns the parameter itself, if it is instance of RxnMolecule, otherwise it returns null.


I recommend to use the static helper method RxnMolecule.getReaction(MoleculeGraph) we are maintaining that, and if anything changes you will not need to adjust a custom algorithm that does the same.


Regards,
Istvan