Changeset 872b51 for molecuilder/src/atom.cpp
- Timestamp:
- Oct 18, 2009, 2:51:38 PM (16 years ago)
- Children:
- 77894f
- Parents:
- b0ee98
- git-author:
- Frederik Heber <heber@…> (10/18/09 14:15:37)
- git-committer:
- Frederik Heber <heber@…> (10/18/09 14:51:38)
- File:
-
- 1 edited
-
molecuilder/src/atom.cpp (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
molecuilder/src/atom.cpp
rb0ee98 r872b51 9 9 #include "config.hpp" 10 10 #include "element.hpp" 11 #include "lists.hpp" 11 12 #include "memoryallocator.hpp" 12 13 #include "parser.hpp" … … 67 68 atom::~atom() 68 69 { 70 BondList::const_iterator Runner; 71 while (!ListOfBonds.empty()) { 72 Runner = ListOfBonds.begin(); 73 removewithoutcheck(*Runner); 74 } 75 unlink(this); 69 76 Free<int>(&ComponentNr, "atom::~atom: *ComponentNr"); 70 77 Free<char>(&Name, "atom::~atom: *Name"); … … 118 125 { 119 126 return (node->IsInParallelepiped(offset, parallelepiped)); 127 }; 128 129 /** Counts the number of bonds weighted by bond::BondDegree. 130 * \param bonds times bond::BondDegree 131 */ 132 int atom::CountBonds() const 133 { 134 int NoBonds = 0; 135 for (BondList::const_iterator Runner = ListOfBonds.begin(); Runner != ListOfBonds.end(); (++Runner)) 136 NoBonds += (*Runner)->BondDegree; 137 return NoBonds; 120 138 }; 121 139 … … 215 233 }; 216 234 217 /** Prints all bonds of this atom from given global lists. 235 /** Output graph info of this atom. 236 * \param *out output stream 237 */ 238 void atom::OutputGraphInfo(ofstream *out) const 239 { 240 *out << Verbose(2) << "Atom " << Name << " is " << ((SeparationVertex) ? "a" : "not a") << " separation vertex, components are "; 241 OutputComponentNumber(out); 242 *out << " with Lowpoint " << LowpointNr << " and Graph Nr. " << GraphNr << "." << endl; 243 }; 244 245 /** Output a list of flags, stating whether the bond was visited or not. 246 * Note, we make use of the last entry of the ComponentNr always being -1 if allocated. 247 * \param *out output stream for debugging 248 */ 249 void atom::OutputComponentNumber(ofstream *out) const 250 { 251 if (ComponentNr != NULL) { 252 for (int i=0; ComponentNr[i] != -1; i++) 253 *out << ComponentNr[i] << " "; 254 } 255 }; 256 257 258 /** Prints all bonds of this atom with total degree. 218 259 * \param *out stream to output to 219 * \param *NumberOfBondsPerAtom array with number of bonds per atomic index220 * \param ***ListOfBondsPerAtom array per atomic index of array with pointer to bond221 260 * \return true - \a *out present, false - \a *out is NULL 222 261 */ 223 bool atom::OutputBondOfAtom(ofstream *out , int *NumberOfBondsPerAtom, bond ***ListOfBondsPerAtom) const262 bool atom::OutputBondOfAtom(ofstream *out) const 224 263 { 225 264 if (out != NULL) { … … 227 266 if (type->Z != 1) { // regard only non-hydrogen 228 267 #endif 229 *out << Verbose(4) << "Atom " << Name << "/" << nr << " with " << NumberOfBondsPerAtom[nr]<< " bonds: ";268 *out << Verbose(4) << "Atom " << Name << "/" << nr << " with " << ListOfBonds.size() << " bonds: "; 230 269 int TotalDegree = 0; 231 for ( int j=0;j<NumberOfBondsPerAtom[nr];j++) {232 *out << * ListOfBondsPerAtom[nr][j]<< "\t";233 TotalDegree += ListOfBondsPerAtom[nr][j]->BondDegree;270 for (BondList::const_iterator Runner = ListOfBonds.begin(); Runner != ListOfBonds.end(); ++Runner) { 271 *out << **Runner << "\t"; 272 TotalDegree += (*Runner)->BondDegree; 234 273 } 235 274 *out << " -- TotalDegree: " << TotalDegree << endl; … … 240 279 } else 241 280 return false; 281 }; 282 283 /** Output of atom::nr along with all bond partners. 284 * \param *AdjacencyFile output stream 285 */ 286 void atom::OutputAdjacency(ofstream *AdjacencyFile) const 287 { 288 *AdjacencyFile << nr << "\t"; 289 for (BondList::const_iterator Runner = ListOfBonds.begin(); Runner != ListOfBonds.end(); (++Runner)) 290 *AdjacencyFile << (*Runner)->GetOtherAtom(this)->nr << "\t"; 291 *AdjacencyFile << endl; 292 }; 293 294 /** Puts a given bond into atom::ListOfBonds. 295 * \param *Binder bond to insert 296 */ 297 bool atom::RegisterBond(bond *Binder) 298 { 299 bool status = false; 300 if (Binder != NULL) { 301 if (Binder->Contains(this)) { 302 ListOfBonds.push_back(Binder); 303 status = true; 304 } else { 305 cout << Verbose(1) << "ERROR: " << *Binder << " does not contain " << *this << "." << endl; 306 } 307 } else { 308 cout << Verbose(1) << "ERROR: Binder is " << Binder << "." << endl; 309 } 310 return status; 311 }; 312 313 /** Removes a given bond from atom::ListOfBonds. 314 * \param *Binder bond to remove 315 */ 316 bool atom::UnregisterBond(bond *Binder) 317 { 318 bool status = false; 319 if (Binder != NULL) { 320 if (Binder->Contains(this)) { 321 ListOfBonds.remove(Binder); 322 status = true; 323 } else { 324 cout << Verbose(1) << "ERROR: " << *Binder << " does not contain " << *this << "." << endl; 325 } 326 } else { 327 cout << Verbose(1) << "ERROR: Binder is " << Binder << "." << endl; 328 } 329 return status; 330 }; 331 332 /** Removes all bonds from atom::ListOfBonds. 333 * \note Does not do any memory de-allocation. 334 */ 335 void atom::UnregisterAllBond() 336 { 337 ListOfBonds.clear(); 338 }; 339 340 /** Corrects the bond degree by one at most if necessary. 341 * \param *out output stream for debugging 342 */ 343 int atom::CorrectBondDegree(ofstream *out) 344 { 345 int NoBonds = 0; 346 int OtherNoBonds = 0; 347 int FalseBondDegree = 0; 348 atom *OtherWalker = NULL; 349 bond *CandidateBond = NULL; 350 351 *out << Verbose(3) << "Walker " << *this << ": " << (int)this->type->NoValenceOrbitals << " > " << NoBonds << "?" << endl; 352 NoBonds = CountBonds(); 353 if ((int)(type->NoValenceOrbitals) > NoBonds) { // we have a mismatch, check all bonding partners for mismatch 354 for (BondList::const_iterator Runner = ListOfBonds.begin(); Runner != ListOfBonds.end(); (++Runner)) { 355 OtherWalker = (*Runner)->GetOtherAtom(this); 356 OtherNoBonds = OtherWalker->CountBonds(); 357 *out << Verbose(3) << "OtherWalker " << *OtherWalker << ": " << (int)OtherWalker->type->NoValenceOrbitals << " > " << NoBonds << "?" << endl; 358 if ((int)(OtherWalker->type->NoValenceOrbitals) > NoBonds) { // check if possible candidate 359 if ((CandidateBond == NULL) || (ListOfBonds.size() > OtherWalker->ListOfBonds.size())) { // pick the one with fewer number of bonds first 360 CandidateBond = (*Runner); 361 *out << Verbose(3) << "New candidate is " << *CandidateBond << "." << endl; 362 } 363 } 364 } 365 if ((CandidateBond != NULL)) { 366 CandidateBond->BondDegree++; 367 *out << Verbose(2) << "Increased bond degree for bond " << *CandidateBond << "." << endl; 368 } else { 369 *out << Verbose(2) << "Could not find correct degree for atom " << *this << "." << endl; 370 FalseBondDegree++; 371 } 372 } 373 return FalseBondDegree; 242 374 }; 243 375 … … 345 477 { 346 478 *file << nr << "\t" << (int)AdaptiveOrder << "\t" << (int)MaxOrder << endl; 347 //cout << Verbose(2) << "Storing: " << Walker->nr << "\t" << (int)Walker->AdaptiveOrder << "\t" << (int)Walker->MaxOrder << "." << endl;479 //cout << Verbose(2) << "Storing: " << nr << "\t" << (int)AdaptiveOrder << "\t" << (int)MaxOrder << "." << endl; 348 480 } 349 481
Note:
See TracChangeset
for help on using the changeset viewer.
