libatomprobe
Library for Atom Probe Tomography (APT) computation
abundance.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 D Haley
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef ATOMPROBE_ABUNDANCE_H
19 #define ATOMPROBE_ABUNDANCE_H
20 
21 #include <vector>
22 #include <string>
23 #include <utility>
24 
25 namespace AtomProbe
26 {
27 
28 //Structure containing information relating to a specific isotope
29 // such as say, U-238.
30 // Example (2^H, Deuterium)
31 //======
32 // |------|
33 // | 2 |<- mass number
34 // | H |<- Symbol
35 // | 1 |<- atomic number
36 // |------|
37 // 2.014101 <- mass
38 // 0.00000000006 <- mass error
39 // 0.000115 <- abundance
40 // 0.000070 <- abundance error
41 //======
43 {
44  std::string symbol; //Isotope symbol
45  size_t massNumber; //Mass number (for C, eg 12 or 13)
46  size_t atomicNumber; //Atomic number (for C, this can only be 12)
47  float mass; // in units specified in as-loaded XML file.
48  float massError; //positive if known, zero if unknown
49  float abundance; //Natural abundance. Zero is not naturally occurring. Between 0 and 1
50  float abundanceError; //positive if known, zero if unknown
51 };
52 
55 {
56  enum
57  {
58  ABUNDANCE_ERR_BAD_DOC=1,
59  ABUNDANCE_ERR_NO_CONTEXT,
60  ABUNDANCE_ERROR_BAD_VALUE,
61  ABUNDANCE_ERROR_FAILED_VALIDATION,
62  ABUNDANCE_ERROR_MISSING_NODE,
63  ABUNDANCE_ERROR_MISSING_ROOT_NODE,
64  ABUNDANCE_ERROR_WRONG_ROOT_NODE,
65  ABUNDANCE_ERROR_ENUM_END
66  };
67 
69  // First vector is indexed by position, not atomic number because
70  //elements may be missing from abundance file, eg Tc
71  std::vector<std::vector<ISOTOPE_ENTRY> > isotopeData;
72 
73  //Check the abundance table for inconsistencies
74  void checkErrors() const;
75 
76 public:
78 
81  size_t open(const char *file, bool strict=false);
82 
84  static const char *getErrorText(size_t errorCode);
85 
87  size_t numIsotopes() const;
89  size_t numElements() const;
90 
92 
96  size_t symbolIndex(const char *symbol, bool caseSensitive=true) const;
97 
99  void getSymbolIndices(const std::vector<std::string> &symbols,
100  std::vector<size_t> &indices) const;
101 
103  void getSymbolIndices(const std::vector<std::pair<std::string,size_t> > &symbols,
104  std::vector<std::pair<size_t,unsigned int> > &indices) const;
105 
107  std::string elementName(size_t elemIdx ) const { return isotopeData[elemIdx][0].symbol;}
108 
110  size_t symbolIdxFromAtomicNumber(size_t atomicNumber) const;
111 
113  std::string elementNames(size_t start, size_t end, char separator=',') const;
114 
116 
119  void isotopeIndex(size_t elem, float mass, size_t &isotopeIdx) const;
120 
122  void isotopeIndex(size_t elem, float mass, float tolerance, size_t &isotopeIdx) const;
123 
125  unsigned int getAtomicNumber(size_t elemIdx) const;
126 
128  const std::vector<ISOTOPE_ENTRY> &isotopes(size_t offset) const;
129 
131 
138  void generateIsotopeDist(const std::vector<size_t> &elementIdx,
139  const std::vector<size_t> &frequency,
140  std::vector<std::pair<float,float> > &massDist) const;
141 
143 
147  void generateGroupedIsotopeDist(const std::vector<size_t> &elementIdx,
148  const std::vector<size_t> &frequency, std::vector<std::pair<float,float> > &massDist,
149  float massTolerance) const;
150 
152  void generateSingleAtomDist(size_t atomIdx, unsigned int repeatCount,
153  std::vector<std::pair<float,float> > &massDist) const;
154 
156  float abundanceBetweenLimits(const std::vector<size_t> &elemIdx,
157  const std::vector<size_t> &frequency,
158  float massStart, float massEnd) const;
159 
161  const ISOTOPE_ENTRY &isotope(size_t elementIdx, size_t isotopeIdx) const;
162 
164  size_t getMajorIsotopeFromElemIdx(size_t elementIdx) const;
165 
167  float getNominalMass(size_t elementIdx) const;
168 
170 
173  size_t getNearestCharge(const std::vector<std::pair<size_t,size_t> > &molecule,float targetMass,size_t maxCharge) const;
174 
175 #ifdef DEBUG
176  //Run the unit testing code
177  static bool runUnitTests();
178 #endif
179 };
180 
181 };
182 
183 #endif
size_t atomicNumber
Definition: abundance.h:46
float massError
Definition: abundance.h:48
Definition: abundance.h:42
size_t massNumber
Definition: abundance.h:45
std::string elementName(size_t elemIdx) const
Obtain the name of an element from its index.
Definition: abundance.h:107
float abundance
Definition: abundance.h:49
Class to load abundance information for natural isotopes.
Definition: abundance.h:54
float mass
Definition: abundance.h:47
std::string symbol
Definition: abundance.h:44
float abundanceError
Definition: abundance.h:50