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