Changes in src/molecule.cpp [7baf4a:f17e1c]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/molecule.cpp
r7baf4a rf17e1c 151 151 molecule::const_iterator molecule::erase( const_iterator loc ) 152 152 { 153 OBSERVE;154 153 molecule::const_iterator iter = loc; 155 154 iter--; … … 157 156 atomIds.erase( atom->getId() ); 158 157 atoms.remove( atom ); 159 formula-=atom->type;160 158 atom->removeFromMolecule(); 161 159 return iter; … … 164 162 molecule::const_iterator molecule::erase( atom * key ) 165 163 { 166 OBSERVE;167 164 molecule::const_iterator iter = find(key); 168 165 if (iter != end()){ 169 166 atomIds.erase( key->getId() ); 170 167 atoms.remove( key ); 171 formula-=key->type;172 168 key->removeFromMolecule(); 173 169 } … … 187 183 pair<molecule::iterator,bool> molecule::insert ( atom * const key ) 188 184 { 189 OBSERVE;190 185 pair<atomIdSet::iterator,bool> res = atomIds.insert(key->getId()); 191 186 if (res.second) { // push atom if went well 192 187 atoms.push_back(key); 193 formula+=key->type;194 188 return pair<iterator,bool>(molecule::iterator(--end()),res.second); 195 189 } else { … … 239 233 if (pointer != NULL) { 240 234 atom *walker = pointer->clone(); 241 formula += walker->type;242 235 walker->setName(pointer->getName()); 243 236 walker->nr = last_atom++; // increase number within molecule … … 626 619 { 627 620 molecule *copy = World::getInstance().createMolecule(); 621 atom *LeftAtom = NULL, *RightAtom = NULL; 628 622 629 623 // copy all atoms 630 for_each(atoms.begin(),atoms.end(),bind1st(mem_fun(&molecule::AddCopyAtom),copy));624 ActOnCopyWithEachAtom ( &molecule::AddCopyAtom, copy ); 631 625 632 626 // copy all bonds 627 bond *Binder = NULL; 628 bond *NewBond = NULL; 633 629 for(molecule::iterator AtomRunner = begin(); AtomRunner != end(); ++AtomRunner) 634 630 for(BondList::iterator BondRunner = (*AtomRunner)->ListOfBonds.begin(); !(*AtomRunner)->ListOfBonds.empty(); BondRunner = (*AtomRunner)->ListOfBonds.begin()) 635 631 if ((*BondRunner)->leftatom == *AtomRunner) { 636 bond *Binder = (*BondRunner);632 Binder = (*BondRunner); 637 633 638 634 // get the pendant atoms of current bond in the copy molecule 639 atomSet::iterator leftiter=find_if(atoms.begin(),atoms.end(),bind2nd(mem_fun(&atom::isFather),Binder->leftatom)); 640 atomSet::iterator rightiter=find_if(atoms.begin(),atoms.end(),bind2nd(mem_fun(&atom::isFather),Binder->rightatom)); 641 ASSERT(leftiter!=atoms.end(),"No original left atom for bondcopy found"); 642 ASSERT(leftiter!=atoms.end(),"No original right atom for bondcopy found"); 643 atom *LeftAtom = *leftiter; 644 atom *RightAtom = *rightiter; 645 646 bond *NewBond = copy->AddBond(LeftAtom, RightAtom, Binder->BondDegree); 635 copy->ActOnAllAtoms( &atom::EqualsFather, (const atom *)Binder->leftatom, (const atom **)&LeftAtom ); 636 copy->ActOnAllAtoms( &atom::EqualsFather, (const atom *)Binder->rightatom, (const atom **)&RightAtom ); 637 638 NewBond = copy->AddBond(LeftAtom, RightAtom, Binder->BondDegree); 647 639 NewBond->Cyclic = Binder->Cyclic; 648 640 if (Binder->Cyclic) … … 651 643 } 652 644 // correct fathers 653 for_each(atoms.begin(),atoms.end(),mem_fun(&atom::CorrectFather));645 ActOnAllAtoms( &atom::CorrectFather ); 654 646 655 647 // copy values … … 860 852 * \param *out output stream 861 853 */ 862 bool molecule::Output(ostream * const output) 863 { 854 bool molecule::Output(ofstream * const output) 855 { 856 int ElementNo[MAX_ELEMENTS], AtomNo[MAX_ELEMENTS]; 857 858 for (int i=0;i<MAX_ELEMENTS;++i) { 859 AtomNo[i] = 0; 860 ElementNo[i] = 0; 861 } 864 862 if (output == NULL) { 865 863 return false; 866 864 } else { 867 int AtomNo[MAX_ELEMENTS];868 memset(AtomNo,0,(MAX_ELEMENTS-1)*sizeof(*AtomNo));869 enumeration<const element*> elementLookup = formula.enumerateElements();870 for(map<const element*,unsigned int>::iterator iter=elementLookup.there.begin();871 iter!=elementLookup.there.end();++iter){872 cout << "Enumerated element " << *iter->first << " with number " << iter->second << endl;873 }874 865 *output << "#Ion_TypeNr._Nr.R[0] R[1] R[2] MoveType (0 MoveIon, 1 FixedIon)" << endl; 875 for_each(atoms.begin(),atoms.end(),boost::bind(&atom::OutputArrayIndexed,_1,output,elementLookup,AtomNo,(const char*)0)); 866 SetIndexedArrayForEachAtomTo ( ElementNo, &element::Z, &AbsoluteValue, 1); 867 int current=1; 868 for (int i=0;i<MAX_ELEMENTS;++i) { 869 if (ElementNo[i] == 1) 870 ElementNo[i] = current++; 871 } 872 ActOnAllAtoms( &atom::OutputArrayIndexed, (ostream * const) output, (const int *)ElementNo, (int *)AtomNo, (const char *) NULL ); 876 873 return true; 877 874 } … … 916 913 { 917 914 DoLog(2) && (Log() << Verbose(2) << endl << "From Contents of ListOfBonds, all non-hydrogen atoms:" << endl); 918 for_each(atoms.begin(),atoms.end(),mem_fun(&atom::OutputBondOfAtom));915 ActOnAllAtoms (&atom::OutputBondOfAtom ); 919 916 DoLog(0) && (Log() << Verbose(0) << endl); 920 917 }; … … 939 936 for (int step=0;step<MDSteps;step++) { 940 937 *output << getAtomCount() << "\n\tCreated by molecuilder, step " << step << ", on " << ctime(&now); 941 for_each(atoms.begin(),atoms.end(),boost::bind(&atom::OutputTrajectoryXYZ,_1,output,step));938 ActOnAllAtoms( &atom::OutputTrajectoryXYZ, output, step ); 942 939 } 943 940 return true; … … 956 953 now = time((time_t *)NULL); // Get the system time and put it into 'now' as 'calender time' 957 954 *output << getAtomCount() << "\n\tCreated by molecuilder on " << ctime(&now); 958 for_each(atoms.begin(),atoms.end(),bind2nd(mem_fun(&atom::OutputXYZLine),output));955 ActOnAllAtoms( &atom::OutputXYZLine, output ); 959 956 return true; 960 957 } else
Note:
See TracChangeset
for help on using the changeset viewer.