Search in sources :

Example 1 with IQueryAtomContainer

use of org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer in project ambit-mirror by ideaconsult.

the class QuerySMARTS method prepareScreening.

public void prepareScreening() throws AmbitException {
    try {
        if (((screening.getValue() == null) && isFp1024_screening()) || ((screening.getFieldname() == null)) && isSk1024_screening()) {
            // if ((screening.getValue()==null) || (screening.getFieldname()==null)) {
            screening.setPageSize(0);
            screening.setPage(0);
            SmartsPatternAmbit matcher = new SmartsPatternAmbit(builder);
            matcher.setUseCDKIsomorphism(false);
            value.setQuery(matcher);
            IQueryAtomContainer container = matcher.getQuery();
            IAtomContainer atomContainer = smartsToChemObject.process(container);
            try {
                AtomConfigurator cfg = new AtomConfigurator();
                cfg.process(atomContainer);
            } catch (Exception x) {
                logger.log(Level.FINE, x.getMessage(), x);
            }
            try {
                CDKHueckelAromaticityDetector.detectAromaticity(atomContainer);
            } catch (Exception x) {
                logger.log(Level.FINE, x.getMessage(), x);
            }
            if ((atomContainer == null) || (atomContainer.getAtomCount() == 0)) {
                screening.setValue(null);
                screening.setFieldname(null);
            } else {
                try {
                    screening.setValue(fp1024_screening ? fpGenerator.process(atomContainer) : null);
                } catch (Exception x) {
                    screening.setValue(null);
                }
                try {
                    screening.setFieldname(sk1024_screening ? skGenerator.process(atomContainer) : null);
                } catch (Exception x) {
                    screening.setFieldname(null);
                }
            }
        }
    } catch (AmbitException x) {
        throw x;
    // screening.setValue(null);
    // screening.setFieldname(null);
    }
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) SmartsPatternAmbit(ambit2.smarts.query.SmartsPatternAmbit) AtomConfigurator(ambit2.core.processors.structure.AtomConfigurator) IQueryAtomContainer(org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) AmbitException(net.idea.modbcum.i.exceptions.AmbitException)

Example 2 with IQueryAtomContainer

use of org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer in project ambit-mirror by ideaconsult.

the class SLN2ChemObject method slnContainerToQueryAtomContainer.

public IQueryAtomContainer slnContainerToQueryAtomContainer(SLNContainer slnContainer) {
    clearAllErrorsAndWarnings();
    IQueryAtomContainer container = new QueryAtomContainer(SilentChemObjectBuilder.getInstance());
    Map<SLNAtom, IQueryAtom> convertedAtoms = new HashMap<SLNAtom, IQueryAtom>();
    for (int i = 0; i < slnContainer.getAtomCount(); i++) {
        SLNAtom slnAtom = (SLNAtom) slnContainer.getAtom(i);
        IQueryAtom atom = slnAtomToQueryAtom(slnAtom);
        if (currentConversionWarning != null)
            conversionWarnings.add(currentConversionWarning + " for atom: " + (i + 1));
        if (atom == null) {
            conversionErrors.add(currentConversionError + " for atom: " + (i + 1));
            continue;
        }
        container.addAtom(atom);
        convertedAtoms.put(slnAtom, atom);
    }
    for (int i = 0; i < slnContainer.getBondCount(); i++) {
        SLNBond slnBbond = (SLNBond) slnContainer.getBond(i);
        IQueryBond bond = slnBondToQueryBond(slnBbond);
        if (currentConversionWarning != null)
            conversionWarnings.add(currentConversionWarning + " for bond: " + (i + 1));
        if (bond == null) {
            conversionErrors.add(currentConversionError + " for bond: " + (i + 1));
            continue;
        }
        IAtom[] newAtoms = new IAtom[2];
        newAtoms[0] = convertedAtoms.get(slnBbond.getAtom(0));
        newAtoms[1] = convertedAtoms.get(slnBbond.getAtom(1));
        if (newAtoms[0] == null || newAtoms[1] == null)
            // one of the atoms is not converted
            continue;
        bond.setAtoms(newAtoms);
        container.addBond(bond);
    }
    return container;
}
Also used : HashMap(java.util.HashMap) IQueryAtom(org.openscience.cdk.isomorphism.matchers.IQueryAtom) SLNBond(ambit2.sln.SLNBond) SLNAtom(ambit2.sln.SLNAtom) IQueryBond(org.openscience.cdk.isomorphism.matchers.IQueryBond) IQueryAtomContainer(org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer) QueryAtomContainer(org.openscience.cdk.isomorphism.matchers.QueryAtomContainer) IQueryAtomContainer(org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer) IAtom(org.openscience.cdk.interfaces.IAtom)

Example 3 with IQueryAtomContainer

use of org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer in project ambit-mirror by ideaconsult.

the class SLN2SMARTS method slnToSmarts.

public String slnToSmarts(String sln) {
    reset();
    SLNContainer container = slnParser.parse(sln);
    String parserErr = slnParser.getErrorMessages();
    if (!parserErr.equals("")) {
        conversionErrors.add(parserErr);
        return null;
    }
    IQueryAtomContainer query = slnConverter.slnContainerToQueryAtomContainer(container);
    String smarts = smartsHelper.toSmarts(query);
    conversionErrors.addAll(slnConverter.getConversionErrors());
    conversionWarnings.addAll(slnConverter.getConversionWarnings());
    return smarts;
}
Also used : SLNContainer(ambit2.sln.SLNContainer) IQueryAtomContainer(org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer)

Example 4 with IQueryAtomContainer

use of org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer in project ambit-mirror by ideaconsult.

the class SMIRKSManager method parse.

public SMIRKSReaction parse(String smirks) {
    parserErrors.clear();
    SMIRKSReaction reaction = new SMIRKSReaction(stco.getBuilder());
    // Separate the components of the SMIRKS string
    int sep1Pos = smirks.indexOf(">");
    if (sep1Pos == -1) {
        parserErrors.add("Invalid SMIRKS: missing separators '>'");
        return reaction;
    }
    int sep2Pos = smirks.indexOf(">", sep1Pos + 1);
    if (sep2Pos == -1) {
        parserErrors.add("Invalid SMIRKS: missing second separator '>'");
        return reaction;
    }
    // Parse the components
    int res = 0;
    IQueryAtomContainer fragment;
    reaction.reactantsSmarts = smirks.substring(0, sep1Pos).trim();
    fragment = parseComponent(reaction.reactantsSmarts, "Reactants", reaction.reactantFlags, reaction.reactants, reaction.reactantCLG);
    if (fragment == null)
        res++;
    else {
        reaction.reactant = fragment;
        if (reaction.reactantFlags.hasRecursiveSmarts)
            reaction.reactantRecursiveAtoms = getRecursiveAtoms(fragment);
    }
    reaction.agentsSmarts = smirks.substring(sep1Pos + 1, sep2Pos).trim();
    if (!reaction.agentsSmarts.equals("")) {
        fragment = parseComponent(reaction.agentsSmarts, "Agents", reaction.agentFlags, reaction.agents, reaction.agentsCLG);
        if (fragment == null)
            res++;
        else
            reaction.agent = fragment;
    }
    reaction.productsSmarts = smirks.substring(sep2Pos + 1).trim();
    fragment = parseComponent(reaction.productsSmarts, "Products", reaction.productFlags, reaction.products, reaction.productsCLG);
    if (fragment == null)
        res++;
    else {
        reaction.product = fragment;
        if (reaction.productFlags.hasRecursiveSmarts)
            reaction.productRecursiveAtoms = getRecursiveAtoms(fragment);
    }
    if (res > 0)
        return reaction;
    reaction.checkMappings();
    // Check for mapping errors
    if (reaction.mapErrors.size() > 0) {
        parserErrors.addAll(reaction.mapErrors);
        return (reaction);
    }
    reaction.generateTransformationData(FlagAromaticityTransformation);
    if (reaction.mapErrors.isEmpty()) {
        // Handle stereo transformation
        if (FlagApplyStereoTransformation) {
            reaction.generateStereoTransformation();
        // reaction.checkStereoTransformation();
        }
        // Handle H atom transformation
        if (FlagHAtomsTransformation)
            reaction.generateHAtomTransformation();
    }
    // Check for errors produced by the generation of transformation data
    if (reaction.mapErrors.size() > 0) {
        parserErrors.addAll(reaction.mapErrors);
        return (reaction);
    }
    return reaction;
}
Also used : IQueryAtomContainer(org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer)

Example 5 with IQueryAtomContainer

use of org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer in project ambit-mirror by ideaconsult.

the class SMIRKSManager method parseComponent.

public IQueryAtomContainer parseComponent(String smarts, String compType, SmartsFlags flags, List<IQueryAtomContainer> fragments, List<Integer> CLG) {
    IQueryAtomContainer fragment = parser.parse(smarts);
    parser.setNeededDataFlags();
    String errorMsg = parser.getErrorMessages();
    if (!errorMsg.equals("")) {
        parserErrors.add("Invalid " + compType + " part in SMIRKS: " + smarts + "   " + errorMsg);
        return (null);
    }
    flags.hasRecursiveSmarts = parser.hasRecursiveSmarts;
    flags.mNeedExplicitHData = parser.needExplicitHData();
    flags.mNeedNeighbourData = parser.needNeighbourData();
    flags.mNeedParentMoleculeData = parser.needParentMoleculeData();
    flags.mNeedRingData = parser.needRingData();
    flags.mNeedRingData2 = parser.needRingData2();
    flags.mNeedValenceData = parser.needValencyData();
    for (int i = 0; i < parser.fragments.size(); i++) fragments.add(parser.fragments.get(i));
    for (int i = 0; i < parser.fragmentComponents.size(); i++) CLG.add(parser.fragmentComponents.get(i));
    return (fragment);
}
Also used : IQueryAtomContainer(org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer)

Aggregations

IQueryAtomContainer (org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer)124 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)61 Test (org.junit.Test)40 ArrayList (java.util.ArrayList)37 IAtom (org.openscience.cdk.interfaces.IAtom)35 IAtomContainerSet (org.openscience.cdk.interfaces.IAtomContainerSet)26 IReactionSet (org.openscience.cdk.interfaces.IReactionSet)26 IReactionProcess (org.openscience.cdk.reaction.IReactionProcess)26 ReactionProcessTest (org.openscience.cdk.reaction.ReactionProcessTest)26 IParameterReact (org.openscience.cdk.reaction.type.parameters.IParameterReact)26 SetReactionCenter (org.openscience.cdk.reaction.type.parameters.SetReactionCenter)26 UniversalIsomorphismTester (org.openscience.cdk.isomorphism.UniversalIsomorphismTester)23 CDKException (org.openscience.cdk.exception.CDKException)20 QueryAtomContainer (org.openscience.cdk.isomorphism.matchers.QueryAtomContainer)18 IBond (org.openscience.cdk.interfaces.IBond)14 IQueryAtom (org.openscience.cdk.isomorphism.matchers.IQueryAtom)12 List (java.util.List)9 IQueryBond (org.openscience.cdk.isomorphism.matchers.IQueryBond)9 SmilesParser (org.openscience.cdk.smiles.SmilesParser)9 InputStream (java.io.InputStream)7