| [c74fdb] | 1 | /* | 
|---|
|  | 2 | * Fragment.hpp | 
|---|
|  | 3 | * | 
|---|
|  | 4 | *  Created on: Aug 8, 2012 | 
|---|
|  | 5 | *      Author: heber | 
|---|
|  | 6 | */ | 
|---|
|  | 7 |  | 
|---|
|  | 8 | #ifndef FRAGMENT_HPP_ | 
|---|
|  | 9 | #define FRAGMENT_HPP_ | 
|---|
|  | 10 |  | 
|---|
|  | 11 |  | 
|---|
|  | 12 | // include config.h | 
|---|
|  | 13 | #ifdef HAVE_CONFIG_H | 
|---|
|  | 14 | #include <config.h> | 
|---|
|  | 15 | #endif | 
|---|
|  | 16 |  | 
|---|
| [a576eb] | 17 | #include <boost/serialization/export.hpp> | 
|---|
|  | 18 | #include <boost/serialization/vector.hpp> | 
|---|
|  | 19 | #include <boost/serialization/utility.hpp> | 
|---|
|  | 20 |  | 
|---|
| [184943] | 21 | #include <iosfwd> | 
|---|
| [c74fdb] | 22 | #include <vector> | 
|---|
|  | 23 |  | 
|---|
| [f3bc5f] | 24 | class FragmentTest; | 
|---|
|  | 25 |  | 
|---|
| [c74fdb] | 26 | class Fragment { | 
|---|
| [184943] | 27 | //!> grant ostream operator access | 
|---|
|  | 28 | friend std::ostream & operator<<(std::ostream &ost, const Fragment &f); | 
|---|
| [f3bc5f] | 29 | //!> grant unit test access | 
|---|
|  | 30 | friend class FragmentTest; | 
|---|
| [c74fdb] | 31 | public: | 
|---|
| [f3bc5f] | 32 | typedef std::vector<double> position_t; | 
|---|
|  | 33 | typedef std::vector< position_t > positions_t; | 
|---|
| [4a77be7] | 34 | typedef double charge_t; | 
|---|
|  | 35 | typedef std::vector< charge_t > charges_t; | 
|---|
| [6829d2] | 36 | typedef unsigned int atomicNumber_t; // typedef is copied | 
|---|
|  | 37 | typedef std::vector< atomicNumber_t > atomicnumbers_t; | 
|---|
|  | 38 | typedef std::pair< position_t, std::pair<atomicNumber_t, charge_t> > nucleus_t; | 
|---|
| [c74fdb] | 39 | typedef std::vector< nucleus_t > nuclei_t; | 
|---|
|  | 40 |  | 
|---|
|  | 41 | /** Default constructor of class Fragment. | 
|---|
|  | 42 | * | 
|---|
|  | 43 | */ | 
|---|
|  | 44 | Fragment(); | 
|---|
|  | 45 |  | 
|---|
|  | 46 | /** Default constructor of class Fragment. | 
|---|
|  | 47 | * | 
|---|
|  | 48 | */ | 
|---|
|  | 49 | Fragment(const nuclei_t &_nuclei) : | 
|---|
|  | 50 | nuclei(_nuclei) | 
|---|
|  | 51 | {} | 
|---|
|  | 52 |  | 
|---|
|  | 53 | /** Constructor of class Fragment. | 
|---|
|  | 54 | * | 
|---|
|  | 55 | * @param _positions given positions | 
|---|
| [6829d2] | 56 | * @param _atomicnumbers given atomic numbers | 
|---|
| [c74fdb] | 57 | * @param _charges given charges | 
|---|
|  | 58 | */ | 
|---|
| [6829d2] | 59 | Fragment( | 
|---|
|  | 60 | const positions_t &_positions, | 
|---|
|  | 61 | const atomicnumbers_t &_atomicnumbers, | 
|---|
|  | 62 | const charges_t &_charges); | 
|---|
| [c74fdb] | 63 |  | 
|---|
|  | 64 | /** Adding another fragment onto this one. | 
|---|
|  | 65 | * | 
|---|
|  | 66 | * \note The operation is area-conserving, i.e. the new area is the sum of | 
|---|
|  | 67 | * both areas. | 
|---|
|  | 68 | * | 
|---|
|  | 69 | * @param other other fragment | 
|---|
|  | 70 | * @return ref to this instance | 
|---|
|  | 71 | */ | 
|---|
|  | 72 | Fragment& operator+=(const Fragment &other); | 
|---|
|  | 73 |  | 
|---|
|  | 74 | /** Assignment operator. | 
|---|
|  | 75 | * | 
|---|
|  | 76 | * @param other other fragment to make ourselves equal to | 
|---|
|  | 77 | * @return ref to this instance | 
|---|
|  | 78 | */ | 
|---|
|  | 79 | Fragment& operator=(const Fragment &other); | 
|---|
|  | 80 |  | 
|---|
|  | 81 | /** Subtracting another fragment from this one. | 
|---|
|  | 82 | * | 
|---|
|  | 83 | * @param other other fragment | 
|---|
|  | 84 | * @return ref to this instance | 
|---|
|  | 85 | */ | 
|---|
|  | 86 | Fragment& operator-=(const Fragment &other); | 
|---|
|  | 87 |  | 
|---|
| [184943] | 88 | /** Getter for all stored positions. | 
|---|
|  | 89 | * | 
|---|
|  | 90 | * @return vector of positions | 
|---|
|  | 91 | */ | 
|---|
|  | 92 | positions_t getPositions() const; | 
|---|
|  | 93 |  | 
|---|
| [6829d2] | 94 | /** Getter for all stored atomic numbers. | 
|---|
|  | 95 | * | 
|---|
|  | 96 | * @return vector of atomic numbers | 
|---|
|  | 97 | */ | 
|---|
|  | 98 | atomicnumbers_t getAtomicNumbers() const; | 
|---|
|  | 99 |  | 
|---|
| [184943] | 100 | /** Getter for all stored charges. | 
|---|
|  | 101 | * | 
|---|
|  | 102 | * @return vector of charges | 
|---|
|  | 103 | */ | 
|---|
|  | 104 | charges_t getCharges() const; | 
|---|
|  | 105 |  | 
|---|
| [f3bc5f] | 106 | /** Equality operator. | 
|---|
|  | 107 | * | 
|---|
|  | 108 | * @param other other instance to check against | 
|---|
|  | 109 | * @return true - both are equal, false - some nucleus_t differ | 
|---|
|  | 110 | */ | 
|---|
|  | 111 | bool operator==(const Fragment& other) const; | 
|---|
|  | 112 |  | 
|---|
|  | 113 | bool operator!=(const Fragment& other) const | 
|---|
|  | 114 | { | 
|---|
|  | 115 | return (!(*this == other)); | 
|---|
|  | 116 | } | 
|---|
|  | 117 |  | 
|---|
|  | 118 | /** Creates type nucleus_t from given \a position and \a charge. | 
|---|
|  | 119 | * | 
|---|
|  | 120 | * @param position position of nucleus to create | 
|---|
| [6829d2] | 121 | * @param atomicnumber atomic number of nucleus to create | 
|---|
| [f3bc5f] | 122 | * @param charge charge of nucleus to create | 
|---|
|  | 123 | * @return nucleus with given \a position and \a charge | 
|---|
|  | 124 | */ | 
|---|
| [6829d2] | 125 | static nucleus_t createNucleus( | 
|---|
|  | 126 | const position_t &position, | 
|---|
|  | 127 | const atomicNumber_t &atomicnumber, | 
|---|
|  | 128 | const double charge); | 
|---|
| [f3bc5f] | 129 |  | 
|---|
|  | 130 | /** Helper function to check whether two positions are equal. | 
|---|
|  | 131 | * | 
|---|
|  | 132 | * @param a first position | 
|---|
|  | 133 | * @param b second position | 
|---|
|  | 134 | * @return a equals b within numerical precision | 
|---|
|  | 135 | */ | 
|---|
|  | 136 | static bool isPositionEqual(const position_t &a, const position_t &b); | 
|---|
|  | 137 |  | 
|---|
| [c74fdb] | 138 | private: | 
|---|
| [f3bc5f] | 139 | /** Helper function that checks whether this nuclei \b position is present. | 
|---|
| [c74fdb] | 140 | * | 
|---|
|  | 141 | * This operation is \f${\cal O}(n)\f$ | 
|---|
|  | 142 | * | 
|---|
|  | 143 | * @param n nuclei to check | 
|---|
|  | 144 | * @return true - is contained, false - is not contained | 
|---|
|  | 145 | */ | 
|---|
|  | 146 | bool containsNuclei(const nucleus_t &n) const; | 
|---|
|  | 147 |  | 
|---|
| [f3bc5f] | 148 | /** Seeks through all nuclei and removes one with matching \b position if found. | 
|---|
| [c74fdb] | 149 | * | 
|---|
|  | 150 | * @param n nuclei to remove | 
|---|
|  | 151 | */ | 
|---|
|  | 152 | void removeNuclei(const nucleus_t &n); | 
|---|
|  | 153 |  | 
|---|
|  | 154 | private: | 
|---|
|  | 155 | nuclei_t nuclei; | 
|---|
| [a576eb] | 156 |  | 
|---|
|  | 157 | private: | 
|---|
|  | 158 | friend class boost::serialization::access; | 
|---|
|  | 159 | // serialization | 
|---|
|  | 160 | template <typename Archive> | 
|---|
|  | 161 | void serialize(Archive& ar, const unsigned int version) | 
|---|
|  | 162 | { | 
|---|
|  | 163 | ar & nuclei; | 
|---|
|  | 164 | } | 
|---|
| [c74fdb] | 165 | }; | 
|---|
|  | 166 |  | 
|---|
| [a576eb] | 167 | // we need to give this class a unique key for serialization | 
|---|
|  | 168 | BOOST_CLASS_EXPORT_KEY(Fragment) | 
|---|
|  | 169 |  | 
|---|
| [f3bc5f] | 170 | /** Equality operator for two nuclei. | 
|---|
|  | 171 | * | 
|---|
|  | 172 | * @param a first nuclei | 
|---|
|  | 173 | * @param b second nuclei | 
|---|
|  | 174 | * @return true - both have same position and charge, false - either charge or position is different | 
|---|
|  | 175 | */ | 
|---|
|  | 176 | bool operator==(const Fragment::nucleus_t &a, const Fragment::nucleus_t &b); | 
|---|
|  | 177 |  | 
|---|
|  | 178 | std::ostream & operator<<(std::ostream &ost, const Fragment::nucleus_t &n); | 
|---|
|  | 179 |  | 
|---|
| [184943] | 180 | std::ostream & operator<<(std::ostream &ost, const Fragment &f); | 
|---|
|  | 181 |  | 
|---|
| [c74fdb] | 182 | template<typename T> T ZeroInstance(); | 
|---|
|  | 183 | template<> Fragment ZeroInstance<Fragment>(); | 
|---|
|  | 184 |  | 
|---|
|  | 185 | #endif /* FRAGMENT_HPP_ */ | 
|---|