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