@ 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 ; } }
Validate the nitrogen rule of this IMolecularFormula .