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