/** * {@inheritDoc} */ @Override public int getConnectedBondsCount(int idx) { final IAtom atom = getAtom(idx); int count = 0; for (int i = 0; i < bondCount; i++) { if (bonds[i].contains(atom)) ++count; } return count; }
/** * {@inheritDoc} */ @Override public void removeAllElements() { removeAllElectronContainers(); for (int f = 0; f < getAtomCount(); f++) { getAtom(f).removeListener(this); } atoms = new IAtom[growArraySize]; atomCount = 0; stereoElements.clear(); notifyChanged(); }
/** * {@inheritDoc} */ @Override public void removeAllElements() { removeAllElectronContainers(); for (int f = 0; f < getAtomCount(); f++) { getAtom(f).removeListener(this); } atoms = new IAtom[growArraySize]; atomCount = 0; stereoElements.clear(); notifyChanged(); }
/** * {@inheritDoc} */ @Override public IAtom getAtom(int idx) { logger.debug("Getting atom at: ", idx); return super.getAtom(idx); }
stringContent.append(", #A:").append(getAtomCount()); for (int i = 0; i < getAtomCount(); i++) { stringContent.append(", ").append(getAtom(i).toString());
/** * {@inheritDoc} */ @Override public void removeAtom(int pos) { removeAtom(getAtom(pos)); }
stringContent.append(", #A:").append(getAtomCount()); for (int i = 0; i < getAtomCount(); i++) { stringContent.append(", ").append(getAtom(i).toString());
/** * {@inheritDoc} */ @Override public int getConnectedBondsCount(int idx) { final IAtom atom = getAtom(idx); int count = 0; for (int i = 0; i < bondCount; i++) { if (bonds[i].contains(atom)) ++count; } return count; }
@Test public void testConfigureAtoms_IAtomContainer() throws Exception { AtomContainer container = new org.openscience.cdk.AtomContainer(); container.addAtom(new Atom("C")); container.addAtom(new Atom("H")); container.addAtom(new Atom("N")); container.addAtom(new Atom("O")); container.addAtom(new Atom("F")); container.addAtom(new Atom("Cl")); Isotopes isofac = Isotopes.getInstance(); isofac.configureAtoms(container); for (int i = 0; i < container.getAtomCount(); i++) { Assert.assertTrue(0 < container.getAtom(i).getAtomicNumber()); } }
/** * {@inheritDoc} */ @Override public void removeAtom(int pos) { removeAtom(getAtom(pos)); }
@Test public void testConfigureAtoms_IAtomContainer() throws Exception { AtomContainer container = new org.openscience.cdk.AtomContainer(); container.addAtom(new Atom("C")); container.addAtom(new Atom("H")); container.addAtom(new Atom("N")); container.addAtom(new Atom("O")); container.addAtom(new Atom("F")); container.addAtom(new Atom("Cl")); XMLIsotopeFactory isofac = XMLIsotopeFactory.getInstance(new ChemObject().getBuilder()); isofac.configureAtoms(container); for (int i = 0; i < container.getAtomCount(); i++) { Assert.assertTrue(0 < container.getAtom(i).getAtomicNumber()); } }
/** * {@inheritDoc} */ @Override public void addBond(int atom1, int atom2, IBond.Order order, IBond.Stereo stereo) { IBond bond = getBuilder().newInstance(IBond.class, getAtom(atom1), getAtom(atom2), order, stereo); addBond(bond); /* * no notifyChanged() here because addBond(bond) does it already */ }
@Test public void testAtomPermutation() { AtomContainer ac = new org.openscience.cdk.AtomContainer(); AtomContainer result; String atoms = new String(""); ac.addAtom(new Atom("C")); ac.addAtom(new Atom("N")); ac.addAtom(new Atom("P")); ac.addAtom(new Atom("O")); ac.addAtom(new Atom("S")); ac.addAtom(new Atom("Br")); ac.addBond(0, 1, IBond.Order.SINGLE); ac.addBond(1, 2, IBond.Order.SINGLE); ac.addBond(2, 3, IBond.Order.SINGLE); ac.addBond(3, 4, IBond.Order.SINGLE); ac.addBond(4, 5, IBond.Order.SINGLE); AtomContainerAtomPermutor acap = new AtomContainerAtomPermutor(ac); int counter = 0; while (acap.hasNext()) { counter++; atoms = ""; result = (AtomContainer) acap.next(); for (int f = 0; f < result.getAtomCount(); f++) { atoms += result.getAtom(f).getSymbol(); } } Assert.assertEquals(719, counter); }
/** * {@inheritDoc} */ @Override public void addBond(int atom1, int atom2, IBond.Order order, IBond.Stereo stereo) { IBond bond = getBuilder().newInstance(IBond.class, getAtom(atom1), getAtom(atom2), order, stereo); addBond(bond); /* * no notifyChanged() here because addBond(bond) does it already */ }
/** * @cdk.bug 1875946 */ @Test public void testPreservingFormalCharge() throws Exception { AtomContainer mol = new AtomContainer(); mol.addAtom(new Atom(Elements.OXYGEN)); mol.getAtom(0).setFormalCharge(-1); mol.addAtom(new Atom(Elements.CARBON)); mol.addBond(0, 1, IBond.Order.SINGLE); addImplicitHydrogens(mol); SmilesGenerator generator = new SmilesGenerator(); generator.create(new AtomContainer(mol)); Assert.assertEquals(-1, mol.getAtom(0).getFormalCharge().intValue()); // mmm, that does not reproduce the bug findings yet :( }
/** * Test generation of a reaction SMILES. I know, it's a stupid alchemic * reaction, but it serves its purpose. */ @Test public void testReactionSMILES() throws Exception { Reaction reaction = new Reaction(); AtomContainer methane = new AtomContainer(); methane.addAtom(new Atom("C")); reaction.addReactant(methane); IAtomContainer magic = new AtomContainer(); magic.addAtom(new PseudoAtom("magic")); reaction.addAgent(magic); IAtomContainer gold = new AtomContainer(); gold.addAtom(new Atom("Au")); reaction.addProduct(gold); methane.getAtom(0).setImplicitHydrogenCount(4); gold.getAtom(0).setImplicitHydrogenCount(0); SmilesGenerator sg = new SmilesGenerator(SmiFlavor.Generic); String smiles = sg.create(reaction); //logger.debug("Generated SMILES: " + smiles); Assert.assertEquals("C>*>[Au]", smiles); }
if (mol.getAtom(i).getFlag(CDKConstants.SINGLE_OR_DOUBLE)) mol.setFlag(CDKConstants.SINGLE_OR_DOUBLE, true); Assert.assertTrue(mol.getAtom(0).getFlag(CDKConstants.SINGLE_OR_DOUBLE)); Assert.assertTrue(mol.getBond(0).getFlag(CDKConstants.SINGLE_OR_DOUBLE)); Assert.assertTrue(mol.getFlag(CDKConstants.SINGLE_OR_DOUBLE));