use of ambit2.reactions.reactor.ReactorStrategy in project ambit-mirror by ideaconsult.
the class ReactorStrategy method readReactorStrategyFromJsonNode.
public static ReactorStrategy readReactorStrategyFromJsonNode(JsonNode node, ReactorStrategy reactorStrategy) throws Exception {
ReactorStrategy strategy = reactorStrategy;
if (strategy == null)
strategy = new ReactorStrategy();
strategy.maxNumOfReactions = JSONParsingUtils.extractIntKeyword(node, "MAX_NUM_OF_REACTIONS", true);
strategy.maxLevel = JSONParsingUtils.extractIntKeyword(node, "MAX_LEVEL", true);
strategy.allowedProducts = JSONParsingUtils.getStructureRecords(node, "ALLOWED_PRODUCTS_SMILES", STRUCTURE_RECORD_INPUT_INFO.smiles, false);
strategy.forbiddenProducts = JSONParsingUtils.getStructureRecords(node, "FORBIDDEN_PRODUCTS_SMILES", STRUCTURE_RECORD_INPUT_INFO.smiles, false);
List<INCHI_OPTION> options = new ArrayList<INCHI_OPTION>();
options.add(INCHI_OPTION.FixedH);
options.add(INCHI_OPTION.SAbs);
options.add(INCHI_OPTION.SAsXYZ);
options.add(INCHI_OPTION.SPXYZ);
options.add(INCHI_OPTION.FixSp3Bug);
InChIGeneratorFactory igf = InChIGeneratorFactory.getInstance();
// Configure products
if (strategy.allowedProducts != null)
for (StructureRecord sr : strategy.allowedProducts) configureStructureRecord(sr, igf, options);
if (strategy.forbiddenProducts != null)
for (StructureRecord sr : strategy.forbiddenProducts) configureStructureRecord(sr, igf, options);
return strategy;
}
use of ambit2.reactions.reactor.ReactorStrategy 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;
}
use of ambit2.reactions.reactor.ReactorStrategy 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");
}
}
}
use of ambit2.reactions.reactor.ReactorStrategy 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);
}
Aggregations