[4694df] | 1 | /*
|
---|
| 2 | * HomologyContainer.hpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: Sep 22, 2012
|
---|
| 5 | * Author: heber
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | #ifndef HOMOLOGYCONTAINER_HPP_
|
---|
| 9 | #define HOMOLOGYCONTAINER_HPP_
|
---|
| 10 |
|
---|
| 11 |
|
---|
| 12 | // include config.h
|
---|
| 13 | #ifdef HAVE_CONFIG_H
|
---|
| 14 | #include <config.h>
|
---|
| 15 | #endif
|
---|
| 16 |
|
---|
[12a24c] | 17 | #include <boost/serialization/export.hpp>
|
---|
| 18 | #include <boost/serialization/map.hpp>
|
---|
| 19 | #include <boost/serialization/vector.hpp>
|
---|
| 20 |
|
---|
[e15ffe] | 21 | #include <iosfwd>
|
---|
[4694df] | 22 | #include <map>
|
---|
[77b350] | 23 | #include <vector>
|
---|
[4694df] | 24 |
|
---|
[77b350] | 25 | #include "Fragmentation/Homology/HomologyGraph.hpp"
|
---|
| 26 |
|
---|
| 27 | class Fragment
|
---|
| 28 | {
|
---|
[e15ffe] | 29 | //!> grant access to output operator
|
---|
| 30 | friend std::ostream& operator<<(std::ostream &out, const Fragment &container);
|
---|
[77b350] | 31 | public:
|
---|
| 32 | typedef std::vector<double> position_t;
|
---|
| 33 | typedef std::vector< position_t > positions_t;
|
---|
| 34 | typedef std::vector< double > charges_t;
|
---|
| 35 | typedef std::pair< position_t, double> nucleus_t;
|
---|
| 36 | typedef std::vector< nucleus_t > nuclei_t;
|
---|
| 37 | Fragment() {}
|
---|
| 38 | Fragment(const positions_t &_positions, const charges_t &_charges) {}
|
---|
[12a24c] | 39 |
|
---|
| 40 | bool operator==(const Fragment &other) const {
|
---|
| 41 | return true;
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | private:
|
---|
| 45 | friend class boost::serialization::access;
|
---|
| 46 | // serialization
|
---|
| 47 | template <typename Archive>
|
---|
| 48 | void serialize(Archive& ar, const unsigned int version)
|
---|
| 49 | {}
|
---|
[77b350] | 50 | };
|
---|
[4694df] | 51 |
|
---|
[e15ffe] | 52 | std::ostream& operator<<(std::ostream &out, const Fragment &container);
|
---|
[4694df] | 53 |
|
---|
[12a24c] | 54 | // we need to give this class a unique key for serialization
|
---|
| 55 | BOOST_CLASS_EXPORT_KEY(Fragment)
|
---|
| 56 |
|
---|
| 57 | class HomologyContainerTest;
|
---|
| 58 |
|
---|
[4694df] | 59 | /** This class takes all KeySets in a Graph, checks for those that homologues
|
---|
| 60 | * of one another and places them together.
|
---|
| 61 | *
|
---|
| 62 | * This is meant as a storage for key, value pairs, where the key is the KeySet
|
---|
| 63 | * and the value is the energy associated to the fragment this keyset
|
---|
| 64 | * represents.
|
---|
| 65 | * Afterwards this can then be used as training data for a high-dimensional
|
---|
| 66 | * approximation to the Born-Oppenheimer-surface decomposed into lower-
|
---|
| 67 | * dimensional terms in an ANOVA-like fashion.
|
---|
| 68 | *
|
---|
| 69 | */
|
---|
| 70 | class HomologyContainer
|
---|
| 71 | {
|
---|
[e15ffe] | 72 | //!> grant access to output operator
|
---|
| 73 | friend std::ostream& operator<<(std::ostream &out, const HomologyContainer &container);
|
---|
[12a24c] | 74 | //!> grant unit test access
|
---|
| 75 | friend class HomologyContainerTest;
|
---|
[4694df] | 76 | public:
|
---|
[77b350] | 77 | typedef double energy_t;
|
---|
| 78 | typedef std::pair<Fragment, energy_t> value_t;
|
---|
| 79 | typedef std::multimap< HomologyGraph, value_t> container_t;
|
---|
| 80 | typedef std::pair< container_t::const_iterator, container_t::const_iterator> range_t;
|
---|
| 81 | public:
|
---|
| 82 | /** Default Constructor of class HomologyContainer.
|
---|
| 83 | *
|
---|
| 84 | */
|
---|
| 85 | HomologyContainer() {}
|
---|
| 86 |
|
---|
| 87 | /** Constructor of class HomologyContainer.
|
---|
| 88 | *
|
---|
| 89 | * @param values values with with to initially fill the container
|
---|
| 90 | */
|
---|
| 91 | HomologyContainer(const container_t &values) :
|
---|
| 92 | container(values)
|
---|
| 93 | {}
|
---|
| 94 | /** Destructor of class HomologyContainer.
|
---|
| 95 | *
|
---|
| 96 | */
|
---|
[4694df] | 97 | ~HomologyContainer() {}
|
---|
| 98 |
|
---|
[12a24c] | 99 | /** Equality comparator.
|
---|
| 100 | *
|
---|
| 101 | * Sadly, the insertion order of a std::multimap's values is not guaranteed
|
---|
| 102 | * by the standard and boost::serialization does not heed the ordering of
|
---|
| 103 | * the values associated to the same key. Hence, we implement a weaker
|
---|
| 104 | * comparator for this class in order for the unit test to pass as we don't
|
---|
| 105 | * actuallty care about the order of the homologous fragments.
|
---|
| 106 | *
|
---|
| 107 | * @param other instance to compare to
|
---|
| 108 | * @return true - each container contains all elements of the other
|
---|
| 109 | */
|
---|
| 110 | bool operator==(const HomologyContainer &other) const {
|
---|
| 111 | return ((*this >= other) && (other >= *this));
|
---|
| 112 | }
|
---|
| 113 | bool operator!=(const HomologyContainer& other) const {
|
---|
| 114 | return !(*this == other);
|
---|
| 115 | }
|
---|
| 116 |
|
---|
| 117 | /** Greater equal comparator, i.e. subset comparator
|
---|
| 118 | *
|
---|
| 119 | * @param other container to check if it's subset
|
---|
| 120 | * @return true - \a other is a subset of this
|
---|
| 121 | */
|
---|
| 122 | bool operator>=(const HomologyContainer &other) const;
|
---|
| 123 |
|
---|
[77b350] | 124 | /** Inserter for more graphs along with values.
|
---|
| 125 | *
|
---|
| 126 | * @param values graph and values to insert
|
---|
| 127 | */
|
---|
| 128 | void insert(const container_t &values) {
|
---|
| 129 | container.insert(values.begin(), values.end());
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | /** Returns iterator range with all contained graphs homologous to the given \a graph.
|
---|
| 133 | *
|
---|
| 134 | * @param graph graph to match
|
---|
| 135 | * @return iterator range with all matches
|
---|
| 136 | */
|
---|
| 137 | range_t getHomologousGraphs(const HomologyGraph &graph) {
|
---|
| 138 | return container.equal_range(graph);
|
---|
| 139 | }
|
---|
| 140 |
|
---|
[4694df] | 141 | private:
|
---|
[77b350] | 142 | //!> multimap containing all homologous graph under same key but each with its value
|
---|
| 143 | container_t container;
|
---|
[12a24c] | 144 |
|
---|
| 145 | private:
|
---|
| 146 | friend class boost::serialization::access;
|
---|
| 147 | // serialization
|
---|
| 148 | template <typename Archive>
|
---|
| 149 | void serialize(Archive& ar, const unsigned int version)
|
---|
| 150 | {
|
---|
| 151 | ar & container;
|
---|
| 152 | }
|
---|
[4694df] | 153 | };
|
---|
| 154 |
|
---|
[e15ffe] | 155 | /** Output operator for HomologyContainer.
|
---|
| 156 | *
|
---|
| 157 | * \param out output stream
|
---|
| 158 | * \param container container to print
|
---|
| 159 | * \return output stream for concatenation
|
---|
| 160 | */
|
---|
| 161 | std::ostream& operator<<(std::ostream &out, const HomologyContainer &container);
|
---|
[4694df] | 162 |
|
---|
[12a24c] | 163 | // we need to give this class a unique key for serialization
|
---|
| 164 | BOOST_CLASS_EXPORT_KEY(HomologyContainer)
|
---|
| 165 |
|
---|
| 166 |
|
---|
[4694df] | 167 | #endif /* HOMOLOGYCONTAINER_HPP_ */
|
---|