source: molecuilder/src/bond.cpp@ d618b5

Last change on this file since d618b5 was e08f45, checked in by Frederik Heber <heber@…>, 17 years ago

Merge branch 'ConcaveHull' of ../espack2 into ConcaveHull

Conflicts:

molecuilder/src/boundary.cpp
molecuilder/src/boundary.hpp
molecuilder/src/builder.cpp
molecuilder/src/linkedcell.cpp
molecuilder/src/linkedcell.hpp
molecuilder/src/vector.cpp
molecuilder/src/vector.hpp
util/src/NanoCreator.c

Basically, this resulted from a lot of conversions two from spaces to one tab, which is my standard indentation. The mess was caused by eclipse auto-indenting. And in espack2:ConcaveHull was the new stuff, so all from ConcaveHull was replaced in case of doubt.
Additionally, vector had ofstream << operator instead ostream << ...

  • Property mode set to 100755
File size: 3.9 KB
RevLine 
[a0bcf1]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 */
14bond::bond()
15{
16 leftatom = NULL;
17 rightatom = NULL;
[e08f45]18 previous = NULL;
19 next = NULL;
[a0bcf1]20 nr = -1;
21 HydrogenBond = 0;
22 BondDegree = 0;
[e08f45]23 Used = white;
24 Cyclic = false;
25 Type = Undetermined;
[a0bcf1]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 */
34bond::bond(atom *left, atom *right, int degree=1, int number=0)
35{
36 leftatom = left;
37 rightatom = right;
[e08f45]38 previous = NULL;
39 next = NULL;
[a0bcf1]40 HydrogenBond = 0;
[e08f45]41 if ((left != NULL) && (right != NULL)) {
42 if ((left->type != NULL) && (left->type->Z == 1))
43 HydrogenBond++;
44 if ((right->type != NULL) && (right->type->Z == 1))
45 HydrogenBond++;
46 }
47 BondDegree = degree;
48 nr = number;
49 Used = white;
50 Cyclic = false;
[a0bcf1]51};
52bond::bond(atom *left, atom *right)
53{
[e08f45]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;
[a0bcf1]69};
70
71/** Empty Destructor for class bond.
72 */
73bond::~bond()
74{
[e08f45]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 }
[a0bcf1]82};
83
84ostream & operator << (ostream &ost, bond &b)
85{
[e08f45]86 ost << "[" << b.leftatom->Name << " <" << b.BondDegree << "(H" << b.HydrogenBond << ")>" << b.rightatom->Name << "]";
87 return ost;
[a0bcf1]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 */
94atom * bond::GetOtherAtom(atom *Atom) const
95{
[e08f45]96 if(leftatom == Atom)
97 return rightatom;
98 if(rightatom == Atom)
99 return leftatom;
100 return NULL;
[a0bcf1]101};
102
103/** Get the other atom in a bond if one is specified.
104 * \param *Atom the pointer to the one atom
105 * \return pointer to the other atom in the bond, NULL if no match (indicates something's wrong with the bond)
106 */
107bond * bond::GetFirstBond()
108{
[e08f45]109 return GetFirst(this);
[a0bcf1]110};
111
112/** Get the other atom in a bond if one is specified.
113 * \param *Atom the pointer to the one atom
114 * \return pointer to the other atom in the bond, NULL if no match (indicates something's wrong with the bond)
115 */
116bond * bond::GetLastBond()
117{
[e08f45]118 return GetLast(this);
[a0bcf1]119};
120
121/** Returns whether vertex was used in DFS.
122 * \return bond::Used
123 */
124enum Shading bond::IsUsed()
125{
[e08f45]126 return Used;
[a0bcf1]127};
128
129/** Checks if an atom exists in a bond.
130 * \param *ptr pointer to atom
131 * \return true if it is either bond::leftatom or bond::rightatom, false otherwise
132 */
133bool bond::Contains(const atom *ptr)
134{
[e08f45]135 return ((leftatom == ptr) || (rightatom == ptr));
[a0bcf1]136};
137
138/** Checks if an atom exists in a bond.
139 * \param nr index of atom
140 * \return true if it is either bond::leftatom or bond::rightatom, false otherwise
141 */
[75793b2]142bool bond::Contains(const int number)
[a0bcf1]143{
[e08f45]144 return ((leftatom->nr == number) || (rightatom->nr == number));
[a0bcf1]145};
146
147/** Masks vertex as used in DFS.
148 * \return bond::Used, false if bond was already marked used
149 */
150bool bond::MarkUsed(enum Shading color) {
[e08f45]151 if (Used == black) {
152 cerr << "ERROR: Bond " << this << " was already marked black!." << endl;
153 return false;
154 } else {
155 Used = color;
156 return true;
157 }
[a0bcf1]158};
159
160/** Resets used flag in DFS.
161 * \return bond::Used
162 */
163void bond::ResetUsed() {
[e08f45]164 Used = white;
[a0bcf1]165};
Note: See TracBrowser for help on using the repository browser.