Reactor API

User 2347372188

31-08-2011 17:42:17

Hello.  I am attempting to use the Reactor API in order to perform a number of molecular transformations.  My problem is that I can't figure out how to get JChem to eat a SMIRKS.  I've tried this:  



                ByteArrayInputStream bs = new ByteArrayInputStream(smirks.getBytes());


                MolImporter mi = new MolImporter(bs);


                Molecule rxn = mi.read();


and this:



                MolHandler mh = new MolHandler(smirks);

                Molecule rxn = mh.getMolecule();



Both yield a MolFormatException.  I know the SMIRKS I'm are good, because I've tested them in the GUI version of Reactor.  Please provide some example code for how to perform a SMIRKS reaction using the JChem API.  Thank you.


-&

ChemAxon d76e6e95eb

31-08-2011 17:50:27

You need to cast the imported molecule object to RxnMolecule, for example:


MolImporter rxnImporter = new MolImporter("input.smirks");
RxnMolecule rxn = (RxnMolecule)rxnImporter.read();

Or


RxnMolecule rxn = (RxnMolecule)MolImporter.importMol("CCCO>>CCC=O");

User 2347372188

31-08-2011 18:02:43

Thanks for the fast response.  When I try this:



                ByteArrayInputStream bs = new ByteArrayInputStream(smirks.getBytes());


                MolImporter mi = new MolImporter(bs);


                RxnMolecule rxn = (RxnMolecule)mi.read();



I get this Exception:



chemaxon.formats.MolFormatException: Cannot recognize format (?)

Unrecognized file contents:

CH3:2]C[CH3:3]>>[CH3:2]O[CH3:3]

at chemaxon.formats.recognizer.RecognitionSubsystem.getFormat(Unknown Source)

at chemaxon.formats.MolInputStream.initTextFormat(Unknown Source)

at chemaxon.formats.MolInputStream.init(Unknown Source)



I'm just try to convert a CH2 to O.


Thanks.


-&

User 2347372188

31-08-2011 18:05:48

Ooops!  I saw an error in my SMIRKS.  It works now.


Thanks.


 


-&

ChemAxon d76e6e95eb

31-08-2011 18:08:53

 


CH3:2]C[CH3:3]>>[CH3:2]O[CH3:3] 


Maybe just a copy/paste error, but the leading [ character seems missing.
Interesting reaction, anyway ;)


 

ChemAxon d76e6e95eb

31-08-2011 18:09:42

OK, you have found the issue while I was typing. :)


In JChem, all atoms having changing bonds, appearing, disappearing should be mapped, otherwise our automapper will do that internally. It mostly calculates map numbers well, but it is always wise to add map numbers yourself to avoid surprises.

ChemAxon e08c317633

31-08-2011 19:38:41

You can also use method Reactor.setReactionString(String) to set the reaction for Reactor directly in SMIRKS. It can handle rules too, see the apidoc for more.


Zsolt