Search in sources :

Example 1 with ReactionDataBase

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

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

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

Example 4 with ReactionDataBase

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

the class ReactionTestUtils method testReactionDataBase.

public static void testReactionDataBase(String reactionDBFileName) throws Exception {
    ReactionDataBase rdb = new ReactionDataBase(reactionDBFileName);
    System.out.println("Reading reaction database: " + reactionDBFileName);
    if (!rdb.errors.isEmpty()) {
        System.out.println("Errors:");
        for (int i = 0; i < rdb.errors.size(); i++) System.out.println(rdb.errors.get(i));
    }
    for (int i = 0; i < rdb.genericReactions.size(); i++) {
        GenericReaction r = rdb.genericReactions.get(i);
        System.out.println(r.toString());
    }
    SMIRKSManager smrkMan = new SMIRKSManager(SilentChemObjectBuilder.getInstance());
    rdb.configureGenericReactions(smrkMan);
    if (!rdb.errors.isEmpty()) {
        System.out.println("Reaction config errors:");
        for (int i = 0; i < rdb.errors.size(); i++) System.out.println(rdb.errors.get(i));
    }
}
Also used : GenericReaction(ambit2.reactions.GenericReaction) SMIRKSManager(ambit2.smarts.SMIRKSManager) ReactionDataBase(ambit2.reactions.ReactionDataBase)

Example 5 with ReactionDataBase

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

ReactionDataBase (ambit2.reactions.ReactionDataBase)5 Reactor (ambit2.reactions.reactor.Reactor)3 ReactorStrategy (ambit2.reactions.reactor.ReactorStrategy)3 File (java.io.File)3 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)3 GenericReaction (ambit2.reactions.GenericReaction)2 ReactorResult (ambit2.reactions.reactor.ReactorResult)2 SMIRKSManager (ambit2.smarts.SMIRKSManager)2 ReactorNode (ambit2.reactions.reactor.ReactorNode)1 ReactionSequence (ambit2.reactions.retrosynth.ReactionSequence)1 ReactionSequenceLevel (ambit2.reactions.retrosynth.ReactionSequenceLevel)1 StartingMaterialsDataBase (ambit2.reactions.retrosynth.StartingMaterialsDataBase)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1