/** * Safely obtain the formal charge on an atom. If the atom had undefined * formal charge it is considered as neutral (0). * * @param a an atom * @return the formal charge */ private static int charge(IAtom a) { Integer chg = a.getFormalCharge(); return chg != null ? chg : 0; }
/** *{@inheritDoc} */ @Override public int encode(IAtom atom, IAtomContainer container) { Integer formalCharge = atom.getFormalCharge(); return formalCharge != null ? formalCharge : 32451193; } },
/** * Get the formal charge as an integer value - null defaults to 0. * * @param atom the atom to get the charge of * @return the formal charge */ private int charge(IAtom atom) { return atom.getFormalCharge() != null ? atom.getFormalCharge() : 0; } }
/** * Access the formal charge - if the charge is null 0 is returned. * @param atom atom * @return formal charge */ int fCharge(IAtom atom) { if (atom.getFormalCharge() == null) return 0; return atom.getFormalCharge(); } }
private IAtomType perceiveRadium(IAtomContainer atomContainer, IAtom atom) throws CDKException { if (hasOneSingleElectron(atomContainer, atom)) { return null; } else if ((atom.getFormalCharge() != CDKConstants.UNSET && atom.getFormalCharge() == 0)) { IAtomType type = getAtomType("Ra.neutral"); if (isAcceptable(atom, atomContainer, type)) return type; } return null; }
private IAtomType perceiveStrontium(IAtomContainer atomContainer, IAtom atom) throws CDKException { if (hasOneSingleElectron(atomContainer, atom)) { return null; } else if ((atom.getFormalCharge() != CDKConstants.UNSET && atom.getFormalCharge() == 2)) { IAtomType type = getAtomType("Sr.2plus"); if (isAcceptable(atom, atomContainer, type)) return type; } return null; }
private IAtomType perceiveBarium(IAtomContainer atomContainer, IAtom atom) throws CDKException { if (hasOneSingleElectron(atomContainer, atom)) { return null; } else if ((atom.getFormalCharge() != CDKConstants.UNSET && atom.getFormalCharge() == 2)) { IAtomType type = getAtomType("Ba.2plus"); if (isAcceptable(atom, atomContainer, type)) { return type; } } return null; }
private IAtomType perceiveGold(IAtomContainer atomContainer, IAtom atom) throws CDKException { if (hasOneSingleElectron(atomContainer, atom)) { return null; } int neighbors = atomContainer.getConnectedBondsCount(atom); if ((atom.getFormalCharge() != CDKConstants.UNSET && atom.getFormalCharge() == 0) && neighbors == 1) { IAtomType type = getAtomType("Au.1"); if (isAcceptable(atom, atomContainer, type)) return type; } return null; }
private IAtomType perceiveThorium(IAtomContainer atomContainer, IAtom atom) throws CDKException { if ("Th".equals(atom.getSymbol())) { if (atom.getFormalCharge() == 0 && atomContainer.getConnectedBondsCount(atom) == 0) { IAtomType type = getAtomType("Th"); if (isAcceptable(atom, atomContainer, type)) { return type; } } } return null; }
@Test public void testFormalNumber_Null() { IAtom atom = mock(IAtom.class); IAtomContainer container = mock(IAtomContainer.class); AtomEncoder encoder = BasicAtomEncoder.FORMAL_CHARGE; when(atom.getFormalCharge()).thenReturn(null); assertThat(encoder.encode(atom, container), is(32451193)); verify(atom, times(1)).getFormalCharge(); verifyNoMoreInteractions(atom, container); }
private IAtomType perceiveGermanium(IAtomContainer atomContainer, IAtom atom) throws CDKException { IBond.Order maxBondOrder = atomContainer.getMaximumBondOrder(atom); if (!isCharged(atom) && maxBondOrder == IBond.Order.SINGLE && atomContainer.getConnectedBondsCount(atom) <= 4) { IAtomType type = getAtomType("Ge"); if (isAcceptable(atom, atomContainer, type)) return type; } if (atom.getFormalCharge() == 0 && atomContainer.getConnectedBondsCount(atom) == 3) { IAtomType type = getAtomType("Ge.3"); if (isAcceptable(atom, atomContainer, type)) return type; } return null; }
/** * @cdk.bug 1875949 */ @org.junit.Test public void testResonanceStructure() throws Exception { String smiles = "[F+]=C-[C-]"; IAtomContainer mol = sp.parseSmiles(smiles); Assert.assertEquals(3, mol.getAtomCount()); Assert.assertEquals(IBond.Order.DOUBLE, mol.getBond(0).getOrder()); Assert.assertEquals(+1, mol.getAtom(0).getFormalCharge().intValue()); Assert.assertEquals(-1, mol.getAtom(2).getFormalCharge().intValue()); }
/** * @cdk.bug 873783. */ @org.junit.Test(timeout = 1000) public void testProton() throws Exception { String smiles = "[H+]"; IAtomContainer mol = sp.parseSmiles(smiles); Assert.assertEquals(1, mol.getAtomCount()); Assert.assertEquals(1, mol.getAtom(0).getFormalCharge().intValue()); }
/** * A unit test for JUnit */ @org.junit.Test(timeout = 1000) public void testFormalChargeReading() throws Exception { String smiles = "[OH-]"; IAtomContainer mol = sp.parseSmiles(smiles); Assert.assertEquals(1, mol.getAtomCount()); Assert.assertEquals("O", mol.getAtom(0).getSymbol()); Assert.assertEquals(-1, mol.getAtom(0).getFormalCharge().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()); }