use of ambit2.reactions.GenericReaction in project ambit-mirror by ideaconsult.
the class ReactionSequence method generateSequenceStepForReactionInstance.
public void generateSequenceStepForReactionInstance(ReactionSequenceLevel level, int moleculeIndex, GenericReaction reaction, List<IAtom> reactionInstance) throws Exception {
ReactionSequenceStep step = new ReactionSequenceStep();
step.reaction = reaction;
IAtomContainer mol = level.molecules.get(moleculeIndex);
IAtomContainer products = reaction.applyAtInstance(mol, reactionInstance, smrkMan, true);
smrkMan.processProduct(products);
// calculate reaction score
TopLayer.setAtomTopLayers(products);
GenericReactionInstance gri = new GenericReactionInstance(reaction, mol, reactionInstance, products);
step.reactionScore = strategy.calcReactionScore(gri);
IAtomContainerSet productFrags = ConnectivityChecker.partitionIntoMolecules(products);
step.outputMolecules = new ArrayList<IAtomContainer>();
for (IAtomContainer frag : productFrags.atomContainers()) {
step.outputMolecules.add(frag);
String inchiKey = setMoleculeInchiKey(frag);
registerMolInchiKey(frag, inchiKey, level.levelIndex + 1);
// Set new molecule status
if (usedInchies.get(inchiKey).molecules.size() > 1)
setMoleculeStatus(frag, MoleculeStatus.EQUIVALENT_TO_OTHER_MOLECULE);
else {
if (startMatDB.isStartingMaterial(inchiKey))
setMoleculeStatus(frag, MoleculeStatus.STARTING_MATERIAL);
else
setMoleculeStatus(frag, MoleculeStatus.ADDED_TO_LEVEL);
}
}
level.associateStep(moleculeIndex, step);
}
use of ambit2.reactions.GenericReaction in project ambit-mirror by ideaconsult.
the class ReactionSequence method handleReactionInstances.
public List<GenericReactionInstance> handleReactionInstances(Map<GenericReaction, List<List<IAtom>>> instances, IAtomContainer target) throws Exception {
List<GenericReactionInstance> griList = new ArrayList<GenericReactionInstance>();
Set<GenericReaction> grKeys = instances.keySet();
for (GenericReaction gr : grKeys) {
List<List<IAtom>> grInst = instances.get(gr);
for (int i = 0; i < grInst.size(); i++) {
IAtomContainer products = gr.applyAtInstance(target, grInst.get(i), smrkMan, true);
smrkMan.processProduct(products);
// calculate reaction score
TopLayer.setAtomTopLayers(products);
GenericReactionInstance gri = new GenericReactionInstance(gr, target, grInst.get(i), products);
gri.reactionScore = strategy.calcReactionScore(gri);
griList.add(gri);
}
// TODO take into account reaction instance occurrences
}
return griList;
}
use of ambit2.reactions.GenericReaction in project ambit-mirror by ideaconsult.
the class ReactionSequence method iterateLevelMolecules.
public void iterateLevelMolecules(ReactionSequenceLevel level) throws Exception {
for (int i = 0; i < level.molecules.size(); i++) {
IAtomContainer mol = level.molecules.get(i);
MoleculeStatus status = getMoleculeStatus(mol);
if (status == MoleculeStatus.ADDED_TO_LEVEL) {
// check for starting material is performed on product generation
Map<GenericReaction, List<List<IAtom>>> allInstances = generateAllReactionInstances(mol);
if (allInstances.isEmpty()) {
setMoleculeStatus(mol, MoleculeStatus.UNRESOLVED);
continue;
}
List<GenericReactionInstance> griList = handleReactionInstances(allInstances, mol);
GenericReactionInstance bestInst = getBestInstance(griList);
generateSequenceStepForReactionInstance(level, i, bestInst);
setMoleculeStatus(mol, MoleculeStatus.RESOLVED);
}
}
}
use of ambit2.reactions.GenericReaction in project ambit-mirror by ideaconsult.
the class ReactionSequenceLevel method toString.
public String toString() {
StringBuffer sb = new StringBuffer();
sb.append("Level " + levelIndex + "\n");
for (int i = 0; i < molecules.size(); i++) {
String smi = null;
try {
IAtomContainer mol = molecules.get(i).clone();
MoleculeTools.convertExplicitHAtomsToImplicit(mol);
smi = SmartsHelper.moleculeToSMILES(mol, true);
} catch (Exception x) {
}
;
sb.append("" + smi);
sb.append(" " + MoleculeStatus.getShortString((MoleculeStatus) molecules.get(i).getProperty(ReactionSequence.MoleculeStatusProperty)));
// sb.append(" " + molecules.get(i).getProperty(ReactionSequence.MoleculeInChIKeyProperty));
Object[] obj = getGenerationInfo(i);
if (obj != null) {
GenericReaction genReaction = (GenericReaction) obj[0];
sb.append(" <R" + genReaction.getExternId() + ",M" + ((Integer) obj[1] + 1));
if (obj[2] != null) {
ReactionScore rscore = (ReactionScore) obj[2];
sb.append(",S" + ((Double) rscore.totalScore).intValue());
sb.append(">");
sb.append(" " + rscore.toStringLine());
} else
sb.append(">");
}
/*
ReactionSequenceStep step = steps.get(i);
if (step != null)
{
//TODO
}
*/
sb.append("\n");
}
return sb.toString();
}
use of ambit2.reactions.GenericReaction in project ambit-mirror by ideaconsult.
the class ReactionTestUtils method testReactor.
public static void testReactor(String smiles, String reactionDBFile, int reactorStepSize) throws Exception {
System.out.println("Setting reactor and reaction database...");
Reactor reactor = new Reactor();
ReactionDataBase reactDB = new ReactionDataBase(reactionDBFile);
System.out.println("Configuring reaction database...");
// reactDB.configureReactions(reactor.getSMIRKSManager());
reactDB.configureGenericReactions(reactor.getSMIRKSManager());
reactor.setReactionDataBase(reactDB);
System.out.println("Configuring reactor strategy ...");
// strategy is in the same file
ReactorStrategy strategy = new ReactorStrategy(new File(reactionDBFile));
strategy.FlagStoreFailedNodes = true;
strategy.FlagStoreSuccessNodes = true;
// if 0 then the reactor will stop after the first success node
strategy.maxNumOfSuccessNodes = 0;
strategy.FlagCheckNodeDuplicationOnPush = true;
strategy.FlagTraceReactionPath = true;
strategy.FlagLogMainReactionFlow = true;
strategy.FlagLogReactionPath = true;
strategy.FlagLogNameInReactionPath = false;
strategy.FlagLogExplicitHToImplicit = true;
reactor.setStrategy(strategy);
// Setup Smirks manager
reactor.getSMIRKSManager().setFlagProcessResultStructures(true);
reactor.getSMIRKSManager().setFlagClearImplicitHAtomsBeforeResultProcess(false);
reactor.getSMIRKSManager().setFlagAddImplicitHAtomsOnResultProcess(false);
reactor.getSMIRKSManager().setFlagConvertExplicitHToImplicitOnResultProcess(false);
if (FlagPrintReactionDB) {
System.out.println("Reaction database:");
for (int i = 0; i < reactDB.genericReactions.size(); i++) {
GenericReaction r = reactDB.genericReactions.get(i);
System.out.println(" " + r.getName() + " " + r.getSmirks() + " " + r.getReactionClass());
}
}
if (FlagPrintReactionStrategy) {
System.out.println();
System.out.println(strategy.toJSONString(""));
System.out.println(strategy.toString());
}
IAtomContainer mol = SmartsHelper.getMoleculeFromSmiles(smiles, true);
System.out.println();
System.out.println("Reactor on target: " + smiles);
System.out.println();
if (reactorStepSize <= 0) {
ReactorResult result = reactor.react(mol);
} else {
reactor.initializeReactor(mol);
List<ReactorNode> nodes = reactor.reactNext(reactorStepSize);
System.out.println("Handled " + nodes.size() + " nodes");
while (!nodes.isEmpty()) {
nodes = reactor.reactNext(reactorStepSize);
System.out.println("Handled " + nodes.size() + " nodes");
}
}
}
Aggregations