Changeset ce5ac3 for src/molecules.cpp
- Timestamp:
- Jul 23, 2009, 12:32:48 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:
- d067d45
- Parents:
- 986c80
- File:
-
- 1 edited
-
src/molecules.cpp (modified) (32 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/molecules.cpp
r986c80 rce5ac3 53 53 BondCount = 0; 54 54 NoNonBonds = 0; 55 NoNonHydrogen = 0;55 NoNonHydrogen = 0; 56 56 NoCyclicBonds = 0; 57 57 ListOfBondsPerAtom = NULL; … … 117 117 { 118 118 if (pointer != NULL) { 119 atom *walker = new atom();120 walker->type = pointer->type;// copy element of atom121 walker->x.CopyVector(&pointer->x); // copy coordination119 atom *walker = new atom(); 120 walker->type = pointer->type; // copy element of atom 121 walker->x.CopyVector(&pointer->x); // copy coordination 122 122 walker->v.CopyVector(&pointer->v); // copy velocity 123 123 walker->FixedIon = pointer->FixedIon; … … 186 186 double *matrix; 187 187 188 // *out << Verbose(3) << "Begin of AddHydrogenReplacementAtom." << endl;188 // *out << Verbose(3) << "Begin of AddHydrogenReplacementAtom." << endl; 189 189 // create vector in direction of bond 190 190 InBondvector.CopyVector(&TopReplacement->x); … … 427 427 } 428 428 429 // *out << Verbose(3) << "End of AddHydrogenReplacementAtom." << endl;429 // *out << Verbose(3) << "End of AddHydrogenReplacementAtom." << endl; 430 430 return AllWentWell; 431 431 }; … … 753 753 Vector * molecule::DetermineCenterOfGravity(ofstream *out) 754 754 { 755 atom *ptr = start->next; // start at first in list756 Vector *a = new Vector();757 Vector tmp;755 atom *ptr = start->next; // start at first in list 756 Vector *a = new Vector(); 757 Vector tmp; 758 758 double Num = 0; 759 759 760 a->Zero();760 a->Zero(); 761 761 762 762 if (ptr != end) { //list not empty? … … 909 909 void molecule::PrincipalAxisSystem(ofstream *out, bool DoRotate) 910 910 { 911 atom *ptr = start; // start at first in list912 double InertiaTensor[NDIM*NDIM];913 Vector *CenterOfGravity = DetermineCenterOfGravity(out);914 915 CenterGravity(out, CenterOfGravity);916 917 // reset inertia tensor918 for(int i=0;i<NDIM*NDIM;i++)919 InertiaTensor[i] = 0.;920 921 // sum up inertia tensor922 while (ptr->next != end) {923 ptr = ptr->next;924 Vector x;925 x.CopyVector(&ptr->x);926 //x.SubtractVector(CenterOfGravity);927 InertiaTensor[0] += ptr->type->mass*(x.x[1]*x.x[1] + x.x[2]*x.x[2]);928 InertiaTensor[1] += ptr->type->mass*(-x.x[0]*x.x[1]);929 InertiaTensor[2] += ptr->type->mass*(-x.x[0]*x.x[2]);930 InertiaTensor[3] += ptr->type->mass*(-x.x[1]*x.x[0]);931 InertiaTensor[4] += ptr->type->mass*(x.x[0]*x.x[0] + x.x[2]*x.x[2]);932 InertiaTensor[5] += ptr->type->mass*(-x.x[1]*x.x[2]);933 InertiaTensor[6] += ptr->type->mass*(-x.x[2]*x.x[0]);934 InertiaTensor[7] += ptr->type->mass*(-x.x[2]*x.x[1]);935 InertiaTensor[8] += ptr->type->mass*(x.x[0]*x.x[0] + x.x[1]*x.x[1]);936 }937 // print InertiaTensor for debugging938 *out << "The inertia tensor is:" << endl;939 for(int i=0;i<NDIM;i++) {940 for(int j=0;j<NDIM;j++)941 *out << InertiaTensor[i*NDIM+j] << " ";942 *out << endl;943 }944 *out << endl;945 946 // diagonalize to determine principal axis system947 gsl_eigen_symmv_workspace *T = gsl_eigen_symmv_alloc(NDIM);948 gsl_matrix_view m = gsl_matrix_view_array(InertiaTensor, NDIM, NDIM);949 gsl_vector *eval = gsl_vector_alloc(NDIM);950 gsl_matrix *evec = gsl_matrix_alloc(NDIM, NDIM);951 gsl_eigen_symmv(&m.matrix, eval, evec, T);952 gsl_eigen_symmv_free(T);953 gsl_eigen_symmv_sort(eval, evec, GSL_EIGEN_SORT_ABS_DESC);954 955 for(int i=0;i<NDIM;i++) {956 *out << Verbose(1) << "eigenvalue = " << gsl_vector_get(eval, i);957 *out << ", eigenvector = (" << evec->data[i * evec->tda + 0] << "," << evec->data[i * evec->tda + 1] << "," << evec->data[i * evec->tda + 2] << ")" << endl;958 }959 960 // check whether we rotate or not961 if (DoRotate) {962 *out << Verbose(1) << "Transforming molecule into PAS ... ";963 // the eigenvectors specify the transformation matrix964 ptr = start;965 while (ptr->next != end) {966 ptr = ptr->next;967 for (int j=0;j<MDSteps;j++)968 Trajectories[ptr].R.at(j).MatrixMultiplication(evec->data);969 ptr->x.MatrixMultiplication(evec->data);970 }971 *out << "done." << endl;972 973 // summing anew for debugging (resulting matrix has to be diagonal!)974 // reset inertia tensor911 atom *ptr = start; // start at first in list 912 double InertiaTensor[NDIM*NDIM]; 913 Vector *CenterOfGravity = DetermineCenterOfGravity(out); 914 915 CenterGravity(out, CenterOfGravity); 916 917 // reset inertia tensor 918 for(int i=0;i<NDIM*NDIM;i++) 919 InertiaTensor[i] = 0.; 920 921 // sum up inertia tensor 922 while (ptr->next != end) { 923 ptr = ptr->next; 924 Vector x; 925 x.CopyVector(&ptr->x); 926 //x.SubtractVector(CenterOfGravity); 927 InertiaTensor[0] += ptr->type->mass*(x.x[1]*x.x[1] + x.x[2]*x.x[2]); 928 InertiaTensor[1] += ptr->type->mass*(-x.x[0]*x.x[1]); 929 InertiaTensor[2] += ptr->type->mass*(-x.x[0]*x.x[2]); 930 InertiaTensor[3] += ptr->type->mass*(-x.x[1]*x.x[0]); 931 InertiaTensor[4] += ptr->type->mass*(x.x[0]*x.x[0] + x.x[2]*x.x[2]); 932 InertiaTensor[5] += ptr->type->mass*(-x.x[1]*x.x[2]); 933 InertiaTensor[6] += ptr->type->mass*(-x.x[2]*x.x[0]); 934 InertiaTensor[7] += ptr->type->mass*(-x.x[2]*x.x[1]); 935 InertiaTensor[8] += ptr->type->mass*(x.x[0]*x.x[0] + x.x[1]*x.x[1]); 936 } 937 // print InertiaTensor for debugging 938 *out << "The inertia tensor is:" << endl; 939 for(int i=0;i<NDIM;i++) { 940 for(int j=0;j<NDIM;j++) 941 *out << InertiaTensor[i*NDIM+j] << " "; 942 *out << endl; 943 } 944 *out << endl; 945 946 // diagonalize to determine principal axis system 947 gsl_eigen_symmv_workspace *T = gsl_eigen_symmv_alloc(NDIM); 948 gsl_matrix_view m = gsl_matrix_view_array(InertiaTensor, NDIM, NDIM); 949 gsl_vector *eval = gsl_vector_alloc(NDIM); 950 gsl_matrix *evec = gsl_matrix_alloc(NDIM, NDIM); 951 gsl_eigen_symmv(&m.matrix, eval, evec, T); 952 gsl_eigen_symmv_free(T); 953 gsl_eigen_symmv_sort(eval, evec, GSL_EIGEN_SORT_ABS_DESC); 954 955 for(int i=0;i<NDIM;i++) { 956 *out << Verbose(1) << "eigenvalue = " << gsl_vector_get(eval, i); 957 *out << ", eigenvector = (" << evec->data[i * evec->tda + 0] << "," << evec->data[i * evec->tda + 1] << "," << evec->data[i * evec->tda + 2] << ")" << endl; 958 } 959 960 // check whether we rotate or not 961 if (DoRotate) { 962 *out << Verbose(1) << "Transforming molecule into PAS ... "; 963 // the eigenvectors specify the transformation matrix 964 ptr = start; 965 while (ptr->next != end) { 966 ptr = ptr->next; 967 for (int j=0;j<MDSteps;j++) 968 Trajectories[ptr].R.at(j).MatrixMultiplication(evec->data); 969 ptr->x.MatrixMultiplication(evec->data); 970 } 971 *out << "done." << endl; 972 973 // summing anew for debugging (resulting matrix has to be diagonal!) 974 // reset inertia tensor 975 975 for(int i=0;i<NDIM*NDIM;i++) 976 976 InertiaTensor[i] = 0.; … … 1001 1001 } 1002 1002 *out << endl; 1003 }1004 1005 // free everything1006 delete(CenterOfGravity);1007 gsl_vector_free(eval);1008 gsl_matrix_free(evec);1003 } 1004 1005 // free everything 1006 delete(CenterOfGravity); 1007 gsl_vector_free(eval); 1008 gsl_matrix_free(evec); 1009 1009 }; 1010 1010 … … 2027 2027 runner = elemente->start; 2028 2028 while (runner->next != elemente->end) { // go through every element 2029 runner = runner->next;2029 runner = runner->next; 2030 2030 if (ElementsInMolecule[runner->Z]) { // if this element got atoms 2031 2031 ElementNo++; … … 2121 2121 bool molecule::Checkout(ofstream *out) const 2122 2122 { 2123 return elemente->Checkout(out, ElementsInMolecule);2123 return elemente->Checkout(out, ElementsInMolecule); 2124 2124 }; 2125 2125 … … 2174 2174 runner = elemente->start; 2175 2175 while (runner->next != elemente->end) { // go through every element 2176 runner = runner->next;2176 runner = runner->next; 2177 2177 if (ElementsInMolecule[runner->Z]) { // if this element got atoms 2178 2178 ElementNo++; … … 2196 2196 void molecule::CountAtoms(ofstream *out) 2197 2197 { 2198 int i = 0;2199 atom *Walker = start;2198 int i = 0; 2199 atom *Walker = start; 2200 2200 while (Walker->next != end) { 2201 2201 Walker = Walker->next; … … 2204 2204 if ((AtomCount == 0) || (i != AtomCount)) { 2205 2205 *out << Verbose(3) << "Mismatch in AtomCount " << AtomCount << " and recounted number " << i << ", renaming all." << endl; 2206 AtomCount = i;2206 AtomCount = i; 2207 2207 2208 2208 // count NonHydrogen atoms and give each atom a unique name 2209 2209 if (AtomCount != 0) { 2210 i=0;2211 NoNonHydrogen = 0;2210 i=0; 2211 NoNonHydrogen = 0; 2212 2212 Walker = start; 2213 while (Walker->next != end) {2214 Walker = Walker->next;2215 Walker->nr = i; // update number in molecule (for easier referencing in FragmentMolecule lateron)2216 if (Walker->type->Z != 1) // count non-hydrogen atoms whilst at it2217 NoNonHydrogen++;2218 Free((void **)&Walker->Name, "molecule::CountAtoms: *walker->Name");2219 Walker->Name = (char *) Malloc(sizeof(char)*6, "molecule::CountAtoms: *walker->Name");2220 sprintf(Walker->Name, "%2s%02d", Walker->type->symbol, Walker->nr+1);2213 while (Walker->next != end) { 2214 Walker = Walker->next; 2215 Walker->nr = i; // update number in molecule (for easier referencing in FragmentMolecule lateron) 2216 if (Walker->type->Z != 1) // count non-hydrogen atoms whilst at it 2217 NoNonHydrogen++; 2218 Free((void **)&Walker->Name, "molecule::CountAtoms: *walker->Name"); 2219 Walker->Name = (char *) Malloc(sizeof(char)*6, "molecule::CountAtoms: *walker->Name"); 2220 sprintf(Walker->Name, "%2s%02d", Walker->type->symbol, Walker->nr+1); 2221 2221 *out << "Naming atom nr. " << Walker->nr << " " << Walker->Name << "." << endl; 2222 i++;2223 }2222 i++; 2223 } 2224 2224 } else 2225 *out << Verbose(3) << "AtomCount is still " << AtomCount << ", thus counting nothing." << endl;2225 *out << Verbose(3) << "AtomCount is still " << AtomCount << ", thus counting nothing." << endl; 2226 2226 } 2227 2227 }; … … 2231 2231 void molecule::CountElements() 2232 2232 { 2233 int i = 0;2233 int i = 0; 2234 2234 for(i=MAX_ELEMENTS;i--;) 2235 ElementsInMolecule[i] = 0;2236 ElementCount = 0;2235 ElementsInMolecule[i] = 0; 2236 ElementCount = 0; 2237 2237 2238 2238 atom *walker = start; … … 2243 2243 } 2244 2244 for(i=MAX_ELEMENTS;i--;) 2245 ElementCount += (ElementsInMolecule[i] != 0 ? 1 : 0);2245 ElementCount += (ElementsInMolecule[i] != 0 ? 1 : 0); 2246 2246 }; 2247 2247 … … 2334 2334 { 2335 2335 2336 // 1 We will parse bonds out of the dbond file created by tremolo.2337 int atom1, atom2, temp;2338 atom *Walker, *OtherWalker;2339 2340 if (!input)2341 {2342 cout << Verbose(1) << "Opening silica failed \n";2343 };2344 2345 *input >> ws >> atom1;2346 *input >> ws >> atom2;2347 cout << Verbose(1) << "Scanning file\n";2348 while (!input->eof()) // Check whether we read everything already2349 {2350 *input >> ws >> atom1;2351 *input >> ws >> atom2;2352 if(atom2<atom1) //Sort indices of atoms in order2353 {2354 temp=atom1;2355 atom1=atom2;2356 atom2=temp;2357 };2358 2359 Walker=start;2360 while(Walker-> nr != atom1) // Find atom corresponding to first index2361 {2362 Walker = Walker->next;2363 };2364 OtherWalker = Walker->next;2365 while(OtherWalker->nr != atom2) // Find atom corresponding to second index2366 {2367 OtherWalker= OtherWalker->next;2368 };2369 AddBond(Walker, OtherWalker); //Add the bond between the two atoms with respective indices.2370 2371 }2372 2373 CreateListOfBondsPerAtom(out);2336 // 1 We will parse bonds out of the dbond file created by tremolo. 2337 int atom1, atom2, temp; 2338 atom *Walker, *OtherWalker; 2339 2340 if (!input) 2341 { 2342 cout << Verbose(1) << "Opening silica failed \n"; 2343 }; 2344 2345 *input >> ws >> atom1; 2346 *input >> ws >> atom2; 2347 cout << Verbose(1) << "Scanning file\n"; 2348 while (!input->eof()) // Check whether we read everything already 2349 { 2350 *input >> ws >> atom1; 2351 *input >> ws >> atom2; 2352 if(atom2<atom1) //Sort indices of atoms in order 2353 { 2354 temp=atom1; 2355 atom1=atom2; 2356 atom2=temp; 2357 }; 2358 2359 Walker=start; 2360 while(Walker-> nr != atom1) // Find atom corresponding to first index 2361 { 2362 Walker = Walker->next; 2363 }; 2364 OtherWalker = Walker->next; 2365 while(OtherWalker->nr != atom2) // Find atom corresponding to second index 2366 { 2367 OtherWalker= OtherWalker->next; 2368 }; 2369 AddBond(Walker, OtherWalker); //Add the bond between the two atoms with respective indices. 2370 2371 } 2372 2373 CreateListOfBondsPerAtom(out); 2374 2374 2375 2375 }; … … 2520 2520 // preferred over carbon bonds). Beforehand, we had picked the first mismatching partner, which lead to oxygenes with single instead of 2521 2521 // double bonds as was expected. 2522 if (BondCount != 0) {2522 if (BondCount != 0) { 2523 2523 NoCyclicBonds = 0; 2524 *out << Verbose(1) << "Correcting Bond degree of each bond ... ";2525 do {2526 No = 0; // No acts as breakup flag (if 1 we still continue)2524 *out << Verbose(1) << "Correcting Bond degree of each bond ... "; 2525 do { 2526 No = 0; // No acts as breakup flag (if 1 we still continue) 2527 2527 Walker = start; 2528 2528 while (Walker->next != end) { // go through every atom … … 2538 2538 for(int i=0;i<NumberOfBondsPerAtom[Walker->nr];i++) { // go through each of its bond partners 2539 2539 OtherWalker = ListOfBondsPerAtom[Walker->nr][i]->GetOtherAtom(Walker); 2540 // count valence of second partner2540 // count valence of second partner 2541 2541 NoBonds = 0; 2542 2542 for(j=0;j<NumberOfBondsPerAtom[OtherWalker->nr];j++) 2543 2543 NoBonds += ListOfBondsPerAtom[OtherWalker->nr][j]->BondDegree; 2544 2544 *out << Verbose(3) << "OtherWalker " << *OtherWalker << ": " << (int)OtherWalker->type->NoValenceOrbitals << " > " << NoBonds << "?" << endl; 2545 if ((int)(OtherWalker->type->NoValenceOrbitals) > NoBonds) { // check if possible candidate2546 if ((Candidate == NULL) || (NumberOfBondsPerAtom[Candidate->nr] > NumberOfBondsPerAtom[OtherWalker->nr])) { // pick the one with fewer number of bonds first2545 if ((int)(OtherWalker->type->NoValenceOrbitals) > NoBonds) { // check if possible candidate 2546 if ((Candidate == NULL) || (NumberOfBondsPerAtom[Candidate->nr] > NumberOfBondsPerAtom[OtherWalker->nr])) { // pick the one with fewer number of bonds first 2547 2547 Candidate = OtherWalker; 2548 2548 CandidateBondNo = i; 2549 *out << Verbose(3) << "New candidate is " << *Candidate << "." << endl;2550 }2551 }2552 }2549 *out << Verbose(3) << "New candidate is " << *Candidate << "." << endl; 2550 } 2551 } 2552 } 2553 2553 if ((Candidate != NULL) && (CandidateBondNo != -1)) { 2554 2554 ListOfBondsPerAtom[Walker->nr][CandidateBondNo]->BondDegree++; … … 2558 2558 FalseBondDegree++; 2559 2559 } 2560 }2561 } while (No);2562 *out << " done." << endl;2563 } else2564 *out << Verbose(1) << "BondCount is " << BondCount << ", no bonds between any of the " << AtomCount << " atoms." << endl;2565 *out << Verbose(1) << "I detected " << BondCount << " bonds in the molecule with distance " << bonddistance << ", " << FalseBondDegree << " bonds could not be corrected." << endl;2566 2567 // output bonds for debugging (if bond chain list was correctly installed)2568 *out << Verbose(1) << endl << "From contents of bond chain list:";2569 bond *Binder = first;2560 } 2561 } while (No); 2562 *out << " done." << endl; 2563 } else 2564 *out << Verbose(1) << "BondCount is " << BondCount << ", no bonds between any of the " << AtomCount << " atoms." << endl; 2565 *out << Verbose(1) << "I detected " << BondCount << " bonds in the molecule with distance " << bonddistance << ", " << FalseBondDegree << " bonds could not be corrected." << endl; 2566 2567 // output bonds for debugging (if bond chain list was correctly installed) 2568 *out << Verbose(1) << endl << "From contents of bond chain list:"; 2569 bond *Binder = first; 2570 2570 while(Binder->next != last) { 2571 2571 Binder = Binder->next; 2572 *out << *Binder << "\t" << endl;2572 *out << *Binder << "\t" << endl; 2573 2573 } 2574 2574 *out << endl; 2575 2575 } else 2576 *out << Verbose(1) << "AtomCount is " << AtomCount << ", thus no bonds, no connections!." << endl;2576 *out << Verbose(1) << "AtomCount is " << AtomCount << ", thus no bonds, no connections!." << endl; 2577 2577 *out << Verbose(0) << "End of CreateAdjacencyList." << endl; 2578 2578 Free((void **)&matrix, "molecule::CreateAdjacencyList: *matrix"); … … 3600 3600 int molecule::FragmentMolecule(ofstream *out, int Order, config *configuration) 3601 3601 { 3602 MoleculeListClass *BondFragments = NULL;3602 MoleculeListClass *BondFragments = NULL; 3603 3603 int *SortIndex = NULL; 3604 3604 int *MinimumRingSize = new int[AtomCount]; … … 3806 3806 Walker = ListOfLocalAtoms[Binder->leftatom->nr]; // get one atom in the reference molecule 3807 3807 if (Walker != NULL) // if this Walker exists in the subgraph ... 3808 for(int i=0;i<NumberOfBondsPerAtom[Walker->nr];i++) { // go through the local list of bonds3809 OtherAtom = ListOfBondsPerAtom[Walker->nr][i]->GetOtherAtom(Walker);3810 if (OtherAtom == ListOfLocalAtoms[Binder->rightatom->nr]) { // found the bond3811 LocalStack->Push(ListOfBondsPerAtom[Walker->nr][i]);3808 for(int i=0;i<NumberOfBondsPerAtom[Walker->nr];i++) { // go through the local list of bonds 3809 OtherAtom = ListOfBondsPerAtom[Walker->nr][i]->GetOtherAtom(Walker); 3810 if (OtherAtom == ListOfLocalAtoms[Binder->rightatom->nr]) { // found the bond 3811 LocalStack->Push(ListOfBondsPerAtom[Walker->nr][i]); 3812 3812 *out << Verbose(3) << "Found local edge " << *(ListOfBondsPerAtom[Walker->nr][i]) << "." << endl; 3813 break;3814 }3815 }3813 break; 3814 } 3815 } 3816 3816 Binder = ReferenceStack->PopFirst(); // loop the stack for next item 3817 3817 *out << Verbose(3) << "Current candidate edge " << Binder << "." << endl; … … 4308 4308 for (int i=0;i<AtomCount;i++) { // reset all atom labels 4309 4309 // initialise each vertex as white with no predecessor, empty queue, color lightgray, not labelled, no sons 4310 Labels[i] = -1;4310 Labels[i] = -1; 4311 4311 SonList[i] = NULL; 4312 4312 PredecessorList[i] = NULL; … … 4316 4316 for (int i=0;i<BondCount;i++) 4317 4317 ColorEdgeList[i] = white; 4318 RootStack->ClearStack();// clearstack and push first atom if exists4318 RootStack->ClearStack(); // clearstack and push first atom if exists 4319 4319 TouchedStack->ClearStack(); 4320 4320 Walker = start->next; … … 4335 4335 ///// OUTER LOOP //////////// 4336 4336 while (!RootStack->IsEmpty()) { 4337 // get new root vertex from atom stack4338 Root = RootStack->PopFirst();4337 // get new root vertex from atom stack 4338 Root = RootStack->PopFirst(); 4339 4339 ShortestPathList[Root->nr] = 0; 4340 4340 if (Labels[Root->nr] == -1) … … 4344 4344 *out << Verbose(0) << "Root for this loop is: " << Root->Name << ".\n"; 4345 4345 4346 // clear snake stack4347 SnakeStack->ClearStack();4346 // clear snake stack 4347 SnakeStack->ClearStack(); 4348 4348 //SnakeStack->TestImplementation(out, start->next); 4349 4349 … … 4352 4352 // - what about cyclic bonds? 4353 4353 Walker = Root; 4354 do {4354 do { 4355 4355 *out << Verbose(1) << "Current Walker is: " << Walker->Name; 4356 4356 // initial setting of the new Walker: label, color, shortest path and put on stacks 4357 if (Labels[Walker->nr] == -1) {// give atom a unique, monotonely increasing number4358 Labels[Walker->nr] = RunningIndex++;4357 if (Labels[Walker->nr] == -1) { // give atom a unique, monotonely increasing number 4358 Labels[Walker->nr] = RunningIndex++; 4359 4359 RootStack->Push(Walker); 4360 4360 } 4361 4361 *out << ", has label " << Labels[Walker->nr]; 4362 if ((ColorVertexList[Walker->nr] == white) || ((Binder != NULL) && (ColorEdgeList[Binder->nr] == white))) {// color it if newly discovered and push on stacks (and if within reach!)4362 if ((ColorVertexList[Walker->nr] == white) || ((Binder != NULL) && (ColorEdgeList[Binder->nr] == white))) { // color it if newly discovered and push on stacks (and if within reach!) 4363 4363 if ((Binder != NULL) && (ColorEdgeList[Binder->nr] == white)) { 4364 4364 // Binder ought to be set still from last neighbour search … … 4374 4374 ColorVertexList[Walker->nr] = darkgray; // mark as dark gray of on snake stack 4375 4375 } 4376 }4376 } 4377 4377 *out << ", SP of " << ShortestPathList[Walker->nr] << " and its color is " << GetColor(ColorVertexList[Walker->nr]) << "." << endl; 4378 4378 4379 4379 // then check the stack for a newly stumbled upon fragment 4380 if (SnakeStack->ItemCount() == Order) { // is stack full?4380 if (SnakeStack->ItemCount() == Order) { // is stack full? 4381 4381 // store the fragment if it is one and get a removal candidate 4382 4382 Removal = StoreFragmentFromStack(out, Root, Walker, Leaflet, SnakeStack, ShortestPathList, SonList, Labels, &FragmentCounter, configuration); … … 4391 4391 } 4392 4392 } 4393 } else4393 } else 4394 4394 Removal = NULL; 4395 4395 … … 4398 4398 if ((Removal == NULL) || (Walker != PredecessorList[Removal->nr])) { // don't look, if a new walker has been set above 4399 4399 *out << Verbose(2) << "Snake has currently " << SnakeStack->ItemCount() << " item(s)." << endl; 4400 OtherAtom = NULL; // this is actually not needed, every atom has at least one neighbour4400 OtherAtom = NULL; // this is actually not needed, every atom has at least one neighbour 4401 4401 if (ShortestPathList[Walker->nr] < Order) { 4402 for(int i=0;i<NumberOfBondsPerAtom[Walker->nr];i++) {4402 for(int i=0;i<NumberOfBondsPerAtom[Walker->nr];i++) { 4403 4403 Binder = ListOfBondsPerAtom[Walker->nr][i]; 4404 4404 *out << Verbose(2) << "Current bond is " << *Binder << ": "; 4405 OtherAtom = Binder->GetOtherAtom(Walker);4405 OtherAtom = Binder->GetOtherAtom(Walker); 4406 4406 if ((Labels[OtherAtom->nr] != -1) && (Labels[OtherAtom->nr] < Labels[Root->nr])) { // we don't step up to labels bigger than us 4407 4407 *out << "Label " << Labels[OtherAtom->nr] << " is smaller than Root's " << Labels[Root->nr] << "." << endl; 4408 4408 //ColorVertexList[OtherAtom->nr] = lightgray; // mark as explored 4409 4409 } else { // otherwise check its colour and element 4410 if (4410 if ( 4411 4411 #ifdef ADDHYDROGEN 4412 4412 (OtherAtom->type->Z != 1) && … … 4430 4430 } 4431 4431 } 4432 }4432 } 4433 4433 } else { // means we have stepped beyond the horizon: Return! 4434 4434 Walker = PredecessorList[Walker->nr]; … … 4436 4436 *out << Verbose(3) << "We have gone too far, stepping back to " << Walker->Name << "." << endl; 4437 4437 } 4438 if (Walker != OtherAtom) {// if no white neighbours anymore, color it black4438 if (Walker != OtherAtom) { // if no white neighbours anymore, color it black 4439 4439 *out << Verbose(2) << "Coloring " << Walker->Name << " black." << endl; 4440 ColorVertexList[Walker->nr] = black;4441 Walker = PredecessorList[Walker->nr];4442 }4443 } 4444 } while ((Walker != Root) || (ColorVertexList[Root->nr] != black));4440 ColorVertexList[Walker->nr] = black; 4441 Walker = PredecessorList[Walker->nr]; 4442 } 4443 } 4444 } while ((Walker != Root) || (ColorVertexList[Root->nr] != black)); 4445 4445 *out << Verbose(2) << "Inner Looping is finished." << endl; 4446 4446 … … 4562 4562 bit = ((i & (1 << j)) != 0); // mask the bit for the j-th bond 4563 4563 if (bit) { // if bit is set, we add this bond partner 4564 OtherWalker = BondsSet[j]->rightatom;// rightatom is always the one more distant, i.e. the one to add4564 OtherWalker = BondsSet[j]->rightatom; // rightatom is always the one more distant, i.e. the one to add 4565 4565 //*out << Verbose(1+verbosity) << "Current Bond is " << ListOfBondsPerAtom[Walker->nr][i] << ", checking on " << *OtherWalker << "." << endl; 4566 4566 *out << Verbose(2+verbosity) << "Adding " << *OtherWalker << " with nr " << OtherWalker->nr << "." << endl; … … 4584 4584 if (SubOrder > 1) { // Due to Added above we have to check extra whether we're not already reaching beyond the desired Order 4585 4585 // --2-- look at all added end pieces of this combination, construct bond subsets and sweep through a power set of these by recursion 4586 SP = RootDistance+1; // this is the next level4586 SP = RootDistance+1; // this is the next level 4587 4587 // first count the members in the subset 4588 4588 SubSetDimension = 0; 4589 Binder = FragmentSearch->BondsPerSPList[2*SP]; // start node for this level4590 while (Binder->next != FragmentSearch->BondsPerSPList[2*SP+1]) { // compare to end node of this level4589 Binder = FragmentSearch->BondsPerSPList[2*SP]; // start node for this level 4590 while (Binder->next != FragmentSearch->BondsPerSPList[2*SP+1]) { // compare to end node of this level 4591 4591 Binder = Binder->next; 4592 4592 for (int k=TouchedIndex;k--;) {
Note:
See TracChangeset
for help on using the changeset viewer.
