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;
}
Aggregations