source: src/Fragmentation/Homology/HomologyContainer.hpp@ 12a24c

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 12a24c was 12a24c, checked in by Frederik Heber <heber@…>, 12 years ago

Added serialization to HomologyContainer and completed HomologyContainerUnitTest.

  • Added specific operator==() to HomologyContainer as multimap's values' ordering is not guaranteed and boost::serialization does not adhere to it (simple copy of multimap probably maintains the ordering).
  • added InsertionTest, EqualityTest, and serializeTest().
  • Property mode set to 100644
File size: 4.7 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/vector.hpp>
20
21#include <iosfwd>
22#include <map>
23#include <vector>
24
25#include "Fragmentation/Homology/HomologyGraph.hpp"
26
27class Fragment
28{
29 //!> grant access to output operator
30 friend std::ostream& operator<<(std::ostream &out, const Fragment &container);
31public:
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) {}
39
40 bool operator==(const Fragment &other) const {
41 return true;
42 }
43
44private:
45 friend class boost::serialization::access;
46 // serialization
47 template <typename Archive>
48 void serialize(Archive& ar, const unsigned int version)
49 {}
50};
51
52std::ostream& operator<<(std::ostream &out, const Fragment &container);
53
54// we need to give this class a unique key for serialization
55BOOST_CLASS_EXPORT_KEY(Fragment)
56
57class HomologyContainerTest;
58
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 */
70class HomologyContainer
71{
72 //!> grant access to output operator
73 friend std::ostream& operator<<(std::ostream &out, const HomologyContainer &container);
74 //!> grant unit test access
75 friend class HomologyContainerTest;
76public:
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;
81public:
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 */
97 ~HomologyContainer() {}
98
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
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
141private:
142 //!> multimap containing all homologous graph under same key but each with its value
143 container_t container;
144
145private:
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 }
153};
154
155/** Output operator for HomologyContainer.
156 *
157 * \param out output stream
158 * \param container container to print
159 * \return output stream for concatenation
160 */
161std::ostream& operator<<(std::ostream &out, const HomologyContainer &container);
162
163// we need to give this class a unique key for serialization
164BOOST_CLASS_EXPORT_KEY(HomologyContainer)
165
166
167#endif /* HOMOLOGYCONTAINER_HPP_ */
Note: See TracBrowser for help on using the repository browser.