Changeset 3ccc3e for src/molecules.cpp
- Timestamp:
- Oct 9, 2008, 6:29:03 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, 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:
- 1e8243
- Parents:
- 18913c
- git-author:
- Frederik Heber <heber@…> (10/09/08 18:27:56)
- git-committer:
- Frederik Heber <heber@…> (10/09/08 18:29:03)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/molecules.cpp
r18913c r3ccc3e 1603 1603 int *MinimumRingSize = NULL; 1604 1604 MoleculeLeafClass *Subgraphs = NULL; 1605 class StackClass<bond *> *BackEdgeStack = NULL; 1605 1606 bond *Binder = first; 1606 1607 if ((Binder->next != last) && (Binder->next->Type == Undetermined)) { 1607 1608 *out << Verbose(0) << "No Depth-First-Search analysis performed so far, calling ..." << endl; 1608 Subgraphs = DepthFirstSearchAnalysis(out, MinimumRingSize);1609 Subgraphs = DepthFirstSearchAnalysis(out, BackEdgeStack); 1609 1610 while (Subgraphs->next != NULL) { 1610 1611 Subgraphs = Subgraphs->next; … … 1619 1620 No++; 1620 1621 } 1622 delete(BackEdgeStack); 1621 1623 return No; 1622 1624 }; … … 1700 1702 double *matrix = ReturnFullMatrixforSymmetric(cell_size); 1701 1703 Vector x; 1704 int FalseBondDegree = 0; 1702 1705 1703 1706 BondDistance = bonddistance; // * ((IsAngstroem) ? 1. : 1./AtomicLengthToAngstroem); … … 1718 1721 j += i+1; 1719 1722 divisor[i] = (int)floor(cell_size[j]/bonddistance); // take smaller value such that size of linked cell is at least bonddistance 1720 *out << Verbose(1) << "divisor[" << i << "] = " << divisor[i] << "." << endl;1723 //*out << Verbose(1) << "divisor[" << i << "] = " << divisor[i] << "." << endl; 1721 1724 } 1722 1725 // 2a. allocate memory for the cell list … … 1743 1746 } 1744 1747 index = n[2] + (n[1] + n[0] * divisor[1]) * divisor[2]; 1745 *out << Verbose(1) << "Atom " << *Walker << " goes into cell number [" << n[0] << "," << n[1] << "," << n[2] << "] = " << index << "." << endl;1748 //*out << Verbose(1) << "Atom " << *Walker << " goes into cell number [" << n[0] << "," << n[1] << "," << n[2] << "] = " << index << "." << endl; 1746 1749 // add copy atom to this cell 1747 1750 if (CellList[index] == NULL) // allocate molecule if not done … … 1785 1788 distance = OtherWalker->x.PeriodicDistance(&(Walker->x), cell_size); 1786 1789 if ((OtherWalker->father->nr > Walker->father->nr) && (distance <= MaxDistance*MaxDistance) && (distance >= MinDistance*MinDistance)) { // create bond if distance is smaller 1787 *out << Verbose(0) << "Adding Bond between " << *Walker << " and " << *OtherWalker << "." << endl;1790 //*out << Verbose(0) << "Adding Bond between " << *Walker << " and " << *OtherWalker << "." << endl; 1788 1791 AddBond(Walker->father, OtherWalker->father, 1); // also increases molecule::BondCount 1789 1792 BondCount++; … … 1844 1847 ListOfBondsPerAtom[Walker->nr][CandidateBondNo]->BondDegree++; 1845 1848 *out << Verbose(2) << "Increased bond degree for bond " << *ListOfBondsPerAtom[Walker->nr][CandidateBondNo] << "." << endl; 1846 } 1849 } else 1850 *out << Verbose(2) << "Could not find correct degree for bond " << *ListOfBondsPerAtom[Walker->nr][CandidateBondNo] << "." << endl; 1851 FalseBondDegree++; 1847 1852 } 1848 1853 } … … 1851 1856 } else 1852 1857 *out << Verbose(1) << "BondCount is " << BondCount << ", no bonds between any of the " << AtomCount << " atoms." << endl; 1853 *out << Verbose(1) << "I detected " << BondCount << " bonds in the molecule with distance " << bonddistance << " ." << endl;1858 *out << Verbose(1) << "I detected " << BondCount << " bonds in the molecule with distance " << bonddistance << ", " << FalseBondDegree << " bonds could not be corrected." << endl; 1854 1859 1855 1860 // output bonds for debugging (if bond chain list was correctly installed) … … 1872 1877 * We use the algorithm from [Even, Graph Algorithms, p.62]. 1873 1878 * \param *out output stream for debugging 1874 * \param *& MinimumRingSize contains smallest ring size in molecular structure on return or -1 if no rings were found1879 * \param *&BackEdgeStack NULL pointer to StackClass with all the found back edges, allocated and filled on return 1875 1880 * \return list of each disconnected subgraph as an individual molecule class structure 1876 1881 */ 1877 MoleculeLeafClass * molecule::DepthFirstSearchAnalysis(ofstream *out, int *&MinimumRingSize) 1878 { 1879 class StackClass<atom *> *AtomStack; 1880 AtomStack = new StackClass<atom *>(AtomCount); 1881 class StackClass<bond *> *BackEdgeStack = new StackClass<bond *> (BondCount); 1882 MoleculeLeafClass * molecule::DepthFirstSearchAnalysis(ofstream *out, class StackClass<bond *> *&BackEdgeStack) 1883 { 1884 class StackClass<atom *> *AtomStack = new StackClass<atom *>(AtomCount); 1885 BackEdgeStack = new StackClass<bond *> (BondCount); 1882 1886 MoleculeLeafClass *SubGraphs = new MoleculeLeafClass(NULL); 1883 1887 MoleculeLeafClass *LeafWalker = SubGraphs; … … 2011 2015 LeafWalker->Leaf->Output(out); 2012 2016 *out << endl; 2013 2017 2014 2018 // step on to next root 2015 2019 while ((Root != end) && (Root->GraphNr != -1)) { … … 2029 2033 } 2030 2034 2031 // analysis of the cycles (print rings, get minimum cycle length)2032 CyclicStructureAnalysis(out, BackEdgeStack, MinimumRingSize);2033 2035 2034 2036 *out << Verbose(1) << "Final graph info for each atom is:" << endl; … … 2068 2070 * as cyclic and print out the cycles. 2069 2071 * \param *out output stream for debugging 2070 * \param *BackEdgeStack stack with all back edges found during DFS scan 2072 * \param *BackEdgeStack stack with all back edges found during DFS scan. Beware: This stack contains the bonds from the total molecule, not from the subgraph! 2071 2073 * \param *&MinimumRingSize contains smallest ring size in molecular structure on return or -1 if no rings were found, if set is maximum search distance 2072 2074 * \todo BFS from the not-same-LP to find back to starting point of tributary cycle over more than one bond … … 2089 2091 ColorList[i] = white; 2090 2092 } 2091 MinimumRingSize = new int[AtomCount];2092 for(int i=AtomCount;i--;)2093 MinimumRingSize[i] = AtomCount;2094 2095 2093 2096 2094 *out << Verbose(1) << "Back edge list - "; … … 2894 2892 MoleculeListClass *BondFragments = NULL; 2895 2893 int *SortIndex = NULL; 2896 int *MinimumRingSize = NULL;2894 int *MinimumRingSize = new int[AtomCount]; 2897 2895 int FragmentCounter; 2898 2896 MoleculeLeafClass *MolecularWalker = NULL; … … 2900 2898 fstream File; 2901 2899 bool FragmentationToDo = true; 2900 class StackClass<bond *> *BackEdgeStack = NULL, *LocalBackEdgeStack = NULL; 2902 2901 bool CheckOrder = false; 2903 2902 Graph **FragmentList = NULL; … … 2931 2930 2932 2931 // ===== 2. perform a DFS analysis to gather info on cyclic structure and a list of disconnected subgraphs ===== 2933 Subgraphs = DepthFirstSearchAnalysis(out, MinimumRingSize);2932 Subgraphs = DepthFirstSearchAnalysis(out, BackEdgeStack); 2934 2933 // fill the bond structure of the individually stored subgraphs 2935 2934 Subgraphs->next->FillBondStructureFromReference(out, this, (FragmentCounter = 0), ListOfLocalAtoms, false); // we want to keep the created ListOfLocalAtoms 2936 2935 // analysis of the cycles (print rings, get minimum cycle length) for each subgraph 2936 for(int i=AtomCount;i--;) 2937 MinimumRingSize[i] = AtomCount; 2938 MolecularWalker = Subgraphs; 2939 FragmentCounter = 0; 2940 while (MolecularWalker->next != NULL) { 2941 MolecularWalker = MolecularWalker->next; 2942 *out << Verbose(0) << "Analysing the cycles of subgraph " << MolecularWalker->Leaf << " with nr. " << FragmentCounter << "." << endl; 2943 LocalBackEdgeStack = new StackClass<bond *> (MolecularWalker->Leaf->BondCount); 2944 // // check the list of local atoms for debugging 2945 // *out << Verbose(0) << "ListOfLocalAtoms for this subgraph is:" << endl; 2946 // for (int i=0;i<AtomCount;i++) 2947 // if (ListOfLocalAtoms[FragmentCounter][i] == NULL) 2948 // *out << "\tNULL"; 2949 // else 2950 // *out << "\t" << ListOfLocalAtoms[FragmentCounter][i]->Name; 2951 MolecularWalker->Leaf->PickLocalBackEdges(out, ListOfLocalAtoms[FragmentCounter++], BackEdgeStack, LocalBackEdgeStack); 2952 MolecularWalker->Leaf->CyclicStructureAnalysis(out, LocalBackEdgeStack, MinimumRingSize); 2953 delete(LocalBackEdgeStack); 2954 } 2955 2937 2956 // ===== 3. if structure still valid, parse key set file and others ===== 2938 2957 FragmentationToDo = FragmentationToDo && ParseKeySetFile(out, configuration->configpath, ParsedFragmentList); … … 2943 2962 // =================================== Begin of FRAGMENTATION =============================== 2944 2963 // ===== 6a. assign each keyset to its respective subgraph ===== 2945 Subgraphs->next->AssignKeySetsToFragment(out, this, ParsedFragmentList, ListOfLocalAtoms, FragmentList, (FragmentCounter = 0), false);2964 Subgraphs->next->AssignKeySetsToFragment(out, this, ParsedFragmentList, ListOfLocalAtoms, FragmentList, (FragmentCounter = 0), true); 2946 2965 2947 2966 // ===== 6b. prepare and go into the adaptive (Order<0), single-step (Order==0) or incremental (Order>0) cycle … … 2980 2999 delete[](MinimumRingSize); 2981 3000 2982 // free the index lookup list2983 for (int i=FragmentCounter;i--;)2984 Free((void **)&ListOfLocalAtoms[i], "molecule::FragmentMolecule - *ListOfLocalAtoms[]");2985 Free((void **)&ListOfLocalAtoms, "molecule::FragmentMolecule - **ListOfLocalAtoms");2986 3001 2987 3002 // ==================================== End of FRAGMENTATION ============================================ … … 3057 3072 }; 3058 3073 3074 3075 /** Picks from a global stack with all back edges the ones in the fragment. 3076 * \param *out output stream for debugging 3077 * \param **ListOfLocalAtoms array of father atom::nr to local atom::nr (reverse of atom::father) 3078 * \param *ReferenceStack stack with all the back egdes 3079 * \param *LocalStack stack to be filled 3080 * \return true - everything ok, false - ReferenceStack was empty 3081 */ 3082 bool molecule::PickLocalBackEdges(ofstream *out, atom **ListOfLocalAtoms, class StackClass<bond *> *&ReferenceStack, class StackClass<bond *> *&LocalStack) 3083 { 3084 bool status = true; 3085 if (ReferenceStack->IsEmpty()) { 3086 cerr << "ReferenceStack is empty!" << endl; 3087 return false; 3088 } 3089 bond *Binder = ReferenceStack->PopFirst(); 3090 bond *FirstBond = Binder; // mark the first bond, so that we don't loop through the stack indefinitely 3091 atom *Walker = NULL, *OtherAtom = NULL; 3092 ReferenceStack->Push(Binder); 3093 3094 do { // go through all bonds and push local ones 3095 Walker = ListOfLocalAtoms[Binder->leftatom->nr]; // get one atom in the reference molecule 3096 if (Walker == NULL) // if this Walker exists in the subgraph ... 3097 continue; 3098 for(int i=0;i<NumberOfBondsPerAtom[Walker->nr];i++) { // go through the local list of bonds 3099 OtherAtom = ListOfBondsPerAtom[Walker->nr][i]->GetOtherAtom(Walker); 3100 if (OtherAtom == ListOfLocalAtoms[Binder->rightatom->nr]) { // found the bond 3101 LocalStack->Push(ListOfBondsPerAtom[Walker->nr][i]); 3102 break; 3103 } 3104 } 3105 Binder = ReferenceStack->PopFirst(); // loop the stack for next item 3106 ReferenceStack->Push(Binder); 3107 } while (FirstBond != Binder); 3108 3109 return status; 3110 }; 3111 3059 3112 /** Stores pairs (Atom::nr, Atom::AdaptiveOrder) into file. 3060 3113 * Atoms not present in the file get "-1". … … 3199 3252 while (Walker->next != end) { 3200 3253 Walker = Walker->next; 3201 *out << Verbose(4) << "Atom " << Walker->Name << " with " << NumberOfBondsPerAtom[Walker->nr] << " bonds: ";3254 *out << Verbose(4) << "Atom " << Walker->Name << "/" << Walker->nr << " with " << NumberOfBondsPerAtom[Walker->nr] << " bonds: "; 3202 3255 TotalDegree = 0; 3203 3256 for (int j=0;j<NumberOfBondsPerAtom[Walker->nr];j++) {
Note:
See TracChangeset
for help on using the changeset viewer.