Skip to content

Commit

Permalink
Bug found calculating the exact mass given a molecular formula when i…
Browse files Browse the repository at this point in the history
…t is negative charged.

Signed-off-by: Egon Willighagen <egonw@users.sourceforge.net>
  • Loading branch information
Miguel Rojas Cherto authored and egonw committed Jul 21, 2009
1 parent 73225a0 commit 3d1de45
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Expand Up @@ -586,7 +586,7 @@ private static double correctMass(double mass, Integer charge) {
if(charge > 0)
mass -= massE*charge;
else if(charge < 0)
mass += massE*charge;
mass += massE*Math.abs(charge);
return mass;
}

Expand Down
Expand Up @@ -397,6 +397,21 @@ public void testGetTotalExactMassWithCharge_IMolecularFormula() throws Exception
formula.setCharge(1);
double totalExactMass2 = MolecularFormulaManipulator.getTotalExactMass(formula);
Assert.assertEquals(33.03349,totalExactMass2,0.0001);
}
/**
* A unit test suite for JUnit. Test total Exact Mass.
*
* @throws IOException
* @throws ClassNotFoundException
* @throws CDKException
*/
@Test
public void testGetTotalExactMassWithChargeNeg_IMolecularFormula() throws IOException, ClassNotFoundException, CDKException{

IMolecularFormula formula = MolecularFormulaManipulator.getMajorIsotopeMolecularFormula("H2PO4", builder);
formula.setCharge(-1);
double totalExactMass2 = MolecularFormulaManipulator.getTotalExactMass(formula);
Assert.assertEquals(96.96961875390926,totalExactMass2,0.0001);
}
@Test
public void testGetNaturalExactMass_IMolecularFormula() throws Exception {
Expand Down

0 comments on commit 3d1de45

Please sign in to comment.