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