Search in sources :

Example 1 with SMIRKSReaction

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);
    }
}
Also used : SMIRKSReaction(ambit2.smarts.SMIRKSReaction) SmilesParser(org.openscience.cdk.smiles.SmilesParser) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) SMIRKSManager(ambit2.smarts.SMIRKSManager) CDKHydrogenAdder(org.openscience.cdk.tools.CDKHydrogenAdder) ResourceException(org.restlet.resource.ResourceException) Dimension(java.awt.Dimension) BufferedImage(java.awt.image.BufferedImage) ResourceException(org.restlet.resource.ResourceException)

Example 2 with SMIRKSReaction

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;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) AtomConfigurator(ambit2.core.processors.structure.AtomConfigurator) AmbitException(net.idea.modbcum.i.exceptions.AmbitException)

Example 3 with SMIRKSReaction

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;
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) AtomConfigurator(ambit2.core.processors.structure.AtomConfigurator) IAtom(org.openscience.cdk.interfaces.IAtom)

Example 4 with SMIRKSReaction

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;
}
Also used : SMIRKSReaction(ambit2.smarts.SMIRKSReaction)

Example 5 with SMIRKSReaction

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);
}
Also used : SMIRKSReaction(ambit2.smarts.SMIRKSReaction)

Aggregations

SMIRKSReaction (ambit2.smarts.SMIRKSReaction)12 SMIRKSManager (ambit2.smarts.SMIRKSManager)10 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)10 ArrayList (java.util.ArrayList)4 IAtomContainerSet (org.openscience.cdk.interfaces.IAtomContainerSet)4 AtomConfigurator (ambit2.core.processors.structure.AtomConfigurator)3 IAtom (org.openscience.cdk.interfaces.IAtom)3 List (java.util.List)2 IBond (org.openscience.cdk.interfaces.IBond)2 SmilesParser (org.openscience.cdk.smiles.SmilesParser)2 HydrogenAdderProcessor (ambit2.core.processors.structure.HydrogenAdderProcessor)1 DBStereo (ambit2.smarts.DoubleBondStereoInfo.DBStereo)1 Dimension (java.awt.Dimension)1 BufferedImage (java.awt.image.BufferedImage)1 AmbitException (net.idea.modbcum.i.exceptions.AmbitException)1 Aromaticity (org.openscience.cdk.aromaticity.Aromaticity)1 CDKException (org.openscience.cdk.exception.CDKException)1 Conformation (org.openscience.cdk.interfaces.IDoubleBondStereochemistry.Conformation)1 IStereoElement (org.openscience.cdk.interfaces.IStereoElement)1 Stereo (org.openscience.cdk.interfaces.ITetrahedralChirality.Stereo)1