use of org.openscience.cdk.Atom in project Smiles2Monomers by yoann-dufresne.
the class BonbMatchingTests method setUp.
@Before
public void setUp() throws Exception {
// cNH
IAtom a2 = new Atom("C");
a2.setImplicitHydrogenCount(0);
a2.setFlag(CDKConstants.ISAROMATIC, true);
IAtom a1 = new Atom("N");
a1.setImplicitHydrogenCount(1);
this.bond1 = new Bond(a1, a2, Order.DOUBLE);
}
use of org.openscience.cdk.Atom in project Smiles2Monomers by yoann-dufresne.
the class Biconnected method createBiconnectedComponents.
/*
* Function to create biconned components
*/
@SuppressWarnings("unchecked")
public static List<Biconnected> createBiconnectedComponents(UndirectedGraph g) {
BiconnectivityInspector bi = new BiconnectivityInspector(g);
List<Set<UndirectedEdge>> biconnecteds = bi.biconnectedSets();
List<Biconnected> bcs = new ArrayList<>();
for (Set<UndirectedEdge> edges : biconnecteds) {
HashSet<Atom> vertices = new HashSet<>();
Iterator<UndirectedEdge> i = edges.iterator();
while (i.hasNext()) {
UndirectedEdge e = i.next();
vertices.add((Atom) e.getSource());
vertices.add((Atom) e.getTarget());
}
Biconnected sg = new Biconnected(g, vertices, edges);
bcs.add(sg);
}
return bcs;
}
use of org.openscience.cdk.Atom in project Smiles2Monomers by yoann-dufresne.
the class Segment method isStringIn.
@SuppressWarnings("unchecked")
public boolean isStringIn(AbstractGraph sg) {
Iterator<Atom> segIt = this.vertexSet().iterator();
int cpt = 0;
while (segIt.hasNext()) {
Atom a = segIt.next();
if (sg.vertexSet().contains(a))
cpt++;
}
if (cpt == 2)
return true;
return false;
}
use of org.openscience.cdk.Atom in project Smiles2Monomers by yoann-dufresne.
the class Extension method createBond.
private void createBond(String name0, int h0, boolean arom0, String name1, int h1, boolean arom1, Order ord) {
if (arom0)
name0 = name0.toLowerCase();
if (arom1)
name1 = name1.toLowerCase();
List<String> names = new ArrayList<>();
names.add(name0 + ":" + h0);
names.add(name1 + ":" + h1);
Collections.sort(names);
// this.inverted = !names.get(0).equals(name0 + ":" + h0);
IAtom c0 = null;
String n0 = names.get(0);
if (Extension.savedAtoms.containsKey(n0))
c0 = Extension.savedAtoms.get(n0);
else {
String[] split = n0.split(":");
char first = Character.toUpperCase(split[0].charAt(0));
String name = first + split[0].substring(1);
c0 = new Atom(name);
c0.setFlag(CDKConstants.ISAROMATIC, Character.isLowerCase(split[0].charAt(0)));
c0.setImplicitHydrogenCount(new Integer(split[1]));
Extension.savedAtoms.put(n0, c0);
}
IAtom c1 = null;
String n1 = names.get(1);
if (Extension.savedAtoms.containsKey(n1))
c1 = Extension.savedAtoms.get(n1);
else {
String[] split = n1.split(":");
char first = Character.toUpperCase(split[0].charAt(0));
String name = first + split[0].substring(1);
c1 = new Atom(name);
c1.setFlag(CDKConstants.ISAROMATIC, Character.isLowerCase(split[0].charAt(0)));
c1.setImplicitHydrogenCount(new Integer(split[1]));
Extension.savedAtoms.put(n1, c1);
}
String key = names.get(0) + ord + names.get(1);
if (Extension.savedBonds.containsKey(key)) {
this.bond = Extension.savedBonds.get(key);
} else {
this.bond = new Bond(c0, c1, ord);
Extension.savedBonds.put(key, this.bond);
}
}
use of org.openscience.cdk.Atom in project Smiles2Monomers by yoann-dufresne.
the class Biconnected method getSegments.
/*
* Find segments in a biconnected graph
*/
@SuppressWarnings("unchecked")
public List<Segment> getSegments(SimpleCycle mainCycle) {
List<Segment> segments = new ArrayList<>();
Set<UndirectedEdge> absents = new HashSet<>();
// Add all graph vertices
Iterator<UndirectedEdge> iv = this.edgeSet().iterator();
while (iv.hasNext()) absents.add(iv.next());
// Remove main cycle vertices.
Iterator<UndirectedEdge> ic = mainCycle.edgeSet().iterator();
while (ic.hasNext()) absents.remove(ic.next());
while (absents.size() != 0) {
// Depth first search for segments
Set<Atom> segV = new HashSet<>();
Set<UndirectedEdge> segE = new HashSet<>();
Stack<UndirectedEdge> stack = new Stack<>();
UndirectedEdge first = absents.iterator().next();
stack.push(first);
segE.add(first);
while (!stack.isEmpty()) {
Set<UndirectedEdge> edges = new HashSet<>();
UndirectedEdge e = stack.pop();
// Add neighbors edges non already folloed
edges.addAll(this.edgesOf(e.getSource()));
edges.addAll(this.edgesOf(e.getTarget()));
for (UndirectedEdge neighbor : edges) if (absents.contains(neighbor)) {
stack.push(neighbor);
absents.remove(neighbor);
}
// Add verticies
segV.add((Atom) e.getSource());
segV.add((Atom) e.getTarget());
}
// Segment creation
Segment seg = new Segment(segV, segE);
segments.add(seg);
}
return segments;
}
Aggregations