Changeset ea7176 for src/molecule.cpp
- Timestamp:
- Mar 19, 2010, 1:29:01 PM (15 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:
- e0b6fd
- Parents:
- 80c63d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/molecule.cpp
r80c63d rea7176 32 32 */ 33 33 molecule::molecule(const periodentafel * const teil) : elemente(teil), 34 first(new bond(0, 0, 1, -1)), last(new bond(0, 0, 1, -1)), MDSteps(0), AtomCount(0),34 first(new bond(0, 0, 1, -1)), last(new bond(0, 0, 1, -1)), MDSteps(0), 35 35 BondCount(0), ElementCount(0), NoNonHydrogen(0), NoNonBonds(0), NoCyclicBonds(0), BondDistance(0.), 36 36 ActiveFlag(false), IndexNr(-1), 37 37 formula(this,boost::bind(&molecule::calcFormula,this)), 38 last_atom(0), 39 InternalPointer(begin()) 38 AtomCount(this,boost::bind(&molecule::doCountAtoms,this)), last_atom(0), InternalPointer(begin()) 40 39 { 41 40 // init bond chain list … … 72 71 const std::string molecule::getName(){ 73 72 return std::string(name); 73 } 74 75 int molecule::getAtomCount() const{ 76 return *AtomCount; 74 77 } 75 78 … … 180 183 if (pointer != NULL) { 181 184 pointer->sort = &pointer->nr; 182 AtomCount++;183 185 if (pointer->type != NULL) { 184 186 if (ElementsInMolecule[pointer->type->Z] == 0) … … 214 216 if ((pointer->type != NULL) && (pointer->type->Z != 1)) 215 217 NoNonHydrogen++; 216 AtomCount++;217 218 retval=walker; 218 219 } … … 611 612 612 613 // copy values 613 copy->CountAtoms();614 614 copy->CountElements(); 615 615 if (first->next != last) { // if adjaceny list is present … … 728 728 bool molecule::RemoveAtom(atom *pointer) 729 729 { 730 OBSERVE; 730 731 if (ElementsInMolecule[pointer->type->Z] != 0) { // this would indicate an error 731 732 ElementsInMolecule[pointer->type->Z]--; // decrease number of atom of this element 732 AtomCount--;733 733 } else 734 734 eLog() << Verbose(1) << "Atom " << pointer->Name << " is of element " << pointer->type->Z << " but the entry in the table of the molecule is 0!" << endl; … … 909 909 now = time((time_t *)NULL); // Get the system time and put it into 'now' as 'calender time' 910 910 for (int step=0;step<MDSteps;step++) { 911 *output << AtomCount<< "\n\tCreated by molecuilder, step " << step << ", on " << ctime(&now);911 *output << getAtomCount() << "\n\tCreated by molecuilder, step " << step << ", on " << ctime(&now); 912 912 ActOnAllAtoms( &atom::OutputTrajectoryXYZ, output, step ); 913 913 } … … 926 926 if (output != NULL) { 927 927 now = time((time_t *)NULL); // Get the system time and put it into 'now' as 'calender time' 928 *output << AtomCount<< "\n\tCreated by molecuilder on " << ctime(&now);928 *output << getAtomCount() << "\n\tCreated by molecuilder on " << ctime(&now); 929 929 ActOnAllAtoms( &atom::OutputXYZLine, output ); 930 930 return true; … … 936 936 * \param *out output stream for debugging 937 937 */ 938 void molecule::CountAtoms() 939 { 940 int i = size(); 941 if ((AtomCount == 0) || (i != AtomCount)) { 942 cout << "!!!!!!!!! Counting needed" << endl; 943 Log() << Verbose(3) << "Mismatch in AtomCount " << AtomCount << " and recounted number " << i << ", renaming all." << endl; 944 AtomCount = i; 945 946 // count NonHydrogen atoms and give each atom a unique name 947 if (AtomCount != 0) { 948 i=0; 949 NoNonHydrogen = 0; 950 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { 951 (*iter)->nr = i; // update number in molecule (for easier referencing in FragmentMolecule lateron) 952 if ((*iter)->type->Z != 1) // count non-hydrogen atoms whilst at it 953 NoNonHydrogen++; 954 Free(&(*iter)->Name); 955 (*iter)->Name = Malloc<char>(6, "molecule::CountAtoms: *walker->Name"); 956 sprintf((*iter)->Name, "%2s%02d", (*iter)->type->symbol, (*iter)->nr+1); 957 Log() << Verbose(3) << "Naming atom nr. " << (*iter)->nr << " " << (*iter)->Name << "." << endl; 958 i++; 959 } 960 } else 961 Log() << Verbose(3) << "AtomCount is still " << AtomCount << ", thus counting nothing." << endl; 962 } 938 int molecule::doCountAtoms() 939 { 940 int res = size(); 941 int i = 0; 942 NoNonHydrogen = 0; 943 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { 944 (*iter)->nr = i; // update number in molecule (for easier referencing in FragmentMolecule lateron) 945 if ((*iter)->type->Z != 1) // count non-hydrogen atoms whilst at it 946 NoNonHydrogen++; 947 Free(&(*iter)->Name); 948 (*iter)->Name = Malloc<char>(6, "molecule::CountAtoms: *walker->Name"); 949 sprintf((*iter)->Name, "%2s%02d", (*iter)->type->symbol, (*iter)->nr+1); 950 Log() << Verbose(3) << "Naming atom nr. " << (*iter)->nr << " " << (*iter)->Name << "." << endl; 951 i++; 952 } 953 return res; 963 954 }; 964 955 … … 1022 1013 /// first count both their atoms and elements and update lists thereby ... 1023 1014 //Log() << Verbose(0) << "Counting atoms, updating list" << endl; 1024 CountAtoms();1025 OtherMolecule->CountAtoms();1026 1015 CountElements(); 1027 1016 OtherMolecule->CountElements(); … … 1030 1019 /// -# AtomCount 1031 1020 if (result) { 1032 if ( AtomCount != OtherMolecule->AtomCount) {1033 Log() << Verbose(4) << "AtomCounts don't match: " << AtomCount << " == " << OtherMolecule->AtomCount<< endl;1021 if (getAtomCount() != OtherMolecule->getAtomCount()) { 1022 Log() << Verbose(4) << "AtomCounts don't match: " << getAtomCount() << " == " << OtherMolecule->getAtomCount() << endl; 1034 1023 result = false; 1035 } else Log() << Verbose(4) << "AtomCounts match: " << AtomCount << " == " << OtherMolecule->AtomCount<< endl;1024 } else Log() << Verbose(4) << "AtomCounts match: " << getAtomCount() << " == " << OtherMolecule->getAtomCount() << endl; 1036 1025 } 1037 1026 /// -# ElementCount … … 1073 1062 if (result) { 1074 1063 Log() << Verbose(5) << "Calculating distances" << endl; 1075 Distances = Calloc<double>( AtomCount, "molecule::IsEqualToWithinThreshold: Distances");1076 OtherDistances = Calloc<double>( AtomCount, "molecule::IsEqualToWithinThreshold: OtherDistances");1064 Distances = Calloc<double>(getAtomCount(), "molecule::IsEqualToWithinThreshold: Distances"); 1065 OtherDistances = Calloc<double>(getAtomCount(), "molecule::IsEqualToWithinThreshold: OtherDistances"); 1077 1066 SetIndexedArrayForEachAtomTo ( Distances, &atom::nr, &atom::DistanceSquaredToVector, (const Vector &)CenterOfGravity); 1078 1067 SetIndexedArrayForEachAtomTo ( OtherDistances, &atom::nr, &atom::DistanceSquaredToVector, (const Vector &)CenterOfGravity); … … 1080 1069 /// ... sort each list (using heapsort (o(N log N)) from GSL) 1081 1070 Log() << Verbose(5) << "Sorting distances" << endl; 1082 PermMap = Calloc<size_t>( AtomCount, "molecule::IsEqualToWithinThreshold: *PermMap");1083 OtherPermMap = Calloc<size_t>( AtomCount, "molecule::IsEqualToWithinThreshold: *OtherPermMap");1084 gsl_heapsort_index (PermMap, Distances, AtomCount, sizeof(double), CompareDoubles);1085 gsl_heapsort_index (OtherPermMap, OtherDistances, AtomCount, sizeof(double), CompareDoubles);1086 PermutationMap = Calloc<int>( AtomCount, "molecule::IsEqualToWithinThreshold: *PermutationMap");1071 PermMap = Calloc<size_t>(getAtomCount(), "molecule::IsEqualToWithinThreshold: *PermMap"); 1072 OtherPermMap = Calloc<size_t>(getAtomCount(), "molecule::IsEqualToWithinThreshold: *OtherPermMap"); 1073 gsl_heapsort_index (PermMap, Distances, getAtomCount(), sizeof(double), CompareDoubles); 1074 gsl_heapsort_index (OtherPermMap, OtherDistances, getAtomCount(), sizeof(double), CompareDoubles); 1075 PermutationMap = Calloc<int>(getAtomCount(), "molecule::IsEqualToWithinThreshold: *PermutationMap"); 1087 1076 Log() << Verbose(5) << "Combining Permutation Maps" << endl; 1088 for(int i= AtomCount;i--;)1077 for(int i=getAtomCount();i--;) 1089 1078 PermutationMap[PermMap[i]] = (int) OtherPermMap[i]; 1090 1079 … … 1092 1081 Log() << Verbose(4) << "Comparing distances" << endl; 1093 1082 flag = 0; 1094 for (int i=0;i< AtomCount;i++) {1083 for (int i=0;i<getAtomCount();i++) { 1095 1084 Log() << Verbose(5) << "Distances squared: |" << Distances[PermMap[i]] << " - " << OtherDistances[OtherPermMap[i]] << "| = " << fabs(Distances[PermMap[i]] - OtherDistances[OtherPermMap[i]]) << " ?<? " << threshold << endl; 1096 1085 if (fabs(Distances[PermMap[i]] - OtherDistances[OtherPermMap[i]]) > threshold*threshold) … … 1129 1118 { 1130 1119 Log() << Verbose(3) << "Begin of GetFatherAtomicMap." << endl; 1131 int *AtomicMap = Malloc<int>( AtomCount, "molecule::GetAtomicMap: *AtomicMap");1132 for (int i= AtomCount;i--;)1120 int *AtomicMap = Malloc<int>(getAtomCount(), "molecule::GetAtomicMap: *AtomicMap"); 1121 for (int i=getAtomCount();i--;) 1133 1122 AtomicMap[i] = -1; 1134 1123 if (OtherMolecule == this) { // same molecule 1135 for (int i= AtomCount;i--;) // no need as -1 means already that there is trivial correspondence1124 for (int i=getAtomCount();i--;) // no need as -1 means already that there is trivial correspondence 1136 1125 AtomicMap[i] = i; 1137 1126 Log() << Verbose(4) << "Map is trivial." << endl;
Note:
See TracChangeset
for help on using the changeset viewer.