| [14de469] | 1 | /** \file bond.cpp | 
|---|
|  | 2 | * | 
|---|
|  | 3 | * Function implementations for the classes BondLeaf, BondTree and bond. | 
|---|
|  | 4 | * | 
|---|
|  | 5 | */ | 
|---|
|  | 6 |  | 
|---|
| [112b09] | 7 | #include "Helpers/MemDebug.hpp" | 
|---|
|  | 8 |  | 
|---|
| [8f4df1] | 9 | #include "Helpers/Log.hpp" | 
|---|
| [952f38] | 10 | #include "Helpers/Verbose.hpp" | 
|---|
| [e41951] | 11 | #include "atom.hpp" | 
|---|
| [357fba] | 12 | #include "bond.hpp" | 
|---|
| [f66195] | 13 | #include "element.hpp" | 
|---|
|  | 14 | #include "lists.hpp" | 
|---|
|  | 15 |  | 
|---|
| [14de469] | 16 |  | 
|---|
|  | 17 | /***************************************** Functions for class bond ********************************/ | 
|---|
|  | 18 |  | 
|---|
|  | 19 | /** Empty Constructor for class bond. | 
|---|
|  | 20 | */ | 
|---|
| [97b825] | 21 | bond::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 | {}; | 
|---|
| [14de469] | 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 | */ | 
|---|
| [97b825] | 40 | bond::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) | 
|---|
| [14de469] | 51 | { | 
|---|
|  | 52 | if ((left != NULL) && (right != NULL)) { | 
|---|
| [d74077] | 53 | if ((left->getType() != NULL) && (left->getType()->Z == 1)) | 
|---|
| [ce5ac3] | 54 | HydrogenBond++; | 
|---|
| [d74077] | 55 | if ((right->getType() != NULL) && (right->getType()->Z == 1)) | 
|---|
| [ce5ac3] | 56 | HydrogenBond++; | 
|---|
| [14de469] | 57 | } | 
|---|
|  | 58 | }; | 
|---|
|  | 59 |  | 
|---|
|  | 60 | /** Empty Destructor for class bond. | 
|---|
|  | 61 | */ | 
|---|
|  | 62 | bond::~bond() | 
|---|
|  | 63 | { | 
|---|
|  | 64 | // remove this node from the list structure | 
|---|
| [266237] | 65 | if (leftatom != NULL) | 
|---|
|  | 66 | leftatom->UnregisterBond(this); | 
|---|
|  | 67 | if (rightatom != NULL) | 
|---|
|  | 68 | rightatom->UnregisterBond(this); | 
|---|
|  | 69 | unlink(this); | 
|---|
| [14de469] | 70 | }; | 
|---|
|  | 71 |  | 
|---|
| [fb73b8] | 72 | ostream & operator << (ostream &ost, const bond &b) | 
|---|
| [14de469] | 73 | { | 
|---|
| [68f03d] | 74 | ost << "[" << b.leftatom->getName() << " <" << b.BondDegree << "(H" << b.HydrogenBond << ")>" << b.rightatom->getName() << "]"; | 
|---|
| [14de469] | 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 | */ | 
|---|
| [fb73b8] | 82 | atom * bond::GetOtherAtom(const ParticleInfo * const Atom) const | 
|---|
| [14de469] | 83 | { | 
|---|
|  | 84 | if(leftatom == Atom) | 
|---|
|  | 85 | return rightatom; | 
|---|
|  | 86 | if(rightatom == Atom) | 
|---|
|  | 87 | return leftatom; | 
|---|
| [58ed4a] | 88 | DoeLog(1) && (eLog()<< Verbose(1) << "Bond " << *this << " does not contain atom " << *Atom << "!" << endl); | 
|---|
| [14de469] | 89 | return NULL; | 
|---|
|  | 90 | }; | 
|---|
|  | 91 |  | 
|---|
|  | 92 |  | 
|---|
|  | 93 | /** Returns whether vertex was used in DFS. | 
|---|
|  | 94 | * \return bond::Used | 
|---|
|  | 95 | */ | 
|---|
|  | 96 | enum 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 | */ | 
|---|
| [fb73b8] | 105 | bool bond::Contains(const ParticleInfo * const ptr) | 
|---|
| [14de469] | 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 | */ | 
|---|
| [fa40b5] | 114 | bool bond::Contains(const int number) | 
|---|
| [14de469] | 115 | { | 
|---|
| [fa40b5] | 116 | return ((leftatom->nr == number) || (rightatom->nr == number)); | 
|---|
| [14de469] | 117 | }; | 
|---|
|  | 118 |  | 
|---|
|  | 119 | /** Masks vertex as used in DFS. | 
|---|
|  | 120 | * \return bond::Used, false if bond was already marked used | 
|---|
|  | 121 | */ | 
|---|
| [fb73b8] | 122 | bool bond::MarkUsed(const enum Shading color) { | 
|---|
| [14de469] | 123 | if (Used == black) { | 
|---|
| [58ed4a] | 124 | DoeLog(1) && (eLog()<< Verbose(1) << "Bond " << this << " was already marked black!." << endl); | 
|---|
| [14de469] | 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 | */ | 
|---|
|  | 135 | void bond::ResetUsed() { | 
|---|
|  | 136 | Used = white; | 
|---|
|  | 137 | }; | 
|---|
| [b9947d] | 138 |  | 
|---|
|  | 139 | /** Calculates the bond length. | 
|---|
|  | 140 | * \return |a - b| with a = bond::leftatom and b = bond::rightatom. | 
|---|
|  | 141 | */ | 
|---|
|  | 142 | double bond::GetDistance() const | 
|---|
|  | 143 | { | 
|---|
| [d74077] | 144 | return (leftatom->distance(*rightatom)); | 
|---|
| [b9947d] | 145 | }; | 
|---|
|  | 146 |  | 
|---|
|  | 147 | /** Calculates the bond length. | 
|---|
|  | 148 | * \return |a - b|^2 with a = bond::leftatom and b = bond::rightatom. | 
|---|
|  | 149 | */ | 
|---|
|  | 150 | double bond::GetDistanceSquared() const | 
|---|
|  | 151 | { | 
|---|
| [d74077] | 152 | return (leftatom->DistanceSquared(*rightatom)); | 
|---|
| [b9947d] | 153 | }; | 
|---|