| [6b919f8] | 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" | 
|---|
| [e138de] | 13 | #include "log.hpp" | 
|---|
| [6b919f8] | 14 | #include "verbose.hpp" | 
|---|
|  | 15 |  | 
|---|
|  | 16 | /** Constructor of class BondedParticle. | 
|---|
|  | 17 | */ | 
|---|
| [70ff32] | 18 | BondedParticle::BondedParticle() | 
|---|
|  | 19 | { | 
|---|
|  | 20 | }; | 
|---|
| [6b919f8] | 21 |  | 
|---|
|  | 22 | /** Destructor of class BondedParticle. | 
|---|
|  | 23 | */ | 
|---|
|  | 24 | BondedParticle::~BondedParticle() | 
|---|
|  | 25 | { | 
|---|
|  | 26 | BondList::const_iterator Runner; | 
|---|
|  | 27 | while (!ListOfBonds.empty()) { | 
|---|
|  | 28 | Runner = ListOfBonds.begin(); | 
|---|
|  | 29 | removewithoutcheck(*Runner); | 
|---|
|  | 30 | } | 
|---|
|  | 31 | }; | 
|---|
|  | 32 |  | 
|---|
|  | 33 | /** Outputs the current atom::AdaptiveOrder and atom::MaxOrder to \a *file. | 
|---|
|  | 34 | * \param *file output stream | 
|---|
|  | 35 | */ | 
|---|
| [b453f9] | 36 | void BondedParticle::OutputOrder(ofstream *file) const | 
|---|
| [6b919f8] | 37 | { | 
|---|
|  | 38 | *file << nr << "\t" << (int)AdaptiveOrder << "\t" << (int)MaxOrder << endl; | 
|---|
| [e138de] | 39 | //Log() << Verbose(2) << "Storing: " << nr << "\t" << (int)AdaptiveOrder << "\t" << (int)MaxOrder << "." << endl; | 
|---|
| [6b919f8] | 40 | }; | 
|---|
|  | 41 |  | 
|---|
|  | 42 | /** Prints all bonds of this atom with total degree. | 
|---|
|  | 43 | */ | 
|---|
| [e138de] | 44 | void BondedParticle::OutputBondOfAtom() const | 
|---|
| [6b919f8] | 45 | { | 
|---|
| [717e0c] | 46 | Log() << Verbose(4) << "Atom " << Name << "/" << nr << " with " << ListOfBonds.size() << " bonds: " << endl; | 
|---|
| [e138de] | 47 | int TotalDegree = 0; | 
|---|
|  | 48 | for (BondList::const_iterator Runner = ListOfBonds.begin(); Runner != ListOfBonds.end(); ++Runner) { | 
|---|
| [717e0c] | 49 | Log() << Verbose(4) << **Runner << endl; | 
|---|
| [e138de] | 50 | TotalDegree += (*Runner)->BondDegree; | 
|---|
|  | 51 | } | 
|---|
| [717e0c] | 52 | Log() << Verbose(4) << " -- TotalDegree: " << TotalDegree << endl; | 
|---|
| [6b919f8] | 53 | }; | 
|---|
|  | 54 |  | 
|---|
|  | 55 | /** Output of atom::nr along with all bond partners. | 
|---|
|  | 56 | * \param *AdjacencyFile output stream | 
|---|
|  | 57 | */ | 
|---|
|  | 58 | void BondedParticle::OutputAdjacency(ofstream *AdjacencyFile) const | 
|---|
|  | 59 | { | 
|---|
|  | 60 | *AdjacencyFile << nr << "\t"; | 
|---|
|  | 61 | for (BondList::const_iterator Runner = ListOfBonds.begin(); Runner != ListOfBonds.end(); (++Runner)) | 
|---|
|  | 62 | *AdjacencyFile << (*Runner)->GetOtherAtom(this)->nr << "\t"; | 
|---|
|  | 63 | *AdjacencyFile << endl; | 
|---|
|  | 64 | }; | 
|---|
|  | 65 |  | 
|---|
|  | 66 | /** Puts a given bond into atom::ListOfBonds. | 
|---|
|  | 67 | * \param *Binder bond to insert | 
|---|
|  | 68 | */ | 
|---|
|  | 69 | bool BondedParticle::RegisterBond(bond *Binder) | 
|---|
|  | 70 | { | 
|---|
|  | 71 | bool status = false; | 
|---|
|  | 72 | if (Binder != NULL) { | 
|---|
|  | 73 | if (Binder->Contains(this)) { | 
|---|
|  | 74 | ListOfBonds.push_back(Binder); | 
|---|
|  | 75 | status = true; | 
|---|
|  | 76 | } else { | 
|---|
| [717e0c] | 77 | eLog() << Verbose(1) << *Binder << " does not contain " << *this << "." << endl; | 
|---|
| [6b919f8] | 78 | } | 
|---|
|  | 79 | } else { | 
|---|
| [717e0c] | 80 | eLog() << Verbose(1) << "Binder is " << Binder << "." << endl; | 
|---|
| [6b919f8] | 81 | } | 
|---|
|  | 82 | return status; | 
|---|
|  | 83 | }; | 
|---|
|  | 84 |  | 
|---|
|  | 85 | /** Removes a given bond from atom::ListOfBonds. | 
|---|
|  | 86 | * \param *Binder bond to remove | 
|---|
|  | 87 | */ | 
|---|
|  | 88 | bool BondedParticle::UnregisterBond(bond *Binder) | 
|---|
|  | 89 | { | 
|---|
|  | 90 | bool status = false; | 
|---|
|  | 91 | if (Binder != NULL) { | 
|---|
|  | 92 | if (Binder->Contains(this)) { | 
|---|
|  | 93 | ListOfBonds.remove(Binder); | 
|---|
|  | 94 | status = true; | 
|---|
|  | 95 | } else { | 
|---|
| [717e0c] | 96 | eLog() << Verbose(1) << *Binder << " does not contain " << *this << "." << endl; | 
|---|
| [6b919f8] | 97 | } | 
|---|
|  | 98 | } else { | 
|---|
| [717e0c] | 99 | eLog() << Verbose(1) << "Binder is " << Binder << "." << endl; | 
|---|
| [6b919f8] | 100 | } | 
|---|
|  | 101 | return status; | 
|---|
|  | 102 | }; | 
|---|
|  | 103 |  | 
|---|
|  | 104 | /** Removes all bonds from atom::ListOfBonds. | 
|---|
|  | 105 | * \note Does not do any memory de-allocation. | 
|---|
|  | 106 | */ | 
|---|
|  | 107 | void BondedParticle::UnregisterAllBond() | 
|---|
|  | 108 | { | 
|---|
|  | 109 | ListOfBonds.clear(); | 
|---|
|  | 110 | }; | 
|---|
|  | 111 |  | 
|---|
|  | 112 | /** Corrects the bond degree by one at most if necessary. | 
|---|
|  | 113 | * \param *out output stream for debugging | 
|---|
|  | 114 | */ | 
|---|
| [e138de] | 115 | int BondedParticle::CorrectBondDegree() | 
|---|
| [6b919f8] | 116 | { | 
|---|
|  | 117 | int NoBonds = 0; | 
|---|
|  | 118 | int OtherNoBonds = 0; | 
|---|
|  | 119 | int FalseBondDegree = 0; | 
|---|
|  | 120 | atom *OtherWalker = NULL; | 
|---|
|  | 121 | bond *CandidateBond = NULL; | 
|---|
|  | 122 |  | 
|---|
|  | 123 | NoBonds = CountBonds(); | 
|---|
| [791138] | 124 | //Log() << Verbose(3) << "Walker " << *this << ": " << (int)this->type->NoValenceOrbitals << " > " << NoBonds << "?" << endl; | 
|---|
| [6b919f8] | 125 | if ((int)(type->NoValenceOrbitals) > NoBonds) { // we have a mismatch, check all bonding partners for mismatch | 
|---|
|  | 126 | for (BondList::const_iterator Runner = ListOfBonds.begin(); Runner != ListOfBonds.end(); (++Runner)) { | 
|---|
|  | 127 | OtherWalker = (*Runner)->GetOtherAtom(this); | 
|---|
|  | 128 | OtherNoBonds = OtherWalker->CountBonds(); | 
|---|
| [791138] | 129 | //Log() << Verbose(3) << "OtherWalker " << *OtherWalker << ": " << (int)OtherWalker->type->NoValenceOrbitals << " > " << OtherNoBonds << "?" << endl; | 
|---|
|  | 130 | if ((int)(OtherWalker->type->NoValenceOrbitals) > OtherNoBonds) { // check if possible candidate | 
|---|
| [6b919f8] | 131 | if ((CandidateBond == NULL) || (ListOfBonds.size() > OtherWalker->ListOfBonds.size())) { // pick the one with fewer number of bonds first | 
|---|
|  | 132 | CandidateBond = (*Runner); | 
|---|
| [e138de] | 133 | //Log() << Verbose(3) << "New candidate is " << *CandidateBond << "." << endl; | 
|---|
| [6b919f8] | 134 | } | 
|---|
|  | 135 | } | 
|---|
|  | 136 | } | 
|---|
|  | 137 | if ((CandidateBond != NULL)) { | 
|---|
|  | 138 | CandidateBond->BondDegree++; | 
|---|
| [791138] | 139 | //Log() << Verbose(2) << "Increased bond degree for bond " << *CandidateBond << "." << endl; | 
|---|
| [6b919f8] | 140 | } else { | 
|---|
| [791138] | 141 | eLog() << Verbose(2) << "Could not find correct degree for atom " << *this << "." << endl; | 
|---|
| [6b919f8] | 142 | FalseBondDegree++; | 
|---|
|  | 143 | } | 
|---|
|  | 144 | } | 
|---|
|  | 145 | return FalseBondDegree; | 
|---|
|  | 146 | }; | 
|---|
|  | 147 |  | 
|---|
| [b70721] | 148 | /** Checks whether there is a bond between \a this atom and the given \a *BondPartner. | 
|---|
|  | 149 | * \param *BondPartner atom to check for | 
|---|
|  | 150 | * \return true - bond exists, false - bond does not exist | 
|---|
|  | 151 | */ | 
|---|
|  | 152 | bool BondedParticle::IsBondedTo(BondedParticle * const BondPartner) | 
|---|
|  | 153 | { | 
|---|
|  | 154 | bool status = false; | 
|---|
|  | 155 |  | 
|---|
|  | 156 | for (BondList::iterator runner = ListOfBonds.begin(); runner != ListOfBonds.end(); runner++) { | 
|---|
|  | 157 | status = status || ((*runner)->Contains(BondPartner)); | 
|---|
|  | 158 | } | 
|---|
|  | 159 | return status; | 
|---|
|  | 160 | }; | 
|---|
|  | 161 |  | 
|---|