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