Changeset 1024cb for src/molecule.cpp
- Timestamp:
- May 31, 2010, 5:32:27 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:
- 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
Legend:
- Unmodified
- Added
- Removed
-
src/molecule.cpp
r42af9e r1024cb 35 35 * Initialises molecule list with correctly referenced start and end, and sets molecule::last_atom to zero. 36 36 */ 37 molecule::molecule(const periodentafel * const teil) : elemente(teil), start(World::getInstance().createAtom()), end(World::getInstance().createAtom()),38 first(new bond( start, end, 1, -1)), last(new bond(start, end, 1, -1)), MDSteps(0), AtomCount(0),37 molecule::molecule(const periodentafel * const teil) : elemente(teil), 38 first(new bond(0, 0, 1, -1)), last(new bond(0, 0, 1, -1)), MDSteps(0), 39 39 BondCount(0), ElementCount(0), NoNonHydrogen(0), NoNonBonds(0), NoCyclicBonds(0), BondDistance(0.), 40 40 ActiveFlag(false), IndexNr(-1), 41 41 formula(this,boost::bind(&molecule::calcFormula,this)), 42 last_atom(0), 43 InternalPointer(start) 44 { 45 // init atom chain list 46 start->father = NULL; 47 end->father = NULL; 48 link(start,end); 49 42 AtomCount(this,boost::bind(&molecule::doCountAtoms,this)), last_atom(0), InternalPointer(begin()) 43 { 50 44 // init bond chain list 51 45 link(first,last); … … 69 63 delete(first); 70 64 delete(last); 71 end->getWorld()->destroyAtom(end);72 start->getWorld()->destroyAtom(start);73 65 }; 74 66 … … 81 73 const std::string molecule::getName(){ 82 74 return std::string(name); 75 } 76 77 int molecule::getAtomCount() const{ 78 return *AtomCount; 83 79 } 84 80 … … 104 100 stringstream sstr; 105 101 periodentafel *periode = World::getInstance().getPeriode(); 106 for (atom *Walker = start; Walker != end; Walker = Walker->next) {107 counts[ Walker->type->getNumber()]++;102 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { 103 counts[(*iter)->type->getNumber()]++; 108 104 } 109 105 std::map<atomicNumber_t,unsigned int>::reverse_iterator iter; … … 115 111 } 116 112 113 /************************** Access to the List of Atoms ****************/ 114 115 116 molecule::iterator molecule::begin(){ 117 return molecule::iterator(atoms.begin(),this); 118 } 119 120 molecule::const_iterator molecule::begin() const{ 121 return atoms.begin(); 122 } 123 124 molecule::iterator molecule::end(){ 125 return molecule::iterator(atoms.end(),this); 126 } 127 128 molecule::const_iterator molecule::end() const{ 129 return atoms.end(); 130 } 131 132 bool molecule::empty() const 133 { 134 return (begin() == end()); 135 } 136 137 size_t molecule::size() const 138 { 139 size_t counter = 0; 140 for (molecule::const_iterator iter = begin(); iter != end (); ++iter) 141 counter++; 142 return counter; 143 } 144 145 molecule::const_iterator molecule::erase( const_iterator loc ) 146 { 147 molecule::const_iterator iter = loc; 148 iter--; 149 atoms.erase( loc ); 150 return iter; 151 } 152 153 molecule::const_iterator molecule::erase( atom *& key ) 154 { 155 cout << "trying to erase atom" << endl; 156 molecule::const_iterator iter = find(key); 157 if (iter != end()){ 158 // remove this position and step forward (post-increment) 159 atoms.erase( iter++ ); 160 } 161 return iter; 162 } 163 164 molecule::const_iterator molecule::find ( atom *& key ) const 165 { 166 return atoms.find( key ); 167 } 168 169 pair<molecule::iterator,bool> molecule::insert ( atom * const key ) 170 { 171 pair<atomSet::iterator,bool> res = atoms.insert(key); 172 return pair<iterator,bool>(iterator(res.first,this),res.second); 173 } 117 174 118 175 /** Adds given atom \a *pointer from molecule list. … … 123 180 bool molecule::AddAtom(atom *pointer) 124 181 { 125 bool retval = false;126 182 OBSERVE; 127 183 if (pointer != NULL) { 128 184 pointer->sort = &pointer->nr; 129 pointer->nr = last_atom++; // increase number within molecule130 AtomCount++;131 185 if (pointer->type != NULL) { 132 186 if (ElementsInMolecule[pointer->type->Z] == 0) … … 141 195 } 142 196 } 143 retval = add(pointer, end);144 } 145 return retval;197 insert(pointer); 198 } 199 return true; 146 200 }; 147 201 … … 157 211 if (pointer != NULL) { 158 212 atom *walker = pointer->clone(); 159 stringstream sstr; 160 sstr << pointer->getName(); 161 walker->setName(sstr.str()); 213 walker->setName(pointer->getName()); 162 214 walker->nr = last_atom++; // increase number within molecule 163 add(walker, end);215 insert(walker); 164 216 if ((pointer->type != NULL) && (pointer->type->Z != 1)) 165 217 NoNonHydrogen++; 166 AtomCount++;167 218 retval=walker; 168 219 } … … 575 626 576 627 // copy values 577 copy->CountAtoms();578 628 copy->CountElements(); 579 629 if (first->next != last) { // if adjaceny list is present … … 610 660 { 611 661 bond *Binder = NULL; 612 if ((atom1 != NULL) && (FindAtom(atom1->nr) != NULL) && (atom2 != NULL) && (FindAtom(atom2->nr) != NULL)) { 613 Binder = new bond(atom1, atom2, degree, BondCount++); 614 atom1->RegisterBond(Binder); 615 atom2->RegisterBond(Binder); 616 if ((atom1->type != NULL) && (atom1->type->Z != 1) && (atom2->type != NULL) && (atom2->type->Z != 1)) 617 NoNonBonds++; 618 add(Binder, last); 619 } else { 620 DoeLog(1) && (eLog()<< Verbose(1) << "Could not add bond between " << atom1->getName() << " and " << atom2->getName() << " as one or both are not present in the molecule." << endl); 621 } 662 663 // some checks to make sure we are able to create the bond 664 ASSERT(atom1, "First atom in bond-creation was an invalid pointer"); 665 ASSERT(atom2, "Second atom in bond-creation was an invalid pointer"); 666 ASSERT(FindAtom(atom1->nr),"First atom in bond-creation was not part of molecule"); 667 ASSERT(FindAtom(atom2->nr),"Second atom in bond-creation was not parto of molecule"); 668 669 Binder = new bond(atom1, atom2, degree, BondCount++); 670 atom1->RegisterBond(Binder); 671 atom2->RegisterBond(Binder); 672 if ((atom1->type != NULL) && (atom1->type->Z != 1) && (atom2->type != NULL) && (atom2->type->Z != 1)) 673 NoNonBonds++; 674 add(Binder, last); 675 622 676 return Binder; 623 677 }; … … 693 747 bool molecule::RemoveAtom(atom *pointer) 694 748 { 749 ASSERT(pointer, "Null pointer passed to molecule::RemoveAtom()."); 750 OBSERVE; 695 751 if (ElementsInMolecule[pointer->type->Z] != 0) { // this would indicate an error 696 752 ElementsInMolecule[pointer->type->Z]--; // decrease number of atom of this element 697 AtomCount--;698 753 } else 699 754 DoeLog(1) && (eLog()<< Verbose(1) << "Atom " << pointer->getName() << " is of element " << pointer->type->Z << " but the entry in the table of the molecule is 0!" << endl); … … 701 756 ElementCount--; 702 757 RemoveBonds(pointer); 703 return remove(pointer, start, end); 758 erase(pointer); 759 return true; 704 760 }; 705 761 … … 718 774 if (ElementsInMolecule[pointer->type->Z] == 0) // was last atom of this element? 719 775 ElementCount--; 720 unlink(pointer);776 erase(pointer); 721 777 return true; 722 778 }; … … 727 783 bool molecule::CleanupMolecule() 728 784 { 729 return (cleanup(first,last) && cleanup(start,end)); 785 for (molecule::iterator iter = begin(); !empty(); iter = begin()) 786 erase(iter); 787 return (cleanup(first,last)); 730 788 }; 731 789 … … 734 792 * \return pointer to atom or NULL 735 793 */ 736 atom * molecule::FindAtom(int Nr) const{ 737 atom * walker = find(&Nr, start,end); 738 if (walker != NULL) { 794 atom * molecule::FindAtom(int Nr) const 795 { 796 molecule::const_iterator iter = begin(); 797 for (; iter != end(); ++iter) 798 if ((*iter)->nr == Nr) 799 break; 800 if (iter != end()) { 739 801 //Log() << Verbose(0) << "Found Atom Nr. " << walker->nr << endl; 740 return walker;802 return (*iter); 741 803 } else { 742 804 DoLog(0) && (Log() << Verbose(0) << "Atom not found in list." << endl); … … 868 930 now = time((time_t *)NULL); // Get the system time and put it into 'now' as 'calender time' 869 931 for (int step=0;step<MDSteps;step++) { 870 *output << AtomCount<< "\n\tCreated by molecuilder, step " << step << ", on " << ctime(&now);932 *output << getAtomCount() << "\n\tCreated by molecuilder, step " << step << ", on " << ctime(&now); 871 933 ActOnAllAtoms( &atom::OutputTrajectoryXYZ, output, step ); 872 934 } … … 885 947 if (output != NULL) { 886 948 now = time((time_t *)NULL); // Get the system time and put it into 'now' as 'calender time' 887 *output << AtomCount<< "\n\tCreated by molecuilder on " << ctime(&now);949 *output << getAtomCount() << "\n\tCreated by molecuilder on " << ctime(&now); 888 950 ActOnAllAtoms( &atom::OutputXYZLine, output ); 889 951 return true; … … 895 957 * \param *out output stream for debugging 896 958 */ 897 void molecule::CountAtoms() 898 { 959 int molecule::doCountAtoms() 960 { 961 int res = size(); 899 962 int i = 0; 900 atom *Walker = start; 901 while (Walker->next != end) { 902 Walker = Walker->next; 963 NoNonHydrogen = 0; 964 for (molecule::const_iterator iter = atoms.begin(); iter != atoms.end(); ++iter) { 965 (*iter)->nr = i; // update number in molecule (for easier referencing in FragmentMolecule lateron) 966 if ((*iter)->type->Z != 1) // count non-hydrogen atoms whilst at it 967 NoNonHydrogen++; 968 stringstream sstr; 969 sstr << (*iter)->type->symbol << (*iter)->nr+1; 970 (*iter)->setName(sstr.str()); 971 Log() << Verbose(3) << "Naming atom nr. " << (*iter)->nr << " " << (*iter)->getName() << "." << endl; 903 972 i++; 904 973 } 905 if ((AtomCount == 0) || (i != AtomCount)) { 906 DoLog(3) && (Log() << Verbose(3) << "Mismatch in AtomCount " << AtomCount << " and recounted number " << i << ", renaming all." << endl); 907 AtomCount = i; 908 909 // count NonHydrogen atoms and give each atom a unique name 910 if (AtomCount != 0) { 911 i=0; 912 NoNonHydrogen = 0; 913 Walker = start; 914 while (Walker->next != end) { 915 Walker = Walker->next; 916 Walker->nr = i; // update number in molecule (for easier referencing in FragmentMolecule lateron) 917 if (Walker->type->Z != 1) // count non-hydrogen atoms whilst at it 918 NoNonHydrogen++; 919 stringstream sstr; 920 sstr << Walker->type->symbol << Walker->nr+1; 921 Walker->setName(sstr.str()); 922 DoLog(3) && (Log() << Verbose(3) << "Naming atom nr. " << Walker->nr << " " << Walker->getName() << "." << endl); 923 i++; 924 } 925 } else 926 DoLog(3) && (Log() << Verbose(3) << "AtomCount is still " << AtomCount << ", thus counting nothing." << endl); 927 } 974 return res; 928 975 }; 929 976 … … 987 1034 /// first count both their atoms and elements and update lists thereby ... 988 1035 //Log() << Verbose(0) << "Counting atoms, updating list" << endl; 989 CountAtoms();990 OtherMolecule->CountAtoms();991 1036 CountElements(); 992 1037 OtherMolecule->CountElements(); … … 995 1040 /// -# AtomCount 996 1041 if (result) { 997 if ( AtomCount != OtherMolecule->AtomCount) {998 DoLog(4) && (Log() << Verbose(4) << "AtomCounts don't match: " << AtomCount << " == " << OtherMolecule->AtomCount<< endl);1042 if (getAtomCount() != OtherMolecule->getAtomCount()) { 1043 DoLog(4) && (Log() << Verbose(4) << "AtomCounts don't match: " << getAtomCount() << " == " << OtherMolecule->getAtomCount() << endl); 999 1044 result = false; 1000 } else Log() << Verbose(4) << "AtomCounts match: " << AtomCount << " == " << OtherMolecule->AtomCount<< endl;1045 } else Log() << Verbose(4) << "AtomCounts match: " << getAtomCount() << " == " << OtherMolecule->getAtomCount() << endl; 1001 1046 } 1002 1047 /// -# ElementCount … … 1035 1080 if (result) { 1036 1081 DoLog(5) && (Log() << Verbose(5) << "Calculating distances" << endl); 1037 Distances = new double[ AtomCount];1038 OtherDistances = new double[ AtomCount];1082 Distances = new double[getAtomCount()]; 1083 OtherDistances = new double[getAtomCount()]; 1039 1084 SetIndexedArrayForEachAtomTo ( Distances, &atom::nr, &atom::DistanceSquaredToVector, (const Vector &)CenterOfGravity); 1040 1085 SetIndexedArrayForEachAtomTo ( OtherDistances, &atom::nr, &atom::DistanceSquaredToVector, (const Vector &)CenterOfGravity); 1041 for(int i=0;i< AtomCount;i++) {1086 for(int i=0;i<getAtomCount();i++) { 1042 1087 Distances[i] = 0.; 1043 1088 OtherDistances[i] = 0.; … … 1046 1091 /// ... sort each list (using heapsort (o(N log N)) from GSL) 1047 1092 DoLog(5) && (Log() << Verbose(5) << "Sorting distances" << endl); 1048 PermMap = new size_t[ AtomCount];1049 OtherPermMap = new size_t[ AtomCount];1050 for(int i=0;i< AtomCount;i++) {1093 PermMap = new size_t[getAtomCount()]; 1094 OtherPermMap = new size_t[getAtomCount()]; 1095 for(int i=0;i<getAtomCount();i++) { 1051 1096 PermMap[i] = 0; 1052 1097 OtherPermMap[i] = 0; 1053 1098 } 1054 gsl_heapsort_index (PermMap, Distances, AtomCount, sizeof(double), CompareDoubles);1055 gsl_heapsort_index (OtherPermMap, OtherDistances, AtomCount, sizeof(double), CompareDoubles);1056 PermutationMap = new int[ AtomCount];1057 for(int i=0;i< AtomCount;i++)1099 gsl_heapsort_index (PermMap, Distances, getAtomCount(), sizeof(double), CompareDoubles); 1100 gsl_heapsort_index (OtherPermMap, OtherDistances, getAtomCount(), sizeof(double), CompareDoubles); 1101 PermutationMap = new int[getAtomCount()]; 1102 for(int i=0;i<getAtomCount();i++) 1058 1103 PermutationMap[i] = 0; 1059 1104 DoLog(5) && (Log() << Verbose(5) << "Combining Permutation Maps" << endl); 1060 for(int i= AtomCount;i--;)1105 for(int i=getAtomCount();i--;) 1061 1106 PermutationMap[PermMap[i]] = (int) OtherPermMap[i]; 1062 1107 … … 1064 1109 DoLog(4) && (Log() << Verbose(4) << "Comparing distances" << endl); 1065 1110 flag = 0; 1066 for (int i=0;i< AtomCount;i++) {1111 for (int i=0;i<getAtomCount();i++) { 1067 1112 DoLog(5) && (Log() << Verbose(5) << "Distances squared: |" << Distances[PermMap[i]] << " - " << OtherDistances[OtherPermMap[i]] << "| = " << fabs(Distances[PermMap[i]] - OtherDistances[OtherPermMap[i]]) << " ?<? " << threshold << endl); 1068 1113 if (fabs(Distances[PermMap[i]] - OtherDistances[OtherPermMap[i]]) > threshold*threshold) … … 1100 1145 int * molecule::GetFatherSonAtomicMap(molecule *OtherMolecule) 1101 1146 { 1102 atom *Walker = NULL, *OtherWalker = NULL;1103 1147 DoLog(3) && (Log() << Verbose(3) << "Begin of GetFatherAtomicMap." << endl); 1104 int *AtomicMap = new int[ AtomCount];1105 for (int i= AtomCount;i--;)1148 int *AtomicMap = new int[getAtomCount()]; 1149 for (int i=getAtomCount();i--;) 1106 1150 AtomicMap[i] = -1; 1107 1151 if (OtherMolecule == this) { // same molecule 1108 for (int i= AtomCount;i--;) // no need as -1 means already that there is trivial correspondence1152 for (int i=getAtomCount();i--;) // no need as -1 means already that there is trivial correspondence 1109 1153 AtomicMap[i] = i; 1110 1154 DoLog(4) && (Log() << Verbose(4) << "Map is trivial." << endl); 1111 1155 } else { 1112 1156 DoLog(4) && (Log() << Verbose(4) << "Map is "); 1113 Walker = start; 1114 while (Walker->next != end) { 1115 Walker = Walker->next; 1116 if (Walker->father == NULL) { 1117 AtomicMap[Walker->nr] = -2; 1157 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { 1158 if ((*iter)->father == NULL) { 1159 AtomicMap[(*iter)->nr] = -2; 1118 1160 } else { 1119 OtherWalker = OtherMolecule->start; 1120 while (OtherWalker->next != OtherMolecule->end) { 1121 OtherWalker = OtherWalker->next; 1161 for (molecule::const_iterator runner = OtherMolecule->begin(); runner != OtherMolecule->end(); ++runner) { 1122 1162 //for (int i=0;i<AtomCount;i++) { // search atom 1123 //for (int j=0;j<OtherMolecule-> AtomCount;j++) {1124 //Log() << Verbose(4) << "Comparing father " << Walker->father << " with the other one " << OtherWalker->father << "." << endl;1125 if ( Walker->father == OtherWalker)1126 AtomicMap[ Walker->nr] = OtherWalker->nr;1163 //for (int j=0;j<OtherMolecule->getAtomCount();j++) { 1164 //Log() << Verbose(4) << "Comparing father " << (*iter)->father << " with the other one " << (*runner)->father << "." << endl; 1165 if ((*iter)->father == (*runner)) 1166 AtomicMap[(*iter)->nr] = (*runner)->nr; 1127 1167 } 1128 1168 } 1129 DoLog(0) && (Log() << Verbose(0) << AtomicMap[ Walker->nr] << "\t");1169 DoLog(0) && (Log() << Verbose(0) << AtomicMap[(*iter)->nr] << "\t"); 1130 1170 } 1131 1171 DoLog(0) && (Log() << Verbose(0) << endl); … … 1161 1201 void molecule::SetIndexedArrayForEachAtomTo ( atom **array, int ParticleInfo::*index) const 1162 1202 { 1163 atom *Walker = start; 1164 while (Walker->next != end) { 1165 Walker = Walker->next; 1166 array[(Walker->*index)] = Walker; 1203 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { 1204 array[((*iter)->*index)] = (*iter); 1167 1205 } 1168 1206 };
Note:
See TracChangeset
for help on using the changeset viewer.