@Test public void implicitToExplicit_al1_al2() { assertThat(Topology.toExplicit(new Graph(0), 0, Configuration.AL1), is(Configuration.AL1)); assertThat(Topology.toExplicit(new Graph(0), 0, Configuration.AL2), is(Configuration.AL2)); }
static Configuration toExplicit(Graph g, int u, Configuration c) { if (c.type() != Implicit) return c; int deg = g.degree(u); int valence = deg + g.atom(u).hydrogens(); if (valence == 4) { return c == ANTI_CLOCKWISE ? TH1 : TH2; } else if (valence == 3) { if (g.atom(u).element() == Element.Sulfur || g.atom(u).element() == Element.Selenium) { int sb = 0, db = 0; final int d = g.degree(u); for (int j=0; j<d; ++j) { final Edge e = g.edgeAt(u, j); if (e.bond().order() == 1) sb++; else if (e.bond().order() == 2) db++; else return Configuration.UNKNOWN; } int q = g.atom(u).charge(); if ((q == 0 && sb == 2 && db == 1) || (q == 1 && sb == 3)) return c == ANTI_CLOCKWISE ? TH1 : TH2; else return Configuration.UNKNOWN; } if (g.atom(u).element() == Element.Phosphorus || g.atom(u).element() == Element.Nitrogen) { if (g.bondedValence(u) == 3 && g.implHCount(u) == 0 && g.atom(u).charge() == 0) { return c == ANTI_CLOCKWISE ? TH1 : TH2; } } int nDoubleBonds = 0; final int d = g.degree(u); for (int j=0; j<d; ++j) { final Edge e = g.edgeAt(u, j); if (e.bond() == Bond.DOUBLE) nDoubleBonds++; } if (nDoubleBonds == 1) { return c == ANTI_CLOCKWISE ? DB1 : DB2; } else { return Configuration.UNKNOWN; } } else if (deg == 2) { int nDoubleBonds = 0; final int d = g.degree(u); for (int j = 0; j < d; ++j) { final Edge e = g.edgeAt(u, j); if (e.bond() != Bond.DOUBLE) nDoubleBonds++; } if (nDoubleBonds == 1) { return c == ANTI_CLOCKWISE ? DB1 : DB2; } else { return c == ANTI_CLOCKWISE ? AL1 : AL2; } } else if (valence == 5) { return c == ANTI_CLOCKWISE ? TB1 : TB2; } else if (valence == 6) { return c == ANTI_CLOCKWISE ? OH1 : OH2; } return Configuration.UNKNOWN; }
Topology { static Configuration toExplicit(Graph g, int u, Configuration c) { if (c.type() != Implicit) return c; int deg = g.degree(u); int valence = deg + g.atom(u).hydrogens(); if (valence == 4) { return c == ANTI_CLOCKWISE ? TH1 : TH2; } else if (valence == 3) { if (g.atom(u).element() == Element.Sulfur || g.atom(u).element() == Element.Selenium) { int sb = 0, db = 0; final int d = g.degree(u); for (int j=0; j<d; ++j) { final Edge e = g.edgeAt(u, j); if (e.bond().order() == 1) sb++; else if (e.bond().order() == 2) db++; else return Configuration.UNKNOWN; } int q = g.atom(u).charge(); if ((q == 0 && sb == 2 && db == 1) || (q == 1 && sb == 3)) return c == ANTI_CLOCKWISE ? TH1 : TH2; else return Configuration.UNKNOWN; } if (g.atom(u).element() == Element.Phosphorus || g.atom(u).element() == Element.Nitrogen) { if (g.bondedValence(u) == 3 && g.implHCount(u) == 0 && g.atom(u).charge() == 0) { return c == ANTI_CLOCKWISE ? TH1 : TH2; } } int nDoubleBonds = 0; final int d = g.degree(u); for (int j=0; j<d; ++j) { final Edge e = g.edgeAt(u, j); if (e.bond() == Bond.DOUBLE) nDoubleBonds++; } if (nDoubleBonds == 1) { return c == ANTI_CLOCKWISE ? DB1 : DB2; } else { return Configuration.UNKNOWN; } } else if (deg == 2) { int nDoubleBonds = 0; final int d = g.degree(u); for (int j = 0; j < d; ++j) { final Edge e = g.edgeAt(u, j); if (e.bond() != Bond.DOUBLE) nDoubleBonds++; } if (nDoubleBonds == 1) { return c == ANTI_CLOCKWISE ? DB1 : DB2; } else { return c == ANTI_CLOCKWISE ? AL1 : AL2; } } else if (valence == 5) { return c == ANTI_CLOCKWISE ? TB1 : TB2; } else if (valence == 6) { return c == ANTI_CLOCKWISE ? OH1 : OH2; } return Configuration.UNKNOWN; } }
Topology { static Configuration toExplicit(Graph g, int u, Configuration c) { if (c.type() != Implicit) return c; int deg = g.degree(u); int valence = deg + g.atom(u).hydrogens(); if (valence == 4) { return c == ANTI_CLOCKWISE ? TH1 : TH2; } else if (valence == 3) { if (g.atom(u).element() == Element.Sulfur || g.atom(u).element() == Element.Selenium) { int sb = 0, db = 0; final int d = g.degree(u); for (int j=0; j<d; ++j) { final Edge e = g.edgeAt(u, j); if (e.bond().order() == 1) sb++; else if (e.bond().order() == 2) db++; else return Configuration.UNKNOWN; } int q = g.atom(u).charge(); if ((q == 0 && sb == 2 && db == 1) || (q == 1 && sb == 3)) return c == ANTI_CLOCKWISE ? TH1 : TH2; else return Configuration.UNKNOWN; } if (g.atom(u).element() == Element.Phosphorus || g.atom(u).element() == Element.Nitrogen) { if (g.bondedValence(u) == 3 && g.implHCount(u) == 0 && g.atom(u).charge() == 0) { return c == ANTI_CLOCKWISE ? TH1 : TH2; } } int nDoubleBonds = 0; final int d = g.degree(u); for (int j=0; j<d; ++j) { final Edge e = g.edgeAt(u, j); if (e.bond() == Bond.DOUBLE) nDoubleBonds++; } if (nDoubleBonds == 1) { return c == ANTI_CLOCKWISE ? DB1 : DB2; } else { return Configuration.UNKNOWN; } } else if (deg == 2) { int nDoubleBonds = 0; final int d = g.degree(u); for (int j = 0; j < d; ++j) { final Edge e = g.edgeAt(u, j); if (e.bond() != Bond.DOUBLE) nDoubleBonds++; } if (nDoubleBonds == 1) { return c == ANTI_CLOCKWISE ? DB1 : DB2; } else { return c == ANTI_CLOCKWISE ? AL1 : AL2; } } else if (valence == 5) { return c == ANTI_CLOCKWISE ? TB1 : TB2; } else if (valence == 6) { return c == ANTI_CLOCKWISE ? OH1 : OH2; } return Configuration.UNKNOWN; }  }
Topology { static Configuration toExplicit(Graph g, int u, Configuration c) { if (c.type() != Implicit) return c; int deg = g.degree(u); int valence = deg + g.atom(u).hydrogens(); if (valence == 4) { return c == ANTI_CLOCKWISE ? TH1 : TH2; } else if (valence == 3) { if (g.atom(u).element() == Element.Sulfur || g.atom(u).element() == Element.Selenium) { int sb = 0, db = 0; final int d = g.degree(u); for (int j=0; j<d; ++j) { final Edge e = g.edgeAt(u, j); if (e.bond().order() == 1) sb++; else if (e.bond().order() == 2) db++; else return Configuration.UNKNOWN; } int q = g.atom(u).charge(); if ((q == 0 && sb == 2 && db == 1) || (q == 1 && sb == 3)) return c == ANTI_CLOCKWISE ? TH1 : TH2; else return Configuration.UNKNOWN; } if (g.atom(u).element() == Element.Phosphorus || g.atom(u).element() == Element.Nitrogen) { if (g.bondedValence(u) == 3 && g.implHCount(u) == 0 && g.atom(u).charge() == 0) { return c == ANTI_CLOCKWISE ? TH1 : TH2; } } int nDoubleBonds = 0; final int d = g.degree(u); for (int j=0; j<d; ++j) { final Edge e = g.edgeAt(u, j); if (e.bond() == Bond.DOUBLE) nDoubleBonds++; } if (nDoubleBonds == 1) { return c == ANTI_CLOCKWISE ? DB1 : DB2; } else { return Configuration.UNKNOWN; } } else if (deg == 2) { int nDoubleBonds = 0; final int d = g.degree(u); for (int j = 0; j < d; ++j) { final Edge e = g.edgeAt(u, j); if (e.bond() != Bond.DOUBLE) nDoubleBonds++; } if (nDoubleBonds == 1) { return c == ANTI_CLOCKWISE ? DB1 : DB2; } else { return c == ANTI_CLOCKWISE ? AL1 : AL2; } } else if (valence == 5) { return c == ANTI_CLOCKWISE ? TB1 : TB2; } else if (valence == 6) { return c == ANTI_CLOCKWISE ? OH1 : OH2; } return Configuration.UNKNOWN; }   }
Topology { static Configuration toExplicit(Graph g, int u, Configuration c) { if (c.type() != Implicit) return c; int deg = g.degree(u); int valence = deg + g.atom(u).hydrogens(); if (valence == 4) { return c == ANTI_CLOCKWISE ? TH1 : TH2; } else if (valence == 3) { if (g.atom(u).element() == Element.Sulfur || g.atom(u).element() == Element.Selenium) { int sb = 0, db = 0; final int d = g.degree(u); for (int j=0; j<d; ++j) { final Edge e = g.edgeAt(u, j); if (e.bond().order() == 1) sb++; else if (e.bond().order() == 2) db++; else return Configuration.UNKNOWN; } int q = g.atom(u).charge(); if ((q == 0 && sb == 2 && db == 1) || (q == 1 && sb == 3)) return c == ANTI_CLOCKWISE ? TH1 : TH2; else return Configuration.UNKNOWN; } if (g.atom(u).element() == Element.Phosphorus || g.atom(u).element() == Element.Nitrogen) { if (g.bondedValence(u) == 3 && g.implHCount(u) == 0 && g.atom(u).charge() == 0) { return c == ANTI_CLOCKWISE ? TH1 : TH2; } } int nDoubleBonds = 0; final int d = g.degree(u); for (int j=0; j<d; ++j) { final Edge e = g.edgeAt(u, j); if (e.bond() == Bond.DOUBLE) nDoubleBonds++; } if (nDoubleBonds == 1) { return c == ANTI_CLOCKWISE ? DB1 : DB2; } else { return Configuration.UNKNOWN; } } else if (deg == 2) { int nDoubleBonds = 0; final int d = g.degree(u); for (int j = 0; j < d; ++j) { final Edge e = g.edgeAt(u, j); if (e.bond() != Bond.DOUBLE) nDoubleBonds++; } if (nDoubleBonds == 1) { return c == ANTI_CLOCKWISE ? DB1 : DB2; } else { return c == ANTI_CLOCKWISE ? AL1 : AL2; } } else if (valence == 5) { return c == ANTI_CLOCKWISE ? TB1 : TB2; } else if (valence == 6) { return c == ANTI_CLOCKWISE ? OH1 : OH2; } return Configuration.UNKNOWN; }    }