use of ambit2.smarts.SMIRKSManager 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.SMIRKSManager in project ambit-mirror by ideaconsult.
the class TestUtilities method testSMIRKS.
public void testSMIRKS(String smirks, String targetSmiles) throws Exception {
System.out.println("Testing SMIRKS: " + smirks);
SMIRKSManager smrkMan = new SMIRKSManager(SilentChemObjectBuilder.getInstance());
smrkMan.setFlagSSMode(FlagSSMode);
// Product processing flags
smrkMan.setFlagProcessResultStructures(FlagProductPreprocessing);
smrkMan.setFlagClearHybridizationBeforeResultProcess(FlagClearHybridizationOnProductPreProcess);
smrkMan.setFlagClearImplicitHAtomsBeforeResultProcess(this.FlagClearImplicitHAtomsBeforeProductPreProcess);
smrkMan.setFlagClearAromaticityBeforeResultProcess(this.FlagClearAromaticityBeforePreProcess);
smrkMan.setFlagAddImplicitHAtomsOnResultProcess(this.FlagAddImplicitHAtomsOnProductPreProcess);
smrkMan.setFlagConvertAddedImplicitHToExplicitOnResultProcess(this.FlagImplicitHToExplicitOnProductPreProcess);
smrkMan.setFlagConvertExplicitHToImplicitOnResultProcess(this.FlagExplicitHToImplicitOnProductPreProcess);
smrkMan.setFlagApplyStereoTransformation(FlagApplyStereoTransformation);
smrkMan.setFlagHAtomsTransformation(FlagHAtomsTransformation);
smrkMan.setFlagHAtomsTransformationMode(FlagHAtomsTransformationMode);
smrkMan.setFlagAromaticityTransformation(FlagAromaticityTransformation);
smrkMan.getSmartsParser().mSupportSingleBondAromaticityNotSpecified = FlagSingleBondAromaticityNotSpecified;
smrkMan.getSmartsParser().mSupportDoubleBondAromaticityNotSpecified = FlagDoubleBondAromaticityNotSpecified;
SMIRKSReaction reaction = smrkMan.parse(smirks);
if (!smrkMan.getErrors().equals("")) {
System.out.println(smrkMan.getErrors());
// System.out.println("\n" + reaction.transformationDataToString());
return;
}
if (FlagPrintTransformationData)
System.out.println(reaction.transformationDataToString());
if (targetSmiles.equals(""))
return;
IAtomContainer target = SmartsHelper.getMoleculeFromSmiles(targetSmiles);
if (FlagTargetPreprocessing)
this.preProcess(target);
if (FlagPrintAtomAttributes) {
System.out.println("Target (reactant):");
System.out.println("Reactant atom attributes:\n" + SmartsHelper.getAtomsAttributes(target));
System.out.println("Reactant bond attributes:\n" + SmartsHelper.getBondAttributes(target));
}
switch(FlagReactionOperation) {
case APPLY:
boolean res = smrkMan.applyTransformation(target, reaction);
if (FlagPrintAtomAttributes) {
System.out.println("Product:");
System.out.println("Product atom attributes:\n" + SmartsHelper.getAtomsAttributes(target));
System.out.println("Product bond attributes:\n" + SmartsHelper.getBondAttributes(target));
}
System.out.println(" " + SmartsHelper.moleculeToSMILES(target, true));
String transformedSmiles = SmartsHelper.moleculeToSMILES(target, true);
if (res) {
System.out.println("Reaction application: " + targetSmiles + " --> " + transformedSmiles + " abs. smiles res " + SmilesGenerator.absolute().create(target));
} else
System.out.println("Reaction not appicable!");
break;
case CombinedOverlappedPos:
IAtomContainerSet resSet = smrkMan.applyTransformationWithCombinedOverlappedPos(target, null, reaction);
if (resSet == null)
System.out.println("Reaction not appicable!");
else {
System.out.println("Reaction application With Combined Overlapped Positions: ");
for (int i = 0; i < resSet.getAtomContainerCount(); i++) System.out.println(SmartsHelper.moleculeToSMILES(resSet.getAtomContainer(i), true));
}
break;
case SingleCopyForEachPos:
IAtomContainerSet resSet2 = smrkMan.applyTransformationWithSingleCopyForEachPos(target, null, reaction, FlagSSModeForSingleCopyForEachPos);
if (resSet2 == null)
System.out.println("Reaction not appicable!");
else {
System.out.println("Reaction application With Single Copy For Each Position: ");
for (int i = 0; i < resSet2.getAtomContainerCount(); i++) System.out.println(SmartsHelper.moleculeToSMILES(resSet2.getAtomContainer(i), true));
}
break;
}
System.out.println();
}
use of ambit2.smarts.SMIRKSManager in project ambit-mirror by ideaconsult.
the class TestUtilities method testSMIRKS_.
// This is the old variant
public void testSMIRKS_(String smirks, String targetSmiles) throws Exception {
System.out.println("Testing SMIRKS: " + smirks);
SMIRKSManager smrkMan = new SMIRKSManager(SilentChemObjectBuilder.getInstance());
smrkMan.setFlagSSMode(FlagSSMode);
smrkMan.getSmartsParser().mSupportSingleBondAromaticityNotSpecified = FlagSingleBondAromaticityNotSpecified;
smrkMan.getSmartsParser().mSupportDoubleBondAromaticityNotSpecified = FlagDoubleBondAromaticityNotSpecified;
SMIRKSReaction reaction = smrkMan.parse(smirks);
if (!smrkMan.getErrors().equals("")) {
System.out.println(smrkMan.getErrors());
// System.out.println("Product Atoms: "+SmartsHelper.getAtomsExpressionTokens(reaction.product));
return;
}
if (FlagPrintTransformationData)
System.out.println(reaction.transformationDataToString());
if (targetSmiles.equals(""))
return;
IAtomContainer target = SmartsHelper.getMoleculeFromSmiles(targetSmiles);
if (FlagTargetPreprocessing)
this.preProcess(target);
if (FlagPrintAtomAttributes) {
System.out.println("Reactant atom attributes:\n" + SmartsHelper.getAtomsAttributes(target));
System.out.println("Reactant bond attributes:\n" + SmartsHelper.getBondAttributes(target));
}
boolean res = smrkMan.applyTransformation(target, reaction);
if (FlagPrintAtomAttributes) {
System.out.println("Product before pre-processiong:");
System.out.println("Product atom attributes:\n" + SmartsHelper.getAtomsAttributes(target));
System.out.println("Product bond attributes:\n" + SmartsHelper.getBondAttributes(target));
}
System.out.println(" " + SmartsHelper.moleculeToSMILES(target, true));
if (FlagProductPreprocessing)
this.preProcessProduct(target);
if (FlagPrintAtomAttributes) {
System.out.println("Product after pre-processiong:");
System.out.println("Product atom attributes:\n" + SmartsHelper.getAtomsAttributes(target));
System.out.println("Product bond attributes:\n" + SmartsHelper.getBondAttributes(target));
}
String transformedSmiles = SmartsHelper.moleculeToSMILES(target, true);
if (res)
System.out.println("Reaction application: " + targetSmiles + " --> " + transformedSmiles);
else
System.out.println("Reaction not appicable!");
}
use of ambit2.smarts.SMIRKSManager in project ambit-mirror by ideaconsult.
the class TestStrVisualizer method testSMIRKS.
public void testSMIRKS(String smirks, IAtomContainer target) throws Exception {
System.out.println("Testing SMIRKS: " + smirks);
SMIRKSManager smrkMan = new SMIRKSManager(SilentChemObjectBuilder.getInstance());
smrkMan.setFlagFilterEquivalentMappings(filterEqMaps);
smrkMan.setSSMode(SmartsConst.SSM_MODE.SSM_NON_IDENTICAL);
SMIRKSReaction reaction = smrkMan.parse(smirks);
if (!smrkMan.getErrors().equals("")) {
System.out.println(smrkMan.getErrors());
return;
}
System.out.println(reaction.transformationDataToString());
setFrame();
String targetSmiles = SmartsHelper.moleculeToSMILES(target, true);
addStructure((IAtomContainer) target.clone());
smrkMan.applyTransformation(target, reaction);
String transformedSmiles = SmartsHelper.moleculeToSMILES(target, true);
addStructure(target);
System.out.println("Reaction application: " + targetSmiles + " --> " + transformedSmiles);
}
use of ambit2.smarts.SMIRKSManager in project ambit-mirror by ideaconsult.
the class AutomaticSmirksTestUtilities method applySmirks.
public List<String> applySmirks(String smrk, String smi) {
try {
SMIRKSManager smrkMan = new SMIRKSManager(SilentChemObjectBuilder.getInstance());
smrkMan.setFlagSSMode(SmartsConst.SSM_MODE.SSM_NON_IDENTICAL_FIRST);
smrkMan.setFlagProcessResultStructures(true);
smrkMan.setFlagClearHybridizationBeforeResultProcess(true);
smrkMan.setFlagClearImplicitHAtomsBeforeResultProcess(true);
smrkMan.setFlagClearAromaticityBeforeResultProcess(true);
smrkMan.setFlagAddImplicitHAtomsOnResultProcess(true);
smrkMan.setFlagConvertAddedImplicitHToExplicitOnResultProcess(false);
smrkMan.setFlagConvertExplicitHToImplicitOnResultProcess(true);
smrkMan.getSmartsParser().mSupportDoubleBondAromaticityNotSpecified = false;
smrkMan.setFlagApplyStereoTransformation(true);
SMIRKSReaction reaction = smrkMan.parse(smrk);
if (!smrkMan.getErrors().equals(""))
throw new RuntimeException("Invalid SMIRKS: " + smrkMan.getErrors());
IAtomContainer target = smilesParser.parseSmiles(smi);
for (IAtom atom : target.atoms()) if (atom.getFlag(CDKConstants.ISAROMATIC))
atom.setFlag(CDKConstants.ISAROMATIC, false);
for (IBond bond : target.bonds()) if (bond.getFlag(CDKConstants.ISAROMATIC))
bond.setFlag(CDKConstants.ISAROMATIC, false);
// do not add Hs: https://sourceforge.net/p/cdk/mailman/message/34608714/
// AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(target);
// CDKHydrogenAdder adder = CDKHydrogenAdder.getInstance(SilentChemObjectBuilder.getInstance());
// adder.addImplicitHydrogens(target);
MoleculeTools.convertImplicitToExplicitHydrogens(target);
// for our project, we want to use daylight aromaticity
// CDKHueckelAromaticityDetector.detectAromaticity(target);
Aromaticity aromaticity = new Aromaticity(ElectronDonation.daylight(), Cycles.or(Cycles.all(), Cycles.edgeShort()));
aromaticity.apply(target);
IAtomContainerSet resSet2 = smrkMan.applyTransformationWithSingleCopyForEachPos(target, null, reaction, SmartsConst.SSM_MODE.SSM_ALL);
List<String> result = new ArrayList<String>();
if (resSet2 != null)
for (int i = 0; i < resSet2.getAtomContainerCount(); i++) {
IAtomContainer mol = resSet2.getAtomContainer(i);
AtomContainerManipulator.suppressHydrogens(mol);
String smiles = SmilesGenerator.absolute().create(mol);
result.add(smiles);
}
return result;
} catch (Exception e) {
System.err.println(e.getMessage());
System.err.println("SMIRKS " + smrk);
System.err.println("SMILES " + smi);
// e.printStackTrace();
return null;
}
}
Aggregations