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