Search in sources :

Example 1 with Reactor

use of ambit2.reactions.reactor.Reactor 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 2 with Reactor

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

Example 3 with Reactor

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

the class ReactorMetabolismTest method setupReactor.

protected void setupReactor() throws Exception {
    reactor = new Reactor();
    // Object o = new Object();
    URL resource = reactor.getClass().getClassLoader().getResource("ambit2/reactions/metabolism-reactions.json");
    ReactionDataBase reactDB = new ReactionDataBase(resource.getFile());
    // reactDB.configureReactions(reactor.getSMIRKSManager());
    reactDB.configureGenericReactions(reactor.getSMIRKSManager());
    reactor.setReactionDataBase(reactDB);
    // strategy is in the same file
    ReactorStrategy strategy = new ReactorStrategy(new File(resource.getFile()));
    strategy.maxNumOfNodes = 140000;
    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 = false;
    strategy.FlagLogReactionPath = false;
    strategy.FlagLogNameInReactionPath = false;
    strategy.FlagLogExplicitHToImplicit = true;
    strategy.FlagLogNumberOfProcessedNodes = true;
    reactor.setStrategy(strategy);
    // Setup Smirks manager
    reactor.getSMIRKSManager().setFlagProcessResultStructures(true);
    reactor.getSMIRKSManager().setFlagClearImplicitHAtomsBeforeResultProcess(false);
    reactor.getSMIRKSManager().setFlagAddImplicitHAtomsOnResultProcess(false);
    reactor.getSMIRKSManager().setFlagConvertExplicitHToImplicitOnResultProcess(false);
}
Also used : ReactorStrategy(ambit2.reactions.reactor.ReactorStrategy) ReactionDataBase(ambit2.reactions.ReactionDataBase) Reactor(ambit2.reactions.reactor.Reactor) File(java.io.File) URL(java.net.URL)

Aggregations

ReactionDataBase (ambit2.reactions.ReactionDataBase)3 Reactor (ambit2.reactions.reactor.Reactor)3 ReactorStrategy (ambit2.reactions.reactor.ReactorStrategy)3 File (java.io.File)3 ReactorResult (ambit2.reactions.reactor.ReactorResult)2 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)2 GenericReaction (ambit2.reactions.GenericReaction)1 ReactorNode (ambit2.reactions.reactor.ReactorNode)1 URL (java.net.URL)1