[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 | */
|
---|
[70ff32] | 17 | bond::bond() : leftatom(NULL), rightatom(NULL), previous(NULL), next(NULL), HydrogenBond(0), BondDegree(0), nr(-1), Cyclic(false), Type(Undetermined), Used(white)
|
---|
[14de469] | 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 | */
|
---|
[fb73b8] | 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)
|
---|
[14de469] | 28 | {
|
---|
| 29 | if ((left != NULL) && (right != NULL)) {
|
---|
[ce5ac3] | 30 | if ((left->type != NULL) && (left->type->Z == 1))
|
---|
| 31 | HydrogenBond++;
|
---|
| 32 | if ((right->type != NULL) && (right->type->Z == 1))
|
---|
| 33 | HydrogenBond++;
|
---|
[14de469] | 34 | }
|
---|
| 35 | };
|
---|
| 36 |
|
---|
| 37 | /** Empty Destructor for class bond.
|
---|
| 38 | */
|
---|
| 39 | bond::~bond()
|
---|
| 40 | {
|
---|
| 41 | // remove this node from the list structure
|
---|
[266237] | 42 | if (leftatom != NULL)
|
---|
| 43 | leftatom->UnregisterBond(this);
|
---|
| 44 | if (rightatom != NULL)
|
---|
| 45 | rightatom->UnregisterBond(this);
|
---|
| 46 | unlink(this);
|
---|
[14de469] | 47 | };
|
---|
| 48 |
|
---|
[fb73b8] | 49 | ostream & operator << (ostream &ost, const bond &b)
|
---|
[14de469] | 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 | */
|
---|
[fb73b8] | 59 | atom * bond::GetOtherAtom(const ParticleInfo * const Atom) const
|
---|
[14de469] | 60 | {
|
---|
| 61 | if(leftatom == Atom)
|
---|
| 62 | return rightatom;
|
---|
| 63 | if(rightatom == Atom)
|
---|
| 64 | return leftatom;
|
---|
[58ed4a] | 65 | DoeLog(1) && (eLog()<< Verbose(1) << "Bond " << *this << " does not contain atom " << *Atom << "!" << endl);
|
---|
[14de469] | 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 | */
|
---|
[fb73b8] | 82 | bool bond::Contains(const ParticleInfo * const ptr)
|
---|
[14de469] | 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 | */
|
---|
[fa40b5] | 91 | bool bond::Contains(const int number)
|
---|
[14de469] | 92 | {
|
---|
[fa40b5] | 93 | return ((leftatom->nr == number) || (rightatom->nr == number));
|
---|
[14de469] | 94 | };
|
---|
| 95 |
|
---|
| 96 | /** Masks vertex as used in DFS.
|
---|
| 97 | * \return bond::Used, false if bond was already marked used
|
---|
| 98 | */
|
---|
[fb73b8] | 99 | bool bond::MarkUsed(const enum Shading color) {
|
---|
[14de469] | 100 | if (Used == black) {
|
---|
[58ed4a] | 101 | DoeLog(1) && (eLog()<< Verbose(1) << "Bond " << this << " was already marked black!." << endl);
|
---|
[14de469] | 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 | };
|
---|
[b9947d] | 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 | };
|
---|