source: src/Fragmentation/Homology/HomologyContainer.hpp@ 228340

Action_Thermostats Add_AtomRandomPerturbation Add_RotateAroundBondAction Add_SelectAtomByNameAction Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_ChronosMutex Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion GeometryObjects Gui_displays_atomic_force_velocity IndependentFragmentGrids_IntegrationTest JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks RotateToPrincipalAxisSystem_UndoRedo StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg ThirdParty_MPQC_rebuilt_buildsystem TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps Ubuntu_1604_changes stable
Last change on this file since 228340 was 814b8c, checked in by Frederik Heber <heber@…>, 8 years ago

AnalyseFragmentResults stores edge per fragment in value_t of HomologyContainer

  • HomologyContainer has additional variable bond graph's edges in value_t which is also serialized.
  • Property mode set to 100644
File size: 6.3 KB
RevLine 
[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>
[bcc24f]19#include <boost/serialization/split_member.hpp>
[12a24c]20#include <boost/serialization/vector.hpp>
[a2a2f7]21#include <boost/serialization/version.hpp>
[12a24c]22
[e15ffe]23#include <iosfwd>
[4694df]24#include <map>
[77b350]25#include <vector>
[4694df]26
[39a07a]27#include "CodePatterns/IteratorAdaptors.hpp"
[bcc24f]28#include "CodePatterns/Observer/Observable.hpp"
[39a07a]29
[814b8c]30#include "Fragmentation/EdgesPerFragment.hpp"
[77b350]31#include "Fragmentation/Homology/HomologyGraph.hpp"
[fbf143]32#include "Fragmentation/Summation/SetValues/Fragment.hpp"
[bf1d1b]33#include "Fragmentation/Summation/SetValues/SamplingGrid.hpp"
[12a24c]34
35class HomologyContainerTest;
36
[4694df]37/** This class takes all KeySets in a Graph, checks for those that homologues
38 * of one another and places them together.
39 *
40 * This is meant as a storage for key, value pairs, where the key is the KeySet
41 * and the value is the energy associated to the fragment this keyset
42 * represents.
43 * Afterwards this can then be used as training data for a high-dimensional
44 * approximation to the Born-Oppenheimer-surface decomposed into lower-
45 * dimensional terms in an ANOVA-like fashion.
46 *
47 */
[bcc24f]48class HomologyContainer : public Observable
[4694df]49{
[e15ffe]50 //!> grant access to output operator
51 friend std::ostream& operator<<(std::ostream &out, const HomologyContainer &container);
[12a24c]52 //!> grant unit test access
53 friend class HomologyContainerTest;
[bf1d1b]54
55public:
56 /** This structure represents all values associated to a specific homology
57 * that we wish to store in this container for later reference.
58 */
59 struct value_t {
60 Fragment fragment;
[814b8c]61 FragmentationEdges::edges_t edges;
[bf1d1b]62 double energy;
63 bool containsGrids;
64 SamplingGrid charge_distribution;
65 SamplingGrid potential_distribution;
66
67 value_t() :
68 energy(0.),
69 containsGrids(false)
70 {}
71
72 bool operator==(const value_t &othervalue) const;
73
74 private:
75 friend class boost::serialization::access;
76 // serialization
77 template <typename Archive>
78 void serialize(Archive& ar, const unsigned int version)
79 {
80 ar & fragment;
[814b8c]81 if (version > 1)
82 ar & edges;
[bf1d1b]83 ar & energy;
84 if (version > 0) {
85 ar & containsGrids;
86 if (containsGrids) {
87 ar & charge_distribution;
88 ar & potential_distribution;
89 }
90 }
91 }
92 };
93
[4694df]94public:
[77b350]95 typedef std::multimap< HomologyGraph, value_t> container_t;
[d058e6]96 typedef container_t::const_iterator const_iterator;
[39a07a]97 typedef MapKeyConstIterator<container_t::const_iterator> const_key_iterator;
[d058e6]98 typedef std::pair< const_iterator, const_iterator> range_t;
[bcc24f]99
[77b350]100public:
101 /** Default Constructor of class HomologyContainer.
102 *
103 */
[bcc24f]104 HomologyContainer();
[77b350]105
106 /** Constructor of class HomologyContainer.
107 *
108 * @param values values with with to initially fill the container
109 */
[bcc24f]110 HomologyContainer(const container_t &values);
111
[77b350]112 /** Destructor of class HomologyContainer.
113 *
114 */
[4694df]115 ~HomologyContainer() {}
116
[12a24c]117 /** Equality comparator.
118 *
119 * Sadly, the insertion order of a std::multimap's values is not guaranteed
120 * by the standard and boost::serialization does not heed the ordering of
121 * the values associated to the same key. Hence, we implement a weaker
122 * comparator for this class in order for the unit test to pass as we don't
123 * actuallty care about the order of the homologous fragments.
124 *
125 * @param other instance to compare to
126 * @return true - each container contains all elements of the other
127 */
128 bool operator==(const HomologyContainer &other) const {
129 return ((*this >= other) && (other >= *this));
130 }
131 bool operator!=(const HomologyContainer& other) const {
132 return !(*this == other);
133 }
134
135 /** Greater equal comparator, i.e. subset comparator
136 *
137 * @param other container to check if it's subset
138 * @return true - \a other is a subset of this
139 */
140 bool operator>=(const HomologyContainer &other) const;
141
[77b350]142 /** Inserter for more graphs along with values.
143 *
144 * @param values graph and values to insert
145 */
[bcc24f]146 void insert(const container_t &values);
[77b350]147
148 /** Returns iterator range with all contained graphs homologous to the given \a graph.
149 *
150 * @param graph graph to match
151 * @return iterator range with all matches
152 */
[a8bc27a]153 range_t getHomologousGraphs(const HomologyGraph &graph) const {
[77b350]154 return container.equal_range(graph);
155 }
156
[d058e6]157 /** Getter for constant iterator to begin of homologous graph container.
158 *
159 * @return begin constant iterator
160 */
161 const_iterator begin() const {
162 return container.begin();
163 }
164
165 /** Getter for constant iterator to past end of homologous graph container.
166 *
167 * @return past end constant iterator
168 */
169 const_iterator end() const {
170 return container.end();
171 }
172
[39a07a]173 const_key_iterator key_begin() const
174 { return const_key_iterator(container.begin()); }
175
176 const_key_iterator key_end() const
177 { return const_key_iterator(container.end()); }
178
[bcc24f]179 const_key_iterator getNextKey(const_key_iterator &iter) const
180 { return const_key_iterator(container.upper_bound(*iter)); }
181
182 /** Clears all homologies from container.
183 *
184 */
185 void clear();
186
[707a2b]187 /** Returns the number of keys in the container.
188 *
189 * \return size of internal container
190 */
191 const size_t size()
192 { return container.size(); }
193
[4694df]194private:
[77b350]195 //!> multimap containing all homologous graph under same key but each with its value
196 container_t container;
[12a24c]197
198private:
199 friend class boost::serialization::access;
200 // serialization
201 template <typename Archive>
[bcc24f]202 void load(Archive& ar, const unsigned int version)
203 {
204 OBSERVE;
205 ar & container;
206 }
207 template <typename Archive>
208 void save(Archive& ar, const unsigned int version) const
[12a24c]209 {
210 ar & container;
211 }
[bcc24f]212 BOOST_SERIALIZATION_SPLIT_MEMBER()
[4694df]213};
214
[e15ffe]215/** Output operator for HomologyContainer.
216 *
217 * \param out output stream
218 * \param container container to print
219 * \return output stream for concatenation
220 */
221std::ostream& operator<<(std::ostream &out, const HomologyContainer &container);
[4694df]222
[12a24c]223// we need to give this class a unique key for serialization
224BOOST_CLASS_EXPORT_KEY(HomologyContainer)
225
[bf1d1b]226// version for serialized information associated to HomologyGraph
[814b8c]227BOOST_CLASS_VERSION(HomologyContainer::value_t, 2)
[12a24c]228
[4694df]229#endif /* HOMOLOGYCONTAINER_HPP_ */
Note: See TracBrowser for help on using the repository browser.