forked from OpenMS/OpenMS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTutorial_EmpiricalFormula.cpp
More file actions
41 lines (30 loc) · 1.22 KB
/
Copy pathTutorial_EmpiricalFormula.cpp
File metadata and controls
41 lines (30 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright (c) 2002-present, OpenMS Inc. -- EKU Tuebingen, ETH Zurich, and FU Berlin
// SPDX-License-Identifier: BSD-3-Clause
//
//! [doxygen_snippet_EmpiricalFormula]
#include <OpenMS/CHEMISTRY/EmpiricalFormula.h>
#include <OpenMS/CHEMISTRY/ElementDB.h>
#include <OpenMS/CHEMISTRY/ISOTOPEDISTRIBUTION/CoarseIsotopePatternGenerator.h>
#include <iostream>
using namespace OpenMS;
using namespace std;
Int main()
{
EmpiricalFormula methanol("CH3OH"), water("H2O");
// sum up empirical formulae
EmpiricalFormula sum = methanol + water;
// get element from ElementDB
const Element * carbon = ElementDB::getInstance()->getElement("Carbon");
// output number of carbon atoms and average weight
cout << "Formula: " << sum
<< "\n average weight: " << sum.getAverageWeight()
<< "\n # of Carbons: " << sum.getNumberOf(carbon);
// extract the isotope distribution
IsotopeDistribution iso_dist = sum.getIsotopeDistribution(CoarseIsotopePatternGenerator(3));
std::cout << "\n\nCoarse isotope distribution of " << sum << ": \n";
for (const auto& it : iso_dist)
{
cout << "m/z: " << it.getMZ() << " abundance: " << it.getIntensity() << endl;
}
} //end of main
//! [doxygen_snippet_EmpiricalFormula]