use of ambit2.reactions.retrosynth.ReactionSequenceLevel in project ambit-mirror by ideaconsult.
the class ReactionSequence method iterateLevelMoleculesRandomly.
public void iterateLevelMoleculesRandomly(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;
}
Object[] obj = SyntheticStrategy.getRandomSelection(allInstances);
GenericReaction gr = (GenericReaction) obj[0];
List<IAtom> inst = (List<IAtom>) obj[1];
generateSequenceStepForReactionInstance(level, i, gr, inst);
setMoleculeStatus(mol, MoleculeStatus.RESOLVED);
}
}
}
use of ambit2.reactions.retrosynth.ReactionSequenceLevel 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.retrosynth.ReactionSequenceLevel 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.retrosynth.ReactionSequenceLevel in project ambit-mirror by ideaconsult.
the class ReactionTestUtils method testReactionSequence.
public static void testReactionSequence(String targetSmiles, String reactionDBFileName, String startMatDBFileName, boolean isRandomStrategy) throws Exception {
String[] startMatSmi = { "CC", "CCC", "CO", "NC(C)C", "Cl" };
StartingMaterialsDataBase smdb = new StartingMaterialsDataBase(startMatSmi);
// Set up reaction DB
ReactionDataBase rdb;
if (reactionDBFileName == null) {
List<String> smirks = new ArrayList<String>();
smirks.add("[C:1]Cl>>[C:1]");
// smirks.add("[C:1][H]>>[C:1]O[H]");
smirks.add("[H][C:1][C:2][H]>>[H][C:1][H].[H][C:2][H]");
// smirks.add("[C:1][C:2]>>[C:1][H].[C:2][H]");
rdb = new ReactionDataBase(smirks);
System.out.println("ReactionDB:\n" + rdb.toString());
} else {
rdb = new ReactionDataBase(reactionDBFileName);
}
System.out.println("Staring material DB:");
for (String s : startMatSmi) System.out.println(" " + s);
System.out.println();
System.out.println("Target: " + targetSmiles);
IAtomContainer target = SmartsHelper.getMoleculeFromSmiles(targetSmiles);
SMIRKSManager smrkMan0 = new SMIRKSManager(SilentChemObjectBuilder.getInstance());
rdb.configureGenericReactions(smrkMan0);
ReactionSequence rseq = new ReactionSequence();
rseq.setStrategy(SyntheticStrategy.getDefaultSyntheticStrategy());
SMIRKSManager smrkMan = rseq.getSmrkMan();
// setup smrkMan
smrkMan.setFlagProcessResultStructures(true);
smrkMan.setFlagClearHybridizationBeforeResultProcess(true);
smrkMan.setFlagClearImplicitHAtomsBeforeResultProcess(false);
smrkMan.setFlagClearAromaticityBeforeResultProcess(true);
smrkMan.setFlagAddImplicitHAtomsOnResultProcess(false);
smrkMan.setFlagConvertAddedImplicitHToExplicitOnResultProcess(false);
smrkMan.setFlagConvertExplicitHToImplicitOnResultProcess(false);
smrkMan.setFlagApplyStereoTransformation(false);
smrkMan.setFlagHAtomsTransformation(false);
// smrkMan.setFlagHAtomsTransformationMode(FlagHAtomsTransformationMode);
smrkMan.setFlagAromaticityTransformation(false);
rseq.setReactDB(rdb);
rseq.setStartMatDB(smdb);
rseq.setTarget(target);
rseq.initilize();
if (isRandomStrategy) {
ReactionSequenceLevel level = rseq.getFirstLevel();
rseq.iterateLevelMoleculesRandomly(level);
for (int i = 0; i < 30; i++) {
level = level.nextLevel;
if (level == null)
break;
rseq.iterateLevelMoleculesRandomly(level);
}
} else {
ReactionSequenceLevel level = rseq.getFirstLevel();
rseq.iterateLevelMolecules(level);
for (int i = 0; i < 30; i++) {
level = level.nextLevel;
if (level == null)
break;
rseq.iterateLevelMolecules(level);
}
}
System.out.println("ReactionSequence:\n" + rseq.toString());
}
Aggregations