Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/atom.cpp

    r1b2d30 rad2b411  
    44 *
    55 */
     6
     7#include "Helpers/MemDebug.hpp"
    68
    79#include "atom.hpp"
     
    1416#include "vector.hpp"
    1517#include "World.hpp"
     18#include "molecule.hpp"
    1619
    1720/************************************* Functions for class atom *************************************/
     
    2124 */
    2225atom::atom() :
    23   previous(NULL), next(NULL), father(this), sort(&nr)
     26  father(this), sort(&nr), mol(0)
    2427{
    2528  node = &x;  // TesselPoint::x can only be referenced from here
     
    2932 */
    3033atom::atom(atom *pointer) :
    31     ParticleInfo(pointer),
    32     previous(NULL), next(NULL), father(pointer), sort(&nr)
     34    ParticleInfo(pointer),father(pointer), sort(&nr)
    3335{
    3436  type = pointer->type;  // copy element of atom
     
    3739  FixedIon = pointer->FixedIon;
    3840  node = &x;
     41  mol = 0;
    3942};
    4043
    4144atom *atom::clone(){
    4245  atom *res = new atom(this);
    43   res->previous=0;
    44   res->next=0;
    4546  res->father = this;
    4647  res->sort = &res->nr;
     
    5051  res->FixedIon = FixedIon;
    5152  res->node = &x;
     53  res->mol = 0;
    5254  World::getInstance().registerAtom(res);
    5355  return res;
     
    5961atom::~atom()
    6062{
     63  removeFromMolecule();
     64  for(BondList::iterator iter=ListOfBonds.begin(); iter!=ListOfBonds.end();){
     65    // deleting the bond will invalidate the iterator !!!
     66    bond *bond =*(iter++);
     67    delete(bond);
     68  }
    6169};
    6270
     
    6775atom *atom::GetTrueFather()
    6876{
    69   atom *walker = this;
    70   do {
    71     if (walker == walker->father) // top most father is the one that points on itself
    72       break;
    73     walker = walker->father;
    74   } while (walker != NULL);
    75   return walker;
     77  if(father == this){ // top most father is the one that points on itself
     78    return this;
     79  }
     80  else if(!father) {
     81    return 0;
     82  }
     83  else {
     84    return father->GetTrueFather();
     85  }
    7686};
    7787
     
    149159  * \return true - \a *out present, false - \a *out is NULL
    150160 */
    151 bool atom::OutputArrayIndexed(ostream * const out, const int *ElementNo, int *AtomNo, const char *comment) const
     161bool atom::OutputArrayIndexed(ofstream * const out, const int *ElementNo, int *AtomNo, const char *comment) const
    152162{
    153163  AtomNo[type->Z]++;  // increment number
     
    226236 * \param *AtomNo pointer to atom counter that is increased by one
    227237 */
    228 void atom::OutputMPQCLine(ostream * const out, const Vector *center, int *AtomNo = NULL) const
     238void atom::OutputMPQCLine(ofstream * const out, const Vector *center, int *AtomNo = NULL) const
    229239{
    230240  *out << "\t\t" << type->symbol << " [ " << x[0]-center->at(0) << "\t" << x[1]-center->at(1) << "\t" << x[2]-center->at(2) << " ]" << endl;
     
    305315}
    306316
    307 atomId_t atom::getId() {
     317atomId_t atom::getId() const {
    308318  return id;
    309319}
     320
     321void atom::setMolecule(molecule *_mol){
     322  // take this atom from the old molecule
     323  removeFromMolecule();
     324  mol = _mol;
     325  if(!mol->containsAtom(this)){
     326    mol->AddAtom(this);
     327  }
     328}
     329
     330void atom::removeFromMolecule(){
     331  if(mol){
     332    if(mol->containsAtom(this)){
     333      mol->erase(this);
     334    }
     335    mol=0;
     336  }
     337}
     338
    310339
    311340atom* NewAtom(atomId_t _id){
Note: See TracChangeset for help on using the changeset viewer.