source: src/Fragmentation/Homology/HomologyContainer.hpp@ 98dbee

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing 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_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 98dbee was bcc24f, checked in by Frederik Heber <heber@…>, 12 years ago

Made HomologyContainer observable.

  • added clear() and getNextKey() functionality.
  • Property mode set to 100644
File size: 5.0 KB
Line 
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
17#include <boost/serialization/export.hpp>
18#include <boost/serialization/map.hpp>
19#include <boost/serialization/split_member.hpp>
20#include <boost/serialization/vector.hpp>
21
22#include <iosfwd>
23#include <map>
24#include <vector>
25
26#include "CodePatterns/IteratorAdaptors.hpp"
27#include "CodePatterns/Observer/Observable.hpp"
28
29#include "Fragmentation/Homology/HomologyGraph.hpp"
30#include "Fragmentation/Summation/SetValues/Fragment.hpp"
31
32class HomologyContainerTest;
33
34/** This class takes all KeySets in a Graph, checks for those that homologues
35 * of one another and places them together.
36 *
37 * This is meant as a storage for key, value pairs, where the key is the KeySet
38 * and the value is the energy associated to the fragment this keyset
39 * represents.
40 * Afterwards this can then be used as training data for a high-dimensional
41 * approximation to the Born-Oppenheimer-surface decomposed into lower-
42 * dimensional terms in an ANOVA-like fashion.
43 *
44 */
45class HomologyContainer : public Observable
46{
47 //!> grant access to output operator
48 friend std::ostream& operator<<(std::ostream &out, const HomologyContainer &container);
49 //!> grant unit test access
50 friend class HomologyContainerTest;
51public:
52 typedef double energy_t;
53 typedef std::pair<Fragment, energy_t> value_t;
54 typedef std::multimap< HomologyGraph, value_t> container_t;
55 typedef container_t::const_iterator const_iterator;
56 typedef MapKeyConstIterator<container_t::const_iterator> const_key_iterator;
57 typedef std::pair< const_iterator, const_iterator> range_t;
58
59public:
60 /** Default Constructor of class HomologyContainer.
61 *
62 */
63 HomologyContainer();
64
65 /** Constructor of class HomologyContainer.
66 *
67 * @param values values with with to initially fill the container
68 */
69 HomologyContainer(const container_t &values);
70
71 /** Destructor of class HomologyContainer.
72 *
73 */
74 ~HomologyContainer() {}
75
76 /** Equality comparator.
77 *
78 * Sadly, the insertion order of a std::multimap's values is not guaranteed
79 * by the standard and boost::serialization does not heed the ordering of
80 * the values associated to the same key. Hence, we implement a weaker
81 * comparator for this class in order for the unit test to pass as we don't
82 * actuallty care about the order of the homologous fragments.
83 *
84 * @param other instance to compare to
85 * @return true - each container contains all elements of the other
86 */
87 bool operator==(const HomologyContainer &other) const {
88 return ((*this >= other) && (other >= *this));
89 }
90 bool operator!=(const HomologyContainer& other) const {
91 return !(*this == other);
92 }
93
94 /** Greater equal comparator, i.e. subset comparator
95 *
96 * @param other container to check if it's subset
97 * @return true - \a other is a subset of this
98 */
99 bool operator>=(const HomologyContainer &other) const;
100
101 /** Inserter for more graphs along with values.
102 *
103 * @param values graph and values to insert
104 */
105 void insert(const container_t &values);
106
107 /** Returns iterator range with all contained graphs homologous to the given \a graph.
108 *
109 * @param graph graph to match
110 * @return iterator range with all matches
111 */
112 range_t getHomologousGraphs(const HomologyGraph &graph) const {
113 return container.equal_range(graph);
114 }
115
116 /** Getter for constant iterator to begin of homologous graph container.
117 *
118 * @return begin constant iterator
119 */
120 const_iterator begin() const {
121 return container.begin();
122 }
123
124 /** Getter for constant iterator to past end of homologous graph container.
125 *
126 * @return past end constant iterator
127 */
128 const_iterator end() const {
129 return container.end();
130 }
131
132 const_key_iterator key_begin() const
133 { return const_key_iterator(container.begin()); }
134
135 const_key_iterator key_end() const
136 { return const_key_iterator(container.end()); }
137
138 const_key_iterator getNextKey(const_key_iterator &iter) const
139 { return const_key_iterator(container.upper_bound(*iter)); }
140
141 /** Clears all homologies from container.
142 *
143 */
144 void clear();
145
146private:
147 //!> multimap containing all homologous graph under same key but each with its value
148 container_t container;
149
150private:
151 friend class boost::serialization::access;
152 // serialization
153 template <typename Archive>
154 void load(Archive& ar, const unsigned int version)
155 {
156 OBSERVE;
157 ar & container;
158 }
159 template <typename Archive>
160 void save(Archive& ar, const unsigned int version) const
161 {
162 ar & container;
163 }
164 BOOST_SERIALIZATION_SPLIT_MEMBER()
165};
166
167/** Output operator for HomologyContainer.
168 *
169 * \param out output stream
170 * \param container container to print
171 * \return output stream for concatenation
172 */
173std::ostream& operator<<(std::ostream &out, const HomologyContainer &container);
174
175// we need to give this class a unique key for serialization
176BOOST_CLASS_EXPORT_KEY(HomologyContainer)
177
178
179#endif /* HOMOLOGYCONTAINER_HPP_ */
Note: See TracBrowser for help on using the repository browser.