@Test public void chargedAtom() throws Exception { IAtom a = new Atom("C"); a.setImplicitHydrogenCount(0); for (int chg = -10; chg < 10; chg++) { a.setFormalCharge(chg); assertThat(new CDKToBeam().toBeamAtom(a).charge(), is(chg)); } }
@Test public void oxidanide() throws Exception { IAtomContainer ac = new AtomContainer(); IAtom a = new Atom("O"); a.setFormalCharge(-1); ac.addAtom(a); Graph g = convert(ac, 0); assertThat(g.atom(0).charge(), is(-1)); assertThat(g.toSmiles(), is("[OH-]")); }
@Test public void oxidandiide() throws Exception { IAtomContainer ac = new AtomContainer(); IAtom a = new Atom("O"); a.setFormalCharge(-2); ac.addAtom(a); Graph g = convert(ac, 0); assertThat(g.atom(0).charge(), is(-2)); assertThat(g.toSmiles(), is("[O-2]")); }
@Test public void azanium() throws Exception { IAtomContainer ac = new AtomContainer(); IAtom a = new Atom("N"); a.setFormalCharge(+1); ac.addAtom(a); Graph g = convert(ac, 0); assertThat(g.atom(0).charge(), is(+1)); assertThat(g.toSmiles(), is("[NH4+]")); }
/** * 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; }
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; } }