use of ambit2.smarts.SMIRKSReaction in project ambit-mirror by ideaconsult.
the class SMIRKSDepict method getImage.
@Override
protected BufferedImage getImage(String smiles, int w, int h, String recordType, QueryType type) throws ResourceException {
try {
String smirks = getSmirks();
if (smirks == null || "".equals(smirks))
throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST);
depict.setImageSize(new Dimension(w, h));
SMIRKSManager smrkMan = new SMIRKSManager(SilentChemObjectBuilder.getInstance());
smrkMan.setFlagProcessResultStructures(true);
smrkMan.setSSMode(SmartsConst.SSM_MODE.SSM_NON_IDENTICAL_FIRST);
SMIRKSReaction smr = smrkMan.parse(smirks);
SmilesParser parser = new SmilesParser(SilentChemObjectBuilder.getInstance());
IAtomContainer reactant = parser.parseSmiles(smiles);
reactant = AtomContainerManipulator.removeHydrogens(reactant);
AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(reactant);
CDKHydrogenAdder adder = CDKHydrogenAdder.getInstance(SilentChemObjectBuilder.getInstance());
CDKHueckelAromaticityDetector.detectAromaticity(reactant);
adder.addImplicitHydrogens(reactant);
HydrogenAdderProcessor.convertImplicitToExplicitHydrogens(reactant);
BufferedImage image = null;
if (smrkMan.applyTransformation(reactant, this, smr)) {
image = depict.getImage(reactant, null, true, false);
} else {
list.add("Not applicable");
image = depict.getImage(list);
}
smr = null;
smrkMan = null;
return image;
} catch (ResourceException x) {
throw x;
} catch (Exception x) {
throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, x.getMessage(), x);
}
}
use of ambit2.smarts.SMIRKSReaction in project ambit-mirror by ideaconsult.
the class SMIRKSManager method applyTransformation.
public boolean applyTransformation(IAtomContainer target, IAcceptable selection, SMIRKSReaction reaction) throws Exception {
SmartsParser.prepareTargetForSMARTSSearch(reaction.reactantFlags, target);
if (reaction.reactantFlags.hasRecursiveSmarts)
mapRecursiveAtomsAgainstTarget(reaction.reactantRecursiveAtoms, target);
// It is absolutely needed that setQuery() function is called after
// recursive atom mapping
// because the recursive mapping calls setQuery() as well
isoTester.setQuery(reaction.reactant);
if (FlagSSMode == SmartsConst.SSM_MODE.SSM_SINGLE) {
// TODO - currently nothing is done
return false;
}
if (FlagSSMode == SmartsConst.SSM_MODE.SSM_NON_IDENTICAL) {
List<List<IAtom>> rMaps = getNonIdenticalMappings(target);
if (rMaps.size() == 0)
return false;
if (FlagFilterEquivalentMappings) {
eqTester.setTarget(target);
eqTester.quickFindEquivalentTerminalHAtoms();
rMaps = eqTester.filterEquivalentMappings(rMaps);
}
boolean applied = false;
for (int i = 0; i < rMaps.size(); i++) {
if ((selection == null) || ((selection != null) && (selection.accept(rMaps.get(i))))) {
applyTransformAtLocation(target, rMaps.get(i), reaction);
applied = true;
}
}
AtomConfigurator cfg = new AtomConfigurator();
try {
cfg.process(target);
} catch (AmbitException e) {
throw e;
}
if (FlagProcessResultStructures)
processProduct(target);
if (FlagCheckResultStereo)
StereoChemUtils.checkStereoElements(target);
return applied;
}
if (FlagSSMode == SmartsConst.SSM_MODE.SSM_NON_IDENTICAL_FIRST) {
List<List<IAtom>> rMaps = getNonIdenticalMappings(target);
if (rMaps.size() == 0)
return false;
// Map filtering here is not needed
boolean applied = false;
for (int i = 0; i < rMaps.size(); i++) {
if ((selection == null) || ((selection != null) && (selection.accept(rMaps.get(i))))) {
applyTransformAtLocation(target, rMaps.get(i), reaction);
applied = true;
// The first acceptable is found and stopped
AtomConfigurator cfg = new AtomConfigurator();
try {
cfg.process(target);
} catch (AmbitException e) {
throw e;
}
if (FlagProcessResultStructures)
processProduct(target);
if (FlagCheckResultStereo)
StereoChemUtils.checkStereoElements(target);
return applied;
}
}
return applied;
}
if (FlagSSMode == SmartsConst.SSM_MODE.SSM_NON_OVERLAPPING) {
List<List<IAtom>> rMaps = getNonOverlappingMappings(target);
if (rMaps.size() == 0)
return false;
// Map filtering here is applied here (it should be not needed)
boolean applied = false;
for (int i = 0; i < rMaps.size(); i++) {
if ((selection == null) || ((selection != null) && (selection.accept(rMaps.get(i))))) {
applyTransformAtLocation(target, rMaps.get(i), reaction);
applied = true;
}
}
AtomConfigurator cfg = new AtomConfigurator();
cfg.process(target);
if (FlagProcessResultStructures)
processProduct(target);
if (FlagCheckResultStereo)
StereoChemUtils.checkStereoElements(target);
return applied;
}
return false;
}
use of ambit2.smarts.SMIRKSReaction in project ambit-mirror by ideaconsult.
the class SMIRKSManager method applyTransformationsAtLocationsWithCloning.
public IAtomContainer applyTransformationsAtLocationsWithCloning(IAtomContainer target, List<List<IAtom>> rMaps, SMIRKSReaction reaction) throws Exception {
// Create a target clone
IAtomContainer clone = getCloneStructure(target);
// Create mappings clones (according to the new atoms of the clone)
List<List<IAtom>> cloneMaps = new ArrayList<List<IAtom>>();
for (int i = 0; i < rMaps.size(); i++) cloneMaps.add(getCloneMapping(target, clone, rMaps.get(i)));
// Apply transformation
for (int i = 0; i < cloneMaps.size(); i++) this.applyTransformAtLocation(clone, cloneMaps.get(i), reaction);
AtomConfigurator cfg = new AtomConfigurator();
cfg.process(clone);
return clone;
}
use of ambit2.smarts.SMIRKSReaction in project ambit-mirror by ideaconsult.
the class TestSMIRKS method applySMIRKSReaction.
IAtomContainer applySMIRKSReaction(String smirks, IAtomContainer target) throws Exception {
smrkMan.setFlagApplyStereoTransformation(FlagApplyStereoTransformation);
SMIRKSReaction reaction = smrkMan.parse(smirks);
if (!smrkMan.getErrors().equals("")) {
throw (new Exception("Smirks Parser errors:\n" + smrkMan.getErrors()));
}
if (smrkMan.applyTransformation(target, reaction))
// all products inside the atomcontainer, could be
return target;
else
return null;
}
use of ambit2.smarts.SMIRKSReaction in project ambit-mirror by ideaconsult.
the class ReactionSearch method matchReaction.
public boolean matchReaction(String targetSmirks) {
SMIRKSReaction targetReaction = smirksMan.parse(targetSmirks);
String parse_error = smirksMan.getErrors();
if (!parse_error.equals("")) {
errors.add("Target Smirks parsing errors: " + parse_error);
return false;
}
return matchReaction(targetReaction);
}
Aggregations