source: src/bond.cpp@ bbbad5

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 bbbad5 was 97b825, checked in by Frederik Heber <heber@…>, 15 years ago

Shortened constructors [Meyers, "Effective C++" item 12]

  • also rearranged some initialization list (one per line).
  • Property mode set to 100644
File size: 3.8 KB
Line 
1/** \file bond.cpp
2 *
3 * Function implementations for the classes BondLeaf, BondTree and bond.
4 *
5 */
6
7#include "Helpers/MemDebug.hpp"
8
9#include "Helpers/Log.hpp"
10#include "Helpers/Verbose.hpp"
11#include "atom.hpp"
12#include "bond.hpp"
13#include "element.hpp"
14#include "lists.hpp"
15
16
17/***************************************** Functions for class bond ********************************/
18
19/** Empty Constructor for class bond.
20 */
21bond::bond() :
22 leftatom(NULL),
23 rightatom(NULL),
24 previous(NULL),
25 next(NULL),
26 HydrogenBond(0),
27 BondDegree(0),
28 nr(-1),
29 Cyclic(false),
30 Type(Undetermined),
31 Used(white)
32{};
33
34/** Constructor for class bond, taking right and left bond partner
35 * \param *left left atom
36 * \param *right right atom
37 * \param degree bond degree
38 * \param number increasing index
39 */
40bond::bond(atom *left, atom *right, const int degree, const int number) :
41 leftatom(left),
42 rightatom(right),
43 previous(NULL),
44 next(NULL),
45 HydrogenBond(0),
46 BondDegree(degree),
47 nr(number),
48 Cyclic(false),
49 Type(Undetermined),
50 Used(white)
51{
52 if ((left != NULL) && (right != NULL)) {
53 if ((left->getType() != NULL) && (left->getType()->Z == 1))
54 HydrogenBond++;
55 if ((right->getType() != NULL) && (right->getType()->Z == 1))
56 HydrogenBond++;
57 }
58};
59
60/** Empty Destructor for class bond.
61 */
62bond::~bond()
63{
64 // remove this node from the list structure
65 if (leftatom != NULL)
66 leftatom->UnregisterBond(this);
67 if (rightatom != NULL)
68 rightatom->UnregisterBond(this);
69 unlink(this);
70};
71
72ostream & operator << (ostream &ost, const bond &b)
73{
74 ost << "[" << b.leftatom->getName() << " <" << b.BondDegree << "(H" << b.HydrogenBond << ")>" << b.rightatom->getName() << "]";
75 return ost;
76};
77
78/** Get the other atom in a bond if one is specified.
79 * \param *Atom the pointer to the one atom
80 * \return pointer to the other atom in the bond, NULL if no match (indicates something's wrong with the bond)
81 */
82atom * bond::GetOtherAtom(const ParticleInfo * const Atom) const
83{
84 if(leftatom == Atom)
85 return rightatom;
86 if(rightatom == Atom)
87 return leftatom;
88 DoeLog(1) && (eLog()<< Verbose(1) << "Bond " << *this << " does not contain atom " << *Atom << "!" << endl);
89 return NULL;
90};
91
92
93/** Returns whether vertex was used in DFS.
94 * \return bond::Used
95 */
96enum Shading bond::IsUsed()
97{
98 return Used;
99};
100
101/** Checks if an atom exists in a bond.
102 * \param *ptr pointer to atom
103 * \return true if it is either bond::leftatom or bond::rightatom, false otherwise
104 */
105bool bond::Contains(const ParticleInfo * const ptr)
106{
107 return ((leftatom == ptr) || (rightatom == ptr));
108};
109
110/** Checks if an atom exists in a bond.
111 * \param nr index of atom
112 * \return true if it is either bond::leftatom or bond::rightatom, false otherwise
113 */
114bool bond::Contains(const int number)
115{
116 return ((leftatom->nr == number) || (rightatom->nr == number));
117};
118
119/** Masks vertex as used in DFS.
120 * \return bond::Used, false if bond was already marked used
121 */
122bool bond::MarkUsed(const enum Shading color) {
123 if (Used == black) {
124 DoeLog(1) && (eLog()<< Verbose(1) << "Bond " << this << " was already marked black!." << endl);
125 return false;
126 } else {
127 Used = color;
128 return true;
129 }
130};
131
132/** Resets used flag in DFS.
133 * \return bond::Used
134 */
135void bond::ResetUsed() {
136 Used = white;
137};
138
139/** Calculates the bond length.
140 * \return |a - b| with a = bond::leftatom and b = bond::rightatom.
141 */
142double bond::GetDistance() const
143{
144 return (leftatom->distance(*rightatom));
145};
146
147/** Calculates the bond length.
148 * \return |a - b|^2 with a = bond::leftatom and b = bond::rightatom.
149 */
150double bond::GetDistanceSquared() const
151{
152 return (leftatom->DistanceSquared(*rightatom));
153};
Note: See TracBrowser for help on using the repository browser.