Search in sources :

Example 1 with GenericReactionInstance

use of ambit2.reactions.GenericReactionInstance in project ambit-mirror by ideaconsult.

the class SyntheticStrategy method calcReactionScore.

public ReactionScore calcReactionScore(GenericReactionInstance gri) {
    ReactionScore rscore = new ReactionScore();
    if (reactionScoreSchema.basicScoreWeight > 0.0) {
        rscore.basicScore = gri.reaction.getBasicScore();
        rscore.totalScore += rscore.basicScore * reactionScoreSchema.basicScoreWeight;
    }
    if (reactionScoreSchema.priorityScoreWeight > 0.0) {
        rscore.priorityScore = gri.reaction.getPriorityScore();
        rscore.totalScore += rscore.priorityScore * reactionScoreSchema.priorityScoreWeight;
    }
    if (reactionScoreSchema.experimentalConditionsScoreWeight > 0.0) {
        rscore.experimentalConditionsScore = gri.reaction.getExperimentalConditionsScore();
        rscore.totalScore += rscore.experimentalConditionsScore * reactionScoreSchema.experimentalConditionsScoreWeight;
    }
    if (reactionScoreSchema.productComplexityWeight > 0.0) {
        rscore.productComplexityScore = calcProductComplexity(gri.products);
        rscore.totalScore += rscore.productComplexityScore * reactionScoreSchema.productComplexityWeight;
    }
    if (reactionScoreSchema.reactionCenterComplexityWeight > 0.0) {
        rscore.reactionCenterComplexityScore = calcReactionCenterComplexity(gri);
        rscore.totalScore += rscore.reactionCenterComplexityScore * reactionScoreSchema.reactionCenterComplexityWeight;
    }
    if (reactionScoreSchema.yieldScoreWeight > 0.0) {
        // average of lo and hi reaction yield
        rscore.yieldScore = 0.5 * (gri.reaction.getYieldHi() + gri.reaction.getYieldLo());
        rscore.totalScore += rscore.yieldScore * reactionScoreSchema.yieldScoreWeight;
    }
    return rscore;
}
Also used : ReactionScore(ambit2.reactions.rules.scores.ReactionScore)

Example 2 with GenericReactionInstance

use of ambit2.reactions.GenericReactionInstance 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 GenericReactionInstance

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

Example 4 with GenericReactionInstance

use of ambit2.reactions.GenericReactionInstance 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)

Aggregations

GenericReactionInstance (ambit2.reactions.GenericReactionInstance)3 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)3 GenericReaction (ambit2.reactions.GenericReaction)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 MoleculeStatus (ambit2.reactions.retrosynth.ReactionSequence.MoleculeStatus)1 ReactionScore (ambit2.reactions.rules.scores.ReactionScore)1 IAtom (org.openscience.cdk.interfaces.IAtom)1 IAtomContainerSet (org.openscience.cdk.interfaces.IAtomContainerSet)1