source: src/Fragmentation/SetValues/Fragment.hpp@ 14de8e1

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

Added serialization capability to Fragment.

  • also added unit test function on this.
  • Property mode set to 100644
File size: 4.1 KB
Line 
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
17#include <boost/serialization/export.hpp>
18#include <boost/serialization/vector.hpp>
19#include <boost/serialization/utility.hpp>
20
21#include <iosfwd>
22#include <vector>
23
24class FragmentTest;
25
26class Fragment {
27 //!> grant ostream operator access
28 friend std::ostream & operator<<(std::ostream &ost, const Fragment &f);
29 //!> grant unit test access
30 friend class FragmentTest;
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
38 /** Default constructor of class Fragment.
39 *
40 */
41 Fragment();
42
43 /** Default constructor of class Fragment.
44 *
45 */
46 Fragment(const nuclei_t &_nuclei) :
47 nuclei(_nuclei)
48 {}
49
50 /** Constructor of class Fragment.
51 *
52 * @param _positions given positions
53 * @param _charges given charges
54 */
55 Fragment(const positions_t &_positions, const charges_t &_charges);
56
57 /** Adding another fragment onto this one.
58 *
59 * \note The operation is area-conserving, i.e. the new area is the sum of
60 * both areas.
61 *
62 * @param other other fragment
63 * @return ref to this instance
64 */
65 Fragment& operator+=(const Fragment &other);
66
67 /** Assignment operator.
68 *
69 * @param other other fragment to make ourselves equal to
70 * @return ref to this instance
71 */
72 Fragment& operator=(const Fragment &other);
73
74 /** Subtracting another fragment from this one.
75 *
76 * @param other other fragment
77 * @return ref to this instance
78 */
79 Fragment& operator-=(const Fragment &other);
80
81 /** Getter for all stored positions.
82 *
83 * @return vector of positions
84 */
85 positions_t getPositions() const;
86
87 /** Getter for all stored charges.
88 *
89 * @return vector of charges
90 */
91 charges_t getCharges() const;
92
93 /** Equality operator.
94 *
95 * @param other other instance to check against
96 * @return true - both are equal, false - some nucleus_t differ
97 */
98 bool operator==(const Fragment& other) const;
99
100 bool operator!=(const Fragment& other) const
101 {
102 return (!(*this == other));
103 }
104
105 /** Creates type nucleus_t from given \a position and \a charge.
106 *
107 * @param position position of nucleus to create
108 * @param charge charge of nucleus to create
109 * @return nucleus with given \a position and \a charge
110 */
111 static nucleus_t createNucleus(const position_t &position, const double charge);
112
113 /** Helper function to check whether two positions are equal.
114 *
115 * @param a first position
116 * @param b second position
117 * @return a equals b within numerical precision
118 */
119 static bool isPositionEqual(const position_t &a, const position_t &b);
120
121private:
122 /** Helper function that checks whether this nuclei \b position is present.
123 *
124 * This operation is \f${\cal O}(n)\f$
125 *
126 * @param n nuclei to check
127 * @return true - is contained, false - is not contained
128 */
129 bool containsNuclei(const nucleus_t &n) const;
130
131 /** Seeks through all nuclei and removes one with matching \b position if found.
132 *
133 * @param n nuclei to remove
134 */
135 void removeNuclei(const nucleus_t &n);
136
137private:
138 nuclei_t nuclei;
139
140private:
141 friend class boost::serialization::access;
142 // serialization
143 template <typename Archive>
144 void serialize(Archive& ar, const unsigned int version)
145 {
146 ar & nuclei;
147 }
148};
149
150// we need to give this class a unique key for serialization
151BOOST_CLASS_EXPORT_KEY(Fragment)
152
153/** Equality operator for two nuclei.
154 *
155 * @param a first nuclei
156 * @param b second nuclei
157 * @return true - both have same position and charge, false - either charge or position is different
158 */
159bool operator==(const Fragment::nucleus_t &a, const Fragment::nucleus_t &b);
160
161std::ostream & operator<<(std::ostream &ost, const Fragment::nucleus_t &n);
162
163std::ostream & operator<<(std::ostream &ost, const Fragment &f);
164
165template<typename T> T ZeroInstance();
166template<> Fragment ZeroInstance<Fragment>();
167
168#endif /* FRAGMENT_HPP_ */
Note: See TracBrowser for help on using the repository browser.