/** * {@inheritDoc} */ @Override public boolean isInRing() { return bond.isInRing(); }
/** * {@inheritDoc} */ @Override public boolean isInRing() { return bond.isInRing(); }
private int countRingBonds(IBond[] bonds) { int rbonds = 0; for (IBond bond : bonds) { if (bond != null && bond.isInRing()) rbonds++; } return rbonds; }
private int countRingBonds(IBond[] bonds) { int rbonds = 0; for (IBond bond : bonds) { if (bond != null && bond.isInRing()) rbonds++; } return rbonds; }
private static int numRingBonds(IAtomContainer mol, IAtom atom) { int cnt = 0; for (IBond bond : mol.getConnectedBondsList(atom)) { if (bond.isInRing()) cnt++; } return cnt; }
private static int numRingBonds(IAtomContainer mol, IAtom atom) { int cnt = 0; for (IBond bond : mol.getConnectedBondsList(atom)) { if (bond.isInRing()) cnt++; } return cnt; }
/** * Simple method for marking ring systems with a flood-fill. * * @param ringSystem ring system vector * @param v start atom * @param rnum the number to mark atoms of this ring */ private void traverseRing(int[] ringSystem, int v, int rnum) { ringSystem[v] = rnum; for (int w : adjList[v]) { if (ringSystem[w] == 0 && bondMap.get(v, w).isInRing()) traverseRing(ringSystem, w, rnum); } }
/** * Simple method for marking ring systems with a flood-fill. * * @param ringSystem ring system vector * @param v start atom * @param rnum the number to mark atoms of this ring */ private void traverseRing(int[] ringSystem, int v, int rnum) { ringSystem[v] = rnum; for (int w : adjList[v]) { if (ringSystem[w] == 0 && bondMap.get(v, w).isInRing()) traverseRing(ringSystem, w, rnum); } }
private static Set<IBond> findCutBonds(IAtomContainer mol, EdgeToBondMap bmap, int[][] adjlist) { Set<IBond> cuts = new HashSet<>(); int numAtoms = mol.getAtomCount(); for (int i = 0; i < numAtoms; i++) { final IAtom atom = mol.getAtom(i); int deg = adjlist[i].length; int elem = atom.getAtomicNumber(); if (elem == 6 && deg <= 2 || deg < 2) continue; for (int w : adjlist[i]) { IBond bond = bmap.get(i, w); if (adjlist[w].length >= 2 && !bond.isInRing()) { cuts.add(bond); } } } return cuts; }
private static Set<IBond> findCutBonds(IAtomContainer mol, EdgeToBondMap bmap, int[][] adjlist) { Set<IBond> cuts = new HashSet<>(); int numAtoms = mol.getAtomCount(); for (int i = 0; i < numAtoms; i++) { final IAtom atom = mol.getAtom(i); int deg = adjlist[i].length; int elem = atom.getAtomicNumber(); if (elem == 6 && deg <= 2 || deg < 2) continue; for (int w : adjlist[i]) { IBond bond = bmap.get(i, w); if (adjlist[w].length >= 2 && !bond.isInRing()) { cuts.add(bond); } } } return cuts; }
@Test public void testRingBondCountT() { Expr expr = new Expr(RING_BOND_COUNT, 3); IAtom atom = mock(IAtom.class); IBond b1 = mock(IBond.class); IBond b2 = mock(IBond.class); IBond b3 = mock(IBond.class); when(atom.isInRing()).thenReturn(true); when(atom.getBondCount()).thenReturn(3); when(b1.isInRing()).thenReturn(true); when(b2.isInRing()).thenReturn(true); when(b3.isInRing()).thenReturn(true); when(atom.bonds()).thenReturn(Arrays.asList(b1, b2, b3)); assertTrue(expr.matches(atom)); }
@Test public void testRingBondCountF() { Expr expr = new Expr(RING_BOND_COUNT, 3); IAtom atom = mock(IAtom.class); IBond b1 = mock(IBond.class); IBond b2 = mock(IBond.class); IBond b3 = mock(IBond.class); when(atom.isInRing()).thenReturn(true); when(atom.getBondCount()).thenReturn(3); when(b1.isInRing()).thenReturn(true); when(b2.isInRing()).thenReturn(true); when(b3.isInRing()).thenReturn(false); when(atom.bonds()).thenReturn(Arrays.asList(b1, b2, b3)); assertFalse(expr.matches(atom)); }
@Test public void testBondIsChainT() { Expr expr = new Expr(IS_IN_CHAIN); IBond bond = mock(IBond.class); when(bond.isInRing()).thenReturn(false); assertTrue(expr.matches(bond)); }
@Test public void testBondIsChainF() { Expr expr = new Expr(IS_IN_CHAIN); IBond bond = mock(IBond.class); when(bond.isInRing()).thenReturn(true); assertFalse(expr.matches(bond)); }
@Test public void testBondIsRingT() { Expr expr = new Expr(IS_IN_RING); IBond bond = mock(IBond.class); when(bond.isInRing()).thenReturn(true); assertTrue(expr.matches(bond)); }
@Test public void testBondIsRingF() { Expr expr = new Expr(IS_IN_RING); IBond bond = mock(IBond.class); when(bond.isInRing()).thenReturn(false); assertFalse(expr.matches(bond)); }
private boolean doAngleSnap(IAtom atom, IAtomContainer placedNeighbours) { if (placedNeighbours.getAtomCount() != 2) return false; IBond b1 = molecule.getBond(atom, placedNeighbours.getAtom(0)); if (!b1.isInRing()) return false; IBond b2 = molecule.getBond(atom, placedNeighbours.getAtom(1)); if (!b2.isInRing()) return false; Point2d p1 = atom.getPoint2d(); Point2d p2 = placedNeighbours.getAtom(0).getPoint2d(); Point2d p3 = placedNeighbours.getAtom(1).getPoint2d(); Vector2d v1 = newVector(p2, p1); Vector2d v2 = newVector(p3, p1); return Math.abs(v2.angle(v1) - ANGLE_120) < 0.01; }
private boolean doAngleSnap(IAtom atom, IAtomContainer placedNeighbours) { if (placedNeighbours.getAtomCount() != 2) return false; IBond b1 = molecule.getBond(atom, placedNeighbours.getAtom(0)); if (!b1.isInRing()) return false; IBond b2 = molecule.getBond(atom, placedNeighbours.getAtom(1)); if (!b2.isInRing()) return false; Point2d p1 = atom.getPoint2d(); Point2d p2 = placedNeighbours.getAtom(0).getPoint2d(); Point2d p3 = placedNeighbours.getAtom(1).getPoint2d(); Vector2d v1 = newVector(p2, p1); Vector2d v2 = newVector(p3, p1); return Math.abs(v2.angle(v1) - ANGLE_120) < 0.01; }
private boolean isInSmallRing(IBond bond, int max) { if (!bond.isInRing()) return false; IAtom beg = bond.getBegin(); IAtom end = bond.getEnd(); int[] mark = new int[container.getAtomCount()]; int bidx = container.indexOf(beg); int eidx = container.indexOf(end); mark[bidx] = 2; return visitSmallRing(mark, eidx, bidx, 1, max); }
@Test public void markAtomsAndBonds() throws Exception { IAtomContainer biphenyl = makeBiphenyl(); Cycles.markRingAtomsAndBonds(biphenyl); int cyclicAtoms = 0; int cyclicBonds = 0; for (IAtom atom : biphenyl.atoms()) { if (atom.isInRing()) cyclicAtoms++; } for (IBond bond : biphenyl.bonds()) { if (bond.isInRing()) cyclicBonds++; } assertThat(cyclicAtoms, is(biphenyl.getAtomCount())); assertThat(cyclicBonds, is(biphenyl.getBondCount()-1)); }