00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef OPENMS_CHEMISTRY_EMPIRICALFORMULA_H
00028 #define OPENMS_CHEMISTRY_EMPIRICALFORMULA_H
00029
00030 #include <iostream>
00031 #include <vector>
00032
00033 #include <OpenMS/DATASTRUCTURES/String.h>
00034 #include <OpenMS/DATASTRUCTURES/HashMap.h>
00035 #include <OpenMS/CHEMISTRY/IsotopeDistribution.h>
00036 #include <OpenMS/CONCEPT/Types.h>
00037
00038 namespace OpenMS
00039 {
00040 class Element;
00041 class ElementDB;
00057 class EmpiricalFormula
00058 {
00059
00060 public:
00061
00065
00066 typedef HashMap<const Element*, UInt>::ConstIterator ConstIterator;
00067 typedef HashMap<const Element*, UInt>::ConstIterator const_iterator;
00068
00072
00073 EmpiricalFormula();
00074
00076 EmpiricalFormula(const EmpiricalFormula& rhs);
00077
00079 EmpiricalFormula(const String& rhs) throw(Exception::ParseError);
00080
00082 EmpiricalFormula(UInt number, const Element* element, Int charge = 0);
00083
00085 virtual ~EmpiricalFormula();
00087
00091
00092 DoubleReal getMonoWeight() const;
00093
00095 DoubleReal getAverageWeight() const;
00096
00102 IsotopeDistribution getIsotopeDistribution(UInt max_depth) const;
00103
00105 const Element* getElement(const String& name) const;
00106
00108 const Element* getElement(UInt atomic_number) const;
00109
00111 const ElementDB* getElementDB() const;
00112
00114 UInt getNumberOf(UInt atomic_number) const;
00115
00117 UInt getNumberOf(const String& name) const;
00118
00120 UInt getNumberOf(const Element* element) const;
00121
00123 UInt getNumberOfAtoms() const;
00124
00126 Int getCharge() const;
00127
00129 void setCharge(Int charge);
00130
00132 String getString() const;
00134
00138
00139 EmpiricalFormula& operator = (const EmpiricalFormula& rhs);
00140
00142 EmpiricalFormula& operator = (const String& rhs) throw(Exception::ParseError);
00143
00145 EmpiricalFormula& operator += (const EmpiricalFormula& rhs);
00146
00148 EmpiricalFormula& operator += (const String& rhs) throw(Exception::ParseError);
00149
00151 EmpiricalFormula operator + (const EmpiricalFormula& rhs) const;
00152
00154 EmpiricalFormula operator + (const String& rhs) const throw(Exception::ParseError);
00155
00157 EmpiricalFormula& operator -= (const EmpiricalFormula& rhs) throw(Exception::SizeUnderflow);
00158
00160 EmpiricalFormula& operator -= (const String& rhs) throw(Exception::ParseError, Exception::SizeUnderflow);
00161
00163 EmpiricalFormula operator - (const EmpiricalFormula& rhs) const throw(Exception::SizeUnderflow);
00164
00166 EmpiricalFormula operator - (const String& rhs) const throw(Exception::ParseError, Exception::SizeUnderflow);
00168
00172
00173 bool isEmpty() const;
00174
00176 bool isCharged() const;
00177
00179 bool hasElement(const Element* element) const;
00180
00182 bool hasElement(const String& name) const;
00183
00185 bool hasElement(UInt atomic_number) const;
00186
00188 bool operator == (const EmpiricalFormula& rhs) const;
00189
00191 bool operator == (const String& rhs) const throw(Exception::ParseError);
00192
00194 bool operator != (const EmpiricalFormula& rhs) const;
00195
00197 bool operator != (const String& rhs) const throw(Exception::ParseError);
00199
00201 friend std::ostream& operator << (std::ostream&, const EmpiricalFormula&);
00202
00206 inline ConstIterator begin() const { return formula_.begin(); }
00207
00208 inline ConstIterator end() const { return formula_.end(); }
00210
00211 protected:
00212
00213 HashMap<const Element*, UInt> formula_;
00214
00215 Int charge_;
00216
00217 void readElementsFromFile_(const String& file_name) throw(Exception::FileNotFound, Exception::ParseError);
00218
00219 Int parseFormula_(HashMap<const Element*, UInt>& ef,const String& formula) const throw(Exception::ParseError);
00220
00221 const ElementDB* element_db_;
00222 };
00223
00224 std::ostream& operator << (std::ostream&, const EmpiricalFormula::EmpiricalFormula&);
00225
00226 }
00227 #endif