Changeset 9879f6 for src/molecule.cpp
- Timestamp:
- Mar 5, 2010, 10:16:47 AM (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:
- d3347e
- Parents:
- e87acf
- git-author:
- Frederik Heber <heber@…> (03/05/10 10:08:44)
- git-committer:
- Frederik Heber <heber@…> (03/05/10 10:16:47)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/molecule.cpp
re87acf r9879f6 37 37 formula(this,boost::bind(&molecule::calcFormula,this)), 38 38 last_atom(0), 39 InternalPointer(start) 40 { 41 // init atom chain list 42 //start->father = NULL; 43 //end->father = NULL; 44 //link(start,end); 45 39 InternalPointer(begin()) 40 { 46 41 // init bond chain list 47 42 link(first,last); … … 67 62 delete(first); 68 63 delete(last); 69 end->getWorld()->destroyAtom(end);70 start->getWorld()->destroyAtom(start);71 64 }; 72 65 … … 103 96 for (int j = 0; j<MAX_ELEMENTS;j++) 104 97 Counts[j] = 0; 105 for (atom *Walker = start; Walker != end; Walker = Walker->next) {106 Counts[ Walker->type->Z]++;98 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { 99 Counts[(*iter)->type->Z]++; 107 100 } 108 101 for(element* Elemental = elemente->end; Elemental != elemente->start; Elemental = Elemental->previous) { … … 124 117 } 125 118 126 molecule::iterator molecule::end e(){119 molecule::iterator molecule::end(){ 127 120 return molecule::iterator(atoms.end(),this); 128 121 } 129 122 130 molecule::const_iterator molecule::end e() const{123 molecule::const_iterator molecule::end() const{ 131 124 return atoms.end(); 125 } 126 127 bool molecule::empty() const 128 { 129 return (begin() == end()); 130 } 131 132 size_t molecule::size() const 133 { 134 size_t counter = 0; 135 for (molecule::const_iterator iter = begin(); iter != end (); ++iter) 136 counter++; 137 return counter; 138 } 139 140 molecule::const_iterator molecule::erase( const_iterator loc ) 141 { 142 molecule::const_iterator iter = loc; 143 iter--; 144 atoms.erase( loc ); 145 return iter; 146 } 147 148 molecule::const_iterator molecule::erase( atom *& key ) 149 { 150 molecule::const_iterator iter = find(key); 151 molecule::const_iterator runner = iter; 152 if (runner != begin()) { 153 runner--; 154 if (iter != end()) 155 atoms.erase( key ); 156 return runner; 157 } else 158 return end(); 159 } 160 161 molecule::const_iterator molecule::find ( atom *& key ) const 162 { 163 return atoms.find( key ); 164 } 165 166 pair<molecule::iterator,bool> molecule::insert ( atom * const key ) 167 { 168 return atoms.insert(key); 132 169 } 133 170 … … 139 176 bool molecule::AddAtom(atom *pointer) 140 177 { 141 bool retval = false;142 178 OBSERVE; 143 179 if (pointer != NULL) { 144 180 pointer->sort = &pointer->nr; 145 pointer->nr = last_atom++; // increase number within molecule146 181 AtomCount++; 147 182 if (pointer->type != NULL) { … … 157 192 } 158 193 } 159 retval = add(pointer, end);160 } 161 return retval;194 insert(pointer); 195 } 196 return true; 162 197 }; 163 198 … … 175 210 walker->Name = Malloc<char>(strlen(pointer->Name) + 1, "atom::atom: *Name"); 176 211 strcpy (walker->Name, pointer->Name); 177 walker->nr = last_atom++; // increase number within molecule 178 add(walker, end); 212 insert(walker); 179 213 if ((pointer->type != NULL) && (pointer->type->Z != 1)) 180 214 NoNonHydrogen++; … … 701 735 ElementCount--; 702 736 RemoveBonds(pointer); 703 return remove(pointer, start, end); 737 erase(pointer); 738 return true; 704 739 }; 705 740 … … 718 753 if (ElementsInMolecule[pointer->type->Z] == 0) // was last atom of this element? 719 754 ElementCount--; 720 unlink(pointer);755 erase(pointer); 721 756 return true; 722 757 }; … … 727 762 bool molecule::CleanupMolecule() 728 763 { 729 return (cleanup(first,last) && cleanup(start,end)); 764 for (molecule::iterator iter = begin(); !empty(); iter = begin()) 765 erase(iter); 766 return (cleanup(first,last)); 730 767 }; 731 768 … … 734 771 * \return pointer to atom or NULL 735 772 */ 736 atom * molecule::FindAtom(int Nr) const{ 737 atom * walker = find(&Nr, start,end); 738 if (walker != NULL) { 773 atom * molecule::FindAtom(int Nr) const 774 { 775 molecule::const_iterator iter = begin(); 776 for (; iter != end(); ++iter) 777 if ((*iter)->nr == Nr) 778 break; 779 if (iter != end()) { 739 780 //Log() << Verbose(0) << "Found Atom Nr. " << walker->nr << endl; 740 return walker;781 return (*iter); 741 782 } else { 742 783 Log() << Verbose(0) << "Atom not found in list." << endl; … … 896 937 void molecule::CountAtoms() 897 938 { 898 int i = 0; 899 atom *Walker = start; 900 while (Walker->next != end) { 901 Walker = Walker->next; 902 i++; 903 } 939 int i = size(); 904 940 if ((AtomCount == 0) || (i != AtomCount)) { 905 941 Log() << Verbose(3) << "Mismatch in AtomCount " << AtomCount << " and recounted number " << i << ", renaming all." << endl; … … 910 946 i=0; 911 947 NoNonHydrogen = 0; 912 Walker = start; 913 while (Walker->next != end) { 914 Walker = Walker->next; 915 Walker->nr = i; // update number in molecule (for easier referencing in FragmentMolecule lateron) 916 if (Walker->type->Z != 1) // count non-hydrogen atoms whilst at it 948 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { 949 (*iter)->nr = i; // update number in molecule (for easier referencing in FragmentMolecule lateron) 950 if ((*iter)->type->Z != 1) // count non-hydrogen atoms whilst at it 917 951 NoNonHydrogen++; 918 Free(& Walker->Name);919 Walker->Name = Malloc<char>(6, "molecule::CountAtoms: *walker->Name");920 sprintf( Walker->Name, "%2s%02d", Walker->type->symbol, Walker->nr+1);921 Log() << Verbose(3) << "Naming atom nr. " << Walker->nr << " " << Walker->Name << "." << endl;952 Free(&(*iter)->Name); 953 (*iter)->Name = Malloc<char>(6, "molecule::CountAtoms: *walker->Name"); 954 sprintf((*iter)->Name, "%2s%02d", (*iter)->type->symbol, (*iter)->nr+1); 955 Log() << Verbose(3) << "Naming atom nr. " << (*iter)->nr << " " << (*iter)->Name << "." << endl; 922 956 i++; 923 957 } … … 1092 1126 int * molecule::GetFatherSonAtomicMap(molecule *OtherMolecule) 1093 1127 { 1094 atom *Walker = NULL, *OtherWalker = NULL;1095 1128 Log() << Verbose(3) << "Begin of GetFatherAtomicMap." << endl; 1096 1129 int *AtomicMap = Malloc<int>(AtomCount, "molecule::GetAtomicMap: *AtomicMap"); … … 1103 1136 } else { 1104 1137 Log() << Verbose(4) << "Map is "; 1105 Walker = start; 1106 while (Walker->next != end) { 1107 Walker = Walker->next; 1108 if (Walker->father == NULL) { 1109 AtomicMap[Walker->nr] = -2; 1138 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { 1139 if ((*iter)->father == NULL) { 1140 AtomicMap[(*iter)->nr] = -2; 1110 1141 } else { 1111 OtherWalker = OtherMolecule->start; 1112 while (OtherWalker->next != OtherMolecule->end) { 1113 OtherWalker = OtherWalker->next; 1142 for (molecule::const_iterator runner = OtherMolecule->begin(); runner != OtherMolecule->end(); ++runner) { 1114 1143 //for (int i=0;i<AtomCount;i++) { // search atom 1115 1144 //for (int j=0;j<OtherMolecule->AtomCount;j++) { 1116 //Log() << Verbose(4) << "Comparing father " << Walker->father << " with the other one " << OtherWalker->father << "." << endl;1117 if ( Walker->father == OtherWalker)1118 AtomicMap[ Walker->nr] = OtherWalker->nr;1145 //Log() << Verbose(4) << "Comparing father " << (*iter)->father << " with the other one " << (*runner)->father << "." << endl; 1146 if ((*iter)->father == (*runner)) 1147 AtomicMap[(*iter)->nr] = (*runner)->nr; 1119 1148 } 1120 1149 } 1121 Log() << Verbose(0) << AtomicMap[ Walker->nr] << "\t";1150 Log() << Verbose(0) << AtomicMap[(*iter)->nr] << "\t"; 1122 1151 } 1123 1152 Log() << Verbose(0) << endl; … … 1153 1182 void molecule::SetIndexedArrayForEachAtomTo ( atom **array, int ParticleInfo::*index) const 1154 1183 { 1155 atom *Walker = start; 1156 while (Walker->next != end) { 1157 Walker = Walker->next; 1158 array[(Walker->*index)] = Walker; 1184 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { 1185 array[((*iter)->*index)] = (*iter); 1159 1186 } 1160 1187 };
Note:
See TracChangeset
for help on using the changeset viewer.