Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/molecule.cpp

    r43dad6 r274d45  
    44 *
    55 */
     6
     7#include "Helpers/MemDebug.hpp"
    68
    79#include <cstring>
     
    3537 * Initialises molecule list with correctly referenced start and end, and sets molecule::last_atom to zero.
    3638 */
    37 molecule::molecule(const periodentafel * const teil) : elemente(teil),
    38   MDSteps(0),
    39   BondCount(0), ElementCount(0), NoNonHydrogen(0), NoNonBonds(0), NoCyclicBonds(0), BondDistance(0.),
    40   ActiveFlag(false), IndexNr(-1),
    41   formula(this,boost::bind(&molecule::calcFormula,this)),
    42   AtomCount(this,boost::bind(&molecule::doCountAtoms,this)), last_atom(0),  InternalPointer(begin())
     39molecule::molecule(const periodentafel * const teil) :
     40  Observable("molecule"),
     41  elemente(teil),  MDSteps(0),  BondCount(0), ElementCount(0), NoNonHydrogen(0), NoNonBonds(0),
     42  NoCyclicBonds(0), BondDistance(0.),  ActiveFlag(false), IndexNr(-1),
     43  formula(this,boost::bind(&molecule::calcFormula,this),"formula"),
     44  AtomCount(this,boost::bind(&molecule::doCountAtoms,this),"AtomCount"), last_atom(0),  InternalPointer(atoms.begin())
    4345{
    4446
     
    143145  molecule::const_iterator iter = loc;
    144146  iter--;
    145   atoms.erase( loc );
     147  atom* atom = *loc;
     148  atomIds.erase( atom->getId() );
     149  atoms.remove( atom );
     150  atom->removeFromMolecule();
    146151  return iter;
    147152}
    148153
    149 molecule::const_iterator molecule::erase( atom *& key )
     154molecule::const_iterator molecule::erase( atom * key )
    150155{
    151156  cout << "trying to erase atom" << endl;
    152157  molecule::const_iterator iter = find(key);
    153158  if (iter != end()){
    154     // remove this position and step forward (post-increment)
    155     atoms.erase( iter++ );
     159    atomIds.erase( key->getId() );
     160    atoms.remove( key );
     161    key->removeFromMolecule();
    156162  }
    157163  return iter;
    158164}
    159165
    160 molecule::const_iterator molecule::find ( atom *& key ) const
    161 {
    162   return atoms.find( key );
     166molecule::const_iterator molecule::find ( atom * key ) const
     167{
     168  molecule::const_iterator iter;
     169  for (molecule::const_iterator Runner = begin(); Runner != end(); ++Runner) {
     170    if (*Runner == key)
     171      return molecule::const_iterator(Runner);
     172  }
     173  return molecule::const_iterator(atoms.end());
    163174}
    164175
    165176pair<molecule::iterator,bool> molecule::insert ( atom * const key )
    166177{
    167   pair<atomSet::iterator,bool> res = atoms.insert(key);
    168   return pair<iterator,bool>(iterator(res.first,this),res.second);
     178  pair<atomIdSet::iterator,bool> res = atomIds.insert(key->getId());
     179  if (res.second) { // push atom if went well
     180    atoms.push_back(key);
     181    return pair<iterator,bool>(molecule::iterator(--end()),res.second);
     182  } else {
     183    return pair<iterator,bool>(molecule::iterator(end()),res.second);
     184  }
     185}
     186
     187bool molecule::containsAtom(atom* key){
     188  return (find(key) != end());
    169189}
    170190
     
    192212    }
    193213    insert(pointer);
     214    pointer->setMolecule(this);
    194215  }
    195216  return true;
     
    657678bond * molecule::AddBond(atom *atom1, atom *atom2, int degree)
    658679{
     680  OBSERVE;
    659681  bond *Binder = NULL;
    660682
     
    780802  for (molecule::iterator iter = begin(); !empty(); iter = begin())
    781803      erase(iter);
     804  return empty();
    782805};
    783806
     
    858881        ElementNo[i] = current++;
    859882    }
    860     ActOnAllAtoms( &atom::OutputArrayIndexed, (ostream * const) output, (const int *)ElementNo, (int *)AtomNo, (const char *) NULL );
     883    ActOnAllAtoms( &atom::OutputArrayIndexed, output, (const int *)ElementNo, (int *)AtomNo, (const char *) NULL );
    861884    return true;
    862885  }
     
    10001023  configuration.MaxPsiDouble /= 2;
    10011024  configuration.PsiType = (configuration.PsiMaxNoDown == configuration.PsiMaxNoUp) ? 0 : 1;
    1002   if ((configuration.PsiType == 1) && (configuration.ProcPEPsi < 2)) {
     1025  if ((configuration.PsiType == 1) && (configuration.ProcPEPsi < 2) && ((configuration.PsiMaxNoDown != 1) || (configuration.PsiMaxNoUp != 0))) {
    10031026    configuration.ProcPEGamma /= 2;
    10041027    configuration.ProcPEPsi *= 2;
     
    10071030    configuration.ProcPEPsi = 1;
    10081031  }
    1009   configuration.InitMaxMinStopStep = configuration.MaxMinStopStep = configuration.MaxPsiDouble;
     1032  cout << configuration.PsiMaxNoDown << ">" << configuration.PsiMaxNoUp << endl;
     1033  if (configuration.PsiMaxNoDown > configuration.PsiMaxNoUp) {
     1034    configuration.InitMaxMinStopStep = configuration.MaxMinStopStep = configuration.PsiMaxNoDown;
     1035    cout << configuration.PsiMaxNoDown << " " << configuration.InitMaxMinStopStep << endl;
     1036  } else {
     1037    configuration.InitMaxMinStopStep = configuration.MaxMinStopStep = configuration.PsiMaxNoUp;
     1038    cout << configuration.PsiMaxNoUp << " " << configuration.InitMaxMinStopStep << endl;
     1039  }
    10101040};
    10111041
Note: See TracChangeset for help on using the changeset viewer.