Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/molecule.cpp

    r7baf4a rf17e1c  
    151151molecule::const_iterator molecule::erase( const_iterator loc )
    152152{
    153   OBSERVE;
    154153  molecule::const_iterator iter = loc;
    155154  iter--;
     
    157156  atomIds.erase( atom->getId() );
    158157  atoms.remove( atom );
    159   formula-=atom->type;
    160158  atom->removeFromMolecule();
    161159  return iter;
     
    164162molecule::const_iterator molecule::erase( atom * key )
    165163{
    166   OBSERVE;
    167164  molecule::const_iterator iter = find(key);
    168165  if (iter != end()){
    169166    atomIds.erase( key->getId() );
    170167    atoms.remove( key );
    171     formula-=key->type;
    172168    key->removeFromMolecule();
    173169  }
     
    187183pair<molecule::iterator,bool> molecule::insert ( atom * const key )
    188184{
    189   OBSERVE;
    190185  pair<atomIdSet::iterator,bool> res = atomIds.insert(key->getId());
    191186  if (res.second) { // push atom if went well
    192187    atoms.push_back(key);
    193     formula+=key->type;
    194188    return pair<iterator,bool>(molecule::iterator(--end()),res.second);
    195189  } else {
     
    239233  if (pointer != NULL) {
    240234    atom *walker = pointer->clone();
    241     formula += walker->type;
    242235    walker->setName(pointer->getName());
    243236    walker->nr = last_atom++;  // increase number within molecule
     
    626619{
    627620  molecule *copy = World::getInstance().createMolecule();
     621  atom *LeftAtom = NULL, *RightAtom = NULL;
    628622
    629623  // copy all atoms
    630   for_each(atoms.begin(),atoms.end(),bind1st(mem_fun(&molecule::AddCopyAtom),copy));
     624  ActOnCopyWithEachAtom ( &molecule::AddCopyAtom, copy );
    631625
    632626  // copy all bonds
     627  bond *Binder = NULL;
     628  bond *NewBond = NULL;
    633629  for(molecule::iterator AtomRunner = begin(); AtomRunner != end(); ++AtomRunner)
    634630    for(BondList::iterator BondRunner = (*AtomRunner)->ListOfBonds.begin(); !(*AtomRunner)->ListOfBonds.empty(); BondRunner = (*AtomRunner)->ListOfBonds.begin())
    635631      if ((*BondRunner)->leftatom == *AtomRunner) {
    636         bond *Binder = (*BondRunner);
     632        Binder = (*BondRunner);
    637633
    638634        // 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);
    647639        NewBond->Cyclic = Binder->Cyclic;
    648640        if (Binder->Cyclic)
     
    651643      }
    652644  // correct fathers
    653   for_each(atoms.begin(),atoms.end(),mem_fun(&atom::CorrectFather));
     645  ActOnAllAtoms( &atom::CorrectFather );
    654646
    655647  // copy values
     
    860852 * \param *out output stream
    861853 */
    862 bool molecule::Output(ostream * const output)
    863 {
     854bool 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  }
    864862  if (output == NULL) {
    865863    return false;
    866864  } 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     }
    874865    *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 );
    876873    return true;
    877874  }
     
    916913{
    917914  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 );
    919916  DoLog(0) && (Log() << Verbose(0) << endl);
    920917};
     
    939936    for (int step=0;step<MDSteps;step++) {
    940937      *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 );
    942939    }
    943940    return true;
     
    956953    now = time((time_t *)NULL);   // Get the system time and put it into 'now' as 'calender time'
    957954    *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 );
    959956    return true;
    960957  } else
Note: See TracChangeset for help on using the changeset viewer.