private void printRadicalAtoms(IAtomContainer mol) { out.print("Atom: "); for (Integer a = 0; a < mol.getSingleElectronCount(); a++) { out.print(mol.getSingleElectron(a).getAtom().getSymbol()); out.print(mol.getSingleElectron(a).getElectronCount()); } out.println(); out.println(); } }
/** * Returns the sum of the SingleElectron for a given Atom. * *@param atom The atom on which the single electron is located *@return The array of SingleElectron of this AtomContainer */ @Override public int getConnectedSingleElectronsCount(IAtom atom) { int count = 0; for (int i = 0; i < singleElectronCount; i++) { if (singleElectrons[i].contains(atom)) ++count; } return count; }
@Test public void testClone_IAtom() throws Exception { ISingleElectron radical = (ISingleElectron) newChemObject(); IAtom atom = radical.getBuilder().newInstance(IAtom.class, "N"); radical.setAtom(atom); // test cloning of atom ISingleElectron clone = (ISingleElectron) radical.clone(); Assert.assertNotSame(atom, clone.getAtom()); }
/** * Compare two {@link IChemObject} classes and return the difference as an {@link IDifference}. * * @param first the first of the two classes to compare * @param second the second of the two classes to compare * @return an {@link IDifference} representation of the difference between the first and second {@link IChemObject}. */ public static IDifference difference(IChemObject first, IChemObject second) { if (!(first instanceof ISingleElectron && second instanceof ISingleElectron)) { return null; } ISingleElectron firstB = (ISingleElectron) first; ISingleElectron secondB = (ISingleElectron) second; IDifferenceList totalDiff = new ChemObjectDifference("SingleElectronDiff"); totalDiff.addChild(AtomDiff.difference(firstB.getAtom(), secondB.getAtom())); totalDiff.addChild(ElectronContainerDiff.difference(first, second)); if (totalDiff.childCount() > 0) { return totalDiff; } else { return null; } }
@Test public void testSingleElectron_IAtom() { IAtom atom = newChemObject().getBuilder().newInstance(IAtom.class, "N"); ISingleElectron radical = new SingleElectron(atom); Assert.assertEquals(1, radical.getElectronCount().intValue()); Assert.assertEquals(atom, radical.getAtom()); Assert.assertTrue(radical.contains(atom)); }
@Test public void testSetAtom_IAtom() { ISingleElectron radical = (ISingleElectron) newChemObject(); IAtom atom = radical.getBuilder().newInstance(IAtom.class, "N"); Assert.assertNull(radical.getAtom()); radical.setAtom(atom); Assert.assertEquals(atom, radical.getAtom()); }
@Test public void testAddSingleElectron_int() { IAtomContainer mol = (IAtomContainer) newChemObject(); IAtom c = mol.getBuilder().newInstance(IAtom.class, "C"); IAtom c1 = mol.getBuilder().newInstance(IAtom.class, "C"); mol.addAtom(c); mol.addAtom(c1); mol.addSingleElectron(1); mol.addSingleElectron(1); Assert.assertEquals(2, mol.getSingleElectronCount()); Assert.assertNotNull(mol.getSingleElectron(1)); Iterator<ISingleElectron> singles = mol.singleElectrons().iterator(); ISingleElectron singleElectron = singles.next(); Assert.assertNotNull(singleElectron); Assert.assertEquals(c1, singleElectron.getAtom()); assertTrue(singleElectron.contains(c1)); singleElectron = singles.next(); Assert.assertNotNull(singleElectron); Assert.assertEquals(c1, singleElectron.getAtom()); assertTrue(singleElectron.contains(c1)); }
if (!electrons[i].contains(atom)) { electrons[newNumSingleElectrons] = electrons[i]; newNumSingleElectrons++; } else { electrons[i].removeListener(this);
/** * {@inheritDoc} */ @Override public void addSingleElectron(int idx) { ISingleElectron electron = getBuilder().newInstance(ISingleElectron.class); electron.setAtom(getAtom(idx)); addSingleElectron(electron); }
@Test @Override public void testGetElectronCount() { ISingleElectron radical = (ISingleElectron) newChemObject(); Assert.assertEquals(1, radical.getElectronCount().intValue()); }
@Test @Override public void testClone() throws Exception { ISingleElectron radical = (ISingleElectron) newChemObject(); Object clone = radical.clone(); Assert.assertNotNull(clone); Assert.assertTrue(clone instanceof ISingleElectron); }
Map<IAtom,Integer> singleElectronsPerAtom = new HashMap<IAtom, Integer>(); for (ISingleElectron e : ac.singleElectrons()) { IAtom atom = e.getAtom(); if(singleElectronsPerAtom.get(atom)==null) singleElectronsPerAtom.put(atom,0);
@Test public void testSingleElectron_IAtom() { IAtom atom = newChemObject().getBuilder().newInstance(IAtom.class, "N"); ISingleElectron radical = new SingleElectron(atom); Assert.assertEquals(1, radical.getElectronCount().intValue()); Assert.assertEquals(atom, radical.getAtom()); Assert.assertTrue(radical.contains(atom)); }
if (!electrons[i].contains(atom)) { electrons[newNumSingleElectrons] = electrons[i]; newNumSingleElectrons++; } else { electrons[i].removeListener(this);
/** * {@inheritDoc} */ @Override public void addSingleElectron(int idx) { ISingleElectron electron = getBuilder().newInstance(ISingleElectron.class); electron.setAtom(getAtom(idx)); addSingleElectron(electron); }