ProteoWizard
Chemistry.hpp
Go to the documentation of this file.
1 //
2 // $Id$
3 //
4 //
5 // Original author: Darren Kessner <darren@proteowizard.org>
6 //
7 // Copyright 2006 Louis Warschaw Prostate Cancer Center
8 // Cedars Sinai Medical Center, Los Angeles, California 90048
9 //
10 // Licensed under the Apache License, Version 2.0 (the "License");
11 // you may not use this file except in compliance with the License.
12 // You may obtain a copy of the License at
13 //
14 // http://www.apache.org/licenses/LICENSE-2.0
15 //
16 // Unless required by applicable law or agreed to in writing, software
17 // distributed under the License is distributed on an "AS IS" BASIS,
18 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 // See the License for the specific language governing permissions and
20 // limitations under the License.
21 //
22 
23 
24 #ifndef _CHEMISTRY_HPP_
25 #define _CHEMISTRY_HPP_
26 
27 
29 #include <iosfwd>
30 #include <string>
31 #include <vector>
33 #include <boost/shared_ptr.hpp>
34 
35 
36 namespace pwiz {
37 namespace chemistry {
38 
39 
40 /// the mass of a proton in unified atomic mass units
41 const double Proton = 1.00727646688;
42 
43 /// the mass of a neutron in unified atomic mass units
44 const double Neutron = 1.00866491560;
45 
46 /// the mass of an electron in unified atomic mass units
47 const double Electron = 0.00054857991;
48 
49 
50 /// struct for holding isotope information
52 {
53  double mass;
54  double abundance;
55 
56  MassAbundance(double m = 0, double a = 0)
57  : mass(m), abundance(a)
58  {}
59 
60  bool operator==(const MassAbundance& that) const;
61  bool operator!=(const MassAbundance& that) const;
62 };
63 
64 
65 /// struct for holding isotope distribution
66 typedef std::vector<MassAbundance> MassDistribution;
67 
68 
69 PWIZ_API_DECL std::ostream& operator<<(std::ostream& os, const MassAbundance& ma);
70 PWIZ_API_DECL std::ostream& operator<<(std::ostream& os, const MassDistribution& md);
71 
72 
73 /// scope for declarations related to elements
74 namespace Element {
75 
76 
77 /// enumeration of the elements
79 {
80  C, H, O, N, S, P, _13C, _2H, _18O, _15N, // Order matters: _15N is the end of the CHONSP entries
81  He, Li, Be, B, F, Ne,
82  Na, Mg, Al, Si, Cl, Ar, K, Ca,
83  Sc, Ti, V, Cr, Mn, Fe, Co, Ni, Cu, Zn,
84  Ga, Ge, As, Se, Br, Kr, Rb, Sr, Y, Zr,
85  Nb, Mo, Tc, Ru, Rh, Pd, Ag, Cd, In, Sn,
86  Sb, Te, I, Xe, Cs, Ba, La, Ce, Pr, Nd,
87  Pm, Sm, Eu, Gd, Tb, Dy, Ho, Er, Tm, Yb,
88  Lu, Hf, Ta, W, Re, Os, Ir, Pt, Au, Hg,
89  Tl, Pb, Bi, Po, At, Rn, Fr, Ra, Ac, Th,
90  Pa, U, Np, Pu, Am, Cm, Bk, Cf, Es, Fm,
91  Md, No, Lr, Rf, Db, Sg, Bh, Hs, Mt, Uun,
92  Uuu, Uub, Uuq, Uuh, _3H
93 };
94 
95 
96 PWIZ_API_DECL std::ostream& operator<<(std::ostream& os, Type type);
97 
98 
99 /// class for obtaining information about elements
100 namespace Info
101 {
102 
103 
105 {
107  std::string symbol;
109  double atomicWeight;
110  MassAbundance monoisotope; /// the most abundant isotope
112 };
113 
114 /// retrieve the record for an element
116 
117 /// retrieve the record for an element
118 PWIZ_API_DECL const Record& record(const std::string& symbol);
119 
120 
121 } // namespace Info
122 
123 
124 PWIZ_API_DECL std::ostream& operator<<(std::ostream& os, const Info::Record& record);
125 
126 
127 } // namespace Element
128 
129 
130 class CompositionMap;
131 
132 /// class to represent a chemical formula
134 {
135  public:
136 
137  /// formula string given by symbol/count pairs, e.g. water: "H2 O1" (whitespace optional)
138  Formula(const std::string& formula = "");
139  Formula(const char* formula);
140  Formula(const Formula& formula);
141  const Formula& operator=(const Formula& formula);
143 
144  double monoisotopicMass() const;
145  double molecularWeight() const;
146  std::string formula() const;
147 
148  /// access to the Element's count in the formula
149  int operator[](Element::Type e) const;
151 
152  // direct access to the map, for iteration
153  typedef std::map<Element::Type, int> Map;
154  Map data() const;
155 
156  // operations
157  Formula& operator+=(const Formula& that);
158  Formula& operator-=(const Formula& that);
159  Formula& operator*=(int scalar);
160 
161  /// formulas are equal iff their elemental compositions are equal
162  bool operator==(const Formula& that) const;
163  bool operator!=(const Formula& that) const;
164 
165  private:
166  class Impl;
167  boost::shared_ptr<Impl> impl_;
168 };
169 
170 
173 PWIZ_API_DECL Formula operator*(const Formula& a, int scalar);
174 PWIZ_API_DECL Formula operator*(int scalar, const Formula& a);
175 
176 
177 /// output a Formula
178 PWIZ_API_DECL std::ostream& operator<<(std::ostream& os, const Formula& formula);
179 
180 
181 } // namespace chemistry
182 } // namespace pwiz
183 
184 
185 #endif // _CHEMISTRY_HPP_
Na
Na
Definition: Chemistry.hpp:82
Ga
Ga
Definition: Chemistry.hpp:84
pwiz::chemistry::Element::Info::Record::symbol
std::string symbol
Definition: Chemistry.hpp:107
Np
Np
Definition: Chemistry.hpp:90
Hf
Hf
Definition: Chemistry.hpp:88
pwiz::chemistry::Element::Info::record
PWIZ_API_DECL const Record & record(const std::string &symbol)
retrieve the record for an element
pwiz::chemistry::Formula::operator!=
bool operator!=(const Formula &that) const
Sm
Sm
Definition: Chemistry.hpp:87
virtual_map.hpp
Bk
Bk
Definition: Chemistry.hpp:90
Xe
Xe
Definition: Chemistry.hpp:86
Gd
Gd
Definition: Chemistry.hpp:87
Si
Si
Definition: Chemistry.hpp:82
Uub
Uub
Definition: Chemistry.hpp:92
As
As
Definition: Chemistry.hpp:84
Am
Am
Definition: Chemistry.hpp:90
S
S
Definition: Chemistry.hpp:80
Ti
Ti
Definition: Chemistry.hpp:83
Cl
Cl
Definition: Chemistry.hpp:82
_2H
_2H
Definition: Chemistry.hpp:80
Ni
Ni
Definition: Chemistry.hpp:83
pwiz
Definition: ChromatogramList_Filter.hpp:36
At
At
Definition: Chemistry.hpp:89
Db
Db
Definition: Chemistry.hpp:91
Md
Md
Definition: Chemistry.hpp:91
pwiz::chemistry::MassAbundance::operator!=
bool operator!=(const MassAbundance &that) const
Ac
Ac
Definition: Chemistry.hpp:89
Bi
Bi
Definition: Chemistry.hpp:89
_13C
_13C
Definition: Chemistry.hpp:80
K
K
Definition: Chemistry.hpp:82
Uuq
Uuq
Definition: Chemistry.hpp:92
pwiz::chemistry::Formula::molecularWeight
double molecularWeight() const
pwiz::chemistry::Formula
class to represent a chemical formula
Definition: Chemistry.hpp:134
Lr
Lr
Definition: Chemistry.hpp:91
Mg
Mg
Definition: Chemistry.hpp:82
pwiz::chemistry::MassAbundance
struct for holding isotope information
Definition: Chemistry.hpp:52
Zr
Zr
Definition: Chemistry.hpp:84
pwiz::chemistry::operator+
PWIZ_API_DECL Formula operator+(const Formula &a, const Formula &b)
Ta
Ta
Definition: Chemistry.hpp:88
Th
Th
Definition: Chemistry.hpp:89
Tc
Tc
Definition: Chemistry.hpp:85
Ag
Ag
Definition: Chemistry.hpp:85
PWIZ_API_DECL
#define PWIZ_API_DECL
Definition: Export.hpp:32
Rb
Rb
Definition: Chemistry.hpp:84
Kr
Kr
Definition: Chemistry.hpp:84
Uuh
Uuh
Definition: Chemistry.hpp:92
_18O
_18O
Definition: Chemistry.hpp:80
pwiz::chemistry::Element::Info::Record::isotopes
MassDistribution isotopes
the most abundant isotope
Definition: Chemistry.hpp:111
pwiz::chemistry::Element::Info::record
PWIZ_API_DECL const Record & record(Type type)
retrieve the record for an element
pwiz::chemistry::Element::Info::Record::monoisotope
MassAbundance monoisotope
Definition: Chemistry.hpp:110
pwiz::chemistry::MassAbundance::operator==
bool operator==(const MassAbundance &that) const
Cu
Cu
Definition: Chemistry.hpp:83
Fm
Fm
Definition: Chemistry.hpp:90
Tl
Tl
Definition: Chemistry.hpp:89
Y
Y
Definition: Chemistry.hpp:84
pwiz::chemistry::Element::Info::Record::type
Type type
Definition: Chemistry.hpp:106
Hs
Hs
Definition: Chemistry.hpp:91
Export.hpp
Yb
Yb
Definition: Chemistry.hpp:87
Cm
Cm
Definition: Chemistry.hpp:90
Re
Re
Definition: Chemistry.hpp:88
Ne
Ne
Definition: Chemistry.hpp:81
pwiz::chemistry::operator<<
PWIZ_API_DECL std::ostream & operator<<(std::ostream &os, const MassAbundance &ma)
Uun
Uun
Definition: Chemistry.hpp:91
W
W
Definition: Chemistry.hpp:88
Ru
Ru
Definition: Chemistry.hpp:85
In
In
Definition: Chemistry.hpp:85
pwiz::chemistry::Formula::monoisotopicMass
double monoisotopicMass() const
Cf
Cf
Definition: Chemistry.hpp:90
pwiz::chemistry::Formula::operator[]
int & operator[](Element::Type e)
Cr
Cr
Definition: Chemistry.hpp:83
pwiz::chemistry::Formula::operator=
const Formula & operator=(const Formula &formula)
Rn
Rn
Definition: Chemistry.hpp:89
pwiz::chemistry::Formula::Formula
Formula(const std::string &formula="")
formula string given by symbol/count pairs, e.g. water: "H2 O1" (whitespace optional)
H
H
Definition: Chemistry.hpp:80
Ge
Ge
Definition: Chemistry.hpp:84
Ba
Ba
Definition: Chemistry.hpp:86
Au
Au
Definition: Chemistry.hpp:88
Sg
Sg
Definition: Chemistry.hpp:91
pwiz::chemistry::operator-
PWIZ_API_DECL Formula operator-(const Formula &a, const Formula &b)
pwiz::chemistry::Formula::operator[]
int operator[](Element::Type e) const
access to the Element's count in the formula
pwiz::chemistry::MassAbundance::MassAbundance
MassAbundance(double m=0, double a=0)
Definition: Chemistry.hpp:56
Eu
Eu
Definition: Chemistry.hpp:87
pwiz::chemistry::Formula::Formula
Formula(const char *formula)
pwiz::chemistry::MassDistribution
std::vector< MassAbundance > MassDistribution
struct for holding isotope distribution
Definition: Chemistry.hpp:66
Es
Es
Definition: Chemistry.hpp:90
Li
Li
Definition: Chemistry.hpp:81
Mt
Mt
Definition: Chemistry.hpp:91
Pr
Pr
Definition: Chemistry.hpp:86
pwiz::chemistry::Electron
const double Electron
the mass of an electron in unified atomic mass units
Definition: Chemistry.hpp:47
Pm
Pm
Definition: Chemistry.hpp:87
Fr
Fr
Definition: Chemistry.hpp:89
He
He
Definition: Chemistry.hpp:81
Be
Be
Definition: Chemistry.hpp:81
pwiz::chemistry::MassAbundance::abundance
double abundance
Definition: Chemistry.hpp:54
V
V
Definition: Chemistry.hpp:83
Co
Co
Definition: Chemistry.hpp:83
Fe
Fe
Definition: Chemistry.hpp:83
Pb
Pb
Definition: Chemistry.hpp:89
B
B
Definition: Chemistry.hpp:81
Nb
Nb
Definition: Chemistry.hpp:85
Cd
Cd
Definition: Chemistry.hpp:85
Uuu
Uuu
Definition: Chemistry.hpp:92
pwiz::chemistry::Element::Info::Record
Definition: Chemistry.hpp:105
Dy
Dy
Definition: Chemistry.hpp:87
F
F
Definition: Chemistry.hpp:81
Os
Os
Definition: Chemistry.hpp:88
pwiz::chemistry::Formula::operator+=
Formula & operator+=(const Formula &that)
C
C
Definition: Chemistry.hpp:80
pwiz::chemistry::Neutron
const double Neutron
the mass of a neutron in unified atomic mass units
Definition: Chemistry.hpp:44
pwiz::chemistry::Formula::impl_
boost::shared_ptr< Impl > impl_
Definition: Chemistry.hpp:166
pwiz::chemistry::Formula::Formula
Formula(const Formula &formula)
Se
Se
Definition: Chemistry.hpp:84
Ar
Ar
Definition: Chemistry.hpp:82
Br
Br
Definition: Chemistry.hpp:84
pwiz::chemistry::Element::operator<<
PWIZ_API_DECL std::ostream & operator<<(std::ostream &os, Type type)
pwiz::chemistry::Element::Info::Record::atomicNumber
int atomicNumber
Definition: Chemistry.hpp:108
Zn
Zn
Definition: Chemistry.hpp:83
pwiz::chemistry::Formula::data
Map data() const
Pt
Pt
Definition: Chemistry.hpp:88
Sn
Sn
Definition: Chemistry.hpp:85
Lu
Lu
Definition: Chemistry.hpp:88
Tb
Tb
Definition: Chemistry.hpp:87
Mo
Mo
Definition: Chemistry.hpp:85
Rf
Rf
Definition: Chemistry.hpp:91
O
O
Definition: Chemistry.hpp:80
Pu
Pu
Definition: Chemistry.hpp:90
U
U
Definition: Chemistry.hpp:90
Nd
Nd
Definition: Chemistry.hpp:86
Mn
Mn
Definition: Chemistry.hpp:83
Ra
Ra
Definition: Chemistry.hpp:89
Rh
Rh
Definition: Chemistry.hpp:85
Al
Al
Definition: Chemistry.hpp:82
pwiz::chemistry::Element::Info::Record::atomicWeight
double atomicWeight
Definition: Chemistry.hpp:109
Cs
Cs
Definition: Chemistry.hpp:86
I
I
Definition: Chemistry.hpp:86
P
P
Definition: Chemistry.hpp:80
La
La
Definition: Chemistry.hpp:86
Ca
Ca
Definition: Chemistry.hpp:82
Tm
Tm
Definition: Chemistry.hpp:87
Sc
Sc
Definition: Chemistry.hpp:83
Er
Er
Definition: Chemistry.hpp:87
Po
Po
Definition: Chemistry.hpp:89
Sb
Sb
Definition: Chemistry.hpp:86
No
No
Definition: Chemistry.hpp:91
Bh
Bh
Definition: Chemistry.hpp:91
pwiz::chemistry::Formula::operator==
bool operator==(const Formula &that) const
formulas are equal iff their elemental compositions are equal
pwiz::chemistry::Formula::operator*=
Formula & operator*=(int scalar)
Ho
Ho
Definition: Chemistry.hpp:87
N
N
Definition: Chemistry.hpp:80
pwiz::chemistry::Formula::formula
std::string formula() const
pwiz::chemistry::detail::Type
pwiz::chemistry::Element::Type Type
Definition: ChemistryData.hpp:37
Ce
Ce
Definition: Chemistry.hpp:86
Hg
Hg
Definition: Chemistry.hpp:88
_15N
_15N
Definition: Chemistry.hpp:80
Pd
Pd
Definition: Chemistry.hpp:85
Pa
Pa
Definition: Chemistry.hpp:90
pwiz::chemistry::Formula::Map
std::map< Element::Type, int > Map
Definition: Chemistry.hpp:153
pwiz::chemistry::MassAbundance::mass
double mass
Definition: Chemistry.hpp:53
pwiz::chemistry::Proton
const double Proton
the mass of a proton in unified atomic mass units
Definition: Chemistry.hpp:41
Sr
Sr
Definition: Chemistry.hpp:84
pwiz::chemistry::Formula::~Formula
~Formula()
Te
Te
Definition: Chemistry.hpp:86
pwiz::chemistry::operator*
PWIZ_API_DECL Formula operator*(const Formula &a, int scalar)
pwiz::chemistry::Formula::operator-=
Formula & operator-=(const Formula &that)
Ir
Ir
Definition: Chemistry.hpp:88