Edge toBeamEdge(IBond b, Map<IAtom, Integer> indices) throws CDKException { checkArgument(b.getAtomCount() == 2, "Invalid number of atoms on bond"); int u = indices.get(b.getBegin()); int v = indices.get(b.getEnd()); return toBeamEdgeLabel(b, this.flavour).edge(u, v); }
private boolean isDirectional(Edge f, Map<Edge,Edge> replacements) { if (f.bond().directional()) return true; Edge g = replacements.get(f); return g != null && g.bond().directional(); }
private Atom reducedAtom(Graph g, int u) { Atom a = g.atom(u); int sum = 0; for (Edge e : g.edges(u)) { sum += e.bond().order(); } return ToSubsetAtoms.toSubset(g.atom(u), g, u); }
if ((f.bond() == Bond.UP || f.bond() == Bond.DOWN) && explicit.bond(u).inverse() != f.bond(u)) { return Status.INVALID; if (explicit.bond(u).inverse() != f2.bond(u)) { acc.put(f, f2.inverse()); BitSet visited = new BitSet(); v, explicit.bond(u) .inverse())); if (existing != null && existing.bond(u) != explicit.bond(u).inverse()) { throw new InvalidSmilesException("unable to assign explict type for " + implicit);
if (v == p) continue; if (e.bond().order() == 2 && hasAdjDirectionalLabels(g, e)) {
/** * Convert a CDK {@link IBond} to a Beam edge. * * @param b the CDK bond * @param indices map of atom indices * @return a Beam edge * @throws IllegalArgumentException the bond did not have 2 atoms or an * unsupported order * @throws NullPointerException the bond order was undefined */ static Edge toBeamEdge(IBond b, int flavour, Map<IAtom, Integer> indices) throws CDKException { checkArgument(b.getAtomCount() == 2, "Invalid number of atoms on bond"); int u = indices.get(b.getBegin()); int v = indices.get(b.getEnd()); return toBeamEdgeLabel(b, flavour).edge(u, v); }
private IStereoElement newExtendedTetrahedral(int u, Graph g, IAtom[] atoms) { int[] terminals = findExtendedTetrahedralEnds(g, u); int[] xs = new int[]{-1, terminals[0], -1, terminals[1]}; int n = 0; for (Edge e : g.edges(terminals[0])) { if (e.bond().order() == 1) xs[n++] = e.other(terminals[0]); } n = 2; for (Edge e : g.edges(terminals[1])) { if (e.bond().order() == 1) xs[n++] = e.other(terminals[1]); } Arrays.sort(xs); Stereo stereo = g.configurationOf(u).shorthand() == Configuration.CLOCKWISE ? Stereo.CLOCKWISE : Stereo.ANTI_CLOCKWISE; return new org.openscience.cdk.stereo.ExtendedTetrahedral(atoms[u], new IAtom[]{atoms[xs[0]], atoms[xs[1]], atoms[xs[2]], atoms[xs[3]]}, stereo); }
private boolean hasAdjDirectionalLabels(Graph g, int u) { final int d = g.degree(u); for (int j = 0; j < d; ++j) { final Edge f = g.edgeAt(u, j); if (f.bond().directional()) return true; } return false; }
@SuppressWarnings("unchecked") @Test public void doubleBond() throws Exception { IAtom u = mock(IAtom.class); IAtom v = mock(IAtom.class); IBond b = new Bond(u, v, IBond.Order.DOUBLE); Map<IAtom, Integer> mock = mock(Map.class); when(mock.get(u)).thenReturn(0); when(mock.get(v)).thenReturn(1); CDKToBeam c2g = new CDKToBeam(); assertThat(c2g.toBeamEdge(b, mock), is(uk.ac.ebi.beam.Bond.DOUBLE.edge(0, 1))); }
boolean safeToClean(Graph g, int v, Map<Edge,Edge> replacements) { final int d = g.degree(v); for (int j = 0; j < d; ++j) { final Edge e = g.edgeAt(v, j); if (e.bond().order() == 2) { int w = e.other(v); final int d2 = g.degree(w); for (int j2 = 0; j2 < d2; ++j2) { final Edge f = g.edgeAt(w, j2); if (isDirectional(f, replacements)) return false; } } } return true; }
private void invertExistingDirectionalLabels(Graph g, BitSet visited, Map<Edge, Edge> replacement, int u) { visited.set(u); if (g.topologyOf(u) == null) return; for (Edge e : g.edges(u)) { int v = e.other(u); if (!visited.get(v)) { Edge f = replacement.get(e); if (f != null && f.bond().directional()) { replacement.put(e, f.inverse()); } else if (e.bond().directional()) { replacement.put(e, e.inverse()); } invertExistingDirectionalLabels(g, visited, replacement, v); } } }
@SuppressWarnings("unchecked") @Test public void quadrupleBond() throws Exception { IAtom u = mock(IAtom.class); IAtom v = mock(IAtom.class); IBond b = new Bond(u, v, IBond.Order.QUADRUPLE); Map<IAtom, Integer> mock = mock(Map.class); when(mock.get(u)).thenReturn(0); when(mock.get(v)).thenReturn(1); CDKToBeam c2g = new CDKToBeam(); assertThat(c2g.toBeamEdge(b, mock), is(uk.ac.ebi.beam.Bond.QUADRUPLE.edge(0, 1))); }
private Atom asBracketAtom(int u, Graph g) { Atom a = g.atom(u); int sum = a.aromatic() ? 1 : 0; for (Edge e : g.edges(u)) { sum += e.bond().order(); } return new AtomImpl.BracketAtom(-1, a.element(), a.aromatic() ? a.element().aromaticImplicitHydrogens(sum) : a.element().implicitHydrogens(sum), 0, 0, a.aromatic()); }
@SuppressWarnings("unchecked") @Test public void tripleBond() throws Exception { IAtom u = mock(IAtom.class); IAtom v = mock(IAtom.class); IBond b = new Bond(u, v, IBond.Order.TRIPLE); Map<IAtom, Integer> mock = mock(Map.class); when(mock.get(u)).thenReturn(0); when(mock.get(v)).thenReturn(1); CDKToBeam c2g = new CDKToBeam(); assertThat(c2g.toBeamEdge(b, mock), is(uk.ac.ebi.beam.Bond.TRIPLE.edge(0, 1))); }
@SuppressWarnings("unchecked") @Test public void singleBond() throws Exception { IAtom u = mock(IAtom.class); IAtom v = mock(IAtom.class); IBond b = new Bond(u, v); Map<IAtom, Integer> mock = mock(Map.class); when(mock.get(u)).thenReturn(0); when(mock.get(v)).thenReturn(1); CDKToBeam c2g = new CDKToBeam(); assertThat(c2g.toBeamEdge(b, mock), is(uk.ac.ebi.beam.Bond.SINGLE.edge(0, 1))); }
@SuppressWarnings("unchecked") @Test public void aromaticBond() throws Exception { IAtom u = mock(IAtom.class); IAtom v = mock(IAtom.class); IBond b = new Bond(u, v); b.setFlag(CDKConstants.ISAROMATIC, true); Map<IAtom, Integer> mock = mock(Map.class); when(mock.get(u)).thenReturn(0); when(mock.get(v)).thenReturn(1); when(u.isAromatic()).thenReturn(true); when(v.isAromatic()).thenReturn(true); CDKToBeam c2g = new CDKToBeam(); assertThat(c2g.toBeamEdge(b, mock), is(uk.ac.ebi.beam.Bond.AROMATIC.edge(0, 1))); }