/** * {@inheritDoc} */ @Override public IAtomContainer newAtomContainer() { if (CDK_LEGACY_AC) return new AtomContainer(0,0,0,0); else return new AtomContainer2(0,0,0,0); } }
@Test public void positionalVariationRoundTrip() throws Exception { try (MDLV3000Reader mdlr = new MDLV3000Reader(getClass().getResourceAsStream("multicenterBond.mol"))) { IAtomContainer mol = mdlr.read(new AtomContainer(0, 0, 0, 0)); String res = writeToStr(mol); assertThat(res, CoreMatchers.containsString("M V30 8 1 8 9 ATTACH=ANY ENDPTS=(5 2 3 4 5 6)\n")); } }
@Test public void testMassDiff() throws Exception { String mdl = "deuterium.mol\n" + "\n" + "\n" + " 1 0 0 0 0 1\n" + " 0.0000 0.0000 0.0000 H +1 0 0 0 0\n"; try (MDLReader reader = new MDLReader(new StringReader(mdl), Mode.STRICT)) { IAtomContainer mol = reader.read(new AtomContainer()); IAtom atom = mol.getAtom(0); Assert.assertEquals(1, atom.getAtomicNumber().intValue()); Assert.assertEquals(2, atom.getMassNumber().intValue()); } }
static Expr getBondExpr(String sma, int flav) { IAtomContainer mol = new AtomContainer(); assertTrue(Smarts.parse(mol, sma, flav)); return getBondExpr(mol.getBond(0)); }
@Test public void testIAtomContainer() throws Exception { String filename = "data/mol2/fromWebsite.mol2"; InputStream in = Mol2ReaderTest.class.getClassLoader().getResourceAsStream(filename); Mol2Reader reader = new Mol2Reader(in); IAtomContainer mol = (IAtomContainer) reader.read(new AtomContainer()); reader.close(); Assert.assertNotNull(mol); Assert.assertEquals(12, mol.getAtomCount()); Assert.assertEquals(12, mol.getBondCount()); }
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 testGetInstance() throws Exception { TemplateHandler3D th3d = TemplateHandler3D.getInstance(); // need to trigger a load of the templates th3d.mapTemplates(new AtomContainer(), 0); Assert.assertEquals(10751, th3d.getTemplateCount()); }
@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 roundtripChemObject() { IAtomContainer mol = new AtomContainer(); IAtom object = new Atom("C"); object.setID("atom1"); 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()); }
private void roundtripBond_Order(IBond.Order order) { IAtomContainer mol = new AtomContainer(); mol.addAtom(new Atom("C")); mol.addAtom(new Atom("C")); mol.addBond(0, 1, order); 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 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 nonExplicitHydrogen() { IAtomContainer mol = new AtomContainer(); assertTrue(Smarts.parse(mol, "[2&H+]")); Expr actual = getAtomExpr(mol.getAtom(0)); Expr expected = and(expr(ISOTOPE, 2), and(expr(TOTAL_H_COUNT, 1), expr(FORMAL_CHARGE, +1))); assertThat(actual, is(expected)); }
@Test public void hashedWedgeBonds() throws IOException, CDKException { IAtomContainer mol = new AtomContainer(); mol.addAtom(new Atom("C")); mol.addAtom(new Atom("O")); mol.addBond(0, 1, IBond.Order.SINGLE, IBond.Stereo.DOWN); mol.getAtom(0).setImplicitHydrogenCount(3); mol.getAtom(1).setImplicitHydrogenCount(1); String res = writeToStr(mol); assertThat(res, CoreMatchers.containsString("M V30 1 1 1 2 CFG=3\n")); }
@Test public void trailingOperator() { IAtomContainer mol = new AtomContainer(); assertFalse(Smarts.parse(mol, "[a#6,]")); assertFalse(Smarts.parse(mol, "[a#6;]")); assertFalse(Smarts.parse(mol, "[a#6&]")); assertFalse(Smarts.parse(mol, "[a#6!]")); }
@Test public void trailingBondOperator() { IAtomContainer mol = new AtomContainer(); assertFalse(Smarts.parse(mol, "*-,*")); assertFalse(Smarts.parse(mol, "*-;*")); assertFalse(Smarts.parse(mol, "*-&*")); assertFalse(Smarts.parse(mol, "*-!*")); }
@Test public void opPrecedence1() { IAtomContainer mol = new AtomContainer(); assertTrue(Smarts.parse(mol, "[a#6,a#7]")); Expr actual = getAtomExpr(mol.getAtom(0)); Expr expected = or(and(expr(IS_AROMATIC), expr(ELEMENT, 6)), and(expr(IS_AROMATIC), expr(ELEMENT, 7))); assertThat(actual, is(expected)); }
@Test public void ringSmallestInvalid() { IAtomContainer mol = new AtomContainer(); assertTrue(Smarts.parse(mol, "[r0]")); // not in ring assertFalse(Smarts.parse(mol, "[r1]")); assertFalse(Smarts.parse(mol, "[r2]")); assertTrue(Smarts.parse(mol, "[r3]")); }
/** * Test if we get the expected {@link IllegalArgumentException} when we pass * an {@link IAtomContainer} without 2D coordinates. */ @Test(expected = IllegalArgumentException.class) public void testCalculateBounds_IReaction_SingleAtom() { IAtomContainer container = new AtomContainer(); container.addAtom(container.getBuilder().newInstance(IAtom.class, "C")); IReaction reaction = container.getBuilder().newInstance(IReaction.class); reaction.addReactant(container.getBuilder().newInstance(IAtomContainer.class, container)); BoundsCalculator.calculateBounds(reaction); }