-
Notifications
You must be signed in to change notification settings - Fork 154
/
AtomContainerPrinter.java
78 lines (67 loc) · 2.19 KB
/
AtomContainerPrinter.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package org.openscience.cdk.smsd.labelling;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IBond;
/**
* @cdk.module smsd
* @cdk.githash
*/
public class AtomContainerPrinter {
private class Edge implements Comparable<Edge> {
public String firstString;
public String lastString;
public int first;
public int last;
public int order;
public Edge(int first, int last, int order, String firstString, String lastString) {
this.first = first;
this.last = last;
this.order = order;
this.firstString = firstString;
this.lastString = lastString;
}
/**
* {@inheritDoc}
*/
@Override
public int compareTo(Edge o) {
if (first < o.first || (first == o.first && last < o.last)) {
return -1;
} else {
return 1;
}
}
@Override
public String toString() {
return firstString + first + ":" + lastString + last + "(" + order + ")";
}
}
public String toString(IAtomContainer atomContainer) {
StringBuilder sb = new StringBuilder();
for (IAtom atom : atomContainer.atoms()) {
sb.append(atom.getSymbol());
}
sb.append(' ');
List<Edge> edges = new ArrayList<Edge>();
for (IBond bond : atomContainer.bonds()) {
IAtom a0 = bond.getAtom(0);
IAtom a1 = bond.getAtom(1);
int a0N = atomContainer.getAtomNumber(a0);
int a1N = atomContainer.getAtomNumber(a1);
String a0S = a0.getSymbol();
String a1S = a1.getSymbol();
int o = bond.getOrder().numeric();
if (a0N < a1N) {
edges.add(new Edge(a0N, a1N, o, a0S, a1S));
} else {
edges.add(new Edge(a1N, a0N, o, a1S, a0S));
}
}
Collections.sort(edges);
sb.append(edges.toString());
return sb.toString();
}
}