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