source: src/bond.cpp@ 68cb0f

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 68cb0f was fa40b5, checked in by Frederik Heber <heber@…>, 17 years ago

these are all smaller fixes due to extensively enabled compiler warnings

e.g. local variable shadows global (mol::nr by local nr)
and others

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