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
36namespace pwiz {
37namespace chemistry {
38
39
40/// the mass of a proton in unified atomic mass units
41const double Proton = 1.00727646688;
42
43/// the mass of a neutron in unified atomic mass units
44const double Neutron = 1.00866491560;
45
46/// the mass of an electron in unified atomic mass units
47const 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
66typedef std::vector<MassAbundance> MassDistribution;
67
68
69PWIZ_API_DECL std::ostream& operator<<(std::ostream& os, const MassAbundance& ma);
70PWIZ_API_DECL std::ostream& operator<<(std::ostream& os, const MassDistribution& md);
71
72
73/// scope for declarations related to elements
74namespace Element {
75
76
77/// enumeration of the elements
78enum PWIZ_API_DECL Type
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
96PWIZ_API_DECL std::ostream& operator<<(std::ostream& os, Type type);
97
98
99/// class for obtaining information about elements
100namespace Info
101{
102
103
105{
106 Type type;
107 std::string symbol;
110 MassAbundance monoisotope; /// the most abundant isotope
112};
113
114/// retrieve the record for an element
115PWIZ_API_DECL const Record& record(Type type);
116
117/// retrieve the record for an element
118PWIZ_API_DECL const Record& record(const std::string& symbol);
119
120
121} // namespace Info
122
123
124PWIZ_API_DECL std::ostream& operator<<(std::ostream& os, const Info::Record& record);
125
126
127} // namespace Element
128
129
130class 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;
150 int& operator[](Element::Type e);
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
175
176
177/// output a Formula
178PWIZ_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_
Au
Definition Chemistry.hpp:88
Cs
Definition Chemistry.hpp:86
Ga
Definition Chemistry.hpp:84
In
Definition Chemistry.hpp:85
Mn
Definition Chemistry.hpp:83
Y
Definition Chemistry.hpp:84
W
Definition Chemistry.hpp:88
No
Definition Chemistry.hpp:91
Pb
Definition Chemistry.hpp:89
Md
Definition Chemistry.hpp:91
Uun
Definition Chemistry.hpp:91
Al
Definition Chemistry.hpp:82
Rh
Definition Chemistry.hpp:85
Ar
Definition Chemistry.hpp:82
Uub
Definition Chemistry.hpp:92
Rf
Definition Chemistry.hpp:91
K
Definition Chemistry.hpp:82
Ag
Definition Chemistry.hpp:85
Db
Definition Chemistry.hpp:91
Si
Definition Chemistry.hpp:82
F
Definition Chemistry.hpp:81
Xe
Definition Chemistry.hpp:86
Uuh
Definition Chemistry.hpp:92
Am
Definition Chemistry.hpp:90
Uuu
Definition Chemistry.hpp:92
Mo
Definition Chemistry.hpp:85
Sc
Definition Chemistry.hpp:83
Cl
Definition Chemistry.hpp:82
P
Definition Chemistry.hpp:80
Cd
Definition Chemistry.hpp:85
Po
Definition Chemistry.hpp:89
Li
Definition Chemistry.hpp:81
Ne
Definition Chemistry.hpp:81
As
Definition Chemistry.hpp:84
Re
Definition Chemistry.hpp:88
Pa
Definition Chemistry.hpp:90
Eu
Definition Chemistry.hpp:87
Cr
Definition Chemistry.hpp:83
Yb
Definition Chemistry.hpp:87
Fr
Definition Chemistry.hpp:89
I
Definition Chemistry.hpp:86
Sg
Definition Chemistry.hpp:91
Ac
Definition Chemistry.hpp:89
Se
Definition Chemistry.hpp:84
Hf
Definition Chemistry.hpp:88
Ti
Definition Chemistry.hpp:83
Lu
Definition Chemistry.hpp:88
Fe
Definition Chemistry.hpp:83
Te
Definition Chemistry.hpp:86
Pr
Definition Chemistry.hpp:86
Pm
Definition Chemistry.hpp:87
Bi
Definition Chemistry.hpp:89
Tm
Definition Chemistry.hpp:87
Os
Definition Chemistry.hpp:88
U
Definition Chemistry.hpp:90
_18O
Definition Chemistry.hpp:80
La
Definition Chemistry.hpp:86
Ba
Definition Chemistry.hpp:86
_15N
Definition Chemistry.hpp:80
N
Definition Chemistry.hpp:80
Pt
Definition Chemistry.hpp:88
Ho
Definition Chemistry.hpp:87
Tl
Definition Chemistry.hpp:89
Ni
Definition Chemistry.hpp:83
Gd
Definition Chemistry.hpp:87
Br
Definition Chemistry.hpp:84
Bh
Definition Chemistry.hpp:91
Er
Definition Chemistry.hpp:87
Ru
Definition Chemistry.hpp:85
Rb
Definition Chemistry.hpp:84
B
Definition Chemistry.hpp:81
Sb
Definition Chemistry.hpp:86
Ge
Definition Chemistry.hpp:84
Zn
Definition Chemistry.hpp:83
Hs
Definition Chemistry.hpp:91
Mt
Definition Chemistry.hpp:91
Cf
Definition Chemistry.hpp:90
C
Definition Chemistry.hpp:80
Nb
Definition Chemistry.hpp:85
He
Definition Chemistry.hpp:81
Tc
Definition Chemistry.hpp:85
Sm
Definition Chemistry.hpp:87
_2H
Definition Chemistry.hpp:80
Zr
Definition Chemistry.hpp:84
Co
Definition Chemistry.hpp:83
Cu
Definition Chemistry.hpp:83
Bk
Definition Chemistry.hpp:90
_13C
Definition Chemistry.hpp:80
Ce
Definition Chemistry.hpp:86
Sn
Definition Chemistry.hpp:85
Pd
Definition Chemistry.hpp:85
Np
Definition Chemistry.hpp:90
V
Definition Chemistry.hpp:83
Ir
Definition Chemistry.hpp:88
Ta
Definition Chemistry.hpp:88
S
Definition Chemistry.hpp:80
At
Definition Chemistry.hpp:89
Ca
Definition Chemistry.hpp:82
Na
Definition Chemistry.hpp:82
Ra
Definition Chemistry.hpp:89
Hg
Definition Chemistry.hpp:88
Lr
Definition Chemistry.hpp:91
Kr
Definition Chemistry.hpp:84
Pu
Definition Chemistry.hpp:90
Dy
Definition Chemistry.hpp:87
Th
Definition Chemistry.hpp:89
Rn
Definition Chemistry.hpp:89
Sr
Definition Chemistry.hpp:84
O
Definition Chemistry.hpp:80
Fm
Definition Chemistry.hpp:90
Be
Definition Chemistry.hpp:81
Cm
Definition Chemistry.hpp:90
Tb
Definition Chemistry.hpp:87
Mg
Definition Chemistry.hpp:82
Es
Definition Chemistry.hpp:90
Nd
Definition Chemistry.hpp:86
H
Definition Chemistry.hpp:80
Uuq
Definition Chemistry.hpp:92
#define PWIZ_API_DECL
Definition Export.hpp:32
class to represent a chemical formula
boost::shared_ptr< Impl > impl_
int & operator[](Element::Type e)
Formula(const Formula &formula)
std::map< Element::Type, int > Map
std::string formula() const
Formula & operator-=(const Formula &that)
const Formula & operator=(const Formula &formula)
double monoisotopicMass() const
Formula & operator*=(int scalar)
Formula(const char *formula)
bool operator==(const Formula &that) const
formulas are equal iff their elemental compositions are equal
double molecularWeight() const
Formula(const std::string &formula="")
formula string given by symbol/count pairs, e.g. water: "H2 O1" (whitespace optional)
Formula & operator+=(const Formula &that)
bool operator!=(const Formula &that) const
int operator[](Element::Type e) const
access to the Element's count in the formula
PWIZ_API_DECL const Record & record(Type type)
retrieve the record for an element
PWIZ_API_DECL std::ostream & operator<<(std::ostream &os, Type type)
PWIZ_API_DECL Formula operator+(const Formula &a, const Formula &b)
const double Electron
the mass of an electron in unified atomic mass units
Definition Chemistry.hpp:47
PWIZ_API_DECL Formula operator-(const Formula &a, const Formula &b)
PWIZ_API_DECL std::ostream & operator<<(std::ostream &os, const MassAbundance &ma)
std::vector< MassAbundance > MassDistribution
struct for holding isotope distribution
Definition Chemistry.hpp:66
PWIZ_API_DECL Formula operator*(const Formula &a, int scalar)
const double Proton
the mass of a proton in unified atomic mass units
Definition Chemistry.hpp:41
const double Neutron
the mass of a neutron in unified atomic mass units
Definition Chemistry.hpp:44
MassDistribution isotopes
the most abundant isotope
struct for holding isotope information
Definition Chemistry.hpp:52
MassAbundance(double m=0, double a=0)
Definition Chemistry.hpp:56
bool operator==(const MassAbundance &that) const
bool operator!=(const MassAbundance &that) const