NitrogenRule implements IRule { @Override public double validate(IMolecularFormula formula) throws CDKException { logger.info("Start validation of ", formula); double mass = MolecularFormulaManipulator.getTotalMassNumber(formula); if (mass == 0) return 0.0; int numberN = MolecularFormulaManipulator.getElementCount(formula, formula.getBuilder().newInstance(IElement.class, "N")); numberN += getOthers(formula); if (formula.getCharge() == null || formula.getCharge() == 0 || !isOdd(Math.abs(formula.getCharge()))) { if (isOdd(mass) && isOdd(numberN)) { return 1.0; } else if (!isOdd(mass) && (numberN == 0 || !isOdd(numberN))) { return 1.0; } else return 0.0; } else { if (!isOdd(mass) && isOdd(numberN)) { return 1.0; } else if (isOdd(mass) && (numberN == 0 || !isOdd(numberN))) { return 1.0; } else return 0.0; } } NitrogenRule(); @Override void setParameters(Object[] params); @Override Object[] getParameters(); @Override double validate(IMolecularFormula formula);  }
@Test public void testDefaultValidFalse() throws ClassNotFoundException, CDKException, Exception { IRule rule = new NitrogenRule(); IMolecularFormula formula = MolecularFormulaManipulator.getMajorIsotopeMolecularFormula("C2H4", builder); Assert.assertEquals(1.0, rule.validate(formula), 0.0001); }
@Test public void testDefaultValidFalse_SetParam() throws ClassNotFoundException, CDKException, Exception { IRule rule = new NitrogenRule(); IMolecularFormula formula = MolecularFormulaManipulator.getMajorIsotopeMolecularFormula("C2H11N4O4", builder); formula.setCharge(1); Assert.assertEquals(1.0, rule.validate(formula), 0.0001); }
@Test public void testDefaultValidTrue() throws ClassNotFoundException, CDKException, Exception { IRule rule = new NitrogenRule(); IMolecularFormula formula = MolecularFormulaManipulator.getMajorIsotopeMolecularFormula("C4H13N1O5", builder); formula.setCharge(0); Assert.assertEquals(1.0, rule.validate(formula), 0.0001); }
@Test public void testC45H75NO15() throws ClassNotFoundException, CDKException, Exception { IRule rule = new NitrogenRule(); IMolecularFormula formula = MolecularFormulaManipulator.getMajorIsotopeMolecularFormula("C45H75NO15", builder); formula.setCharge(0); Assert.assertEquals(1.0, rule.validate(formula), 0.0001); }
@Test public void testC45H71N7O10() throws ClassNotFoundException, CDKException, Exception { IRule rule = new NitrogenRule(); IMolecularFormula formula = MolecularFormulaManipulator.getMajorIsotopeMolecularFormula("C45H71N7O10", builder); formula.setCharge(0); Assert.assertEquals(1.0, rule.validate(formula), 0.0001); }
@Test public void testC49H75NO12() throws ClassNotFoundException, CDKException, Exception { IRule rule = new NitrogenRule(); IMolecularFormula formula = MolecularFormulaManipulator.getMajorIsotopeMolecularFormula("C49H75NO12", builder); formula.setCharge(0); Assert.assertEquals(1.0, rule.validate(formula), 0.0001); }
@Test public void testC50H95NO10() throws ClassNotFoundException, CDKException, Exception { IRule rule = new NitrogenRule(); IMolecularFormula formula = MolecularFormulaManipulator.getMajorIsotopeMolecularFormula("C50H95NO10", builder); formula.setCharge(0); Assert.assertEquals(1.0, rule.validate(formula), 0.0001); }
@Test public void testC47H75N5O10() throws ClassNotFoundException, CDKException, Exception { IRule rule = new NitrogenRule(); IMolecularFormula formula = MolecularFormulaManipulator.getMajorIsotopeMolecularFormula("C47H75N5O10", builder); formula.setCharge(0); Assert.assertEquals(1.0, rule.validate(formula), 0.0001); }
@Test public void testC36H42N2O23() throws ClassNotFoundException, CDKException, Exception { IRule rule = new NitrogenRule(); IMolecularFormula formula = MolecularFormulaManipulator.getMajorIsotopeMolecularFormula("C36H42N2O23", builder); formula.setCharge(0); Assert.assertEquals(1.0, rule.validate(formula), 0.0001); }
@Test public void testN() throws ClassNotFoundException, CDKException, Exception { IRule rule = new NitrogenRule(); IMolecularFormula formula = MolecularFormulaManipulator.getMajorIsotopeMolecularFormula("NH3", builder); formula.setCharge(0); Assert.assertEquals(1.0, rule.validate(formula), 0.0001); }
@Test public void testNPlus() throws ClassNotFoundException, CDKException, Exception { IRule rule = new NitrogenRule(); IMolecularFormula formula = MolecularFormulaManipulator.getMajorIsotopeMolecularFormula("NH4", builder); formula.setCharge(1); Assert.assertEquals(1.0, rule.validate(formula), 0.0001); }
@Test public void testNominalMass() throws ClassNotFoundException, CDKException, Exception { IRule rule = new NitrogenRule(); IMolecularFormula formula = MolecularFormulaManipulator.getMolecularFormula("C25H53NO7P", builder); formula.setCharge(1); Assert.assertEquals(1.0, rule.validate(formula), 0.0001); }
@Test public void testDoubleCharge() throws ClassNotFoundException, CDKException, Exception { IRule rule = new NitrogenRule(); IMolecularFormula formula = MolecularFormulaManipulator.getMolecularFormula("C22H34N2S2", builder); formula.setCharge(2); Assert.assertEquals(1.0, rule.validate(formula), 0.0001); }
@Test public void testWithFe() throws ClassNotFoundException, CDKException, Exception { IRule rule = new NitrogenRule(); IMolecularFormula formula = MolecularFormulaManipulator.getMolecularFormula("C40H46FeN6O8S2", builder); formula.setCharge(2); Assert.assertEquals(1.0, rule.validate(formula), 0.0001); }
@Test public void testWithCo() throws ClassNotFoundException, CDKException, Exception { IRule rule = new NitrogenRule(); IMolecularFormula formula = MolecularFormulaManipulator.getMolecularFormula("C43H50CoN4O16", builder); formula.setCharge(0); Assert.assertEquals(1.0, rule.validate(formula), 0.0001); }