source: src/bond.cpp@ fcbfc8

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

Output of atom and bond to stream now is set to const bond/atom

  • Property mode set to 100644
File size: 4.0 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, const 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 cerr << "Bond " << *this << " does not contain atom " << *Atom << "!" << endl;
101 return NULL;
102};
103
104/** Get the other atom in a bond if one is specified.
105 * \param *Atom the pointer to the one atom
106 * \return pointer to the other atom in the bond, NULL if no match (indicates something's wrong with the bond)
107 */
108bond * bond::GetFirstBond()
109{
110 return GetFirst(this);
111};
112
113/** Get the other atom in a bond if one is specified.
114 * \param *Atom the pointer to the one atom
115 * \return pointer to the other atom in the bond, NULL if no match (indicates something's wrong with the bond)
116 */
117bond * bond::GetLastBond()
118{
119 return GetLast(this);
120};
121
122/** Returns whether vertex was used in DFS.
123 * \return bond::Used
124 */
125enum Shading bond::IsUsed()
126{
127 return Used;
128};
129
130/** Checks if an atom exists in a bond.
131 * \param *ptr pointer to atom
132 * \return true if it is either bond::leftatom or bond::rightatom, false otherwise
133 */
134bool bond::Contains(const atom *ptr)
135{
136 return ((leftatom == ptr) || (rightatom == ptr));
137};
138
139/** Checks if an atom exists in a bond.
140 * \param nr index of atom
141 * \return true if it is either bond::leftatom or bond::rightatom, false otherwise
142 */
143bool bond::Contains(const int number)
144{
145 return ((leftatom->nr == number) || (rightatom->nr == number));
146};
147
148/** Masks vertex as used in DFS.
149 * \return bond::Used, false if bond was already marked used
150 */
151bool bond::MarkUsed(enum Shading color) {
152 if (Used == black) {
153 cerr << "ERROR: Bond " << this << " was already marked black!." << endl;
154 return false;
155 } else {
156 Used = color;
157 return true;
158 }
159};
160
161/** Resets used flag in DFS.
162 * \return bond::Used
163 */
164void bond::ResetUsed() {
165 Used = white;
166};
Note: See TracBrowser for help on using the repository browser.