Changeset 30c753 for src/molecule.cpp
- Timestamp:
- Dec 28, 2011, 3:25:48 PM (13 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:
- 59fff1
- Parents:
- f99714
- git-author:
- Frederik Heber <heber@…> (12/22/11 13:14:16)
- git-committer:
- Frederik Heber <heber@…> (12/28/11 15:25:48)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/molecule.cpp
rf99714 r30c753 150 150 151 151 molecule::iterator molecule::begin(){ 152 return molecule::iterator(atoms.begin(),this);152 return iterator(atomIds.begin(), FromIdToAtom()); 153 153 } 154 154 155 155 molecule::const_iterator molecule::begin() const{ 156 return atoms.begin();156 return const_iterator(atomIds.begin(), FromIdToAtom()); 157 157 } 158 158 159 159 molecule::iterator molecule::end(){ 160 return molecule::iterator(atoms.end(),this);160 return iterator(atomIds.end(), FromIdToAtom()); 161 161 } 162 162 163 163 molecule::const_iterator molecule::end() const{ 164 return atoms.end();164 return const_iterator(atomIds.end(), FromIdToAtom()); 165 165 } 166 166 167 167 bool molecule::empty() const 168 168 { 169 return ( begin() == end());169 return (atomIds.empty()); 170 170 } 171 171 … … 182 182 OBSERVE; 183 183 molecule::const_iterator iter = loc; 184 iter++;184 ++iter; 185 185 atom* atom = *loc; 186 186 atomIds.erase( atom->getId() ); 187 atoms.remove( atom );188 187 formula-=atom->getType(); 189 188 atom->removeFromMolecule(); … … 196 195 molecule::const_iterator iter = find(key); 197 196 if (iter != end()){ 198 iter++;197 ++iter; 199 198 atomIds.erase( key->getId() ); 200 atoms.remove( key );201 199 formula-=key->getType(); 202 200 key->removeFromMolecule(); … … 207 205 molecule::const_iterator molecule::find ( atom * key ) const 208 206 { 209 molecule::const_iterator iter; 210 for (molecule::const_iterator Runner = begin(); Runner != end(); ++Runner) { 211 if (*Runner == key) 212 return molecule::const_iterator(Runner); 213 } 214 return molecule::const_iterator(atoms.end()); 207 return const_iterator(atomIds.find(key->getId()), FromIdToAtom()); 215 208 } 216 209 … … 220 213 pair<atomIdSet::iterator,bool> res = atomIds.insert(key->getId()); 221 214 if (res.second) { // push atom if went well 222 atoms.push_back(key);223 215 formula+=key->getType(); 224 return pair<iterator,bool>( molecule::iterator(--end()),res.second);216 return pair<iterator,bool>(iterator(res.first, FromIdToAtom()),res.second); 225 217 } else { 226 return pair<iterator,bool>( molecule::iterator(end()),res.second);218 return pair<iterator,bool>(end(),res.second); 227 219 } 228 220 } … … 235 227 { 236 228 World::AtomComposite vector_of_atoms; 237 BOOST_FOREACH(atom *_atom, atoms) 238 vector_of_atoms.push_back(_atom); 229 // std::copy(MyIter(atomIds.begin(), FromIdToAtom()), 230 // MyIter(atomIds.end(), FromIdToAtom()), 231 // vector_of_atoms.begin()); 232 // for (MyIter iter = MyIter(atomIds.begin(), FromIdToAtom()); 233 // iter != MyIter(atomIds.end(), FromIdToAtom()); 234 // ++iter) 235 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) 236 vector_of_atoms.push_back(*iter); 239 237 return vector_of_atoms; 240 238 } … … 635 633 636 634 // copy all atoms 637 for_each(atoms.begin(),atoms.end(),bind1st(mem_fun(&molecule::AddCopyAtom),copy)); 635 std::map< const atom *, atom *> FatherFinder; 636 for (const_iterator iter = begin(); iter != end(); ++iter) { 637 atom *const copy_atom = copy->AddCopyAtom(*iter); 638 FatherFinder.insert( std::make_pair( *iter, copy_atom ) ); 639 } 640 641 // copy all bonds 642 for(const_iterator AtomRunner = begin(); AtomRunner != end(); ++AtomRunner) { 643 const BondList& ListOfBonds = (*AtomRunner)->getListOfBonds(); 644 for(BondList::const_iterator BondRunner = ListOfBonds.begin(); 645 BondRunner != ListOfBonds.end(); 646 ++BondRunner) 647 if ((*BondRunner)->leftatom == *AtomRunner) { 648 bond *Binder = (*BondRunner); 649 // get the pendant atoms of current bond in the copy molecule 650 ASSERT(FatherFinder.count(Binder->leftatom), 651 "molecule::CopyMolecule() - No copy of original left atom for bond copy found"); 652 ASSERT(FatherFinder.count(Binder->rightatom), 653 "molecule::CopyMolecule() - No copy of original right atom for bond copy found"); 654 atom * const LeftAtom = FatherFinder[Binder->leftatom]; 655 atom * const RightAtom = FatherFinder[Binder->rightatom]; 656 657 bond * const NewBond = copy->AddBond(LeftAtom, RightAtom, Binder->BondDegree); 658 NewBond->Cyclic = Binder->Cyclic; 659 if (Binder->Cyclic) 660 copy->NoCyclicBonds++; 661 NewBond->Type = Binder->Type; 662 } 663 } 664 // correct fathers 665 //for_each(begin(),end(),mem_fun(&atom::CorrectFather)); 666 667 return copy; 668 }; 669 670 671 /** Destroys all atoms inside this molecule. 672 */ 673 void molecule::removeAtomsinMolecule() 674 { 675 // remove each atom from world 676 for(const_iterator AtomRunner = begin(); !empty(); AtomRunner = begin()) 677 World::getInstance().destroyAtom(*AtomRunner); 678 }; 679 680 681 /** 682 * Copies all atoms of a molecule which are within the defined parallelepiped. 683 * 684 * @param offest for the origin of the parallelepiped 685 * @param three vectors forming the matrix that defines the shape of the parallelpiped 686 */ 687 molecule* molecule::CopyMoleculeFromSubRegion(const Shape ®ion) const { 688 molecule *copy = World::getInstance().createMolecule(); 689 690 // copy all atoms 691 std::map< const atom *, atom *> FatherFinder; 692 for (const_iterator iter = begin(); iter != end(); ++iter) { 693 if((*iter)->IsInShape(region)){ 694 atom *const copy_atom = copy->AddCopyAtom(*iter); 695 FatherFinder.insert( std::make_pair( *iter, copy_atom ) ); 696 } 697 } 638 698 639 699 // copy all bonds … … 645 705 if ((*BondRunner)->leftatom == *AtomRunner) { 646 706 bond *Binder = (*BondRunner); 647 // get the pendant atoms of current bond in the copy molecule 648 atomSet::iterator leftiter=find_if(copy->atoms.begin(),copy->atoms.end(),bind2nd(mem_fun(&atom::isFather),Binder->leftatom)); 649 atomSet::iterator rightiter=find_if(copy->atoms.begin(),copy->atoms.end(),bind2nd(mem_fun(&atom::isFather),Binder->rightatom)); 650 ASSERT(leftiter!=copy->atoms.end(),"No copy of original left atom for bond copy found"); 651 ASSERT(leftiter!=copy->atoms.end(),"No copy of original right atom for bond copy found"); 652 atom *LeftAtom = *leftiter; 653 atom *RightAtom = *rightiter; 654 655 bond *NewBond = copy->AddBond(LeftAtom, RightAtom, Binder->BondDegree); 656 NewBond->Cyclic = Binder->Cyclic; 657 if (Binder->Cyclic) 658 copy->NoCyclicBonds++; 659 NewBond->Type = Binder->Type; 707 if ((FatherFinder.count(Binder->leftatom)) 708 && (FatherFinder.count(Binder->rightatom))) { 709 // if copy present, then it must be from subregion 710 atom * const LeftAtom = FatherFinder[Binder->leftatom]; 711 atom * const RightAtom = FatherFinder[Binder->rightatom]; 712 713 bond * const NewBond = copy->AddBond(LeftAtom, RightAtom, Binder->BondDegree); 714 NewBond->Cyclic = Binder->Cyclic; 715 if (Binder->Cyclic) 716 copy->NoCyclicBonds++; 717 NewBond->Type = Binder->Type; 718 } 660 719 } 661 720 } 662 721 // correct fathers 663 //for_each(atoms.begin(),atoms.end(),mem_fun(&atom::CorrectFather)); 664 665 return copy; 666 }; 667 668 669 /** Destroys all atoms inside this molecule. 670 */ 671 void molecule::removeAtomsinMolecule() 672 { 673 // remove each atom from world 674 for(molecule::const_iterator AtomRunner = begin(); !empty(); AtomRunner = begin()) 675 World::getInstance().destroyAtom(*AtomRunner); 676 }; 677 678 679 /** 680 * Copies all atoms of a molecule which are within the defined parallelepiped. 681 * 682 * @param offest for the origin of the parallelepiped 683 * @param three vectors forming the matrix that defines the shape of the parallelpiped 684 */ 685 molecule* molecule::CopyMoleculeFromSubRegion(const Shape ®ion) const { 686 molecule *copy = World::getInstance().createMolecule(); 687 688 BOOST_FOREACH(atom *iter,atoms){ 689 if(iter->IsInShape(region)){ 690 copy->AddCopyAtom(iter); 691 } 692 } 722 //for_each(begin(),end(),mem_fun(&atom::CorrectFather)); 693 723 694 724 //TODO: copy->BuildInducedSubgraph(this); … … 878 908 enumeration<const element*> elementLookup = formula.enumerateElements(); 879 909 *output << "#Ion_TypeNr._Nr.R[0] R[1] R[2] MoveType (0 MoveIon, 1 FixedIon)" << endl; 880 for_each( atoms.begin(),atoms.end(),boost::bind(&atom::OutputArrayIndexed,_1,output,elementLookup,AtomNo,(const char*)0));910 for_each(begin(),end(),boost::bind(&atom::OutputArrayIndexed,_1,output,elementLookup,AtomNo,(const char*)0)); 881 911 return true; 882 912 } … … 900 930 memset(AtomNo,0,(MAX_ELEMENTS-1)*sizeof(*AtomNo)); 901 931 enumeration<const element*> elementLookup = formula.enumerateElements(); 902 for_each( atoms.begin(),atoms.end(),boost::bind(&atom::OutputTrajectory,_1,output,elementLookup, AtomNo, (const int)step));932 for_each(begin(),end(),boost::bind(&atom::OutputTrajectory,_1,output,elementLookup, AtomNo, (const int)step)); 903 933 } 904 934 return true; … … 941 971 for (int step=0;step<MDSteps;step++) { 942 972 *output << getAtomCount() << "\n\tCreated by molecuilder, step " << step << ", on " << ctime(&now); 943 for_each( atoms.begin(),atoms.end(),boost::bind(&atom::OutputTrajectoryXYZ,_1,output,step));973 for_each(begin(),end(),boost::bind(&atom::OutputTrajectoryXYZ,_1,output,step)); 944 974 } 945 975 return true; … … 958 988 now = time((time_t *)NULL); // Get the system time and put it into 'now' as 'calender time' 959 989 *output << getAtomCount() << "\n\tCreated by molecuilder on " << ctime(&now); 960 for_each( atoms.begin(),atoms.end(),bind2nd(mem_fun(&atom::OutputXYZLine),output));990 for_each(begin(),end(),bind2nd(mem_fun(&atom::OutputXYZLine),output)); 961 991 return true; 962 992 } else … … 972 1002 int i = 0; 973 1003 NoNonHydrogen = 0; 974 for (molecule::const_iterator iter = atoms.begin(); iter != atoms.end(); ++iter) {1004 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { 975 1005 (*iter)->setNr(i); // update number in molecule (for easier referencing in FragmentMolecule lateron) 976 1006 if ((*iter)->getType()->getAtomicNumber() != 1) // count non-hydrogen atoms whilst at it
Note:
See TracChangeset
for help on using the changeset viewer.