/** * {@inheritDoc} */ @Override public IAtom newAtom() { return new Atom(); }
static IAtom atom(String symb, int h) { IAtom atom = new org.openscience.cdk.silent.Atom(symb); atom.setImplicitHydrogenCount(h); return atom; } }
static IAtom atomAt(String symb, Point2d p) { IAtom atom = new Atom(symb); atom.setPoint2d(p); return atom; }
static IAtom atom(String symbol, int hCount, double x, double y) { IAtom a = new Atom(symbol); a.setImplicitHydrogenCount(hCount); a.setPoint2d(new Point2d(x, y)); return a; }
@Test public void outputValencyWhenNeeded() throws IOException, CDKException { IAtomContainer mol = new AtomContainer(); mol.addAtom(new Atom("Na")); mol.addAtom(new Atom("Na")); mol.getAtom(0).setImplicitHydrogenCount(0); // Na metal mol.getAtom(1).setImplicitHydrogenCount(1); // Na hydride String res = writeToStr(mol); assertThat(res, CoreMatchers.containsString("M V30 1 Na 0 0 0 0 VAL=-1\n")); assertThat(res, CoreMatchers.containsString("M V30 2 Na 0 0 0 0\n")); }
@Test public void unspecifiedIsotope() throws Exception { IAtom a = new Atom("C"); a.setImplicitHydrogenCount(0); assertThat(new CDKToBeam().toBeamAtom(a).isotope(), is(-1)); }
@Test public void writeLeadingZero() throws IOException, CDKException { IAtomContainer mol = new AtomContainer(); Atom atom = new Atom("C"); atom.setPoint2d(new Point2d(0.5, 1.2)); mol.addAtom(atom); assertThat(writeToStr(mol), CoreMatchers.containsString("0.5 1.2")); }
private void roundtripAtomType_MaxBondOrder(Order order) { IAtomContainer mol = new AtomContainer(); IAtom object = new Atom("C"); object.setMaxBondOrder(order); mol.addAtom(object); Model model = Convertor.molecule2Model(mol); IAtomContainer rtMol = Convertor.model2Molecule(model, builder); String diff = AtomContainerDiff.diff(mol, rtMol); Assert.assertEquals("Unexpected diff: " + diff, 0, diff.length()); } }
@Test public void testAtom_IElement() { IElement element = newChemObject().getBuilder().newInstance(IElement.class); IAtom a = new Atom(element); Assert.assertNotNull(a); }
@Test public void methane_Atom() throws Exception { IAtom a = new Atom("C"); a.setImplicitHydrogenCount(4); assertThat(new CDKToBeam().toBeamAtom(a).element(), is(Element.Carbon)); assertThat(new CDKToBeam().toBeamAtom(a).hydrogens(), is(4)); }
@Test public void C13_isomeric() throws Exception { IAtomContainer ac = new AtomContainer(); IAtom a = new Atom("C"); a.setMassNumber(13); ac.addAtom(a); Graph g = convert(ac, SmiFlavor.AtomicMass); assertThat(g.atom(0).isotope(), is(13)); assertThat(g.toSmiles(), is("[13CH4]")); }
@Test public void outputRadical() throws IOException, CDKException { IAtomContainer mol = new AtomContainer(); mol.addAtom(new Atom("C")); mol.getAtom(0).setImplicitHydrogenCount(3); mol.addSingleElectron(0); String res = writeToStr(mol); assertThat(res, CoreMatchers.containsString("M V30 1 C 0 0 0 0 RAD=2 VAL=3\n")); }
@Test public void roundtripIsotope_ExactMass() { IAtomContainer mol = new AtomContainer(); IAtom object = new Atom("C"); object.setExactMass(0.3); mol.addAtom(object); Model model = Convertor.molecule2Model(mol); IAtomContainer rtMol = Convertor.model2Molecule(model, builder); String diff = AtomContainerDiff.diff(mol, rtMol); Assert.assertEquals("Unexpected diff: " + diff, 0, diff.length()); }
@Test public void roundtripIsotope_NaturalAbundance() { IAtomContainer mol = new AtomContainer(); IAtom object = new Atom("C"); object.setNaturalAbundance(0.95); mol.addAtom(object); Model model = Convertor.molecule2Model(mol); IAtomContainer rtMol = Convertor.model2Molecule(model, builder); String diff = AtomContainerDiff.diff(mol, rtMol); Assert.assertEquals("Unexpected diff: " + diff, 0, diff.length()); }
@Test(expected = CDKException.class) public void unsetBondOrder() throws IOException, CDKException { IAtomContainer mol = new AtomContainer(); mol.addAtom(new Atom("H")); mol.addAtom(new Atom("C")); mol.addBond(0, 1, IBond.Order.UNSET); mol.getAtom(0).setImplicitHydrogenCount(0); mol.getAtom(0).setMassNumber(2); mol.getAtom(1).setImplicitHydrogenCount(3); writeToStr(mol); }
@Test public void testAtom_String_Point2d() { Point2d point2d = new Point2d(1.0, 2.0); IAtom a = new Atom("C", point2d); Assert.assertEquals("C", a.getSymbol()); Assert.assertEquals(point2d, a.getPoint2d()); Assert.assertNull(a.getPoint3d()); Assert.assertNull(a.getFractionalPoint3d()); }
@Test public void testAtom_NH4plus() { IAtom a = new Atom("NH4+"); Assert.assertEquals("N", a.getSymbol()); Assert.assertEquals((Integer) 7, a.getAtomicNumber()); Assert.assertEquals((Integer) 4, a.getImplicitHydrogenCount()); Assert.assertEquals((Integer) 1, a.getFormalCharge()); Assert.assertNull(a.getPoint2d()); Assert.assertNull(a.getPoint3d()); Assert.assertNull(a.getFractionalPoint3d()); }
@Test public void testAtom_13CH3() { IAtom a = new Atom("13CH3"); Assert.assertEquals("C", a.getSymbol()); Assert.assertEquals((Integer) 13, a.getMassNumber()); Assert.assertEquals((Integer) 6, a.getAtomicNumber()); Assert.assertEquals((Integer) 3, a.getImplicitHydrogenCount()); Assert.assertEquals((Integer) 0, a.getFormalCharge()); Assert.assertNull(a.getPoint2d()); Assert.assertNull(a.getPoint3d()); Assert.assertNull(a.getFractionalPoint3d()); }