Skip to content

Commit

Permalink
The formal charge of the IAtomcontainer is transfered to IMolecularFo…
Browse files Browse the repository at this point in the history
…rmula

Signed-off-by: Egon Willighagen <egonw@users.sourceforge.net>
  • Loading branch information
Miguel Rojas Cherto authored and egonw committed May 18, 2009
1 parent b72fa58 commit 2f30841
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -728,10 +728,12 @@ public static IMolecularFormula getMolecularFormula(IAtomContainer atomContainer
*/
@TestMethod("testGetMolecularFormula_IAtomContainer_IMolecularFormula")
public static IMolecularFormula getMolecularFormula(IAtomContainer atomContainer, IMolecularFormula formula) {

int charge = 0;
for (IAtom iAtom : atomContainer.atoms()) {
formula.addIsotope(iAtom);
charge += iAtom.getFormalCharge();
}
formula.setCharge(charge);
return formula;
}
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,26 @@ public void testGetMolecularFormula_IAtomContainer(){
Assert.assertEquals(MolecularFormulaManipulator.getElementCount(mf2, elemH), MolecularFormulaManipulator.getElementCount(mf1,elemH));

}

/**
* A unit test suite for JUnit.
*
* @return The test suite
*/
@Test
public void testGetMolecularFormula_IAtomContainer_withCharge(){
IAtomContainer ac = builder.newAtomContainer();
ac.addAtom(builder.newAtom("C"));
ac.getAtom(0).setFormalCharge(1);
ac.addAtom(builder.newAtom("C"));
ac.addAtom(builder.newAtom("H"));
ac.addAtom(builder.newAtom("H"));
ac.addAtom(builder.newAtom("H"));

IMolecularFormula mf1 = MolecularFormulaManipulator.getMolecularFormula(ac);

Assert.assertEquals(1, mf1.getCharge(),0.000);
}
/**
* A unit test suite for JUnit.
*
Expand Down

0 comments on commit 2f30841

Please sign in to comment.