source: src/Fragmentation/SetValues/Fragment.hpp@ 302345

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

Added extensive unit tests and some more functions to Fragment.

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