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