Search in sources :

Example 1 with QueryAtomContainer

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

the class MoleculeEditAction method getMoleculeForEdit.

protected IAtomContainerSet getMoleculeForEdit(IAtomContainer atomContainer) throws Exception {
    if (atomContainer == null)
        return null;
    if (atomContainer instanceof QueryAtomContainer) {
        return null;
    }
    IAtomContainerSet molecules = ConnectivityChecker.partitionIntoMolecules(atomContainer);
    IAtomContainerSet m = new AtomContainerSet();
    for (int i = 0; i < molecules.getAtomContainerCount(); i++) {
        IAtomContainer a = molecules.getAtomContainer(i);
        if (!GeometryTools.has2DCoordinates(a)) {
            if (sdg == null)
                sdg = new StructureDiagramGenerator();
            sdg.setMolecule((IAtomContainer) a);
            sdg.generateCoordinates(new Vector2d(0, 1));
            molecules.replaceAtomContainer(i, sdg.getMolecule());
        }
        m.addAtomContainer(molecules.getAtomContainer(i));
    }
    if (// otherwise JChemPaint crashes
    m.getAtomContainerCount() == 0)
        m.addAtomContainer(MoleculeTools.newMolecule(DefaultChemObjectBuilder.getInstance()));
    return m;
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) Vector2d(javax.vecmath.Vector2d) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) QueryAtomContainer(org.openscience.cdk.isomorphism.matchers.QueryAtomContainer) AtomContainerSet(org.openscience.cdk.silent.AtomContainerSet) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) StructureDiagramGenerator(org.openscience.cdk.layout.StructureDiagramGenerator)

Example 2 with QueryAtomContainer

use of org.openscience.cdk.isomorphism.matchers.QueryAtomContainer 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 QueryAtomContainer

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

the class SmartsParser method newFragment.

void newFragment() {
    // A new fragments is started. It is inside
    numFragments++;
    // "current component"
    curFragment = new QueryAtomContainer(SilentChemObjectBuilder.getInstance());
    fragments.add(curFragment);
    fragmentComponents.add(new Integer(curComponent));
}
Also used : IQueryAtomContainer(org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer) QueryAtomContainer(org.openscience.cdk.isomorphism.matchers.QueryAtomContainer)

Example 4 with QueryAtomContainer

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

the class SmartsParser method parse.

public IQueryAtomContainer parse(String sm) {
    smarts = sm;
    container = new QueryAtomContainer(SilentChemObjectBuilder.getInstance());
    errors.clear();
    nullifyDataFlags();
    init();
    parse();
    return container;
}
Also used : IQueryAtomContainer(org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer) QueryAtomContainer(org.openscience.cdk.isomorphism.matchers.QueryAtomContainer)

Example 5 with QueryAtomContainer

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

the class SmartsParser method parse.

void parse() {
    while ((curChar < nChars) && (errors.size() == 0)) {
        if (Character.isLetter(smarts.charAt(curChar))) {
            parseAtom();
        } else if (Character.isDigit(smarts.charAt(curChar))) {
            parseAtomIndex();
        } else {
            // symbol '%' is handled by
            parseSpecialSymbol();
        // parseAtomIndex() as well
        }
    }
    // Treat unclosed brackets
    if (!brackets.empty())
        newError("There are unclosed brackets", -1, "");
    // Treat incorrectly used indexes
    if (indexes.size() != 0) {
        newError("There are unclosed ring indices", -1, "");
        Set<Integer> keys = indexes.keySet();
        for (Integer key : keys) newError("Ring index " + key + " is unclosed", -1, "");
    }
    if (directionalBonds.size() > 0)
        setDoubleBondsStereoInfo();
    // Handle chirality info
    List<SmartsAtomExpression> caList = new ArrayList<SmartsAtomExpression>();
    for (int i = 0; i < container.getAtomCount(); i++) if (container.getAtom(i) instanceof SmartsAtomExpression) {
        SmartsAtomExpression sa = (SmartsAtomExpression) container.getAtom(i);
        handleChirality(sa);
        if (sa.stereoTokenIndices != null) {
            checkChirality(sa, i);
            caList.add(sa);
        }
    }
    if (!caList.isEmpty())
        container.setProperty("ChiralAtoms", caList);
    setNeededDataFlags();
    // The global work variables are stored in order to use them again in
    // the recursion
    // and to preserve the original values for the code after recursion
    IQueryAtomContainer container0 = container;
    List<IQueryAtomContainer> fragments0 = fragments;
    List<Integer> fragmentComponents0 = fragmentComponents;
    // Handle recursive smarts
    for (int i = 0; i < container0.getAtomCount(); i++) {
        if (container0.getAtom(i) instanceof SmartsAtomExpression) {
            SmartsAtomExpression sa = (SmartsAtomExpression) container0.getAtom(i);
            for (int j = 0; j < sa.recSmartsStrings.size(); j++) {
                hasRecursiveSmarts = true;
                smarts = sa.recSmartsStrings.get(j);
                // New instances of the global working variables are created
                // for the recursion process
                // This is needed in order to not mess up the original
                // containers.
                // Generally within recursive SMARTS expression fragments
                // and component level groping do not make sense,
                // however in the current version the parser will parse this
                // information, but it will not be stored any where
                container = new QueryAtomContainer(SilentChemObjectBuilder.getInstance());
                fragments = new ArrayList<IQueryAtomContainer>();
                fragmentComponents = new ArrayList<Integer>();
                init();
                insideRecSmarts = true;
                parse();
                sa.recSmartsContainers.add(container);
                insideRecSmarts = false;
            }
        }
    }
    // Restoring the global work variables after recursion
    container = container0;
    fragments = fragments0;
    fragmentComponents = fragmentComponents0;
}
Also used : ArrayList(java.util.ArrayList) IQueryAtomContainer(org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer) IQueryAtomContainer(org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer) QueryAtomContainer(org.openscience.cdk.isomorphism.matchers.QueryAtomContainer)

Aggregations

QueryAtomContainer (org.openscience.cdk.isomorphism.matchers.QueryAtomContainer)143 Test (org.junit.Test)120 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)78 IQueryAtomContainer (org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer)60 IAtom (org.openscience.cdk.interfaces.IAtom)54 IAtomContainerSet (org.openscience.cdk.interfaces.IAtomContainerSet)35 ArrayList (java.util.ArrayList)31 IReactionProcess (org.openscience.cdk.reaction.IReactionProcess)30 IParameterReact (org.openscience.cdk.reaction.type.parameters.IParameterReact)29 SetReactionCenter (org.openscience.cdk.reaction.type.parameters.SetReactionCenter)29 IReactionSet (org.openscience.cdk.interfaces.IReactionSet)28 ReactionProcessTest (org.openscience.cdk.reaction.ReactionProcessTest)28 SmilesParser (org.openscience.cdk.smiles.SmilesParser)26 UniversalIsomorphismTester (org.openscience.cdk.isomorphism.UniversalIsomorphismTester)15 IBond (org.openscience.cdk.interfaces.IBond)14 ISingleElectron (org.openscience.cdk.interfaces.ISingleElectron)14 IChemObjectBuilder (org.openscience.cdk.interfaces.IChemObjectBuilder)10 AnyOrderQueryBond (org.openscience.cdk.isomorphism.matchers.smarts.AnyOrderQueryBond)9 InputStream (java.io.InputStream)8 CDKException (org.openscience.cdk.exception.CDKException)8