User 05309f4af8
22-06-2009 03:33:46
Hi,
I have a quick question about reaction library. i used ConcurrentReactorProcessor api to get all products from reaction iterators. please see code as below:
public static void reactorTest() throws MolFormatException, IOException, MolImporter mol = new MolImporter(new File("D:\\JChem\\reactor\\test.rxn"), ""); List<MoleculeIterator> molIteratorList = new ArrayList<MoleculeIterator>(); RxnMolecule r = (RxnMolecule) mol.read(); // create ConcurrentReactorProcessor How do i know which several reactants reaction to each product.
ReactionException {
MoleculeIterator a = new MolImporter(new File("D:\\JChem\\reactor\\A.sd"), "").getMoleculeIterator();
MoleculeIterator b = new MolImporter(new File("D:\\JChem\\reactor\\B.sd"), "").getMoleculeIterator();
List<Molecule> testa = new ArrayList<Molecule>();
List<Molecule> testb = new ArrayList<Molecule>();
List<List<Molecule>> list = new ArrayList<List<Molecule>>();
while (a.hasNext()) {
testa.add(a.next());
}
while (b.hasNext()) {
testb.add(b.next());
}
list.add(testa);
list.add(testb);
for (List<Molecule> molList : list) {
molIteratorList.add(MoleculeIteratorFactory.createMoleculeIterator(molList));
}
// create Reactor
Reactor reactor = new Reactor();
// set properties (reverse mode)
// reactor.setReverse(true);
reactor.setIgnoreRules(Reactor.IGNORE_REACTIVITY| Reactor.IGNORE_SELECTIVITY);
Reaction reaction = new Reaction();
reaction.setReaction(r);
// set the reaction ('rxmol' is the reaction molecule)
// reaction rules are read from RDF/MRV tags
reactor.setReaction(reaction);
ConcurrentReactorProcessor crp = new ConcurrentReactorProcessor();
// set the reactor for ConcurrentReactorProcessor
crp.setReactor(reactor);
// set the reactant iterators and the processing mode for
crp.setReactantIterators(molIteratorList.toArray(new MoleculeIterator[0]),ConcurrentReactorProcessor.MODE_COMBINATORIAL);
// react the reactants and export the output (reactions are performed in concurrent mode)
Molecule[] products = null;
while ((products = crp.react()) != null) {
for (Molecule product : products) {
System.out.println("get product: " + product.toFormat("smiles"));
}
}
}
Thank you in advance!
andy