/** * {@inheritDoc} */ @Override public Double getCharge() { return atom.getCharge(); }
/** * {@inheritDoc} */ @Override public Double getCharge() { return atom.getCharge(); }
public static boolean hasPartialCharges(IAtomContainer molecule) { for (IAtom atom : molecule.atoms()) if (atom.getCharge() != 0.0000) return true; return false; }
/** * Get the summed charge of all atoms in an AtomContainer * * @param atomContainer The IAtomContainer to manipulate * @return The summed charges of all atoms in this AtomContainer. */ public static double getTotalCharge(IAtomContainer atomContainer) { double charge = 0.0; for (IAtom atom : atomContainer.atoms()) { // we assume CDKConstant.UNSET is equal to 0 Double thisCharge = atom.getCharge(); if (thisCharge != CDKConstants.UNSET) charge += thisCharge; } return charge; }
/** * Main method which assigns MMFF94 partial charges * * @param ac AtomContainer * @return AtomContainer with MMFF94 partial charges as atom properties */ public IAtomContainer assignMMFF94PartialCharges(IAtomContainer ac) throws CDKException { if (!mmff.assignAtomTypes(ac)) throw new CDKException("Molecule had an atom of unknown MMFF type"); mmff.partialCharges(ac); mmff.clearProps(ac); for (IAtom atom : ac.atoms()) atom.setProperty(MMFF_94_CHARGE, atom.getCharge()); return ac; }
private static double[] listcharges(IAtomContainer container) throws CDKException { int natom = container.getAtomCount(); double[] charges = new double[natom]; try { IAtomContainer mol = container.getBuilder().newInstance(IAtomContainer.class, ((IAtomContainer) container.clone())); GasteigerMarsiliPartialCharges peoe = new GasteigerMarsiliPartialCharges(); peoe.assignGasteigerMarsiliSigmaPartialCharges(mol, true); for (int i = 0; i < natom; i++) { IAtom atom = mol.getAtom(i); charges[i] = atom.getCharge(); } } catch (Exception ex1) { throw new CDKException("Problems with assignGasteigerMarsiliPartialCharges due to " + ex1.toString(), ex1); } return charges; }
private static double[] listcharges(IAtomContainer container) throws CDKException { int natom = container.getAtomCount(); double[] charges = new double[natom]; try { IAtomContainer mol = container.getBuilder().newInstance(IAtomContainer.class, ((IAtomContainer) container.clone())); GasteigerMarsiliPartialCharges peoe = new GasteigerMarsiliPartialCharges(); peoe.assignGasteigerMarsiliSigmaPartialCharges(mol, true); for (int i = 0; i < natom; i++) { IAtom atom = mol.getAtom(i); charges[i] = atom.getCharge(); } } catch (Exception ex1) { throw new CDKException("Problems with assignGasteigerMarsiliPartialCharges due to " + ex1.toString(), ex1); } return charges; }
/** * Main method which assigns MMFF94 partial charges * * @param ac AtomContainer * @return AtomContainer with MMFF94 partial charges as atom properties */ public IAtomContainer assignMMFF94PartialCharges(IAtomContainer ac) throws CDKException { if (!mmff.assignAtomTypes(ac)) throw new CDKException("Molecule had an atom of unknown MMFF type"); mmff.partialCharges(ac); mmff.clearProps(ac); for (IAtom atom : ac.atoms()) atom.setProperty(MMFF_94_CHARGE, atom.getCharge()); return ac; }
/** * Checks that the default charge is set to NaN */ @Test public void testDefaultChargeValue() { IAtom atom = (IAtom) newChemObject(); Assert.assertEquals(CDKConstants.UNSET, atom.getCharge()); // Assert.assertEquals(0.0, atom.getCharge(), 0.00000001); } }
private void assertPartialChargeSum(IAtomContainer mol, double expected) { double actual = 0; for (int i = 0; i < mol.getAtomCount(); i++) actual += mol.getAtom(i).getCharge(); assertEquals("Unexpected partial charge sum", expected, actual, 0.001); } }
@Test public void readCharge() throws Exception { String data = "HETATM 3486 MG MG A 302 24.885 14.008 59.194 1.00 29.42 MG+2\n" + "END"; IChemFile chemFile = getChemFileFromString(data); IAtomContainer atomContainer = getFirstAtomContainer(chemFile, 1, 1, 1); Assert.assertEquals(new Double(2.0), atomContainer.getAtom(0).getCharge()); }
/** * Method to test the get/setCharge() methods. */ @Test public void testSetCharge_Double() { double charge = 0.15; IAtom a = (IAtom) newChemObject(); a.setCharge(charge); Assert.assertEquals(charge, a.getCharge(), 0.001); }
private void assertPartialCharges(IAtomContainer mol, double... expected) { double[] actual = new double[mol.getAtomCount()]; for (int i = 0; i < mol.getAtomCount(); i++) actual[i] = mol.getAtom(i).getCharge(); assertArrayEquals(expected, actual, 0.001); }
/** * Method to test the clone() method */ @Test public void testClone_Charge() throws Exception { IAtom atom = (IAtom) newChemObject(); atom.setCharge(1.0); IAtom clone = (IAtom) atom.clone(); // test cloning atom.setCharge(5.0); Assert.assertEquals(1.0, clone.getCharge(), 0.001); }
@Test public void testPartialCharge() throws Exception { IAtomContainer mol = new AtomContainer(); Atom atom = new Atom("C"); mol.addAtom(atom); double charge = -0.267; atom.setCharge(charge); IAtomContainer roundTrippedMol = CMLRoundTripTool.roundTripMolecule(convertor, mol); Assert.assertEquals(1, roundTrippedMol.getAtomCount()); IAtom roundTrippedAtom = roundTrippedMol.getAtom(0); Assert.assertEquals(charge, roundTrippedAtom.getCharge(), 0.0001); }
@Ignore("Have to figure out how to store partial charges in CML2") public void testAtomPartialCharge() throws Exception { IAtomContainer mol = new AtomContainer(); Atom atom = new Atom("N"); double partialCharge = 0.5; atom.setCharge(partialCharge); mol.addAtom(atom); IAtomContainer roundTrippedMol = CMLRoundTripTool.roundTripMolecule(convertor, mol); Assert.assertEquals(1, roundTrippedMol.getAtomCount()); IAtom roundTrippedAtom = roundTrippedMol.getAtom(0); Assert.assertEquals(atom.getCharge(), roundTrippedAtom.getCharge(), 0.0001); }