Search in sources :

Example 1 with QuerySequenceElement

use of ambit2.smarts.QuerySequenceElement in project ambit-mirror by ideaconsult.

the class StructureKeysBitSetGenerator method prepareKeySequences.

protected synchronized void prepareKeySequences(List<String> keys, int nKeys) throws EmptyMoleculeException {
    smartsKeys = keys;
    IQueryAtomContainer query;
    sequences.clear();
    smartsQueries.clear();
    SmartsParser parser = new SmartsParser();
    for (int i = 0; i < nKeys; i++) {
        query = parser.parse(smartsKeys.get(i));
        // parser.setNeededDataFlags();       --> This should not be needed for the key smarts queries
        isoTester.setQuery(query);
        List<QuerySequenceElement> sequence = isoTester.transferSequenceToOwner();
        sequences.add(sequence);
        smartsQueries.add(query);
    }
}
Also used : SmartsParser(ambit2.smarts.SmartsParser) QuerySequenceElement(ambit2.smarts.QuerySequenceElement) IQueryAtomContainer(org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer)

Example 2 with QuerySequenceElement

use of ambit2.smarts.QuerySequenceElement in project ambit-mirror by ideaconsult.

the class SmartsIsomorphismTester method setQueryAtomSequence.

void setQueryAtomSequence(IQueryAtom firstAt) {
    IQueryAtom firstAtom;
    QuerySequenceElement seqEl;
    TopLayer topLayer;
    int n;
    if (firstAt == null)
        firstAtom = (IQueryAtom) query.getFirstAtom();
    else
        firstAtom = firstAt;
    sequence.clear();
    sequencedAtoms.clear();
    sequencedBondAt1.clear();
    sequencedBondAt2.clear();
    // Set first sequence atom
    sequencedAtoms.add(firstAtom);
    seqEl = new QuerySequenceElement();
    seqEl.center = firstAtom;
    topLayer = (TopLayer) firstAtom.getProperty(TopLayer.TLProp);
    n = topLayer.atoms.size();
    seqEl.atoms = new IQueryAtom[n];
    seqEl.bonds = new IQueryBond[n];
    for (int i = 0; i < n; i++) {
        sequencedAtoms.add((IQueryAtom) topLayer.atoms.get(i));
        seqEl.atoms[i] = (IQueryAtom) topLayer.atoms.get(i);
        seqEl.bonds[i] = (IQueryBond) topLayer.bonds.get(i);
        addSeqBond(seqEl.center, seqEl.atoms[i]);
    }
    sequence.add(seqEl);
    // Sequencing the entire query structure
    Stack<QuerySequenceElement> stack = new Stack<QuerySequenceElement>();
    stack.push(seqEl);
    while (!stack.empty()) {
        // curAddedAtoms.clear();
        QuerySequenceElement curSeqAt = stack.pop();
        for (int i = 0; i < curSeqAt.atoms.length; i++) {
            topLayer = (TopLayer) curSeqAt.atoms[i].getProperty(TopLayer.TLProp);
            if (topLayer.atoms.size() == 1)
                // it is terminal atom and no further sequencing should be done
                continue;
            int[] a = getSeqAtomsInLayer(topLayer);
            n = 0;
            for (int k = 0; k < a.length; k++) if (a[k] == 0)
                n++;
            if (n > 0) {
                seqEl = new QuerySequenceElement();
                seqEl.center = curSeqAt.atoms[i];
                seqEl.atoms = new IQueryAtom[n];
                seqEl.bonds = new IQueryBond[n];
                sequence.add(seqEl);
                stack.add(seqEl);
            }
            int j = 0;
            for (int k = 0; k < a.length; k++) {
                if (a[k] == 0) {
                    seqEl.atoms[j] = (IQueryAtom) topLayer.atoms.get(k);
                    seqEl.bonds[j] = (IQueryBond) topLayer.bonds.get(k);
                    addSeqBond(seqEl.center, seqEl.atoms[j]);
                    sequencedAtoms.add(seqEl.atoms[j]);
                    // curAddedAtoms.add(seqEl.atoms[j]);
                    j++;
                } else {
                    if (curSeqAt.center == topLayer.atoms.get(k))
                        continue;
                    // is already sequenced
                    if (getSeqBond(curSeqAt.atoms[i], topLayer.atoms.get(k)) != -1)
                        continue;
                    // topLayer.atoms.get(k) atom is already sequenced.
                    // Therefore sequnce element of 'bond' type is registered.
                    // newSeqEl is not added in the stack (this is not needed for this bond)
                    QuerySequenceElement newSeqEl = new QuerySequenceElement();
                    newSeqEl.center = null;
                    newSeqEl.atoms = new IQueryAtom[2];
                    newSeqEl.bonds = new IQueryBond[1];
                    newSeqEl.atoms[0] = curSeqAt.atoms[i];
                    newSeqEl.atoms[1] = (IQueryAtom) topLayer.atoms.get(k);
                    addSeqBond(newSeqEl.atoms[0], newSeqEl.atoms[1]);
                    newSeqEl.bonds[0] = (IQueryBond) topLayer.bonds.get(k);
                    sequence.add(newSeqEl);
                }
            }
        }
    }
    for (int i = 0; i < sequence.size(); i++) sequence.get(i).setAtomNums(query);
}
Also used : QuerySequenceElement(ambit2.smarts.QuerySequenceElement) IQueryAtom(org.openscience.cdk.isomorphism.matchers.IQueryAtom) TopLayer(ambit2.smarts.TopLayer) Stack(java.util.Stack)

Example 3 with QuerySequenceElement

use of ambit2.smarts.QuerySequenceElement in project ambit-mirror by ideaconsult.

the class SmartsIsomorphismTester method executeSequence.

void executeSequence(boolean stopAtFirstMapping) {
    isomorphismFound = false;
    stack.clear();
    // Initial nodes
    QuerySequenceElement el = sequence.get(0);
    for (int k = 0; k < target.getAtomCount(); k++) {
        IAtom at = target.getAtom(k);
        if (smartsMatch.match(el.center, at)) {
            Node node = new Node();
            node.sequenceElNum = 0;
            node.nullifyAtoms(query.getAtomCount());
            node.atoms[el.centerNum] = at;
            stack.push(node);
        }
    }
    // Expanding the tree of all possible mappings
    if (stopAtFirstMapping) {
        while (!stack.isEmpty()) {
            expandNode(stack.pop());
            if (isomorphismFound)
                break;
        }
    } else {
        while (!stack.isEmpty()) expandNode(stack.pop());
    }
}
Also used : QuerySequenceElement(ambit2.smarts.QuerySequenceElement) Node(ambit2.smarts.Node) IAtom(org.openscience.cdk.interfaces.IAtom)

Example 4 with QuerySequenceElement

use of ambit2.smarts.QuerySequenceElement in project ambit-mirror by ideaconsult.

the class SmartsIsomorphismTester method executeSequenceAtPos.

void executeSequenceAtPos(int pos) {
    isomorphismFound = false;
    stack.clear();
    // Initial node
    QuerySequenceElement el = sequence.get(0);
    IAtom at = target.getAtom(pos);
    if (smartsMatch.match(el.center, at)) {
        Node node = new Node();
        node.sequenceElNum = 0;
        node.nullifyAtoms(query.getAtomCount());
        node.atoms[el.centerNum] = at;
        stack.push(node);
    }
    // Expanding the tree of all possible mappings
    while (!stack.isEmpty()) {
        expandNode(stack.pop());
        if (isomorphismFound)
            break;
    }
}
Also used : QuerySequenceElement(ambit2.smarts.QuerySequenceElement) Node(ambit2.smarts.Node) IAtom(org.openscience.cdk.interfaces.IAtom)

Example 5 with QuerySequenceElement

use of ambit2.smarts.QuerySequenceElement in project ambit-mirror by ideaconsult.

the class SmartsIsomorphismTester method expandNode.

void expandNode(Node node) {
    // System.out.println(node.toString(target));
    QuerySequenceElement el = sequence.get(node.sequenceElNum);
    if (// This node describers a bond that closes a ring
    el.center == null) {
        // Checking whether this bond is present in the target
        IAtom tAt0 = node.atoms[query.getAtomNumber(el.atoms[0])];
        IAtom tAt1 = node.atoms[query.getAtomNumber(el.atoms[1])];
        IBond tBo = target.getBond(tAt0, tAt1);
        if (tBo != null)
            if (smartsMatch.match(el.bonds[0], tBo)) {
                node.sequenceElNum++;
                // stack.push(node);
                if (node.sequenceElNum == sequence.size()) {
                    // The node is not added in the stack if the end of the sequence is reached
                    boolean FlagOK = true;
                    if (FlagOK) {
                        isomorphismFound = true;
                        if (FlagStoreIsomorphismNode)
                            isomorphismNodes.add(node);
                    }
                } else
                    stack.push(node);
            }
    } else {
        targetAt.clear();
        IAtom tAt = node.atoms[el.centerNum];
        List<IAtom> conAt = target.getConnectedAtomsList(tAt);
        for (int i = 0; i < conAt.size(); i++) {
            if (!containsAtom(node.atoms, conAt.get(i)))
                targetAt.add(conAt.get(i));
        }
        if (el.atoms.length <= targetAt.size())
            generateNodes(node);
    }
}
Also used : QuerySequenceElement(ambit2.smarts.QuerySequenceElement) IBond(org.openscience.cdk.interfaces.IBond) IAtom(org.openscience.cdk.interfaces.IAtom)

Aggregations

QuerySequenceElement (ambit2.smarts.QuerySequenceElement)7 Node (ambit2.smarts.Node)3 IAtom (org.openscience.cdk.interfaces.IAtom)3 Stack (java.util.Stack)2 IQueryAtomContainer (org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer)2 ChemObjectFactory (ambit2.smarts.ChemObjectFactory)1 SmartsParser (ambit2.smarts.SmartsParser)1 TopLayer (ambit2.smarts.TopLayer)1 CDKException (org.openscience.cdk.exception.CDKException)1 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)1 IBond (org.openscience.cdk.interfaces.IBond)1 IQueryAtom (org.openscience.cdk.isomorphism.matchers.IQueryAtom)1