Search in sources :

Example 1 with ReactionSequenceLevel

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);
        }
    }
}
Also used : GenericReaction(ambit2.reactions.GenericReaction) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) ArrayList(java.util.ArrayList) List(java.util.List) MoleculeStatus(ambit2.reactions.retrosynth.ReactionSequence.MoleculeStatus) IAtom(org.openscience.cdk.interfaces.IAtom)

Example 2 with ReactionSequenceLevel

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);
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) GenericReactionInstance(ambit2.reactions.GenericReactionInstance)

Example 3 with ReactionSequenceLevel

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);
        }
    }
}
Also used : GenericReaction(ambit2.reactions.GenericReaction) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) ArrayList(java.util.ArrayList) List(java.util.List) GenericReactionInstance(ambit2.reactions.GenericReactionInstance) MoleculeStatus(ambit2.reactions.retrosynth.ReactionSequence.MoleculeStatus) IAtom(org.openscience.cdk.interfaces.IAtom)

Example 4 with ReactionSequenceLevel

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());
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) StartingMaterialsDataBase(ambit2.reactions.retrosynth.StartingMaterialsDataBase) SMIRKSManager(ambit2.smarts.SMIRKSManager) ArrayList(java.util.ArrayList) ReactionDataBase(ambit2.reactions.ReactionDataBase) ReactionSequence(ambit2.reactions.retrosynth.ReactionSequence) ReactionSequenceLevel(ambit2.reactions.retrosynth.ReactionSequenceLevel)

Aggregations

IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)4 ArrayList (java.util.ArrayList)3 GenericReaction (ambit2.reactions.GenericReaction)2 GenericReactionInstance (ambit2.reactions.GenericReactionInstance)2 MoleculeStatus (ambit2.reactions.retrosynth.ReactionSequence.MoleculeStatus)2 List (java.util.List)2 IAtom (org.openscience.cdk.interfaces.IAtom)2 ReactionDataBase (ambit2.reactions.ReactionDataBase)1 ReactionSequence (ambit2.reactions.retrosynth.ReactionSequence)1 ReactionSequenceLevel (ambit2.reactions.retrosynth.ReactionSequenceLevel)1 StartingMaterialsDataBase (ambit2.reactions.retrosynth.StartingMaterialsDataBase)1 SMIRKSManager (ambit2.smarts.SMIRKSManager)1 IAtomContainerSet (org.openscience.cdk.interfaces.IAtomContainerSet)1