Search in sources :

Example 1 with ReactorResult

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

the class ReactorMetabolismTest method metabolize.

protected boolean metabolize(String smiles) throws Exception {
    IAtomContainer mol = SmartsHelper.getMoleculeFromSmiles(smiles, true);
    ReactorResult result = reactor.react(mol);
    System.out.println(smiles + "  nodes = " + result.numReactorNodes);
    return (result.numSuccessNodes > 0);
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) ReactorResult(ambit2.reactions.reactor.ReactorResult)

Example 2 with ReactorResult

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

the class ReactorCli method runReactor.

protected int runReactor() throws Exception {
    if (inputSmiles == null)
        throw new Exception("Smiles not assigned! Use -s command line option.");
    if (reactorConfigFile == null)
        throw new Exception("Reactor configuratio file not assigned! Use -c command line option.");
    System.out.println("input smiles: " + inputSmiles);
    System.out.println("reactor config: " + reactorConfigFile);
    System.out.println("Setting reactor and reaction database...");
    Reactor reactor = new Reactor();
    ReactionDataBase reactDB = new ReactionDataBase(reactorConfigFile);
    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(reactorConfigFile));
    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);
    IAtomContainer mol = SmartsHelper.getMoleculeFromSmiles(inputSmiles, true);
    System.out.println();
    System.out.println("Reactor on target: " + inputSmiles);
    System.out.println();
    ReactorResult result = reactor.react(mol);
    return 0;
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) ReactorResult(ambit2.reactions.reactor.ReactorResult) ReactorStrategy(ambit2.reactions.reactor.ReactorStrategy) ReactionDataBase(ambit2.reactions.ReactionDataBase) Reactor(ambit2.reactions.reactor.Reactor) File(java.io.File)

Example 3 with ReactorResult

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

the class Reactor method generateChildrenNodes.

int generateChildrenNodes(ReactorNode node, IAtomContainer reagent) throws EmptyMoleculeException {
    int numOfReactionInstances = 0;
    for (int i = 0; i < reactionDataBase.genericReactions.size(); i++) {
        GenericReaction reaction = reactionDataBase.genericReactions.get(i);
        List<List<IAtom>> instances = reaction.findReactionInstances(reagent, smrkMan);
        // Check reaction conditions
        if (strategy.FlagCheckReactionConditions)
            if (reaction.getConditions() != null) {
                ReactorInfoPack ri = new ReactorInfoPack();
                ri.reactor = this;
                ri.reaction = reaction;
                ri.reagent = reagent;
                if (!reaction.checkConditionsForTarget(ri))
                    continue;
            }
        numOfReactionInstances += instances.size();
        for (int k = 0; k < instances.size(); k++) {
            List<IAtom> instance = instances.get(k);
            IAtomContainer products = null;
            try {
                products = reaction.applyAtInstance(reagent, instance, smrkMan, true);
            } catch (Exception x) {
                logger.severe("Reaction application error: " + reaction.getName() + "  " + reaction.getSmirks() + "  applied for reagent " + molToSmiles(reagent) + "   " + x.getMessage());
            }
            if (products == null)
                continue;
            if (smrkMan.isFlagProcessResultStructures()) {
                try {
                    smrkMan.processProduct(products);
                } catch (Exception e) {
                }
            }
            // System.out.println("Reaction: " + reaction.getSmirks()+"\n" + "Products: " + molToSmiles(products));
            IAtomContainerSet productsSet = ConnectivityChecker.partitionIntoMolecules(products);
            ReactorNode newNode = node.clone();
            // Update reactorResult status
            reactorResult.numReactions++;
            reactorResult.numReactorNodes++;
            // newNode.level = ...
            if (strategy.FlagTraceParentNodes)
                newNode.parentNode = node;
            if (strategy.FlagTraceReactionPath)
                setReactionPath(productsSet, reagent, reaction);
            addReagents(newNode, productsSet);
            if (strategy.FlagCheckNodeDuplicationOnPush) {
                String hash = newNode.calcNodeHash();
                if (!nodeHashCodes.contains(hash)) {
                    nodeHashCodes.add(hash);
                    reactorNodes.push(newNode);
                }
            } else
                reactorNodes.push(newNode);
        }
    }
    if (numOfReactionInstances == 0) {
        // No reaction was applied then moving the reagent to finalized/forbidden/allowed products
        ReactorNode newNode = node.clone();
        finalizeProduct(newNode, reagent);
        // updateNodeState(newNode);
        reactorNodes.push(newNode);
        reactorResult.numReactorNodes++;
    }
    return numOfReactionInstances;
}
Also used : GenericReaction(ambit2.reactions.GenericReaction) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) ArrayList(java.util.ArrayList) List(java.util.List) IAtom(org.openscience.cdk.interfaces.IAtom) EmptyMoleculeException(ambit2.base.exceptions.EmptyMoleculeException)

Example 4 with ReactorResult

use of ambit2.reactions.reactor.ReactorResult 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");
        }
    }
}
Also used : GenericReaction(ambit2.reactions.GenericReaction) ReactorNode(ambit2.reactions.reactor.ReactorNode) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) ReactorResult(ambit2.reactions.reactor.ReactorResult) ReactorStrategy(ambit2.reactions.reactor.ReactorStrategy) ReactionDataBase(ambit2.reactions.ReactionDataBase) Reactor(ambit2.reactions.reactor.Reactor) File(java.io.File)

Aggregations

IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)4 ReactorResult (ambit2.reactions.reactor.ReactorResult)3 GenericReaction (ambit2.reactions.GenericReaction)2 ReactionDataBase (ambit2.reactions.ReactionDataBase)2 Reactor (ambit2.reactions.reactor.Reactor)2 ReactorStrategy (ambit2.reactions.reactor.ReactorStrategy)2 File (java.io.File)2 EmptyMoleculeException (ambit2.base.exceptions.EmptyMoleculeException)1 ReactorNode (ambit2.reactions.reactor.ReactorNode)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 IAtom (org.openscience.cdk.interfaces.IAtom)1 IAtomContainerSet (org.openscience.cdk.interfaces.IAtomContainerSet)1