Changeset b8eb3a
- Timestamp:
- May 8, 2008, 12:02:43 PM (17 years ago)
- Children:
- 9c3496
- Parents:
- c901e3
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
molecuilder/src/moleculelist.cpp
rc901e3 rb8eb3a 347 347 return false; 348 348 }; 349 350 /** Fills the bond structure of this chain list subgraphs that are derived from a complete \a *reference molecule. 351 * Calls this routine in each MoleculeLeafClass::next subgraph if it's not NULL. 352 * \param *out output stream for debugging 353 * \param *reference reference molecule with the bond structure to be copied 354 * \param &FragmentCounter Counter needed to address \a **ListOfLocalAtoms 355 * \param ***ListOfLocalAtoms Lookup table for each subgraph and index of each atom in \a *reference, may be NULL on start, then it is filled 356 * \param FreeList true - ***ListOfLocalAtoms is free'd before return, false - it is not 357 * \return true - success, false - faoilure 358 */ 359 bool MoleculeLeafClass::FillBondStructureFromReference(ofstream *out, molecule *reference, int &FragmentCounter, atom ***&ListOfLocalAtoms, bool FreeList) 360 { 361 atom *Walker = NULL, *OtherWalker = NULL; 362 bond *Binder = NULL; 363 bool status = true; 364 int AtomNo; 365 366 if (ListOfLocalAtoms == NULL) { // allocated initial pointer 367 // count the number of fragments 368 MoleculeLeafClass *MolecularWalker = this; 369 while (MolecularWalker->next != NULL) { 370 MolecularWalker = MolecularWalker->next; 371 FragmentCounter++; 372 } 373 // allocate and set each field to NULL 374 ListOfLocalAtoms = (atom ***) Malloc(sizeof(atom **)*(FragmentCounter+1), "MoleculeLeafClass::FillBondStructureFromReference - ***ListOfLocalAtoms"); 375 if (ListOfLocalAtoms == NULL) 376 return false; 377 for (int i=0;i<=FragmentCounter;i++) 378 ListOfLocalAtoms[i] = NULL; 379 FragmentCounter = 0; 380 FreeList = FreeList && true; 381 } 382 if (ListOfLocalAtoms[FragmentCounter] == NULL) { // allocate and fill list of this fragment/subgraph 383 status = status && CreateFatherLookupTable(out, Leaf->start, Leaf->end, ListOfLocalAtoms[FragmentCounter], reference->AtomCount); 384 FreeList = FreeList && true; 385 } 386 387 if (status) { 388 *out << Verbose(1) << "Creating adjacency list for subgraph " << this << "." << endl; 389 Walker = Leaf->start; 390 while (Walker->next != Leaf->end) { 391 Walker = Walker->next; 392 AtomNo = Walker->father->nr; // global id of the current walker 393 for(int i=0;i<reference->NumberOfBondsPerAtom[AtomNo];i++) { // go through father's bonds and copy them all 394 Binder = reference->ListOfBondsPerAtom[AtomNo][i]; 395 OtherWalker = ListOfLocalAtoms[FragmentCounter][Binder->GetOtherAtom(Walker->father)->nr]; // local copy of current bond partner of walker 396 if (OtherWalker != NULL) { 397 if (OtherWalker->nr > Walker->nr) 398 Leaf->AddBond(Walker, OtherWalker, Binder->BondDegree); 399 } else { 400 *out << Verbose(1) << "OtherWalker = ListOfLocalAtoms[" << FragmentCounter << "][" << Binder->GetOtherAtom(Walker->father)->nr << "] is NULL!" << endl; 401 status = false; 402 } 403 } 404 } 405 Leaf->CreateListOfBondsPerAtom(out); 406 FragmentCounter++; 407 if (next != NULL) 408 status = next->FillBondStructureFromReference(out, reference, FragmentCounter, ListOfLocalAtoms); 409 } 410 411 if (FreeList) { 412 // free the index lookup list 413 for (int i=0;i<FragmentCounter;i++) 414 Free((void **)&ListOfLocalAtoms[i], "MoleculeLeafClass::FillBondStructureFromReference - **ListOfLocalAtoms[]"); 415 if (previous == NULL) // if we are the first in this chain list, empty initial pointer 416 Free((void **)&ListOfLocalAtoms, "MoleculeLeafClass::FillBondStructureFromReference - ***ListOfLocalAtoms"); 417 } 418 419 return status; 420 }; 421 422
Note:
See TracChangeset
for help on using the changeset viewer.