/** * Given two atoms which are implicitly connected determine the explicit * bond type. The type is 'aromatic' if both atoms are aromatic, if either * or both atoms are non-aromatic then the bond type is 'single'. * * @param u an atom * @param v another atom (connected to u) * @return the bond type */ static Bond type(Atom u, Atom v) { return u.aromatic() && v.aromatic() ? Bond.AROMATIC : Bond.SINGLE; } }
/** * Given two atoms which are explicit connected determine the implicit bond * type. If both atoms are aromatic but connected by a single bond the bond * type is {@link Bond#SINGLE} otherwise it is implicit. * * @param u an atom * @param v another atom (connected to u) * @param b explicit bond type * @return the bond type */ static Bond type(Atom u, Atom v, Bond b) { if (u.aromatic() && v.aromatic()) return b == Bond.AROMATIC ? Bond.IMPLICIT : b; else return b == Bond.AROMATIC ? Bond.AROMATIC : Bond.IMPLICIT; } }
static Atom fromSubset(Atom a, int sum, int deg) { // atom is already a non-subset atom if (!a.subset()) return a; Element e = a.element(); if (a.aromatic() && deg <= sum) sum++; int hCount = a.aromatic() ? Element.implicitAromHydrogenCount(e, sum) : Element.implicitHydrogenCount(e, sum); // XXX: if there was an odd number of availableElectrons there was an odd number // or aromatic bonds (usually 1 or 3) - if there was one it was // only a single bond it's likely a spouting from a ring - otherwise // someones making our life difficult (e.g. c1=cc=cc=c1) in which we // 'give' back 2 free availableElectrons for use indeterminacy the hCount // int hCount = (electrons & 0x1) == 1 ? deg > 1 ? (electrons + 2) / 2 // : electrons / 2 // : electrons / 2; return new AtomImpl.BracketAtom(-1, a.element(), hCount, 0, 0, a.aromatic()); } }
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()); }
/** * Create a new CDK {@link IAtom} from the Beam Atom. * * @param beamAtom an Atom from the Beam ChemicalGraph * @param hCount hydrogen count for the atom * @return the CDK atom to have it's properties set */ IAtom toCDKAtom(Atom beamAtom, int hCount) { IAtom cdkAtom = newCDKAtom(beamAtom); cdkAtom.setImplicitHydrogenCount(hCount); cdkAtom.setFormalCharge(beamAtom.charge()); if (beamAtom.isotope() >= 0) cdkAtom.setMassNumber(beamAtom.isotope()); if (beamAtom.aromatic()) cdkAtom.setIsAromatic(true); if (beamAtom.atomClass() > 0) cdkAtom.setProperty(ATOM_ATOM_MAPPING, beamAtom.atomClass()); return cdkAtom; }
@Test public void aliphaticAtom() throws Exception { IAtom a = new Atom("C"); a.setImplicitHydrogenCount(0); assertFalse(new CDKToBeam().toBeamAtom(a).aromatic()); }
static Atom toSubset(Atom a, Graph g, int u) { // atom is already a subset atom if (a.subset()) return a; // element is not organic and thus cannot be part of the subset if (!a.element().organic()) return a; // if any of these values are set the atom cannot be a subset atom if (a.charge() != 0 || a.atomClass() != 0 || a.isotope() >= 0) return a; Atom subset = a.aromatic() ? AtomImpl.AromaticSubset.ofElement(a.element()) : AtomImpl.AliphaticSubset.ofElement(a.element()); // does the implied availableElectrons from the bond order sum match that // which was stored - if aromatic we only check the lowest valence state int impliedHCount = subset.hydrogens(g, u); // mismatch in number of hydrogens we must write this as a bracket atom return impliedHCount != a.hydrogens() ? a : subset; } }
@Test public void aromaticAtom() throws Exception { IAtom a = new Atom("C"); a.setImplicitHydrogenCount(0); a.setFlag(CDKConstants.ISAROMATIC, true); assertTrue(new CDKToBeam().toBeamAtom(a).aromatic()); }