Changeset 1024cb for src/molecule_fragmentation.cpp
- Timestamp:
- May 31, 2010, 5:32:27 PM (16 years ago)
- Branches:
- Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, Candidate_v1.7.0, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
- Children:
- e08c46
- Parents:
- 42af9e (diff), a7b761b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - git-author:
- Frederik Heber <heber@…> (05/31/10 17:29:30)
- git-committer:
- Frederik Heber <heber@…> (05/31/10 17:32:27)
- File:
-
- 1 edited
-
src/molecule_fragmentation.cpp (modified) (25 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/molecule_fragmentation.cpp
r42af9e r1024cb 39 39 int FragmentCount; 40 40 // get maximum bond degree 41 atom *Walker = start; 42 while (Walker->next != end) { 43 Walker = Walker->next; 44 c = (Walker->ListOfBonds.size() > c) ? Walker->ListOfBonds.size() : c; 41 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { 42 c = ((*iter)->ListOfBonds.size() > c) ? (*iter)->ListOfBonds.size() : c; 45 43 } 46 44 FragmentCount = NoNonHydrogen*(1 << (c*order)); … … 353 351 map<double, pair<int,int> > * ReMapAdaptiveCriteriaListToValue(map<int, pair<double,int> > *AdaptiveCriteriaList, molecule *mol) 354 352 { 355 atom *Walker = mol->start;353 atom *Walker = NULL; 356 354 map<double, pair<int,int> > *FinalRootCandidates = new map<double, pair<int,int> > ; 357 355 DoLog(1) && (Log() << Verbose(1) << "Root candidate list is: " << endl); … … 385 383 bool MarkUpdateCandidates(bool *AtomMask, map<double, pair<int,int> > &FinalRootCandidates, int Order, molecule *mol) 386 384 { 387 atom *Walker = mol->start;385 atom *Walker = NULL; 388 386 int No = -1; 389 387 bool status = false; … … 429 427 bool molecule::CheckOrderAtSite(bool *AtomMask, Graph *GlobalKeySetList, int Order, int *MinimumRingSize, char *path) 430 428 { 431 atom *Walker = start;432 429 bool status = false; 433 430 434 431 // initialize mask list 435 for(int i= AtomCount;i--;)432 for(int i=getAtomCount();i--;) 436 433 AtomMask[i] = false; 437 434 438 435 if (Order < 0) { // adaptive increase of BondOrder per site 439 if (AtomMask[ AtomCount] == true) // break after one step436 if (AtomMask[getAtomCount()] == true) // break after one step 440 437 return false; 441 438 … … 451 448 if (AdaptiveCriteriaList->empty()) { 452 449 DoeLog(2) && (eLog()<< Verbose(2) << "Unable to parse file, incrementing all." << endl); 453 while (Walker->next != end) { 454 Walker = Walker->next; 450 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { 455 451 #ifdef ADDHYDROGEN 456 if ( Walker->type->Z != 1) // skip hydrogen452 if ((*iter)->type->Z != 1) // skip hydrogen 457 453 #endif 458 454 { 459 AtomMask[ Walker->nr] = true; // include all (non-hydrogen) atoms455 AtomMask[(*iter)->nr] = true; // include all (non-hydrogen) atoms 460 456 status = true; 461 457 } … … 472 468 delete[](FinalRootCandidates); 473 469 } else { // global increase of Bond Order 474 while (Walker->next != end) { 475 Walker = Walker->next; 470 for(molecule::const_iterator iter = begin(); iter != end(); ++iter) { 476 471 #ifdef ADDHYDROGEN 477 if ( Walker->type->Z != 1) // skip hydrogen472 if ((*iter)->type->Z != 1) // skip hydrogen 478 473 #endif 479 474 { 480 AtomMask[ Walker->nr] = true; // include all (non-hydrogen) atoms481 if ((Order != 0) && ( Walker->AdaptiveOrder < Order)) // && (Walker->AdaptiveOrder < MinimumRingSize[Walker->nr]))475 AtomMask[(*iter)->nr] = true; // include all (non-hydrogen) atoms 476 if ((Order != 0) && ((*iter)->AdaptiveOrder < Order)) // && ((*iter)->AdaptiveOrder < MinimumRingSize[(*iter)->nr])) 482 477 status = true; 483 478 } 484 479 } 485 if (( Order == 0) && (AtomMask[AtomCount] == false)) // single stepping, just check480 if ((!Order) && (!AtomMask[getAtomCount()])) // single stepping, just check 486 481 status = true; 487 482 … … 494 489 } 495 490 496 PrintAtomMask(AtomMask, AtomCount); // for debugging491 PrintAtomMask(AtomMask, getAtomCount()); // for debugging 497 492 498 493 return status; … … 510 505 return false; 511 506 } 512 SortIndex = new int[ AtomCount];513 for(int i= AtomCount;i--;)507 SortIndex = new int[getAtomCount()]; 508 for(int i=getAtomCount();i--;) 514 509 SortIndex[i] = -1; 515 510 … … 518 513 519 514 return true; 515 }; 516 517 518 519 /** Creates a lookup table for true father's Atom::Nr -> atom ptr. 520 * \param *start begin of list (STL iterator, i.e. first item) 521 * \paran *end end of list (STL iterator, i.e. one past last item) 522 * \param **Lookuptable pointer to return allocated lookup table (should be NULL on start) 523 * \param count optional predetermined size for table (otherwise we set the count to highest true father id) 524 * \return true - success, false - failure 525 */ 526 bool molecule::CreateFatherLookupTable(atom **&LookupTable, int count) 527 { 528 bool status = true; 529 int AtomNo; 530 531 if (LookupTable != NULL) { 532 Log() << Verbose(0) << "Pointer for Lookup table is not NULL! Aborting ..." <<endl; 533 return false; 534 } 535 536 // count them 537 if (count == 0) { 538 for (molecule::iterator iter = begin(); iter != end(); ++iter) { // create a lookup table (Atom::nr -> atom) used as a marker table lateron 539 count = (count < (*iter)->GetTrueFather()->nr) ? (*iter)->GetTrueFather()->nr : count; 540 } 541 } 542 if (count <= 0) { 543 Log() << Verbose(0) << "Count of lookup list is 0 or less." << endl; 544 return false; 545 } 546 547 // allocate and fill 548 LookupTable = new atom *[count]; 549 if (LookupTable == NULL) { 550 eLog() << Verbose(0) << "LookupTable memory allocation failed!" << endl; 551 performCriticalExit(); 552 status = false; 553 } else { 554 for (int i=0;i<count;i++) 555 LookupTable[i] = NULL; 556 for (molecule::iterator iter = begin(); iter != end(); ++iter) { 557 AtomNo = (*iter)->GetTrueFather()->nr; 558 if ((AtomNo >= 0) && (AtomNo < count)) { 559 //*out << "Setting LookupTable[" << AtomNo << "] to " << *(*iter) << endl; 560 LookupTable[AtomNo] = (*iter); 561 } else { 562 Log() << Verbose(0) << "Walker " << *(*iter) << " exceeded range of nuclear ids [0, " << count << ")." << endl; 563 status = false; 564 break; 565 } 566 } 567 } 568 569 return status; 520 570 }; 521 571 … … 541 591 { 542 592 MoleculeListClass *BondFragments = NULL; 543 int *MinimumRingSize = new int[ AtomCount];593 int *MinimumRingSize = new int[getAtomCount()]; 544 594 int FragmentCounter; 545 595 MoleculeLeafClass *MolecularWalker = NULL; … … 569 619 570 620 // create lookup table for Atom::nr 571 FragmentationToDo = FragmentationToDo && CreateFatherLookupTable( start, end, ListOfAtoms, AtomCount);621 FragmentationToDo = FragmentationToDo && CreateFatherLookupTable(ListOfAtoms, getAtomCount()); 572 622 573 623 // === compare it with adjacency file === … … 579 629 580 630 // analysis of the cycles (print rings, get minimum cycle length) for each subgraph 581 for(int i= AtomCount;i--;)582 MinimumRingSize[i] = AtomCount;631 for(int i=getAtomCount();i--;) 632 MinimumRingSize[i] = getAtomCount(); 583 633 MolecularWalker = Subgraphs; 584 634 FragmentCounter = 0; … … 586 636 MolecularWalker = MolecularWalker->next; 587 637 // fill the bond structure of the individually stored subgraphs 588 MolecularWalker->FillBondStructureFromReference(this, FragmentCounter, ListOfLocalAtoms, false); // we want to keep the created ListOfLocalAtoms638 MolecularWalker->FillBondStructureFromReference(this, FragmentCounter, ListOfLocalAtoms, false); // we want to keep the created ListOfLocalAtoms 589 639 DoLog(0) && (Log() << Verbose(0) << "Analysing the cycles of subgraph " << MolecularWalker->Leaf << " with nr. " << FragmentCounter << "." << endl); 590 640 LocalBackEdgeStack = new StackClass<bond *> (MolecularWalker->Leaf->BondCount); 591 641 // // check the list of local atoms for debugging 592 642 // Log() << Verbose(0) << "ListOfLocalAtoms for this subgraph is:" << endl; 593 // for (int i=0;i< AtomCount;i++)643 // for (int i=0;i<getAtomCount();i++) 594 644 // if (ListOfLocalAtoms[FragmentCounter][i] == NULL) 595 645 // Log() << Verbose(0) << "\tNULL"; … … 617 667 // ===== 6b. prepare and go into the adaptive (Order<0), single-step (Order==0) or incremental (Order>0) cycle 618 668 KeyStack *RootStack = new KeyStack[Subgraphs->next->Count()]; 619 AtomMask = new bool[ AtomCount+1];620 AtomMask[ AtomCount] = false;669 AtomMask = new bool[getAtomCount()+1]; 670 AtomMask[getAtomCount()] = false; 621 671 FragmentationToDo = false; // if CheckOrderAtSite just ones recommends fragmentation, we will save fragments afterwards 622 672 while ((CheckOrder = CheckOrderAtSite(AtomMask, ParsedFragmentList, Order, MinimumRingSize, configuration->configpath))) { 623 673 FragmentationToDo = FragmentationToDo || CheckOrder; 624 AtomMask[ AtomCount] = true; // last plus one entry is used as marker that we have been through this loop once already in CheckOrderAtSite()674 AtomMask[getAtomCount()] = true; // last plus one entry is used as marker that we have been through this loop once already in CheckOrderAtSite() 625 675 // ===== 6b. fill RootStack for each subgraph (second adaptivity check) ===== 626 676 Subgraphs->next->FillRootStackForSubgraphs(RootStack, AtomMask, (FragmentCounter = 0)); … … 762 812 bool molecule::ParseOrderAtSiteFromFile(char *path) 763 813 { 764 unsigned char *OrderArray = new unsigned char[ AtomCount];765 bool *MaxArray = new bool[ AtomCount];814 unsigned char *OrderArray = new unsigned char[getAtomCount()]; 815 bool *MaxArray = new bool[getAtomCount()]; 766 816 bool status; 767 817 int AtomNr, value; … … 769 819 ifstream file; 770 820 771 for(int i=0;i< AtomCount;i++) {821 for(int i=0;i<getAtomCount();i++) { 772 822 OrderArray[i] = 0; 773 823 MaxArray[i] = false; … … 871 921 atom *OtherFather = NULL; 872 922 atom *FatherOfRunner = NULL; 873 Leaf->CountAtoms(); 874 875 atom *Runner = Leaf->start; 876 while (Runner->next != Leaf->end) { 877 Runner = Runner->next; 923 924 #ifdef ADDHYDROGEN 925 molecule::const_iterator runner; 926 #endif 927 // we increment the iter just before skipping the hydrogen 928 for (molecule::const_iterator iter = Leaf->begin(); iter != Leaf->end();) { 878 929 LonelyFlag = true; 879 FatherOfRunner = Runner->father; 930 FatherOfRunner = (*iter)->father; 931 ASSERT(FatherOfRunner,"Atom without father found"); 880 932 if (SonList[FatherOfRunner->nr] != NULL) { // check if this, our father, is present in list 881 933 // create all bonds … … 888 940 // Log() << Verbose(3) << "Adding Bond: "; 889 941 // Log() << Verbose(0) << 890 Leaf->AddBond( Runner, SonList[OtherFather->nr], (*BondRunner)->BondDegree);942 Leaf->AddBond((*iter), SonList[OtherFather->nr], (*BondRunner)->BondDegree); 891 943 // Log() << Verbose(0) << "." << endl; 892 //NumBonds[ Runner->nr]++;944 //NumBonds[(*iter)->nr]++; 893 945 } else { 894 946 // Log() << Verbose(3) << "Not adding bond, labels in wrong order." << endl; … … 898 950 // Log() << Verbose(0) << ", who has no son in this fragment molecule." << endl; 899 951 #ifdef ADDHYDROGEN 900 //Log() << Verbose(3) << "Adding Hydrogen to " << Runner->Name << " and a bond in between." << endl;901 if(!Leaf->AddHydrogenReplacementAtom((*BondRunner), Runner, FatherOfRunner, OtherFather, IsAngstroem))952 //Log() << Verbose(3) << "Adding Hydrogen to " << (*iter)->Name << " and a bond in between." << endl; 953 if(!Leaf->AddHydrogenReplacementAtom((*BondRunner), (*iter), FatherOfRunner, OtherFather, IsAngstroem)) 902 954 exit(1); 903 955 #endif 904 //NumBonds[ Runner->nr] += Binder->BondDegree;956 //NumBonds[(*iter)->nr] += Binder->BondDegree; 905 957 } 906 958 } 907 959 } else { 908 DoeLog(1) && (eLog()<< Verbose(1) << "Son " << Runner->getName() << " has father " << FatherOfRunner->getName() << " but its entry in SonList is " << SonList[FatherOfRunner->nr] << "!" << endl); 909 } 910 if ((LonelyFlag) && (Leaf->AtomCount > 1)) { 911 DoLog(0) && (Log() << Verbose(0) << *Runner << "has got bonds only to hydrogens!" << endl); 912 } 960 DoeLog(1) && (eLog()<< Verbose(1) << "Son " << (*iter)->getName() << " has father " << FatherOfRunner->getName() << " but its entry in SonList is " << SonList[FatherOfRunner->nr] << "!" << endl); 961 } 962 if ((LonelyFlag) && (Leaf->getAtomCount() > 1)) { 963 DoLog(0) && (Log() << Verbose(0) << **iter << "has got bonds only to hydrogens!" << endl); 964 } 965 ++iter; 913 966 #ifdef ADDHYDROGEN 914 while ((Runner->next != Leaf->end) && (Runner->next->type->Z == 1)) // skip added hydrogen 915 Runner = Runner->next; 967 while ((iter != Leaf->end()) && ((*iter)->type->Z == 1)){ // skip added hydrogen 968 iter++; 969 } 916 970 #endif 917 971 } … … 928 982 molecule * molecule::StoreFragmentFromKeySet(KeySet &Leaflet, bool IsAngstroem) 929 983 { 930 atom **SonList = new atom*[ AtomCount];984 atom **SonList = new atom*[getAtomCount()]; 931 985 molecule *Leaf = World::getInstance().createMolecule(); 932 986 933 for(int i=0;i< AtomCount;i++)987 for(int i=0;i<getAtomCount();i++) 934 988 SonList[i] = NULL; 935 989 … … 1561 1615 FragmentSearch.FragmentSet = new KeySet; 1562 1616 FragmentSearch.Root = FindAtom(RootKeyNr); 1563 FragmentSearch.ShortestPathList = new int[ AtomCount];1564 for (int i= AtomCount;i--;) {1617 FragmentSearch.ShortestPathList = new int[getAtomCount()]; 1618 for (int i=getAtomCount();i--;) { 1565 1619 FragmentSearch.ShortestPathList[i] = -1; 1566 1620 } 1567 1621 1568 1622 // Construct the complete KeySet which we need for topmost level only (but for all Roots) 1569 atom *Walker = start;1570 1623 KeySet CompleteMolecule; 1571 while (Walker->next != end) { 1572 Walker = Walker->next; 1573 CompleteMolecule.insert(Walker->GetTrueFather()->nr); 1624 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { 1625 CompleteMolecule.insert((*iter)->GetTrueFather()->nr); 1574 1626 } 1575 1627 … … 1582 1634 RootKeyNr = RootStack.front(); 1583 1635 RootStack.pop_front(); 1584 Walker = FindAtom(RootKeyNr);1636 atom *Walker = FindAtom(RootKeyNr); 1585 1637 // check cyclic lengths 1586 1638 //if ((MinimumRingSize[Walker->GetTrueFather()->nr] != -1) && (Walker->GetTrueFather()->AdaptiveOrder+1 > MinimumRingSize[Walker->GetTrueFather()->nr])) { … … 1671 1723 Vector Translationvector; 1672 1724 //class StackClass<atom *> *CompStack = NULL; 1673 class StackClass<atom *> *AtomStack = new StackClass<atom *>( AtomCount);1725 class StackClass<atom *> *AtomStack = new StackClass<atom *>(getAtomCount()); 1674 1726 bool flag = true; 1675 1727 1676 1728 DoLog(2) && (Log() << Verbose(2) << "Begin of ScanForPeriodicCorrection." << endl); 1677 1729 1678 ColorList = new enum Shading[ AtomCount];1679 for (int i=0;i< AtomCount;i++)1730 ColorList = new enum Shading[getAtomCount()]; 1731 for (int i=0;i<getAtomCount();i++) 1680 1732 ColorList[i] = (enum Shading)0; 1681 1733 while (flag) { 1682 1734 // remove bonds that are beyond bonddistance 1683 for(int i=NDIM;i--;) 1684 Translationvector[i] = 0.; 1735 Translationvector.Zero(); 1685 1736 // scan all bonds 1686 1737 Binder = first; … … 1711 1762 Log() << Verbose(0) << Translationvector << endl; 1712 1763 // apply to all atoms of first component via BFS 1713 for (int i= AtomCount;i--;)1764 for (int i=getAtomCount();i--;) 1714 1765 ColorList[i] = white; 1715 1766 AtomStack->Push(Binder->leftatom); … … 1735 1786 //delete(CompStack); 1736 1787 } 1737 1738 1788 // free allocated space from ReturnFullMatrixforSymmetric() 1739 1789 delete(AtomStack);
Note:
See TracChangeset
for help on using the changeset viewer.
