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