Search in sources :

Example 6 with Atom

use of org.openscience.cdk.Atom in project Smiles2Monomers by yoann-dufresne.

the class CompatibilityGraph method isCompatible.

@SuppressWarnings("unchecked")
public boolean isCompatible(SimpleCycle mainCycle, Segment s1, Segment s2) {
    Set<Atom> inCycle = new HashSet<>(mainCycle.vertexSet());
    Stack<Atom> stack = new Stack<>();
    // Init
    Iterator<Atom> i = inCycle.iterator();
    Atom init = null;
    do {
        init = i.next();
    } while (!s2.containsVertex(init));
    inCycle.remove(init);
    stack.push(init);
    // follow path
    while (!stack.isEmpty()) {
        Atom a = stack.pop();
        if (s1.containsVertex(a))
            continue;
        List<UndirectedEdge> edges = mainCycle.edgesOf(a);
        for (UndirectedEdge e : edges) {
            if (inCycle.contains(e.getSource())) {
                inCycle.remove(e.getSource());
                stack.push((Atom) e.getSource());
            }
            if (inCycle.contains(e.getTarget())) {
                inCycle.remove(e.getTarget());
                stack.push((Atom) e.getTarget());
            }
        }
    }
    // Is compatible ?
    for (Atom a : inCycle) if (s2.containsVertex(a)) {
        return false;
    }
    return true;
}
Also used : UndirectedEdge(org._3pq.jgrapht.edge.UndirectedEdge) Atom(org.openscience.cdk.Atom) HashSet(java.util.HashSet) Stack(java.util.Stack)

Aggregations

Atom (org.openscience.cdk.Atom)6 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 UndirectedEdge (org._3pq.jgrapht.edge.UndirectedEdge)3 Stack (java.util.Stack)2 Bond (org.openscience.cdk.Bond)2 IAtom (org.openscience.cdk.interfaces.IAtom)2 Set (java.util.Set)1 Before (org.junit.Before)1 BiconnectivityInspector (org.openscience.cdk.graph.BiconnectivityInspector)1 IBond (org.openscience.cdk.interfaces.IBond)1