source: molecuilder/src/atom_bondedparticle.cpp@ 94d0ad

Last change on this file since 94d0ad was 94d0ad, checked in by Frederik Heber <heber@…>, 16 years ago

Begun with ticket #38 (make const what is const).

  • basically all changes to member function that now state that they do not change member attributes.
  • in molecule_template.hpp all member functions are declared const, as we only need start and end from molecule and these are never changed (lots of overloaded templates removed thereby).
  • Vector::Distance...() and ...DistanceSquared() are const now too
  • Property mode set to 100644
File size: 4.6 KB
Line 
1/*
2 * atom_bondedparticle.cpp
3 *
4 * Created on: Oct 19, 2009
5 * Author: heber
6 */
7
8#include "atom.hpp"
9#include "atom_bondedparticle.hpp"
10#include "bond.hpp"
11#include "element.hpp"
12#include "lists.hpp"
13#include "verbose.hpp"
14
15/** Constructor of class BondedParticle.
16 */
17BondedParticle::BondedParticle(){};
18
19/** Destructor of class BondedParticle.
20 */
21BondedParticle::~BondedParticle()
22{
23 BondList::const_iterator Runner;
24 while (!ListOfBonds.empty()) {
25 Runner = ListOfBonds.begin();
26 removewithoutcheck(*Runner);
27 }
28};
29
30/** Outputs the current atom::AdaptiveOrder and atom::MaxOrder to \a *file.
31 * \param *file output stream
32 */
33void BondedParticle::OutputOrder(ofstream *file) const
34{
35 *file << nr << "\t" << (int)AdaptiveOrder << "\t" << (int)MaxOrder << endl;
36 //cout << Verbose(2) << "Storing: " << nr << "\t" << (int)AdaptiveOrder << "\t" << (int)MaxOrder << "." << endl;
37};
38
39/** Prints all bonds of this atom with total degree.
40 * \param *out stream to output to
41 * \return true - \a *out present, false - \a *out is NULL
42 */
43bool BondedParticle::OutputBondOfAtom(ofstream *out) const
44{
45 if (out != NULL) {
46 *out << Verbose(4) << "Atom " << Name << "/" << nr << " with " << ListOfBonds.size() << " bonds: ";
47 int TotalDegree = 0;
48 for (BondList::const_iterator Runner = ListOfBonds.begin(); Runner != ListOfBonds.end(); ++Runner) {
49 *out << **Runner << "\t";
50 TotalDegree += (*Runner)->BondDegree;
51 }
52 *out << " -- TotalDegree: " << TotalDegree << endl;
53 return true;
54 } else
55 return false;
56};
57
58/** Output of atom::nr along with all bond partners.
59 * \param *AdjacencyFile output stream
60 */
61void BondedParticle::OutputAdjacency(ofstream *AdjacencyFile) const
62{
63 *AdjacencyFile << nr << "\t";
64 for (BondList::const_iterator Runner = ListOfBonds.begin(); Runner != ListOfBonds.end(); (++Runner))
65 *AdjacencyFile << (*Runner)->GetOtherAtom(this)->nr << "\t";
66 *AdjacencyFile << endl;
67};
68
69/** Puts a given bond into atom::ListOfBonds.
70 * \param *Binder bond to insert
71 */
72bool BondedParticle::RegisterBond(bond *Binder)
73{
74 bool status = false;
75 if (Binder != NULL) {
76 if (Binder->Contains(this)) {
77 ListOfBonds.push_back(Binder);
78 status = true;
79 } else {
80 cout << Verbose(1) << "ERROR: " << *Binder << " does not contain " << *this << "." << endl;
81 }
82 } else {
83 cout << Verbose(1) << "ERROR: Binder is " << Binder << "." << endl;
84 }
85 return status;
86};
87
88/** Removes a given bond from atom::ListOfBonds.
89 * \param *Binder bond to remove
90 */
91bool BondedParticle::UnregisterBond(bond *Binder)
92{
93 bool status = false;
94 if (Binder != NULL) {
95 if (Binder->Contains(this)) {
96 ListOfBonds.remove(Binder);
97 status = true;
98 } else {
99 cout << Verbose(1) << "ERROR: " << *Binder << " does not contain " << *this << "." << endl;
100 }
101 } else {
102 cout << Verbose(1) << "ERROR: Binder is " << Binder << "." << endl;
103 }
104 return status;
105};
106
107/** Removes all bonds from atom::ListOfBonds.
108 * \note Does not do any memory de-allocation.
109 */
110void BondedParticle::UnregisterAllBond()
111{
112 ListOfBonds.clear();
113};
114
115/** Corrects the bond degree by one at most if necessary.
116 * \param *out output stream for debugging
117 */
118int BondedParticle::CorrectBondDegree(ofstream *out)
119{
120 int NoBonds = 0;
121 int OtherNoBonds = 0;
122 int FalseBondDegree = 0;
123 atom *OtherWalker = NULL;
124 bond *CandidateBond = NULL;
125
126 *out << Verbose(3) << "Walker " << *this << ": " << (int)this->type->NoValenceOrbitals << " > " << NoBonds << "?" << endl;
127 NoBonds = CountBonds();
128 if ((int)(type->NoValenceOrbitals) > NoBonds) { // we have a mismatch, check all bonding partners for mismatch
129 for (BondList::const_iterator Runner = ListOfBonds.begin(); Runner != ListOfBonds.end(); (++Runner)) {
130 OtherWalker = (*Runner)->GetOtherAtom(this);
131 OtherNoBonds = OtherWalker->CountBonds();
132 *out << Verbose(3) << "OtherWalker " << *OtherWalker << ": " << (int)OtherWalker->type->NoValenceOrbitals << " > " << NoBonds << "?" << endl;
133 if ((int)(OtherWalker->type->NoValenceOrbitals) > NoBonds) { // check if possible candidate
134 if ((CandidateBond == NULL) || (ListOfBonds.size() > OtherWalker->ListOfBonds.size())) { // pick the one with fewer number of bonds first
135 CandidateBond = (*Runner);
136 *out << Verbose(3) << "New candidate is " << *CandidateBond << "." << endl;
137 }
138 }
139 }
140 if ((CandidateBond != NULL)) {
141 CandidateBond->BondDegree++;
142 *out << Verbose(2) << "Increased bond degree for bond " << *CandidateBond << "." << endl;
143 } else {
144 *out << Verbose(2) << "Could not find correct degree for atom " << *this << "." << endl;
145 FalseBondDegree++;
146 }
147 }
148 return FalseBondDegree;
149};
150
Note: See TracBrowser for help on using the repository browser.