double element::chemicalMass( const element& e ) { std::pair<double, double> sum = std::accumulate( e.isotopes().begin(), e.isotopes().end() , std::make_pair( 0.0, 0.0 ) , []( const std::pair<double, double>& a, const toe::isotope& i ){ return std::make_pair( a.first + (i.mass * i.abundance), a.second + i.abundance ); }); //assert( adportable::compare<double>::approximatelyEqual( sum.second, 1.0 ) ); return sum.first; }
// static double element::monoIsotopicMass( const element& e, int isotope ) { if ( isotope == 0 ) { // return most abundunt auto it = std::max_element( e.isotopes().begin(), e.isotopes().end(), []( const toe::isotope& a, const toe::isotope& b ){ return a.abundance < b.abundance; }); if ( it != e.isotopes().end() ) return it->mass; } else { // find specified isotope auto it = std::find_if( e.isotopes().begin(), e.isotopes().end(), [=]( const toe::isotope& a ){ return int ( a.mass + 0.3 ) == isotope; }); if ( it != e.isotopes().end() ) return it->mass; } return 0; }