/** * Returns all the rings in the RingSet that share * one or more atoms with a given ring. * * @param ring A ring with which all return rings must share one or more atoms * @return All the rings that share one or more atoms with a given ring. */ @Override public IRingSet getConnectedRings(IRing ring) { IRingSet connectedRings = ring.getBuilder().newInstance(IRingSet.class); IRing tempRing; IAtom atom; for (int i = 0; i < ring.getAtomCount(); i++) { atom = ring.getAtom(i); for (int j = 0; j < getAtomContainerCount(); j++) { tempRing = (IRing) getAtomContainer(j); if (tempRing != ring && !connectedRings.contains(tempRing) && tempRing.contains(atom)) { connectedRings.addAtomContainer(tempRing); } } } return connectedRings; }
/** * Check if a ring in a ring set is a macro cycle. We define this as a * ring with >= 10 atom and has at least one bond that isn't contained * in any other rings. * * @param ring ring to check * @param rs rest of ring system * @return ring is a macro cycle */ private boolean isMacroCycle(IRing ring, IRingSet rs) { if (ring.getAtomCount() < 8) return false; for (IBond bond : ring.bonds()) { boolean found = false; for (IAtomContainer other : rs.atomContainers()) { if (ring == other) continue; if (other.contains(bond)) { found = true; break; } } if (!found) return true; } return false; }
private void getBondsInRing(IAtomContainer mol, IRing ring, int[] bonds) { for (int i = 0; i < ring.getBondCount(); i++) { int m = mol.indexOf(ring.getBond(i)); bonds[m] = 1; } }
static boolean isAromaticRing(IRing ring) { for (int i = 0; i < ring.getAtomCount(); i++) if (!ring.getAtom(i).getFlag(CDKConstants.ISAROMATIC)) return (false); return (true); }
/** * Marks the ring aromatic if all atoms and all bonds are aromatic. * * The method assumes that aromaticity of atoms and bonds have been * detected beforehand * * @param ring The ring to examine */ public static void markAromaticRings(IRing ring) { // return as soon as the conditions are not met: // 1. all atoms are labeled aromatic for (IAtom atom : ring.atoms()) if (!atom.getFlag(CDKConstants.ISAROMATIC)) return; // 2. all bonds are labeled aromatic for (IBond bond : ring.bonds()) if (!bond.getFlag(CDKConstants.ISAROMATIC)) return; // OK, all conditions are met, so ring is aromatic ring.setFlag(CDKConstants.ISAROMATIC, true); }
@Test public void testRing_int() { IRing r = new Ring(5); // This does not create a ring! Assert.assertEquals(0, r.getAtomCount()); Assert.assertEquals(0, r.getBondCount()); }
/** * Set all the atoms in unplaced rings to be unplaced */ private void resetUnplacedRings() { IRing ring = null; if (sssr == null) { return; } int unplacedCounter = 0; for (int f = 0; f < sssr.getAtomContainerCount(); f++) { ring = (IRing) sssr.getAtomContainer(f); if (!ring.getFlag(CDKConstants.ISPLACED)) { logger.debug("Ring with " + ring.getAtomCount() + " atoms is not placed."); unplacedCounter++; for (int g = 0; g < ring.getAtomCount(); g++) { ring.getAtom(g).setFlag(CDKConstants.ISPLACED, false); } } } logger.debug("There are " + unplacedCounter + " unplaced Rings."); }
double addAngle = 2 * Math.PI / ring.getRingSize(); IAtom startAtom = ring.getAtom(0); Point2d p = new Point2d(ringCenter.x + radius, ringCenter.y); startAtom.setPoint2d(p); int ringSize = ring.getRingSize(); if (startAngles.get(ringSize) != null) startAngle = startAngles.get(ringSize); List<IBond> bonds = ring.getConnectedBondsList(startAtom); IAtom currentAtom = startAtom; IBond currentBond = (IBond) bonds.get(0); for (int i = 0; i < ring.getBondCount(); i++) { currentBond = ring.getNextBond(currentBond, currentAtom); currentAtom = currentBond.getOther(currentAtom); atomsToDraw.addElement(currentAtom);
private IRing combineRings(IRingSet ringset, int i, int j) { int c = 0; for (int b = 0; b < cb[i].length; b++) { c = cb[i][b] + cb[j][b]; if (c > 1) break; //at least one common bond } if (c < 2) return null; IRing ring = molecule.getBuilder().newInstance(IRing.class); IRing ring1 = (IRing) ringset.getAtomContainer(i); IRing ring2 = (IRing) ringset.getAtomContainer(j); for (int b = 0; b < cb[i].length; b++) { c = cb[i][b] + cb[j][b]; if ((c == 1) && (cb[i][b] == 1)) ring.addBond(molecule.getBond(b)); else if ((c == 1) && (cb[j][b] == 1)) ring.addBond(molecule.getBond(b)); } for (int a = 0; a < ring1.getAtomCount(); a++) ring.addAtom(ring1.getAtom(a)); for (int a = 0; a < ring2.getAtomCount(); a++) ring.addAtom(ring2.getAtom(a)); return ring; }
/** * Layout a macro cycle (the rest of the ring set is untouched). * * @param macrocycle the macrocycle * @param ringset the ring set the macrocycle belongs to (may only be it's self) * @return layout was successfully, if false caller fall-back to regular polygons */ boolean layout(IRing macrocycle, IRingSet ringset) { final IAtomContainer anon = roundUpIfNeeded(AtomContainerManipulator.anonymise(macrocycle)); final Collection<Point2d[]> coords = TEMPLATES.getCoordinates(anon); if (coords.isEmpty()) return false; Point2d[] best = new Point2d[anon.getAtomCount()]; int bestOffset = selectCoords(coords, best, macrocycle, ringset); for (int i = 0; i < macrocycle.getAtomCount(); i++) { macrocycle.getAtom(i).setPoint2d(best[(bestOffset + i) % macrocycle.getAtomCount()]); macrocycle.getAtom(i).setFlag(ISPLACED, true); macrocycle.getAtom(i).setProperty(MACROCYCLE_ATOM_HINT, true); } macrocycle.setFlag(ISPLACED, true); return true; }
IRingSet ringSet = ring.getBuilder().newInstance(IRingSet.class); IBond bond; int minMaxSize = Integer.MAX_VALUE; int minMax = 0; logger.debug("Molecule: " + molecule); Iterator<IBond> bonds = ring.bonds().iterator(); while (bonds.hasNext()) { bond = (IBond) bonds.next(); r2 = getRing(bond.getEnd(), molecule); logger.debug("checkEdges: " + bond); if (r1.getAtomCount() > r2.getAtomCount()) { ringSet.addAtomContainer(r1); } else { if (((IRing) ringSet.getAtomContainer(i)).getBondCount() < minMaxSize) { minMaxSize = ((IRing) ringSet.getAtomContainer(i)).getBondCount(); minMax = i; return (IBond) ring.getElectronContainer(minMax);
/** * Completes the layout of a partially laid out ring. * * @param rset ring set * @param ring the ring to complete * @param bondLength the bond length */ boolean completePartiallyPlacedRing(IRingSet rset, IRing ring, double bondLength) { if (ring.getFlag(CDKConstants.ISPLACED)) return true; IRing partiallyPlacedRing = molecule.getBuilder().newInstance(IRing.class); for (IAtom atom : ring.atoms()) if (atom.getPoint2d() != null) atom.setFlag(CDKConstants.ISPLACED, true); AtomPlacer.copyPlaced(partiallyPlacedRing, ring); if (partiallyPlacedRing.getAtomCount() > 1 && partiallyPlacedRing.getAtomCount() < ring.getAtomCount()) { placeConnectedRings(rset, partiallyPlacedRing, RingPlacer.FUSED, bondLength); placeConnectedRings(rset, partiallyPlacedRing, RingPlacer.BRIDGED, bondLength); placeConnectedRings(rset, partiallyPlacedRing, RingPlacer.SPIRO, bondLength); ring.setFlag(CDKConstants.ISPLACED, true); return true; } else { return false; } }
final SmilesParser smipar = new SmilesParser(ring.getBuilder()); initCache(smipar); for (int i = 0; i < ring.getAtomCount(); i++) { if (ring.getAtom(i).getSymbol().equals("N")) { ncount = ncount + 1; if (ring.getAtomCount() == 6 & ncount == 1) { return 10; } else if (ring.getAtomCount() == 5 & ncount == 1) { return 4;
/** * Copy placed atoms/bonds from one container to another. * * @param dest destination container * @param src source container */ static void copyPlaced(IRing dest, IAtomContainer src) { for (IBond bond : src.bonds()) { IAtom beg = bond.getBegin(); IAtom end = bond.getEnd(); if (beg.getFlag(CDKConstants.ISPLACED)) { dest.addAtom(beg); if (end.getFlag(CDKConstants.ISPLACED)) { dest.addAtom(end); dest.addBond(bond); } } else if (end.getFlag(CDKConstants.ISPLACED)) { dest.addAtom(end); } } }
ring.getBond(0).setOrder(IBond.Order.DOUBLE); ring.getBond(2).setOrder(IBond.Order.DOUBLE); ring.getBond(4).setOrder(IBond.Order.DOUBLE); for(IAtom atom : ring.atoms()) this.chemModelRelay.addPhantomAtom(atom); for(IBond atom : ring.bonds()) this.chemModelRelay.addPhantomBond(atom); for(IAtom atom : ring.atoms()){ IAtom closestAtomInRing = this.chemModelRelay.getClosestAtom(atom); if( closestAtomInRing != null) {
/** * Checks if <code>atom1</code> and <code>atom2</code> share membership in the same ring or ring system. * Membership in the same ring is checked if the RingSet contains the SSSR of a molecule; membership in * the same ring or same ring system is checked if the RingSet contains all rings of a molecule.<BR><BR> * * <p><B>Important:</B> This method only returns meaningful results if <code>atom1</code> and * <code>atom2</code> are members of the same molecule for which the RingSet was calculated! * * @param ringSet The collection of rings * @param atom1 The first atom * @param atom2 The second atom * @return boolean true if <code>atom1</code> and <code>atom2</code> share membership of at least one ring or ring system, false otherwise */ public static boolean isSameRing(IRingSet ringSet, IAtom atom1, IAtom atom2) { for (IAtomContainer atomContainer : ringSet.atomContainers()) { IRing ring = (IRing) atomContainer; if (ring.contains(atom1) && ring.contains(atom2)) return true; } return false; }
/** * Removes rings which do not have all sp2/planar3 aromatic atoms. * and also gets rid of rings that have more than 8 atoms in them. * * @param m The {@link IAtomContainer} from which we want to remove rings * @return The set of reduced rings */ private IRingSet removeExtraRings(IAtomContainer m) throws Exception { IRingSet rs = Cycles.sssr(m).toRingSet(); //remove rings which dont have all aromatic atoms (according to hybridization set by lower case symbols in smiles): Iterator<IAtomContainer> i = rs.atomContainers().iterator(); while (i.hasNext()) { IRing r = (IRing) i.next(); if (r.getAtomCount() > 8) { i.remove(); } else { for (IAtom a : r.atoms()) { Hybridization h = a.getHybridization(); if (h == CDKConstants.UNSET || !(h == Hybridization.SP2 || h == Hybridization.PLANAR3)) { i.remove(); break; } } } } return rs; }
for (int i = 0; i < ring.getBondCount(); i++) { if (!ring.getBond(i).getFlag(CDKConstants.ISAROMATIC)) allaromatic = false; for (int i = 0; i < ring.getBondCount(); i++) { if (ring.getBond(i).getFlag(CDKConstants.ISAROMATIC)) ring.getBond(i).setOrder(IBond.Order.SINGLE); if (ring.getRingSize() == 6) { if (MolecularFormulaManipulator.getElementCount(formula, new Element("C")) == 6) { result = DeAromatizationTool.deAromatizeBenzene(ring); if (ring.getRingSize() == 5) { if (MolecularFormulaManipulator.getElementCount(formula, new Element("C")) == 4 && MolecularFormulaManipulator.getElementCount(formula, new Element("N")) == 1) {
/** * Converts a RingSet to an AtomContainer. * *@param ringSet The RingSet to be converted. *@return The AtomContainer containing the bonds and atoms of the ringSet. */ public static IAtomContainer convertToAtomContainer(IRingSet ringSet) { IRing ring = (IRing) ringSet.getAtomContainer(0); if (ring == null) return null; IAtomContainer ac = ring.getBuilder().newInstance(IAtomContainer.class); for (int i = 0; i < ringSet.getAtomContainerCount(); i++) { ring = (IRing) ringSet.getAtomContainer(i); for (int r = 0; r < ring.getBondCount(); r++) { IBond bond = ring.getBond(r); if (!ac.contains(bond)) { for (int j = 0; j < bond.getAtomCount(); j++) { ac.addAtom(bond.getAtom(j)); } ac.addBond(bond); } } } return ac; }
otherAtoms.add(atom); final boolean snap = ring.getProperty(SNAP_HINT) != null && ring.getProperty(SNAP_HINT, Boolean.class); bondAtom2Vector.sub(ringCenter); final int numUnplaced = ring.getRingSize() - sharedAtoms.getAtomCount(); for (int i = 0; i < ring.getBondCount(); i++) { currentBond = ring.getNextBond(currentBond, currentAtom); currentAtom = currentBond.getOther(currentAtom); if (!sharedAtoms.contains(currentAtom)) {