Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/molecule.cpp

    rf17e1c r7baf4a  
    151151molecule::const_iterator molecule::erase( const_iterator loc )
    152152{
     153  OBSERVE;
    153154  molecule::const_iterator iter = loc;
    154155  iter--;
     
    156157  atomIds.erase( atom->getId() );
    157158  atoms.remove( atom );
     159  formula-=atom->type;
    158160  atom->removeFromMolecule();
    159161  return iter;
     
    162164molecule::const_iterator molecule::erase( atom * key )
    163165{
     166  OBSERVE;
    164167  molecule::const_iterator iter = find(key);
    165168  if (iter != end()){
    166169    atomIds.erase( key->getId() );
    167170    atoms.remove( key );
     171    formula-=key->type;
    168172    key->removeFromMolecule();
    169173  }
     
    183187pair<molecule::iterator,bool> molecule::insert ( atom * const key )
    184188{
     189  OBSERVE;
    185190  pair<atomIdSet::iterator,bool> res = atomIds.insert(key->getId());
    186191  if (res.second) { // push atom if went well
    187192    atoms.push_back(key);
     193    formula+=key->type;
    188194    return pair<iterator,bool>(molecule::iterator(--end()),res.second);
    189195  } else {
     
    233239  if (pointer != NULL) {
    234240    atom *walker = pointer->clone();
     241    formula += walker->type;
    235242    walker->setName(pointer->getName());
    236243    walker->nr = last_atom++;  // increase number within molecule
     
    619626{
    620627  molecule *copy = World::getInstance().createMolecule();
    621   atom *LeftAtom = NULL, *RightAtom = NULL;
    622628
    623629  // copy all atoms
    624   ActOnCopyWithEachAtom ( &molecule::AddCopyAtom, copy );
     630  for_each(atoms.begin(),atoms.end(),bind1st(mem_fun(&molecule::AddCopyAtom),copy));
    625631
    626632  // copy all bonds
    627   bond *Binder = NULL;
    628   bond *NewBond = NULL;
    629633  for(molecule::iterator AtomRunner = begin(); AtomRunner != end(); ++AtomRunner)
    630634    for(BondList::iterator BondRunner = (*AtomRunner)->ListOfBonds.begin(); !(*AtomRunner)->ListOfBonds.empty(); BondRunner = (*AtomRunner)->ListOfBonds.begin())
    631635      if ((*BondRunner)->leftatom == *AtomRunner) {
    632         Binder = (*BondRunner);
     636        bond *Binder = (*BondRunner);
    633637
    634638        // 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);
    639647        NewBond->Cyclic = Binder->Cyclic;
    640648        if (Binder->Cyclic)
     
    643651      }
    644652  // correct fathers
    645   ActOnAllAtoms( &atom::CorrectFather );
     653  for_each(atoms.begin(),atoms.end(),mem_fun(&atom::CorrectFather));
    646654
    647655  // copy values
     
    852860 * \param *out output stream
    853861 */
    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   }
     862bool molecule::Output(ostream * const output)
     863{
    862864  if (output == NULL) {
    863865    return false;
    864866  } 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    }
    865874    *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));
    873876    return true;
    874877  }
     
    913916{
    914917  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));
    916919  DoLog(0) && (Log() << Verbose(0) << endl);
    917920};
     
    936939    for (int step=0;step<MDSteps;step++) {
    937940      *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));
    939942    }
    940943    return true;
     
    953956    now = time((time_t *)NULL);   // Get the system time and put it into 'now' as 'calender time'
    954957    *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));
    956959    return true;
    957960  } else
Note: See TracChangeset for help on using the changeset viewer.