/** * {@inheritDoc} */ @Override public Integer getAtomicNumber() { return atom.getAtomicNumber(); }
@Override public boolean matches(IAtom a, IAtom b) { return a.getAtomicNumber().equals(b.getAtomicNumber()); } };
@Override public boolean matches(IAtom a, IAtom b) { return a.getAtomicNumber().equals(b.getAtomicNumber()); } };
private boolean doMirror(List<IAtom> atoms) { int p = 1; for (int i = 0; i < atoms.size(); i++) { IAtom a = atoms.get(i); for (int j = i+1; j < atoms.size(); j++) { IAtom b = atoms.get(j); if (a.getAtomicNumber() > b.getAtomicNumber()) p *= -1; } } return p < 0; }
/** * Given an array of atoms, find the first hydrogen atom. * * @param atoms array of non-null atoms. * @return a hydrogen atom */ private IAtom findHydrogen(final IAtom[] atoms) { for (final IAtom a : atoms) { if (Integer.valueOf(1).equals(a.getAtomicNumber())) return a; } return null; }
/** * Access the default position of the hydrogen label when the atom has no * bonds. * * @param atom hydrogens will be labelled * @return the position */ static HydrogenPosition usingDefaultPlacement(final IAtom atom) { if (PREFIXED_H.contains(Elements.ofNumber(atom.getAtomicNumber()))) return Left; return Right; } }
static IAtomContainer mock(int nAtoms) { IAtomContainer container = Mockito.mock(IAtomContainer.class); when(container.getAtomCount()).thenReturn(nAtoms); for (int i = 0; i < nAtoms; i++) { IAtom atom = Mockito.mock(IAtom.class); when(atom.getSymbol()).thenReturn("C"); when(atom.getAtomicNumber()).thenReturn(6); when(container.getAtom(i)).thenReturn(atom); } return container; } }
@Test public void useDefaultPlacementWithNoBonds() throws Exception { IAtom atom = mock(IAtom.class); when(atom.getAtomicNumber()).thenReturn(8); assertThat(HydrogenPosition.position(atom, Collections.<IAtom> emptyList()), is(Left)); }
@Test public void testAliphaticElementF() { for (int num = 1; num < 54; ++num) { Expr expr = new Expr(ALIPHATIC_ELEMENT, num); IAtom atom = mock(IAtom.class); when(atom.getAtomicNumber()).thenReturn(num); when(atom.isAromatic()).thenReturn(true); assertFalse(expr.matches(atom)); } }
@Test public void testAliphaticElementFalse2() { for (int num = 1; num < 54; ++num) { Expr expr = new Expr(ALIPHATIC_ELEMENT, num); IAtom atom = mock(IAtom.class); when(atom.getAtomicNumber()).thenReturn(num + 1); when(atom.isAromatic()).thenReturn(false); assertFalse(expr.matches(atom)); } }
@Test public void testAromaticElementT() { for (int num = 1; num < 54; ++num) { Expr expr = new Expr(AROMATIC_ELEMENT, num); IAtom atom = mock(IAtom.class); when(atom.getAtomicNumber()).thenReturn(num); when(atom.isAromatic()).thenReturn(true); assertTrue(expr.matches(atom)); } }
@Test public void unknownAtomTypeDoesNotModifyProperties() { IAtom atom = new Atom(Elements.CARBON); IAtomType atomType = new AtomType(Elements.Unknown.toIElement()); atomType.setAtomTypeName("X"); AtomTypeManipulator.configure(atom, atomType); assertThat(atom.getSymbol(), is("C")); assertThat(atom.getAtomicNumber(), is(6)); }
/** * A unit test for JUnit */ @Test public void testSingleH() throws Exception { // Beam allows bare 'H' - this is a common typo for '[H]' - there is // a 'strict' option which won't allow these but this isn't exposed // in the public API yet IAtomContainer mol = load("H"); assertThat(mol.getAtom(0).getAtomicNumber(), is(1)); assertThat(mol.getAtomCount(), is(1)); }
@Test public void testAtomicNumber() throws Exception { String cmlString = "<molecule><atomArray><atom id='a1' elementType=\"C\"><scalar dataType=\"xsd:integer\" dictRef=\"cdk:atomicNumber\">6</scalar></atom></atomArray></molecule>"; IChemFile chemFile = parseCMLString(cmlString); IAtomContainer mol = checkForSingleMoleculeFile(chemFile); Assert.assertEquals(1, mol.getAtomCount()); IAtom atom = mol.getAtom(0); Assert.assertEquals("C", atom.getSymbol()); Assert.assertEquals(6, atom.getAtomicNumber().intValue()); }
@Test public void testAtom_Ominus() { IAtom a = new Atom("O-"); Assert.assertEquals("O", a.getSymbol()); Assert.assertEquals((Integer) 8, a.getAtomicNumber()); Assert.assertEquals(null, a.getImplicitHydrogenCount()); Assert.assertEquals(Integer.valueOf(-1), a.getFormalCharge()); Assert.assertNull(a.getPoint2d()); Assert.assertNull(a.getPoint3d()); Assert.assertNull(a.getFractionalPoint3d()); }
@Test public void testAtom_Ca2plus() { IAtom a = new Atom("Ca+2"); Assert.assertEquals("Ca", a.getSymbol()); Assert.assertEquals((Integer) 20, a.getAtomicNumber()); Assert.assertEquals(null, a.getImplicitHydrogenCount()); Assert.assertEquals(Integer.valueOf(+2), a.getFormalCharge()); Assert.assertNull(a.getPoint2d()); Assert.assertNull(a.getPoint3d()); Assert.assertNull(a.getFractionalPoint3d()); }
@Test public void testAtom_NH4plus_direct() { IAtom a = new Atom(7, 4, +1); 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_Cl_direct() { IAtom a = new Atom(17); Assert.assertEquals("Cl", a.getSymbol()); Assert.assertEquals((Integer) 17, a.getAtomicNumber()); Assert.assertEquals((Integer) 0, a.getImplicitHydrogenCount()); Assert.assertEquals((Integer) 0, a.getFormalCharge()); Assert.assertNull(a.getPoint2d()); Assert.assertNull(a.getPoint3d()); Assert.assertNull(a.getFractionalPoint3d()); }
@Test public void testAtom_NH4plus_direct() { IAtom a = new Atom(7, 4, +1); 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_Cl_direct() { IAtom a = new Atom(17); Assert.assertEquals("Cl", a.getSymbol()); Assert.assertEquals((Integer) 17, a.getAtomicNumber()); Assert.assertEquals((Integer) 0, a.getImplicitHydrogenCount()); Assert.assertEquals((Integer) 0, a.getFormalCharge()); Assert.assertNull(a.getPoint2d()); Assert.assertNull(a.getPoint3d()); Assert.assertNull(a.getFractionalPoint3d()); }