Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • molecuilder/src/molecules.cpp

    • Property mode changed from 100644 to 100755
    rf5d7e1 r848729  
    11/** \file molecules.cpp
    2  * 
     2 *
    33 * Functions for the class molecule.
    4  * 
     4 *
    55 */
    66
     
    2525      sum += (gsl_vector_get(x,j) - (vectors[i])->x[j])*(gsl_vector_get(x,j) - (vectors[i])->x[j]);
    2626  }
    27  
     27
    2828  return sum;
    2929};
     
    3434 * Initialises molecule list with correctly referenced start and end, and sets molecule::last_atom to zero.
    3535 */
    36 molecule::molecule(periodentafel *teil) 
    37 { 
     36molecule::molecule(periodentafel *teil)
     37{
    3838  // init atom chain list
    39   start = new atom; 
     39  start = new atom;
    4040  end = new atom;
    41   start->father = NULL; 
     41  start->father = NULL;
    4242  end->father = NULL;
    4343  link(start,end);
     
    4646  last = new bond(start, end, 1, -1);
    4747  link(first,last);
    48   // other stuff 
     48  // other stuff
    4949  MDSteps = 0;
    50   last_atom = 0; 
     50  last_atom = 0;
    5151  elemente = teil;
    5252  AtomCount = 0;
     
    6767 * Initialises molecule list with correctly referenced start and end, and sets molecule::last_atom to zero.
    6868 */
    69 molecule::~molecule() 
     69molecule::~molecule()
    7070{
    7171  if (ListOfBondsPerAtom != NULL)
     
    7878  delete(last);
    7979  delete(end);
    80   delete(start); 
     80  delete(start);
    8181};
    8282
    8383/** Adds given atom \a *pointer from molecule list.
    84  * Increases molecule::last_atom and gives last number to added atom and names it according to its element::abbrev and molecule::AtomCount 
     84 * Increases molecule::last_atom and gives last number to added atom and names it according to its element::abbrev and molecule::AtomCount
    8585 * \param *pointer allocated and set atom
    8686 * \return true - succeeded, false - atom not found in list
    8787 */
    8888bool molecule::AddAtom(atom *pointer)
    89 { 
     89{
    9090  if (pointer != NULL) {
    91     pointer->sort = &pointer->nr; 
     91    pointer->sort = &pointer->nr;
    9292    pointer->nr = last_atom++;  // increase number within molecule
    9393    AtomCount++;
     
    106106    return add(pointer, end);
    107107  } else
    108     return false; 
     108    return false;
    109109};
    110110
     
    115115 */
    116116atom * molecule::AddCopyAtom(atom *pointer)
    117 { 
     117{
    118118  if (pointer != NULL) {
    119119        atom *walker = new atom();
     
    122122    walker->v.CopyVector(&pointer->v); // copy velocity
    123123    walker->FixedIon = pointer->FixedIon;
    124     walker->sort = &walker->nr; 
     124    walker->sort = &walker->nr;
    125125    walker->nr = last_atom++;  // increase number within molecule
    126126    walker->father = pointer; //->GetTrueFather();
     
    133133    return walker;
    134134  } else
    135     return NULL; 
     135    return NULL;
    136136};
    137137
     
    156156 *    The lengths for these are \f$f\f$ and \f$g\f$ (from triangle H1-H2-(center of H1-H2-H3)) with knowledge that
    157157 *    the median lines in an isosceles triangle meet in the center point with a ratio 2:1.
    158  *    \f[ f = \frac{b}{\sqrt{3}} \qquad g = \frac{b}{2} 
     158 *    \f[ f = \frac{b}{\sqrt{3}} \qquad g = \frac{b}{2}
    159159 *    \f]
    160  *    as the coordination of all three atoms in the coordinate system of these three vectors: 
     160 *    as the coordination of all three atoms in the coordinate system of these three vectors:
    161161 *    \f$\pmatrix{d & f & 0}\f$, \f$\pmatrix{d & -0.5 \cdot f & g}\f$ and \f$\pmatrix{d & -0.5 \cdot f & -g}\f$.
    162  * 
     162 *
    163163 * \param *out output stream for debugging
    164  * \param *Bond pointer to bond between \a *origin and \a *replacement 
    165  * \param *TopOrigin son of \a *origin of upper level molecule (the atom added to this molecule as a copy of \a *origin) 
     164 * \param *Bond pointer to bond between \a *origin and \a *replacement
     165 * \param *TopOrigin son of \a *origin of upper level molecule (the atom added to this molecule as a copy of \a *origin)
    166166 * \param *origin pointer to atom which acts as the origin for scaling the added hydrogen to correct bond length
    167167 * \param *replacement pointer to the atom which shall be copied as a hydrogen atom in this molecule
     
    191191  InBondvector.SubtractVector(&TopOrigin->x);
    192192  bondlength = InBondvector.Norm();
    193    
     193
    194194   // is greater than typical bond distance? Then we have to correct periodically
    195195   // the problem is not the H being out of the box, but InBondvector have the wrong direction
    196    // due to TopReplacement or Origin being on the wrong side! 
    197   if (bondlength > BondDistance) { 
     196   // due to TopReplacement or Origin being on the wrong side!
     197  if (bondlength > BondDistance) {
    198198//    *out << Verbose(4) << "InBondvector is: ";
    199199//    InBondvector.Output(out);
     
    215215//    *out << endl;
    216216  } // periodic correction finished
    217  
     217
    218218  InBondvector.Normalize();
    219219  // get typical bond length and store as scale factor for later
     
    222222    cerr << Verbose(3) << "ERROR: There is no typical hydrogen bond distance in replacing bond (" << TopOrigin->Name << "<->" << TopReplacement->Name << ") of degree " << TopBond->BondDegree << "!" << endl;
    223223    return false;
    224     BondRescale = bondlength; 
     224    BondRescale = bondlength;
    225225  } else {
    226226    if (!IsAngstroem)
     
    273273      if (FirstOtherAtom != NULL) { // then we just have this double bond and the plane does not matter at all
    274274//        *out << Verbose(3) << "Regarding the double bond (" << TopOrigin->Name << "<->" << TopReplacement->Name << ") to be constructed: Taking " << FirstOtherAtom->Name << " and " << SecondOtherAtom->Name << " along with " << TopOrigin->Name << " to determine orthogonal plane." << endl;
    275        
     275
    276276        // determine the plane of these two with the *origin
    277277        AllWentWell = AllWentWell && Orthovector1.MakeNormalVector(&TopOrigin->x, &FirstOtherAtom->x, &SecondOtherAtom->x);
     
    286286      Orthovector1.Normalize();
    287287      //*out << Verbose(3) << "ReScaleCheck: " << Orthovector1.Norm() << " and " << InBondvector.Norm() << "." << endl;
    288      
     288
    289289      // create the two Hydrogens ...
    290290      FirstOtherAtom = new atom();
     
    318318        SecondOtherAtom->x.x[i] = InBondvector.x[i] * cos(bondangle) + Orthovector1.x[i] * (-sin(bondangle));
    319319      }
    320       FirstOtherAtom->x.Scale(&BondRescale);  // rescale by correct BondDistance 
     320      FirstOtherAtom->x.Scale(&BondRescale);  // rescale by correct BondDistance
    321321      SecondOtherAtom->x.Scale(&BondRescale);
    322322      //*out << Verbose(3) << "ReScaleCheck: " << FirstOtherAtom->x.Norm() << " and " << SecondOtherAtom->x.Norm() << "." << endl;
    323323      for(int i=NDIM;i--;) { // and make relative to origin atom
    324         FirstOtherAtom->x.x[i] += TopOrigin->x.x[i]; 
     324        FirstOtherAtom->x.x[i] += TopOrigin->x.x[i];
    325325        SecondOtherAtom->x.x[i] += TopOrigin->x.x[i];
    326326      }
     
    365365//      *out << endl;
    366366      AllWentWell = AllWentWell && Orthovector2.MakeNormalVector(&InBondvector, &Orthovector1);
    367 //      *out << Verbose(3) << "Orthovector2: "; 
     367//      *out << Verbose(3) << "Orthovector2: ";
    368368//      Orthovector2.Output(out);
    369369//      *out << endl;
    370      
     370
    371371      // create correct coordination for the three atoms
    372372      alpha = (TopOrigin->type->HBondAngle[2])/180.*M_PI/2.;  // retrieve triple bond angle from database
     
    380380      factors[0] = d;
    381381      factors[1] = f;
    382       factors[2] = 0.; 
     382      factors[2] = 0.;
    383383      FirstOtherAtom->x.LinearCombinationOfVectors(&InBondvector, &Orthovector1, &Orthovector2, factors);
    384384      factors[1] = -0.5*f;
    385       factors[2] = g; 
     385      factors[2] = g;
    386386      SecondOtherAtom->x.LinearCombinationOfVectors(&InBondvector, &Orthovector1, &Orthovector2, factors);
    387       factors[2] = -g; 
     387      factors[2] = -g;
    388388      ThirdOtherAtom->x.LinearCombinationOfVectors(&InBondvector, &Orthovector1, &Orthovector2, factors);
    389389
     
    437437 */
    438438bool molecule::AddXYZFile(string filename)
    439 { 
     439{
    440440  istringstream *input = NULL;
    441441  int NumberOfAtoms = 0; // atom number in xyz read
     
    446446  string line;    // currently parsed line
    447447  double x[3];    // atom coordinates
    448  
     448
    449449  xyzfile.open(filename.c_str());
    450450  if (!xyzfile)
     
    454454  input = new istringstream(line);
    455455  *input >> NumberOfAtoms;
    456   cout << Verbose(0) << "Parsing " << NumberOfAtoms << " atoms in file." << endl; 
     456  cout << Verbose(0) << "Parsing " << NumberOfAtoms << " atoms in file." << endl;
    457457  getline(xyzfile,line,'\n'); // Read comment
    458458  cout << Verbose(1) << "Comment: " << line << endl;
    459  
     459
    460460  if (MDSteps == 0) // no atoms yet present
    461461    MDSteps++;
     
    491491  xyzfile.close();
    492492  delete(input);
    493   return true; 
     493  return true;
    494494};
    495495
     
    503503  atom *LeftAtom = NULL, *RightAtom = NULL;
    504504  atom *Walker = NULL;
    505  
     505
    506506  // copy all atoms
    507507  Walker = start;
     
    510510    CurrentAtom = copy->AddCopyAtom(Walker);
    511511  }
    512  
     512
    513513  // copy all bonds
    514514  bond *Binder = first;
     
    534534      copy->NoCyclicBonds++;
    535535    NewBond->Type = Binder->Type;
    536   } 
     536  }
    537537  // correct fathers
    538538  Walker = copy->start;
     
    551551    copy->CreateListOfBondsPerAtom((ofstream *)&cout);
    552552  }
    553  
     553
    554554  return copy;
    555555};
     
    576576
    577577/** Remove bond from bond chain list.
    578  * \todo Function not implemented yet 
     578 * \todo Function not implemented yet
    579579 * \param *pointer bond pointer
    580580 * \return true - bound found and removed, false - bond not found/removed
     
    588588
    589589/** Remove every bond from bond chain list that atom \a *BondPartner is a constituent of.
    590  * \todo Function not implemented yet 
     590 * \todo Function not implemented yet
    591591 * \param *BondPartner atom to be removed
    592592 * \return true - bounds found and removed, false - bonds not found/removed
     
    621621  Vector *min = new Vector;
    622622  Vector *max = new Vector;
    623  
     623
    624624  // gather min and max for each axis
    625625  ptr = start->next;  // start at first in list
     
    667667{
    668668  Vector *min = new Vector;
    669  
     669
    670670//  *out << Verbose(3) << "Begin of CenterEdge." << endl;
    671671  atom *ptr = start->next;  // start at first in list
     
    683683      }
    684684    }
    685 //    *out << Verbose(4) << "Maximum is "; 
     685//    *out << Verbose(4) << "Maximum is ";
    686686//    max->Output(out);
    687687//    *out << ", Minimum is ";
     
    691691    max->AddVector(min);
    692692    Translate(min);
    693   } 
     693  }
    694694  delete(min);
    695695//  *out << Verbose(3) << "End of CenterEdge." << endl;
    696 }; 
     696};
    697697
    698698/** Centers the center of the atoms at (0,0,0).
     
    704704  int Num = 0;
    705705  atom *ptr = start->next;  // start at first in list
    706  
     706
    707707  for(int i=NDIM;i--;) // zero center vector
    708708    center->x[i] = 0.;
    709    
     709
    710710  if (ptr != end) {   //list not empty?
    711711    while (ptr->next != end) {  // continue with second if present
    712712      ptr = ptr->next;
    713713      Num++;
    714       center->AddVector(&ptr->x);       
     714      center->AddVector(&ptr->x);
    715715    }
    716716    center->Scale(-1./Num); // divide through total number (and sign for direction)
    717717    Translate(center);
    718718  }
    719 }; 
     719};
    720720
    721721/** Returns vector pointing to center of gravity.
     
    729729  Vector tmp;
    730730  double Num = 0;
    731  
     731
    732732  a->Zero();
    733733
     
    737737      Num += 1.;
    738738      tmp.CopyVector(&ptr->x);
    739       a->AddVector(&tmp);       
     739      a->AddVector(&tmp);
    740740    }
    741741    a->Scale(-1./Num); // divide through total mass (and sign for direction)
     
    757757        Vector tmp;
    758758  double Num = 0;
    759        
     759
    760760        a->Zero();
    761761
     
    766766      tmp.CopyVector(&ptr->x);
    767767      tmp.Scale(ptr->type->mass);  // scale by mass
    768       a->AddVector(&tmp);       
     768      a->AddVector(&tmp);
    769769    }
    770770    a->Scale(-1./Num); // divide through total mass (and sign for direction)
     
    789789    Translate(center);
    790790  }
    791 }; 
     791};
    792792
    793793/** Scales all atoms by \a *factor.
     
    803803      Trajectories[ptr].R.at(j).Scale(factor);
    804804    ptr->x.Scale(factor);
    805   }     
    806 };
    807 
    808 /** Translate all atoms by given vector. 
     805  }
     806};
     807
     808/** Translate all atoms by given vector.
    809809 * \param trans[] translation vector.
    810810 */
     
    818818      Trajectories[ptr].R.at(j).Translate(trans);
    819819    ptr->x.Translate(trans);
    820   }     
    821 };
    822 
    823 /** Mirrors all atoms against a given plane. 
     820  }
     821};
     822
     823/** Mirrors all atoms against a given plane.
    824824 * \param n[] normal vector of mirror plane.
    825825 */
     
    833833      Trajectories[ptr].R.at(j).Mirror(n);
    834834    ptr->x.Mirror(n);
    835   }     
     835  }
    836836};
    837837
     
    847847  bool flag;
    848848  Vector Testvector, Translationvector;
    849  
     849
    850850  do {
    851851    Center.Zero();
     
    863863          if (Walker->nr < Binder->GetOtherAtom(Walker)->nr) // otherwise we shift one to, the other fro and gain nothing
    864864            for (int j=0;j<NDIM;j++) {
    865               tmp = Walker->x.x[j] - Binder->GetOtherAtom(Walker)->x.x[j]; 
     865              tmp = Walker->x.x[j] - Binder->GetOtherAtom(Walker)->x.x[j];
    866866              if ((fabs(tmp)) > BondDistance) {
    867867                flag = false;
     
    879879        cout << Verbose(1) << "vector is: ";
    880880        Testvector.Output((ofstream *)&cout);
    881         cout << endl;     
     881        cout << endl;
    882882#ifdef ADDHYDROGEN
    883883        // now also change all hydrogens
     
    892892            cout << Verbose(1) << "Hydrogen vector is: ";
    893893            Testvector.Output((ofstream *)&cout);
    894             cout << endl;     
     894            cout << endl;
    895895          }
    896896        }
     
    914914
    915915        CenterGravity(out, CenterOfGravity);
    916        
    917         // reset inertia tensor 
     916
     917        // reset inertia tensor
    918918        for(int i=0;i<NDIM*NDIM;i++)
    919919                InertiaTensor[i] = 0.;
    920        
     920
    921921        // sum up inertia tensor
    922922        while (ptr->next != end) {
     
    943943        }
    944944        *out << endl;
    945        
     945
    946946        // diagonalize to determine principal axis system
    947947        gsl_eigen_symmv_workspace *T = gsl_eigen_symmv_alloc(NDIM);
     
    952952        gsl_eigen_symmv_free(T);
    953953        gsl_eigen_symmv_sort(eval, evec, GSL_EIGEN_SORT_ABS_DESC);
    954        
     954
    955955        for(int i=0;i<NDIM;i++) {
    956956                *out << Verbose(1) << "eigenvalue = " << gsl_vector_get(eval, i);
    957957                *out << ", eigenvector = (" << evec->data[i * evec->tda + 0] << "," << evec->data[i * evec->tda + 1] << "," << evec->data[i * evec->tda + 2] << ")" << endl;
    958958        }
    959        
     959
    960960        // check whether we rotate or not
    961961        if (DoRotate) {
    962           *out << Verbose(1) << "Transforming molecule into PAS ... "; 
     962          *out << Verbose(1) << "Transforming molecule into PAS ... ";
    963963          // the eigenvectors specify the transformation matrix
    964964          ptr = start;
     
    972972
    973973          // summing anew for debugging (resulting matrix has to be diagonal!)
    974           // reset inertia tensor 
     974          // reset inertia tensor
    975975    for(int i=0;i<NDIM*NDIM;i++)
    976976      InertiaTensor[i] = 0.;
    977    
     977
    978978    // sum up inertia tensor
    979979    ptr = start;
     
    10021002    *out << endl;
    10031003        }
    1004        
     1004
    10051005        // free everything
    10061006        delete(CenterOfGravity);
     
    10311031
    10321032  CountElements();  // make sure ElementsInMolecule is up to date
    1033  
     1033
    10341034  // check file
    10351035  if (input == NULL) {
     
    10871087              Trajectories[walker].U.at(MDSteps).x[d] += 0.5*delta_t*(Trajectories[walker].F.at(MDSteps-1).x[d]+Trajectories[walker].F.at(MDSteps).x[d])/IonMass;
    10881088            }
    1089 //            cout << "Integrated position&velocity of step " << (MDSteps) << ": ("; 
     1089//            cout << "Integrated position&velocity of step " << (MDSteps) << ": (";
    10901090//            for (int d=0;d<NDIM;d++)
    10911091//              cout << Trajectories[walker].R.at(MDSteps).x[d] << " ";          // next step
     
    11211121  MDSteps++;
    11221122
    1123  
     1123
    11241124  // exit
    11251125  return true;
    11261126};
    11271127
    1128 /** Align all atoms in such a manner that given vector \a *n is along z axis. 
     1128/** Align all atoms in such a manner that given vector \a *n is along z axis.
    11291129 * \param n[] alignment vector.
    11301130 */
     
    11451145    ptr = ptr->next;
    11461146    tmp = ptr->x.x[0];
    1147     ptr->x.x[0] =  cos(alpha) * tmp + sin(alpha) * ptr->x.x[2]; 
     1147    ptr->x.x[0] =  cos(alpha) * tmp + sin(alpha) * ptr->x.x[2];
    11481148    ptr->x.x[2] = -sin(alpha) * tmp + cos(alpha) * ptr->x.x[2];
    11491149    for (int j=0;j<MDSteps;j++) {
    11501150      tmp = Trajectories[ptr].R.at(j).x[0];
    1151       Trajectories[ptr].R.at(j).x[0] =  cos(alpha) * tmp + sin(alpha) * Trajectories[ptr].R.at(j).x[2]; 
     1151      Trajectories[ptr].R.at(j).x[0] =  cos(alpha) * tmp + sin(alpha) * Trajectories[ptr].R.at(j).x[2];
    11521152      Trajectories[ptr].R.at(j).x[2] = -sin(alpha) * tmp + cos(alpha) * Trajectories[ptr].R.at(j).x[2];
    11531153    }
    1154   }     
     1154  }
    11551155  // rotate n vector
    11561156  tmp = n->x[0];
     
    11601160  n->Output((ofstream *)&cout);
    11611161  cout << endl;
    1162  
     1162
    11631163  // rotate on z-y plane
    11641164  ptr = start;
     
    11681168    ptr = ptr->next;
    11691169    tmp = ptr->x.x[1];
    1170     ptr->x.x[1] =  cos(alpha) * tmp + sin(alpha) * ptr->x.x[2]; 
     1170    ptr->x.x[1] =  cos(alpha) * tmp + sin(alpha) * ptr->x.x[2];
    11711171    ptr->x.x[2] = -sin(alpha) * tmp + cos(alpha) * ptr->x.x[2];
    11721172    for (int j=0;j<MDSteps;j++) {
    11731173      tmp = Trajectories[ptr].R.at(j).x[1];
    1174       Trajectories[ptr].R.at(j).x[1] =  cos(alpha) * tmp + sin(alpha) * Trajectories[ptr].R.at(j).x[2]; 
     1174      Trajectories[ptr].R.at(j).x[1] =  cos(alpha) * tmp + sin(alpha) * Trajectories[ptr].R.at(j).x[2];
    11751175      Trajectories[ptr].R.at(j).x[2] = -sin(alpha) * tmp + cos(alpha) * Trajectories[ptr].R.at(j).x[2];
    11761176    }
    1177   }     
     1177  }
    11781178  // rotate n vector (for consistency check)
    11791179  tmp = n->x[1];
    11801180  n->x[1] =  cos(alpha) * tmp +  sin(alpha) * n->x[2];
    11811181  n->x[2] = -sin(alpha) * tmp +  cos(alpha) * n->x[2];
    1182  
     1182
    11831183  cout << Verbose(1) << "alignment vector after second rotation: ";
    11841184  n->Output((ofstream *)&cout);
     
    11911191 * \return true - succeeded, false - atom not found in list
    11921192 */
    1193 bool molecule::RemoveAtom(atom *pointer) 
    1194 { 
     1193bool molecule::RemoveAtom(atom *pointer)
     1194{
    11951195  if (ElementsInMolecule[pointer->type->Z] != 0)  // this would indicate an error
    11961196    ElementsInMolecule[pointer->type->Z]--;  // decrease number of atom of this element
    11971197  else
    1198     cerr << "ERROR: Atom " << pointer->Name << " is of element " << pointer->type->Z << " but the entry in the table of the molecule is 0!" << endl; 
     1198    cerr << "ERROR: Atom " << pointer->Name << " is of element " << pointer->type->Z << " but the entry in the table of the molecule is 0!" << endl;
    11991199  if (ElementsInMolecule[pointer->type->Z] == 0)  // was last atom of this element?
    12001200    ElementCount--;
     
    12061206 * \return true - succeeded, false - atom not found in list
    12071207 */
    1208 bool molecule::CleanupMolecule() 
    1209 { 
    1210   return (cleanup(start,end) && cleanup(first,last)); 
     1208bool molecule::CleanupMolecule()
     1209{
     1210  return (cleanup(start,end) && cleanup(first,last));
    12111211};
    12121212
     
    12221222  } else {
    12231223    cout << Verbose(0) << "Atom not found in list." << endl;
    1224     return NULL; 
     1224    return NULL;
    12251225  }
    12261226};
     
    12711271  struct lsq_params *par = (struct lsq_params *)params;
    12721272  atom *ptr = par->mol->start;
    1273  
     1273
    12741274  // initialize vectors
    12751275  a.x[0] = gsl_vector_get(x,0);
     
    13011301{
    13021302    int np = 6;
    1303    
     1303
    13041304   const gsl_multimin_fminimizer_type *T =
    13051305     gsl_multimin_fminimizer_nmsimplex;
     
    13071307   gsl_vector *ss;
    13081308   gsl_multimin_function minex_func;
    1309  
     1309
    13101310   size_t iter = 0, i;
    13111311   int status;
    13121312   double size;
    1313  
     1313
    13141314   /* Initial vertex size vector */
    13151315   ss = gsl_vector_alloc (np);
    1316  
     1316
    13171317   /* Set all step sizes to 1 */
    13181318   gsl_vector_set_all (ss, 1.0);
    1319  
     1319
    13201320   /* Starting point */
    13211321   par->x = gsl_vector_alloc (np);
    13221322   par->mol = this;
    1323  
     1323
    13241324   gsl_vector_set (par->x, 0, 0.0);  // offset
    13251325   gsl_vector_set (par->x, 1, 0.0);
     
    13281328   gsl_vector_set (par->x, 4, 0.0);
    13291329   gsl_vector_set (par->x, 5, 1.0);
    1330  
     1330
    13311331   /* Initialize method and iterate */
    13321332   minex_func.f = &LeastSquareDistance;
    13331333   minex_func.n = np;
    13341334   minex_func.params = (void *)par;
    1335  
     1335
    13361336   s = gsl_multimin_fminimizer_alloc (T, np);
    13371337   gsl_multimin_fminimizer_set (s, &minex_func, par->x, ss);
    1338  
     1338
    13391339   do
    13401340     {
    13411341       iter++;
    13421342       status = gsl_multimin_fminimizer_iterate(s);
    1343  
     1343
    13441344       if (status)
    13451345         break;
    1346  
     1346
    13471347       size = gsl_multimin_fminimizer_size (s);
    13481348       status = gsl_multimin_test_size (size, 1e-2);
    1349  
     1349
    13501350       if (status == GSL_SUCCESS)
    13511351         {
    13521352           printf ("converged to minimum at\n");
    13531353         }
    1354  
     1354
    13551355       printf ("%5d ", (int)iter);
    13561356       for (i = 0; i < (size_t)np; i++)
     
    13611361     }
    13621362   while (status == GSL_CONTINUE && iter < 100);
    1363  
     1363
    13641364  for (i=0;i<(size_t)np;i++)
    13651365    gsl_vector_set(par->x, i, gsl_vector_get(s->x, i));
     
    13781378  int ElementNo, AtomNo;
    13791379  CountElements();
    1380  
     1380
    13811381  if (out == NULL) {
    13821382    return false;
     
    14131413  int ElementNo, AtomNo;
    14141414  CountElements();
    1415  
     1415
    14161416  if (out == NULL) {
    14171417    return false;
     
    14601460  atom *Walker = start;
    14611461  while (Walker->next != end) {
    1462     Walker = Walker->next; 
     1462    Walker = Walker->next;
    14631463#ifdef ADDHYDROGEN
    14641464    if (Walker->type->Z != 1) {   // regard only non-hydrogen
     
    14911491  int No = 0;
    14921492  time_t now;
    1493  
     1493
    14941494  now = time((time_t *)NULL);   // Get the system time and put it into 'now' as 'calender time'
    14951495  walker = start;
     
    15181518{
    15191519  atom *walker = NULL;
    1520   int No = 0;
     1520  int AtomNo = 0, ElementNo;
    15211521  time_t now;
    1522  
     1522  element *runner = NULL;
     1523
    15231524  now = time((time_t *)NULL);   // Get the system time and put it into 'now' as 'calender time'
    15241525  walker = start;
    15251526  while (walker->next != end) { // go through every atom and count
    15261527    walker = walker->next;
    1527     No++;
     1528    AtomNo++;
    15281529  }
    15291530  if (out != NULL) {
    1530     *out << No << "\n\tCreated by molecuilder on " << ctime(&now);
    1531     walker = start;
    1532     while (walker->next != end) { // go through every atom of this element
    1533       walker = walker->next;
    1534       walker->OutputXYZLine(out);
     1531    *out << AtomNo << "\n\tCreated by molecuilder on " << ctime(&now);
     1532    ElementNo = 0;
     1533    runner = elemente->start;
     1534    while (runner->next != elemente->end) { // go through every element
     1535                runner = runner->next;
     1536      if (ElementsInMolecule[runner->Z]) { // if this element got atoms
     1537        ElementNo++;
     1538        walker = start;
     1539        while (walker->next != end) { // go through every atom of this element
     1540          walker = walker->next;
     1541          if (walker->type == runner) { // if this atom fits to element
     1542            walker->OutputXYZLine(out);
     1543          }
     1544        }
     1545      }
    15351546    }
    15361547    return true;
     
    15631574              Walker->nr = i;   // update number in molecule (for easier referencing in FragmentMolecule lateron)
    15641575              if (Walker->type->Z != 1) // count non-hydrogen atoms whilst at it
    1565                 NoNonHydrogen++; 
     1576                NoNonHydrogen++;
    15661577              Free((void **)&Walker->Name, "molecule::CountAtoms: *walker->Name");
    15671578              Walker->Name = (char *) Malloc(sizeof(char)*6, "molecule::CountAtoms: *walker->Name");
     
    15711582            }
    15721583    } else
    1573         *out << Verbose(3) << "AtomCount is still " << AtomCount << ", thus counting nothing." << endl; 
     1584        *out << Verbose(3) << "AtomCount is still " << AtomCount << ", thus counting nothing." << endl;
    15741585  }
    15751586};
     
    15831594        ElementsInMolecule[i] = 0;
    15841595        ElementCount = 0;
    1585        
     1596
    15861597  atom *walker = start;
    15871598  while (walker->next != end) {
     
    16191630    Binder = Binder->next;
    16201631    if (Binder->Cyclic)
    1621       No++;   
     1632      No++;
    16221633  }
    16231634  delete(BackEdgeStack);
     
    16771688
    16781689/** Creates an adjacency list of the molecule.
     1690 * We obtain an outside file with the indices of atoms which are bondmembers.
     1691 */
     1692void molecule::CreateAdjacencyList2(ofstream *out, ifstream *input)
     1693{
     1694
     1695        // 1 We will parse bonds out of the dbond file created by tremolo.
     1696                        int atom1, atom2, temp;
     1697                        atom *Walker, *OtherWalker;
     1698
     1699                if (!input)
     1700                {
     1701                        cout << Verbose(1) << "Opening silica failed \n";
     1702                };
     1703
     1704                        *input >> ws >> atom1;
     1705                        *input >> ws >> atom2;
     1706                cout << Verbose(1) << "Scanning file\n";
     1707                while (!input->eof()) // Check whether we read everything already
     1708                {
     1709                                *input >> ws >> atom1;
     1710                                *input >> ws >> atom2;
     1711                        if(atom2<atom1) //Sort indices of atoms in order
     1712                        {
     1713                                temp=atom1;
     1714                                atom1=atom2;
     1715                                atom2=temp;
     1716                        };
     1717
     1718                        Walker=start;
     1719                        while(Walker-> nr != atom1) // Find atom corresponding to first index
     1720                        {
     1721                                Walker = Walker->next;
     1722                        };
     1723                        OtherWalker = Walker->next;
     1724                        while(OtherWalker->nr != atom2) // Find atom corresponding to second index
     1725                        {
     1726                                OtherWalker= OtherWalker->next;
     1727                        };
     1728                        AddBond(Walker, OtherWalker); //Add the bond between the two atoms with respective indices.
     1729                       
     1730                }
     1731
     1732                CreateListOfBondsPerAtom(out);
     1733
     1734};
     1735
     1736
     1737/** Creates an adjacency list of the molecule.
    16791738 * Generally, we use the CSD approach to bond recognition, that is the the distance
    16801739 * between two atoms A and B must be within [Rcov(A)+Rcov(B)-t,Rcov(A)+Rcov(B)+t] with
    1681  * a threshold t = 0.4 Angstroem. 
     1740 * a threshold t = 0.4 Angstroem.
    16821741 * To make it O(N log N) the function uses the linked-cell technique as follows:
    16831742 * The procedure is step-wise:
     
    16961755void molecule::CreateAdjacencyList(ofstream *out, double bonddistance, bool IsAngstroem)
    16971756{
     1757
    16981758  atom *Walker = NULL, *OtherWalker = NULL, *Candidate = NULL;
    16991759  int No, NoBonds, CandidateBondNo;
     
    17041764  Vector x;
    17051765  int FalseBondDegree = 0;
    1706  
     1766
    17071767  BondDistance = bonddistance; // * ((IsAngstroem) ? 1. : 1./AtomicLengthToAngstroem);
    17081768  *out << Verbose(0) << "Begin of CreateAdjacencyList." << endl;
     
    17111771    cleanup(first,last);
    17121772  }
    1713        
     1773
    17141774  // count atoms in molecule = dimension of matrix (also give each unique name and continuous numbering)
    17151775  CountAtoms(out);
     
    17301790    for (int i=NumberCells;i--;)
    17311791      CellList[i] = NULL;
    1732  
     1792
    17331793    // 2b. put all atoms into its corresponding list
    17341794    Walker = start;
     
    17511811      if (CellList[index] == NULL)  // allocate molecule if not done
    17521812        CellList[index] = new molecule(elemente);
    1753       OtherWalker = CellList[index]->AddCopyAtom(Walker); // add a copy of walker to this atom, father will be walker for later reference 
    1754       //*out << Verbose(1) << "Copy Atom is " << *OtherWalker << "." << endl; 
     1813      OtherWalker = CellList[index]->AddCopyAtom(Walker); // add a copy of walker to this atom, father will be walker for later reference
     1814      //*out << Verbose(1) << "Copy Atom is " << *OtherWalker << "." << endl;
    17551815    }
    17561816    //for (int i=0;i<NumberCells;i++)
    17571817      //*out << Verbose(1) << "Cell number " << i << ": " << CellList[i] << "." << endl;
    1758      
     1818
     1819
    17591820    // 3a. go through every cell
    17601821    for (N[0]=divisor[0];N[0]--;)
     
    17691830              Walker = Walker->next;
    17701831              //*out << Verbose(0) << "Current Atom is " << *Walker << "." << endl;
    1771               // 3c. check for possible bond between each atom in this and every one in the 27 cells 
     1832              // 3c. check for possible bond between each atom in this and every one in the 27 cells
    17721833              for (n[0]=-1;n[0]<=1;n[0]++)
    17731834                for (n[1]=-1;n[1]<=1;n[1]++)
     
    18011862          }
    18021863        }
     1864
     1865
     1866
    18031867    // 4. free the cell again
    18041868    for (int i=NumberCells;i--;)
     
    18071871      }
    18081872    Free((void **)&CellList, "molecule::CreateAdjacencyList - ** CellList");
    1809    
     1873
    18101874    // create the adjacency list per atom
    18111875    CreateListOfBondsPerAtom(out);
    1812                
     1876
    18131877    // correct Bond degree of each bond by checking both bond partners for a mismatch between valence and current sum of bond degrees,
    18141878    // iteratively increase the one first where the other bond partner has the fewest number of bonds (i.e. in general bonds oxygene
     
    18591923                        *out << Verbose(1) << "BondCount is " << BondCount << ", no bonds between any of the " << AtomCount << " atoms." << endl;
    18601924          *out << Verbose(1) << "I detected " << BondCount << " bonds in the molecule with distance " << bonddistance << ", " << FalseBondDegree << " bonds could not be corrected." << endl;
    1861                
     1925
    18621926          // output bonds for debugging (if bond chain list was correctly installed)
    18631927          *out << Verbose(1) << endl << "From contents of bond chain list:";
     
    18691933    *out << endl;
    18701934  } else
    1871         *out << Verbose(1) << "AtomCount is " << AtomCount << ", thus no bonds, no connections!." << endl; 
     1935        *out << Verbose(1) << "AtomCount is " << AtomCount << ", thus no bonds, no connections!." << endl;
    18721936  *out << Verbose(0) << "End of CreateAdjacencyList." << endl;
    18731937  Free((void **)&matrix, "molecule::CreateAdjacencyList: *matrix");
    1874 };
     1938
     1939};
     1940
     1941
    18751942
    18761943/** Performs a Depth-First search on this molecule.
     
    18931960  bond *Binder = NULL;
    18941961  bool BackStepping = false;
    1895  
     1962
    18961963  *out << Verbose(0) << "Begin of DepthFirstSearchAnalysis" << endl;
    1897  
     1964
    18981965  ResetAllBondsToUnused();
    18991966  ResetAllAtomNumbers();
     
    19081975    LeafWalker->Leaf = new molecule(elemente);
    19091976    LeafWalker->Leaf->AddCopyAtom(Root);
    1910    
     1977
    19111978    OldGraphNr = CurrentGraphNr;
    19121979    Walker = Root;
     
    19191986          AtomStack->Push(Walker);
    19201987          CurrentGraphNr++;
    1921         }     
     1988        }
    19221989        do { // (3) if Walker has no unused egdes, go to (5)
    19231990          BackStepping = false; // reset backstepping flag for (8)
     
    19532020          Binder = NULL;
    19542021      } while (1);  // (2)
    1955      
     2022
    19562023      // if we came from backstepping, yet there were no more unused bonds, we end up here with no Ancestor, because Walker is Root! Then we are finished!
    19572024      if ((Walker == Root) && (Binder == NULL))
    19582025        break;
    1959        
    1960       // (5) if Ancestor of Walker is ... 
     2026
     2027      // (5) if Ancestor of Walker is ...
    19612028      *out << Verbose(1) << "(5) Number of Walker[" << Walker->Name << "]'s Ancestor[" << Walker->Ancestor->Name << "] is " << Walker->Ancestor->GraphNr << "." << endl;
    19622029      if (Walker->Ancestor->GraphNr != Root->GraphNr) {
     
    20012068        } while (OtherAtom != Walker);
    20022069        ComponentNumber++;
    2003    
     2070
    20042071        // (11) Root is separation vertex,  set Walker to Root and go to (4)
    20052072        Walker = Root;
     
    20142081
    20152082    // From OldGraphNr to CurrentGraphNr ranges an disconnected subgraph
    2016     *out << Verbose(0) << "Disconnected subgraph ranges from " << OldGraphNr << " to " << CurrentGraphNr << "." << endl;   
     2083    *out << Verbose(0) << "Disconnected subgraph ranges from " << OldGraphNr << " to " << CurrentGraphNr << "." << endl;
    20172084    LeafWalker->Leaf->Output(out);
    20182085    *out << endl;
     
    20222089      //*out << Verbose(1) << "Current next subgraph root candidate is " << Root->Name << "." << endl;
    20232090      if (Root->GraphNr != -1) // if already discovered, step on
    2024         Root = Root->next; 
     2091        Root = Root->next;
    20252092    }
    20262093  }
     
    20442111    *out << " with Lowpoint " << Walker->LowpointNr << " and Graph Nr. " << Walker->GraphNr << "." << endl;
    20452112  }
    2046  
     2113
    20472114  *out << Verbose(1) << "Final graph info for each bond is:" << endl;
    20482115  Binder = first;
     
    20552122    *out << ((Binder->rightatom->SeparationVertex) ? "SP," : "") << "L" << Binder->rightatom->LowpointNr << " G" << Binder->rightatom->GraphNr << " Comp.";
    20562123    OutputComponentNumber(out, Binder->rightatom);
    2057     *out << ">." << endl; 
     2124    *out << ">." << endl;
    20582125    if (Binder->Cyclic) // cyclic ??
    20592126      *out << Verbose(3) << "Lowpoint at each side are equal: CYCLIC!" << endl;
     
    20702137 * the other our initial Walker - and do a Breadth First Search for the Root. We mark down each Predecessor and as soon as
    20712138 * we have found the Root via BFS, we may climb back the closed cycle via the Predecessors. Thereby we mark atoms and bonds
    2072  * as cyclic and print out the cycles. 
     2139 * as cyclic and print out the cycles.
    20732140 * \param *out output stream for debugging
    20742141 * \param *BackEdgeStack stack with all back edges found during DFS scan. Beware: This stack contains the bonds from the total molecule, not from the subgraph!
     
    20812148  int *ShortestPathList = (int *) Malloc(sizeof(int)*AtomCount, "molecule::CyclicStructureAnalysis: *ShortestPathList");
    20822149  enum Shading *ColorList = (enum Shading *) Malloc(sizeof(enum Shading)*AtomCount, "molecule::CyclicStructureAnalysis: *ColorList");
    2083   class StackClass<atom *> *BFSStack = new StackClass<atom *> (AtomCount);   // will hold the current ring 
     2150  class StackClass<atom *> *BFSStack = new StackClass<atom *> (AtomCount);   // will hold the current ring
    20842151  class StackClass<atom *> *TouchedStack = new StackClass<atom *> (AtomCount);   // contains all "touched" atoms (that need to be reset after BFS loop)
    20852152  atom *Walker = NULL, *OtherAtom = NULL, *Root = NULL;
     
    20932160    ColorList[i] = white;
    20942161  }
    2095  
     2162
    20962163  *out << Verbose(1) << "Back edge list - ";
    20972164  BackEdgeStack->Output(out);
    2098  
     2165
    20992166  *out << Verbose(1) << "Analysing cycles ... " << endl;
    21002167  NumCycles = 0;
     
    21022169    BackEdge = BackEdgeStack->PopFirst();
    21032170    // this is the target
    2104     Root = BackEdge->leftatom; 
     2171    Root = BackEdge->leftatom;
    21052172    // this is the source point
    2106     Walker = BackEdge->rightatom; 
     2173    Walker = BackEdge->rightatom;
    21072174    ShortestPathList[Walker->nr] = 0;
    21082175    BFSStack->ClearStack();  // start with empty BFS stack
     
    21182185        if (Binder != BackEdge) { // only walk along DFS spanning tree (otherwise we always find SP of one being backedge Binder)
    21192186          OtherAtom = Binder->GetOtherAtom(Walker);
    2120 #ifdef ADDHYDROGEN         
     2187#ifdef ADDHYDROGEN
    21212188          if (OtherAtom->type->Z != 1) {
    21222189#endif
     
    21272194              PredecessorList[OtherAtom->nr] = Walker;  // Walker is the predecessor
    21282195              ShortestPathList[OtherAtom->nr] = ShortestPathList[Walker->nr]+1;
    2129               *out << Verbose(2) << "Coloring OtherAtom " << OtherAtom->Name << " lightgray, its predecessor is " << Walker->Name << " and its Shortest Path is " << ShortestPathList[OtherAtom->nr] << " egde(s) long." << endl; 
     2196              *out << Verbose(2) << "Coloring OtherAtom " << OtherAtom->Name << " lightgray, its predecessor is " << Walker->Name << " and its Shortest Path is " << ShortestPathList[OtherAtom->nr] << " egde(s) long." << endl;
    21302197              //if (ShortestPathList[OtherAtom->nr] < MinimumRingSize[Walker->GetTrueFather()->nr]) { // Check for maximum distance
    21312198                *out << Verbose(3) << "Putting OtherAtom into queue." << endl;
     
    21372204            if (OtherAtom == Root)
    21382205              break;
    2139 #ifdef ADDHYDROGEN         
     2206#ifdef ADDHYDROGEN
    21402207          } else {
    21412208            *out << Verbose(2) << "Skipping hydrogen atom " << *OtherAtom << "." << endl;
     
    21752242      }
    21762243    } while ((!BFSStack->IsEmpty()) && (OtherAtom != Root) && (OtherAtom != NULL)); // || (ShortestPathList[OtherAtom->nr] < MinimumRingSize[Walker->GetTrueFather()->nr])));
    2177    
     2244
    21782245    if (OtherAtom == Root) {
    21792246      // now climb back the predecessor list and thus find the cycle members
     
    22032270      *out << Verbose(1) << "No ring containing " << *Root << " with length equal to or smaller than " << MinimumRingSize[Walker->GetTrueFather()->nr] << " found." << endl;
    22042271    }
    2205    
     2272
    22062273    // now clean the lists
    22072274    while (!TouchedStack->IsEmpty()){
     
    22132280  }
    22142281  if (MinRingSize != -1) {
    2215     // go over all atoms 
     2282    // go over all atoms
    22162283    Root = start;
    22172284    while(Root->next != end) {
    22182285      Root = Root->next;
    2219      
     2286
    22202287      if (MinimumRingSize[Root->GetTrueFather()->nr] == AtomCount) { // check whether MinimumRingSize is set, if not BFS to next where it is
    22212288        Walker = Root;
     
    22542321          }
    22552322          ColorList[Walker->nr] = black;
    2256           //*out << Verbose(1) << "Coloring Walker " << Walker->Name << " black." << endl; 
     2323          //*out << Verbose(1) << "Coloring Walker " << Walker->Name << " black." << endl;
    22572324        }
    2258    
     2325
    22592326        // now clean the lists
    22602327        while (!TouchedStack->IsEmpty()){
     
    23052372void molecule::OutputComponentNumber(ofstream *out, atom *vertex)
    23062373{
    2307   for(int i=0;i<NumberOfBondsPerAtom[vertex->nr];i++) 
     2374  for(int i=0;i<NumberOfBondsPerAtom[vertex->nr];i++)
    23082375    *out << vertex->ComponentNr[i] << "  ";
    23092376};
     
    23832450{
    23842451  int c = 0;
    2385   int FragmentCount; 
     2452  int FragmentCount;
    23862453  // get maximum bond degree
    23872454  atom *Walker = start;
     
    23932460  *out << Verbose(1) << "Upper limit for this subgraph is " << FragmentCount << " for " << NoNonHydrogen << " non-H atoms with maximum bond degree of " << c << "." << endl;
    23942461  return FragmentCount;
    2395 }; 
     2462};
    23962463
    23972464/** Scans a single line for number and puts them into \a KeySet.
    23982465 * \param *out output stream for debugging
    23992466 * \param *buffer buffer to scan
    2400  * \param &CurrentSet filled KeySet on return 
     2467 * \param &CurrentSet filled KeySet on return
    24012468 * \return true - at least one valid atom id parsed, false - CurrentSet is empty
    24022469 */
     
    24062473  int AtomNr;
    24072474  int status = 0;
    2408  
     2475
    24092476  line.str(buffer);
    24102477  while (!line.eof()) {
     
    24422509  double TEFactor;
    24432510  char *filename = (char *) Malloc(sizeof(char)*MAXSTRINGSIZE, "molecule::ParseKeySetFile - filename");
    2444  
     2511
    24452512  if (FragmentList == NULL) { // check list pointer
    24462513    FragmentList = new Graph;
    24472514  }
    2448  
     2515
    24492516  // 1st pass: open file and read
    24502517  *out << Verbose(1) << "Parsing the KeySet file ... " << endl;
     
    24752542    status = false;
    24762543  }
    2477  
     2544
    24782545  // 2nd pass: open TEFactors file and read
    24792546  *out << Verbose(1) << "Parsing the TEFactors file ... " << endl;
     
    24872554        InputFile >> TEFactor;
    24882555        (*runner).second.second = TEFactor;
    2489         *out << Verbose(2) << "Setting " << ++NumberOfFragments << " fragment's TEFactor to " << (*runner).second.second << "." << endl; 
     2556        *out << Verbose(2) << "Setting " << ++NumberOfFragments << " fragment's TEFactor to " << (*runner).second.second << "." << endl;
    24902557      } else {
    24912558        status = false;
     
    25282595  if(output != NULL) {
    25292596    for(Graph::iterator runner = KeySetList.begin(); runner != KeySetList.end(); runner++) {
    2530       for (KeySet::iterator sprinter = (*runner).first.begin();sprinter != (*runner).first.end(); sprinter++) { 
     2597      for (KeySet::iterator sprinter = (*runner).first.begin();sprinter != (*runner).first.end(); sprinter++) {
    25312598        if (sprinter != (*runner).first.begin())
    25322599          output << "\t";
     
    25942661    status = false;
    25952662  }
    2596  
     2663
    25972664  return status;
    25982665};
     
    26032670 * \param **ListOfAtoms allocated (molecule::AtomCount) and filled lookup table for ids (Atom::nr) to *Atom
    26042671 * \return true - structure is equal, false - not equivalence
    2605  */ 
     2672 */
    26062673bool molecule::CheckAdjacencyFileAgainstMolecule(ofstream *out, char *path, atom **ListOfAtoms)
    26072674{
     
    26102677  bool status = true;
    26112678  char *buffer = (char *) Malloc(sizeof(char)*MAXSTRINGSIZE, "molecule::CheckAdjacencyFileAgainstMolecule: *buffer");
    2612  
     2679
    26132680  filename << path << "/" << FRAGMENTPREFIX << ADJACENCYFILE;
    26142681  File.open(filename.str().c_str(), ios::out);
     
    26692736  *out << endl;
    26702737  Free((void **)&buffer, "molecule::CheckAdjacencyFileAgainstMolecule: *buffer");
    2671  
     2738
    26722739  return status;
    26732740};
     
    26912758  for(int i=AtomCount;i--;)
    26922759    AtomMask[i] = false;
    2693  
     2760
    26942761  if (Order < 0) { // adaptive increase of BondOrder per site
    26952762    if (AtomMask[AtomCount] == true)  // break after one step
     
    27312798          line >> ws >> Value; // skip time entry
    27322799          line >> ws >> Value;
    2733           No -= 1;  // indices start at 1 in file, not 0 
     2800          No -= 1;  // indices start at 1 in file, not 0
    27342801          //*out << Verbose(2) << " - yields (" << No << "," << Value << ", " << FragOrder << ")" << endl;
    27352802
     
    27402807            // as the smallest number in each set has always been the root (we use global id to keep the doubles away), seek smallest and insert into AtomMask
    27412808            pair <map<int, pair<double,int> >::iterator, bool> InsertedElement = AdaptiveCriteriaList.insert( make_pair(*((*marker).second.begin()), pair<double,int>( fabs(Value), FragOrder) ));
    2742             map<int, pair<double,int> >::iterator PresentItem = InsertedElement.first; 
     2809            map<int, pair<double,int> >::iterator PresentItem = InsertedElement.first;
    27432810            if (!InsertedElement.second) { // this root is already present
    2744               if ((*PresentItem).second.second < FragOrder)  // if order there is lower, update entry with higher-order term 
    2745                 //if ((*PresentItem).second.first < (*runner).first)    // as higher-order terms are not always better, we skip this part (which would always include this site into adaptive increase) 
     2811              if ((*PresentItem).second.second < FragOrder)  // if order there is lower, update entry with higher-order term
     2812                //if ((*PresentItem).second.first < (*runner).first)    // as higher-order terms are not always better, we skip this part (which would always include this site into adaptive increase)
    27462813                {  // if value is smaller, update value and order
    27472814                (*PresentItem).second.first = fabs(Value);
     
    27812848        Walker = FindAtom(No);
    27822849        //if (Walker->AdaptiveOrder < MinimumRingSize[Walker->nr]) {
    2783           *out << Verbose(2) << "Root " << No << " is still above threshold (10^{" << Order <<"}: " << runner->first << ", setting entry " << No << " of Atom mask to true." << endl; 
     2850          *out << Verbose(2) << "Root " << No << " is still above threshold (10^{" << Order <<"}: " << runner->first << ", setting entry " << No << " of Atom mask to true." << endl;
    27842851          AtomMask[No] = true;
    27852852          status = true;
    27862853        //} else
    2787           //*out << Verbose(2) << "Root " << No << " is still above threshold (10^{" << Order <<"}: " << runner->first << ", however MinimumRingSize of " << MinimumRingSize[Walker->nr] << " does not allow further adaptive increase." << endl; 
     2854          //*out << Verbose(2) << "Root " << No << " is still above threshold (10^{" << Order <<"}: " << runner->first << ", however MinimumRingSize of " << MinimumRingSize[Walker->nr] << " does not allow further adaptive increase." << endl;
    27882855      }
    27892856      // close and done
     
    28192886    if ((Order == 0) && (AtomMask[AtomCount] == false))  // single stepping, just check
    28202887      status = true;
    2821      
     2888
    28222889    if (!status) {
    28232890      if (Order == 0)
     
    28272894    }
    28282895  }
    2829  
     2896
    28302897  // print atom mask for debugging
    28312898  *out << "              ";
     
    28362903    *out << (AtomMask[i] ? "t" : "f");
    28372904  *out << endl;
    2838  
     2905
    28392906  return status;
    28402907};
     
    28502917  int AtomNo = 0;
    28512918  atom *Walker = NULL;
    2852  
     2919
    28532920  if (SortIndex != NULL) {
    28542921    *out << Verbose(1) << "SortIndex is " << SortIndex << " and not NULL as expected." << endl;
     
    29082975  atom **ListOfAtoms = NULL;
    29092976  atom ***ListOfLocalAtoms = NULL;
    2910   bool *AtomMask = NULL; 
    2911  
     2977  bool *AtomMask = NULL;
     2978
    29122979  *out << endl;
    29132980#ifdef ADDHYDROGEN
     
    29182985
    29192986  // ++++++++++++++++++++++++++++ INITIAL STUFF: Bond structure analysis, file parsing, ... ++++++++++++++++++++++++++++++++++++++++++
    2920  
     2987
    29212988  // ===== 1. Check whether bond structure is same as stored in files ====
    2922  
     2989
    29232990  // fill the adjacency list
    29242991  CreateListOfBondsPerAtom(out);
     
    29262993  // create lookup table for Atom::nr
    29272994  FragmentationToDo = FragmentationToDo && CreateFatherLookupTable(out, start, end, ListOfAtoms, AtomCount);
    2928  
     2995
    29292996  // === compare it with adjacency file ===
    2930   FragmentationToDo = FragmentationToDo && CheckAdjacencyFileAgainstMolecule(out, configuration->configpath, ListOfAtoms); 
     2997  FragmentationToDo = FragmentationToDo && CheckAdjacencyFileAgainstMolecule(out, configuration->configpath, ListOfAtoms);
    29312998  Free((void **)&ListOfAtoms, "molecule::FragmentMolecule - **ListOfAtoms");
    29322999
     
    29573024    delete(LocalBackEdgeStack);
    29583025  }
    2959  
     3026
    29603027  // ===== 3. if structure still valid, parse key set file and others =====
    29613028  FragmentationToDo = FragmentationToDo && ParseKeySetFile(out, configuration->configpath, ParsedFragmentList);
     
    29633030  // ===== 4. check globally whether there's something to do actually (first adaptivity check)
    29643031  FragmentationToDo = FragmentationToDo && ParseOrderAtSiteFromFile(out, configuration->configpath);
    2965  
    2966   // =================================== Begin of FRAGMENTATION =============================== 
    2967   // ===== 6a. assign each keyset to its respective subgraph ===== 
     3032
     3033  // =================================== Begin of FRAGMENTATION ===============================
     3034  // ===== 6a. assign each keyset to its respective subgraph =====
    29683035  Subgraphs->next->AssignKeySetsToFragment(out, this, ParsedFragmentList, ListOfLocalAtoms, FragmentList, (FragmentCounter = 0), true);
    29693036
     
    29763043    FragmentationToDo = FragmentationToDo || CheckOrder;
    29773044    AtomMask[AtomCount] = true;   // last plus one entry is used as marker that we have been through this loop once already in CheckOrderAtSite()
    2978     // ===== 6b. fill RootStack for each subgraph (second adaptivity check) ===== 
     3045    // ===== 6b. fill RootStack for each subgraph (second adaptivity check) =====
    29793046    Subgraphs->next->FillRootStackForSubgraphs(out, RootStack, AtomMask, (FragmentCounter = 0));
    29803047
     
    30003067  delete(ParsedFragmentList);
    30013068  delete[](MinimumRingSize);
    3002  
     3069
    30033070
    30043071  // ==================================== End of FRAGMENTATION ============================================
     
    30063073  // ===== 8a. translate list into global numbers (i.e. ones that are valid in "this" molecule, not in MolecularWalker->Leaf)
    30073074  Subgraphs->next->TranslateIndicesToGlobalIDs(out, FragmentList, (FragmentCounter = 0), TotalNumberOfKeySets, TotalGraph);
    3008  
     3075
    30093076  // free subgraph memory again
    30103077  FragmentCounter = 0;
     
    30313098    }
    30323099    *out << k << "/" << BondFragments->NumberOfMolecules << " fragments generated from the keysets." << endl;
    3033    
     3100
    30343101    // ===== 9. Save fragments' configuration and keyset files et al to disk ===
    30353102    if (BondFragments->NumberOfMolecules != 0) {
    30363103      // create the SortIndex from BFS labels to order in the config file
    30373104      CreateMappingLabelsToConfigSequence(out, SortIndex);
    3038      
     3105
    30393106      *out << Verbose(1) << "Writing " << BondFragments->NumberOfMolecules << " possible bond fragmentation configs" << endl;
    30403107      if (BondFragments->OutputConfigForListOfFragments(out, configuration, SortIndex))
     
    30423109      else
    30433110        *out << Verbose(1) << "Some config writing failed." << endl;
    3044  
     3111
    30453112      // store force index reference file
    30463113      BondFragments->StoreForcesFile(out, configuration->configpath, SortIndex);
    3047      
    3048       // store keysets file 
     3114
     3115      // store keysets file
    30493116      StoreKeySetFile(out, TotalGraph, configuration->configpath);
    3050  
    3051       // store Adjacency file 
     3117
     3118      // store Adjacency file
    30523119      StoreAdjacencyToFile(out, configuration->configpath);
    3053  
     3120
    30543121      // store Hydrogen saturation correction file
    30553122      BondFragments->AddHydrogenCorrection(out, configuration->configpath);
    3056      
     3123
    30573124      // store adaptive orders into file
    30583125      StoreOrderAtSiteFile(out, configuration->configpath);
    3059      
     3126
    30603127      // restore orbital and Stop values
    30613128      CalculateOrbitals(*configuration);
    3062      
     3129
    30633130      // free memory for bond part
    30643131      *out << Verbose(1) << "Freeing bond memory" << endl;
    30653132      delete(FragmentList); // remove bond molecule from memory
    3066       Free((void **)&SortIndex, "molecule::FragmentMolecule: *SortIndex"); 
     3133      Free((void **)&SortIndex, "molecule::FragmentMolecule: *SortIndex");
    30673134    } else
    30683135      *out << Verbose(1) << "FragmentList is zero on return, splitting failed." << endl;
    3069   //} else 
     3136  //} else
    30703137  //  *out << Verbose(1) << "No fragments to store." << endl;
    30713138  *out << Verbose(0) << "End of bond fragmentation." << endl;
     
    30933160  atom *Walker = NULL, *OtherAtom = NULL;
    30943161  ReferenceStack->Push(Binder);
    3095  
     3162
    30963163  do {  // go through all bonds and push local ones
    30973164    Walker = ListOfLocalAtoms[Binder->leftatom->nr];  // get one atom in the reference molecule
    3098     if (Walker != NULL) // if this Walker exists in the subgraph ... 
     3165    if (Walker != NULL) // if this Walker exists in the subgraph ...
    30993166        for(int i=0;i<NumberOfBondsPerAtom[Walker->nr];i++) {    // go through the local list of bonds
    31003167        OtherAtom = ListOfBondsPerAtom[Walker->nr][i]->GetOtherAtom(Walker);
     
    31093176    ReferenceStack->Push(Binder);
    31103177  } while (FirstBond != Binder);
    3111  
     3178
    31123179  return status;
    31133180};
     
    31853252      Walker->AdaptiveOrder = OrderArray[Walker->nr];
    31863253      Walker->MaxOrder = MaxArray[Walker->nr];
    3187       *out << Verbose(2) << *Walker << " gets order " << (int)Walker->AdaptiveOrder << " and is " << (!Walker->MaxOrder ? "not " : " ") << "maxed." << endl; 
     3254      *out << Verbose(2) << *Walker << " gets order " << (int)Walker->AdaptiveOrder << " and is " << (!Walker->MaxOrder ? "not " : " ") << "maxed." << endl;
    31883255    }
    31893256    file.close();
     
    31963263  Free((void **)&OrderArray, "molecule::ParseOrderAtSiteFromFile - *OrderArray");
    31973264  Free((void **)&MaxArray, "molecule::ParseOrderAtSiteFromFile - *MaxArray");
    3198  
     3265
    31993266  *out << Verbose(1) << "End of ParseOrderAtSiteFromFile" << endl;
    32003267  return status;
     
    32543321  Walker = start;
    32553322  while (Walker->next != end) {
    3256     Walker = Walker->next; 
     3323    Walker = Walker->next;
    32573324    *out << Verbose(4) << "Atom " << Walker->Name << "/" << Walker->nr << " with " << NumberOfBondsPerAtom[Walker->nr] << " bonds: ";
    32583325    TotalDegree = 0;
     
    32623329    }
    32633330    *out << " -- TotalDegree: " << TotalDegree << endl;
    3264   }     
     3331  }
    32653332  *out << Verbose(1) << "End of Creating ListOfBondsPerAtom." << endl << endl;
    32663333};
     
    32683335/** Adds atoms up to \a BondCount distance from \a *Root and notes them down in \a **AddedAtomList.
    32693336 * Gray vertices are always enqueued in an StackClass<atom *> FIFO queue, the rest is usual BFS with adding vertices found was
    3270  * white and putting into queue. 
     3337 * white and putting into queue.
    32713338 * \param *out output stream for debugging
    32723339 * \param *Mol Molecule class to add atoms to
     
    32773344 * \param BondOrder maximum distance for vertices to add
    32783345 * \param IsAngstroem lengths are in angstroem or bohrradii
    3279  */ 
     3346 */
    32803347void molecule::BreadthFirstSearchAdd(ofstream *out, molecule *Mol, atom **&AddedAtomList, bond **&AddedBondList, atom *Root, bond *Bond, int BondOrder, bool IsAngstroem)
    32813348{
     
    33033370  }
    33043371  ShortestPathList[Root->nr] = 0;
    3305  
     3372
    33063373  // and go on ... Queue always contains all lightgray vertices
    33073374  while (!AtomStack->IsEmpty()) {
     
    33113378    // followed by n+1 till top of stack.
    33123379    Walker = AtomStack->PopFirst(); // pop oldest added
    3313     *out << Verbose(1) << "Current Walker is: " << Walker->Name << ", and has " << NumberOfBondsPerAtom[Walker->nr] << " bonds." << endl; 
     3380    *out << Verbose(1) << "Current Walker is: " << Walker->Name << ", and has " << NumberOfBondsPerAtom[Walker->nr] << " bonds." << endl;
    33143381    for(int i=0;i<NumberOfBondsPerAtom[Walker->nr];i++) {
    33153382      Binder = ListOfBondsPerAtom[Walker->nr][i];
     
    33183385        *out << Verbose(2) << "Current OtherAtom is: " << OtherAtom->Name << " for bond " << *Binder << "." << endl;
    33193386        if (ColorList[OtherAtom->nr] == white) {
    3320           if (Binder != Bond) // let other atom white if it's via Root bond. In case it's cyclic it has to be reached again (yet Root is from OtherAtom already black, thus no problem) 
     3387          if (Binder != Bond) // let other atom white if it's via Root bond. In case it's cyclic it has to be reached again (yet Root is from OtherAtom already black, thus no problem)
    33213388            ColorList[OtherAtom->nr] = lightgray;
    33223389          PredecessorList[OtherAtom->nr] = Walker;  // Walker is the predecessor
    33233390          ShortestPathList[OtherAtom->nr] = ShortestPathList[Walker->nr]+1;
    3324           *out << Verbose(2) << "Coloring OtherAtom " << OtherAtom->Name << " " << ((ColorList[OtherAtom->nr] == white) ? "white" : "lightgray") << ", its predecessor is " << Walker->Name << " and its Shortest Path is " << ShortestPathList[OtherAtom->nr] << " egde(s) long." << endl; 
     3391          *out << Verbose(2) << "Coloring OtherAtom " << OtherAtom->Name << " " << ((ColorList[OtherAtom->nr] == white) ? "white" : "lightgray") << ", its predecessor is " << Walker->Name << " and its Shortest Path is " << ShortestPathList[OtherAtom->nr] << " egde(s) long." << endl;
    33253392          if ((((ShortestPathList[OtherAtom->nr] < BondOrder) && (Binder != Bond))) ) { // Check for maximum distance
    33263393            *out << Verbose(3);
     
    33703437          // This has to be a cyclic bond, check whether it's present ...
    33713438          if (AddedBondList[Binder->nr] == NULL) {
    3372             if ((Binder != Bond) && (Binder->Cyclic) && (((ShortestPathList[Walker->nr]+1) < BondOrder))) { 
     3439            if ((Binder != Bond) && (Binder->Cyclic) && (((ShortestPathList[Walker->nr]+1) < BondOrder))) {
    33733440              AddedBondList[Binder->nr] = Mol->AddBond(AddedAtomList[Walker->nr], AddedAtomList[OtherAtom->nr], Binder->BondDegree);
    33743441              AddedBondList[Binder->nr]->Cyclic = Binder->Cyclic;
     
    33853452    }
    33863453    ColorList[Walker->nr] = black;
    3387     *out << Verbose(1) << "Coloring Walker " << Walker->Name << " black." << endl; 
     3454    *out << Verbose(1) << "Coloring Walker " << Walker->Name << " black." << endl;
    33883455  }
    33893456  Free((void **)&PredecessorList, "molecule::BreadthFirstSearchAdd: **PredecessorList");
     
    34093476
    34103477  *out << Verbose(2) << "Begin of BuildInducedSubgraph." << endl;
    3411  
     3478
    34123479  // reset parent list
    34133480  *out << Verbose(3) << "Resetting ParentList." << endl;
    34143481  for (int i=Father->AtomCount;i--;)
    34153482    ParentList[i] = NULL;
    3416  
     3483
    34173484  // fill parent list with sons
    34183485  *out << Verbose(3) << "Filling Parent List." << endl;
     
    34553522 * \param *&Leaf KeySet to look through
    34563523 * \param *&ShortestPathList list of the shortest path to decide which atom to suggest as removal candidate in the end
    3457  * \param index of the atom suggested for removal 
     3524 * \param index of the atom suggested for removal
    34583525 */
    34593526int molecule::LookForRemovalCandidate(ofstream *&out, KeySet *&Leaf, int *&ShortestPathList)
     
    34613528  atom *Runner = NULL;
    34623529  int SP, Removal;
    3463  
     3530
    34643531  *out << Verbose(2) << "Looking for removal candidate." << endl;
    34653532  SP = -1; //0;  // not -1, so that Root is never removed
     
    34793546/** Stores a fragment from \a KeySet into \a molecule.
    34803547 * First creates the minimal set of atoms from the KeySet, then creates the bond structure from the complete
    3481  * molecule and adds missing hydrogen where bonds were cut. 
     3548 * molecule and adds missing hydrogen where bonds were cut.
    34823549 * \param *out output stream for debugging messages
    3483  * \param &Leaflet pointer to KeySet structure 
     3550 * \param &Leaflet pointer to KeySet structure
    34843551 * \param IsAngstroem whether we have Ansgtroem or bohrradius
    34853552 * \return pointer to constructed molecule
     
    34923559  bool LonelyFlag = false;
    34933560  int size;
    3494  
     3561
    34953562//  *out << Verbose(1) << "Begin of StoreFragmentFromKeyset." << endl;
    3496  
     3563
    34973564  Leaf->BondDistance = BondDistance;
    34983565  for(int i=NDIM*2;i--;)
    3499     Leaf->cell_size[i] = cell_size[i]; 
     3566    Leaf->cell_size[i] = cell_size[i];
    35003567
    35013568  // initialise SonList (indicates when we need to replace a bond with hydrogen instead)
     
    35103577    size++;
    35113578  }
    3512  
     3579
    35133580  // create the bonds between all: Make it an induced subgraph and add hydrogen
    35143581//  *out << Verbose(2) << "Creating bonds from father graph (i.e. induced subgraph creation)." << endl;
     
    35203587    if (SonList[FatherOfRunner->nr] != NULL)  {  // check if this, our father, is present in list
    35213588      // create all bonds
    3522       for (int i=0;i<NumberOfBondsPerAtom[FatherOfRunner->nr];i++) { // go through every bond of father 
     3589      for (int i=0;i<NumberOfBondsPerAtom[FatherOfRunner->nr];i++) { // go through every bond of father
    35233590        OtherFather = ListOfBondsPerAtom[FatherOfRunner->nr][i]->GetOtherAtom(FatherOfRunner);
    35243591//        *out << Verbose(2) << "Father " << *FatherOfRunner << " of son " << *SonList[FatherOfRunner->nr] << " is bound to " << *OtherFather;
    35253592        if (SonList[OtherFather->nr] != NULL) {
    3526 //          *out << ", whose son is " << *SonList[OtherFather->nr] << "." << endl; 
     3593//          *out << ", whose son is " << *SonList[OtherFather->nr] << "." << endl;
    35273594          if (OtherFather->nr > FatherOfRunner->nr) { // add bond (nr check is for adding only one of both variants: ab, ba)
    35283595//            *out << Verbose(3) << "Adding Bond: ";
    3529 //            *out << 
     3596//            *out <<
    35303597            Leaf->AddBond(Runner, SonList[OtherFather->nr], ListOfBondsPerAtom[FatherOfRunner->nr][i]->BondDegree);
    35313598//            *out << "." << endl;
    35323599            //NumBonds[Runner->nr]++;
    3533           } else { 
     3600          } else {
    35343601//            *out << Verbose(3) << "Not adding bond, labels in wrong order." << endl;
    35353602          }
    35363603          LonelyFlag = false;
    35373604        } else {
    3538 //          *out << ", who has no son in this fragment molecule." << endl; 
     3605//          *out << ", who has no son in this fragment molecule." << endl;
    35393606#ifdef ADDHYDROGEN
    35403607          //*out << Verbose(3) << "Adding Hydrogen to " << Runner->Name << " and a bond in between." << endl;
     
    35543621    while ((Runner->next != Leaf->end) && (Runner->next->type->Z == 1)) // skip added hydrogen
    35553622      Runner = Runner->next;
    3556 #endif       
     3623#endif
    35573624  }
    35583625  Leaf->CreateListOfBondsPerAtom(out);
     
    35873654  StackClass<atom *> *TouchedStack = new StackClass<atom *>((int)pow(4,Order)+2); // number of atoms reached from one with maximal 4 bonds plus Root itself
    35883655  StackClass<atom *> *SnakeStack = new StackClass<atom *>(Order+1); // equal to Order is not possible, as then the StackClass<atom *> cannot discern between full and empty stack!
    3589   MoleculeLeafClass *Leaflet = NULL, *TempLeaf = NULL; 
     3656  MoleculeLeafClass *Leaflet = NULL, *TempLeaf = NULL;
    35903657  MoleculeListClass *FragmentList = NULL;
    35913658  atom *Walker = NULL, *OtherAtom = NULL, *Root = NULL, *Removal = NULL;
     
    36373704                // clear snake stack
    36383705          SnakeStack->ClearStack();
    3639     //SnakeStack->TestImplementation(out, start->next);   
     3706    //SnakeStack->TestImplementation(out, start->next);
    36403707
    36413708    ///// INNER LOOP ////////////
     
    36583725        }
    36593726        if (ShortestPathList[Walker->nr] == -1) {
    3660           ShortestPathList[Walker->nr] = ShortestPathList[PredecessorList[Walker->nr]->nr]+1; 
     3727          ShortestPathList[Walker->nr] = ShortestPathList[PredecessorList[Walker->nr]->nr]+1;
    36613728          TouchedStack->Push(Walker); // mark every atom for lists cleanup later, whose shortest path has been changed
    36623729        }
     
    36963763                                OtherAtom = Binder->GetOtherAtom(Walker);
    36973764            if ((Labels[OtherAtom->nr] != -1) && (Labels[OtherAtom->nr] < Labels[Root->nr])) { // we don't step up to labels bigger than us
    3698               *out << "Label " << Labels[OtherAtom->nr] << " is smaller than Root's " << Labels[Root->nr] << "." << endl; 
     3765              *out << "Label " << Labels[OtherAtom->nr] << " is smaller than Root's " << Labels[Root->nr] << "." << endl;
    36993766              //ColorVertexList[OtherAtom->nr] = lightgray;    // mark as explored
    37003767            } else { // otherwise check its colour and element
    37013768                                if (
    37023769#ifdef ADDHYDROGEN
    3703               (OtherAtom->type->Z != 1) && 
     3770              (OtherAtom->type->Z != 1) &&
    37043771#endif
    37053772                    (ColorEdgeList[Binder->nr] == white)) {  // skip hydrogen, look for unexplored vertices
     
    37113778                //} else {
    37123779                //  *out << Verbose(3) << "Predecessor of " << OtherAtom->Name << " is " << PredecessorList[OtherAtom->nr]->Name << "." << endl;
    3713                 //} 
     3780                //}
    37143781                Walker = OtherAtom;
    37153782                break;
    37163783              } else {
    3717                 if (OtherAtom->type->Z == 1) 
     3784                if (OtherAtom->type->Z == 1)
    37183785                  *out << "Links to a hydrogen atom." << endl;
    3719                 else                 
     3786                else
    37203787                  *out << "Bond has not white but " << GetColor(ColorEdgeList[Binder->nr]) << " color." << endl;
    37213788              }
     
    37273794          *out << Verbose(3) << "We have gone too far, stepping back to " << Walker->Name << "." << endl;
    37283795        }
    3729                         if (Walker != OtherAtom) {      // if no white neighbours anymore, color it black 
     3796                        if (Walker != OtherAtom) {      // if no white neighbours anymore, color it black
    37303797          *out << Verbose(2) << "Coloring " << Walker->Name << " black." << endl;
    37313798                                ColorVertexList[Walker->nr] = black;
     
    37343801      }
    37353802        } while ((Walker != Root) || (ColorVertexList[Root->nr] != black));
    3736     *out << Verbose(2) << "Inner Looping is finished." << endl;   
     3803    *out << Verbose(2) << "Inner Looping is finished." << endl;
    37373804
    37383805    // if we reset all AtomCount atoms, we have again technically O(N^2) ...
     
    37503817    }
    37513818  }
    3752   *out << Verbose(1) << "Outer Looping over all vertices is done." << endl; 
     3819  *out << Verbose(1) << "Outer Looping over all vertices is done." << endl;
    37533820
    37543821  // copy together
    3755   *out << Verbose(1) << "Copying all fragments into MoleculeList structure." << endl; 
     3822  *out << Verbose(1) << "Copying all fragments into MoleculeList structure." << endl;
    37563823  FragmentList = new MoleculeListClass(FragmentCounter, AtomCount);
    37573824  RunningIndex = 0;
     
    38243891
    38253892  NumCombinations = 1 << SetDimension;
    3826  
     3893
    38273894  // Hier muessen von 1 bis NumberOfBondsPerAtom[Walker->nr] alle Kombinationen
    38283895  // von Endstuecken (aus den Bonds) hinzugefᅵᅵgt werden und fᅵᅵr verbleibende ANOVAOrder
    38293896  // rekursiv GraphCrawler in der nᅵᅵchsten Ebene aufgerufen werden
    3830  
     3897
    38313898  *out << Verbose(1+verbosity) << "Begin of SPFragmentGenerator." << endl;
    38323899  *out << Verbose(1+verbosity) << "We are " << RootDistance << " away from Root, which is " << *FragmentSearch->Root << ", SubOrder is " << SubOrder << ", SetDimension is " << SetDimension << " and this means " <<  NumCombinations-1 << " combination(s)." << endl;
    38333900
    3834   // initialised touched list (stores added atoms on this level) 
     3901  // initialised touched list (stores added atoms on this level)
    38353902  *out << Verbose(1+verbosity) << "Clearing touched list." << endl;
    38363903  for (TouchedIndex=SubOrder+1;TouchedIndex--;)  // empty touched list
    38373904    TouchedList[TouchedIndex] = -1;
    38383905  TouchedIndex = 0;
    3839  
     3906
    38403907  // create every possible combination of the endpieces
    38413908  *out << Verbose(1+verbosity) << "Going through all combinations of the power set." << endl;
     
    38453912    for (int j=SetDimension;j--;)
    38463913      bits += (i & (1 << j)) >> j;
    3847      
     3914
    38483915    *out << Verbose(1+verbosity) << "Current set is " << Binary(i | (1 << SetDimension)) << ", number of bits is " << bits << "." << endl;
    38493916    if (bits <= SubOrder) { // if not greater than additional atoms allowed on stack, continue
     
    38533920        bit = ((i & (1 << j)) != 0);  // mask the bit for the j-th bond
    38543921        if (bit) {  // if bit is set, we add this bond partner
    3855                 OtherWalker = BondsSet[j]->rightatom;   // rightatom is always the one more distant, i.e. the one to add 
     3922                OtherWalker = BondsSet[j]->rightatom;   // rightatom is always the one more distant, i.e. the one to add
    38563923          //*out << Verbose(1+verbosity) << "Current Bond is " << ListOfBondsPerAtom[Walker->nr][i] << ", checking on " << *OtherWalker << "." << endl;
    38573924          *out << Verbose(2+verbosity) << "Adding " << *OtherWalker << " with nr " << OtherWalker->nr << "." << endl;
    3858           TestKeySetInsert = FragmentSearch->FragmentSet->insert(OtherWalker->nr); 
     3925          TestKeySetInsert = FragmentSearch->FragmentSet->insert(OtherWalker->nr);
    38593926          if (TestKeySetInsert.second) {
    38603927            TouchedList[TouchedIndex++] = OtherWalker->nr;  // note as added
     
    38693936        }
    38703937      }
    3871      
    3872       SpaceLeft = SubOrder - Added ;// SubOrder - bits; // due to item's maybe being already present, this does not work anymore 
     3938
     3939      SpaceLeft = SubOrder - Added ;// SubOrder - bits; // due to item's maybe being already present, this does not work anymore
    38733940      if (SpaceLeft > 0) {
    38743941        *out << Verbose(1+verbosity) << "There's still some space left on stack: " << SpaceLeft << "." << endl;
     
    38983965          }
    38993966          *out << Verbose(2+verbosity) << "Calling subset generator " << SP << " away from root " << *FragmentSearch->Root << " with sub set dimension " << SubSetDimension << "." << endl;
    3900           SPFragmentGenerator(out, FragmentSearch, SP, BondsList, SubSetDimension, SubOrder-bits); 
     3967          SPFragmentGenerator(out, FragmentSearch, SP, BondsList, SubSetDimension, SubOrder-bits);
    39013968          Free((void **)&BondsList, "molecule::SPFragmentGenerator: **BondsList");
    39023969        }
     
    39073974        *out << Verbose(2) << "Found a new fragment[" << FragmentSearch->FragmentCounter << "], local nr.s are: ";
    39083975        for(KeySet::iterator runner = FragmentSearch->FragmentSet->begin(); runner != FragmentSearch->FragmentSet->end(); runner++)
    3909           *out << (*runner) << " "; 
     3976          *out << (*runner) << " ";
    39103977        *out << endl;
    39113978        //if (!CheckForConnectedSubgraph(out, FragmentSearch->FragmentSet))
     
    39153982        //Removal = StoreFragmentFromStack(out, FragmentSearch->Root, FragmentSearch->Leaflet, FragmentSearch->FragmentStack, FragmentSearch->ShortestPathList, &FragmentSearch->FragmentCounter, FragmentSearch->configuration);
    39163983      }
    3917      
     3984
    39183985      // --3-- remove all added items in this level from snake stack
    39193986      *out << Verbose(1+verbosity) << "Removing all items that were added on this SP level " << RootDistance << "." << endl;
     
    39263993      *out << Verbose(2) << "Remaining local nr.s on snake stack are: ";
    39273994      for(KeySet::iterator runner = FragmentSearch->FragmentSet->begin(); runner != FragmentSearch->FragmentSet->end(); runner++)
    3928         *out << (*runner) << " "; 
     3995        *out << (*runner) << " ";
    39293996      *out << endl;
    39303997      TouchedIndex = 0; // set Index to 0 for list of atoms added on this level
     
    39334000    }
    39344001  }
    3935   Free((void **)&TouchedList, "molecule::SPFragmentGenerator: *TouchedList"); 
     4002  Free((void **)&TouchedList, "molecule::SPFragmentGenerator: *TouchedList");
    39364003  *out << Verbose(1+verbosity) << "End of SPFragmentGenerator, " << RootDistance << " away from Root " << *FragmentSearch->Root << " and SubOrder is " << SubOrder << "." << endl;
    39374004};
     
    39424009 * \return true - connected, false - disconnected
    39434010 * \note this is O(n^2) for it's just a bug checker not meant for permanent use!
    3944  */ 
     4011 */
    39454012bool molecule::CheckForConnectedSubgraph(ofstream *out, KeySet *Fragment)
    39464013{
     
    39484015  bool BondStatus = false;
    39494016  int size;
    3950  
     4017
    39514018  *out << Verbose(1) << "Begin of CheckForConnectedSubgraph" << endl;
    39524019  *out << Verbose(2) << "Disconnected atom: ";
    3953  
     4020
    39544021  // count number of atoms in graph
    39554022  size = 0;
     
    39974064 * \param *out output stream for debugging
    39984065 * \param Order bond order (limits BFS exploration and "number of digits" in power set generation
    3999  * \param FragmentSearch UniqueFragments structure containing TEFactor, root atom and so on 
     4066 * \param FragmentSearch UniqueFragments structure containing TEFactor, root atom and so on
    40004067 * \param RestrictedKeySet Restricted vertex set to use in context of molecule
    40014068 * \return number of inserted fragments
    40024069 * \note ShortestPathList in FragmentSearch structure is probably due to NumberOfAtomsSPLevel and SP not needed anymore
    40034070 */
    4004 int molecule::PowerSetGenerator(ofstream *out, int Order, struct UniqueFragments &FragmentSearch, KeySet RestrictedKeySet) 
     4071int molecule::PowerSetGenerator(ofstream *out, int Order, struct UniqueFragments &FragmentSearch, KeySet RestrictedKeySet)
    40054072{
    40064073  int SP, AtomKeyNr;
     
    40234090    FragmentSearch.BondsPerSPCount[i] = 0;
    40244091  FragmentSearch.BondsPerSPCount[0] = 1;
    4025   Binder = new bond(FragmentSearch.Root, FragmentSearch.Root); 
     4092  Binder = new bond(FragmentSearch.Root, FragmentSearch.Root);
    40264093  add(Binder, FragmentSearch.BondsPerSPList[1]);
    4027  
     4094
    40284095  // do a BFS search to fill the SP lists and label the found vertices
    40294096  // Actually, we should construct a spanning tree vom the root atom and select all edges therefrom and put them into
    40304097  // according shortest path lists. However, we don't. Rather we fill these lists right away, as they do form a spanning
    40314098  // tree already sorted into various SP levels. That's why we just do loops over the depth (CurrentSP) and breadth
    4032   // (EdgeinSPLevel) of this tree ... 
     4099  // (EdgeinSPLevel) of this tree ...
    40334100  // In another picture, the bonds always contain a direction by rightatom being the one more distant from root and hence
    40344101  // naturally leftatom forming its predecessor, preventing the BFS"seeker" from continuing in the wrong direction.
     
    40834150    }
    40844151  }
    4085  
     4152
    40864153  // outputting all list for debugging
    40874154  *out << Verbose(0) << "Printing all found lists." << endl;
     
    40924159      Binder = Binder->next;
    40934160      *out << Verbose(2) << *Binder << endl;
    4094     } 
    4095   }
    4096  
     4161    }
     4162  }
     4163
    40974164  // creating fragments with the found edge sets  (may be done in reverse order, faster)
    40984165  SP = -1;  // the Root <-> Root edge must be subtracted!
     
    41014168    while (Binder->next != FragmentSearch.BondsPerSPList[2*i+1]) {
    41024169      Binder = Binder->next;
    4103       SP ++; 
     4170      SP ++;
    41044171    }
    41054172  }
     
    41084175    // start with root (push on fragment stack)
    41094176    *out << Verbose(0) << "Starting fragment generation with " << *FragmentSearch.Root << ", local nr is " << FragmentSearch.Root->nr << "." << endl;
    4110     FragmentSearch.FragmentSet->clear(); 
     4177    FragmentSearch.FragmentSet->clear();
    41114178    *out << Verbose(0) << "Preparing subset for this root and calling generator." << endl;
    41124179    // prepare the subset and call the generator
    41134180    BondsList = (bond **) Malloc(sizeof(bond *)*FragmentSearch.BondsPerSPCount[0], "molecule::PowerSetGenerator: **BondsList");
    41144181    BondsList[0] = FragmentSearch.BondsPerSPList[0]->next;  // on SP level 0 there's only the root bond
    4115    
     4182
    41164183    SPFragmentGenerator(out, &FragmentSearch, 0, BondsList, FragmentSearch.BondsPerSPCount[0], Order);
    4117    
     4184
    41184185    Free((void **)&BondsList, "molecule::PowerSetGenerator: **BondsList");
    41194186  } else {
     
    41244191  // remove root from stack
    41254192  *out << Verbose(0) << "Removing root again from stack." << endl;
    4126   FragmentSearch.FragmentSet->erase(FragmentSearch.Root->nr);   
     4193  FragmentSearch.FragmentSet->erase(FragmentSearch.Root->nr);
    41274194
    41284195  // free'ing the bonds lists
     
    41434210  }
    41444211
    4145   // return list 
     4212  // return list
    41464213  *out << Verbose(0) << "End of PowerSetGenerator." << endl;
    41474214  return (FragmentSearch.FragmentCounter - Counter);
     
    41744241    // remove bonds that are beyond bonddistance
    41754242    for(int i=NDIM;i--;)
    4176       Translationvector.x[i] = 0.; 
     4243      Translationvector.x[i] = 0.;
    41774244    // scan all bonds
    41784245    Binder = first;
     
    42214288        }
    42224289      }
    4223       // re-add bond   
     4290      // re-add bond
    42244291      link(Binder, OtherBinder);
    42254292    } else {
     
    42754342        IteratorB++;
    42764343      } // end of while loop
    4277     }// end of check in case of equal sizes 
     4344    }// end of check in case of equal sizes
    42784345  }
    42794346  return false; // if we reach this point, they are equal
     
    43194386 * \param graph1 first (dest) graph
    43204387 * \param graph2 second (source) graph
    4321  * \param *counter keyset counter that gets increased 
     4388 * \param *counter keyset counter that gets increased
    43224389 */
    43234390inline void InsertGraphIntoGraph(ofstream *out, Graph &graph1, Graph &graph2, int *counter)
     
    43644431  int RootKeyNr, RootNr;
    43654432  struct UniqueFragments FragmentSearch;
    4366  
     4433
    43674434  *out << Verbose(0) << "Begin of FragmentBOSSANOVA." << endl;
    43684435
     
    43874454    Walker = Walker->next;
    43884455    CompleteMolecule.insert(Walker->GetTrueFather()->nr);
    4389   } 
     4456  }
    43904457
    43914458  // this can easily be seen: if Order is 5, then the number of levels for each lower order is the total sum of the number of levels above, as
     
    44014468    //if ((MinimumRingSize[Walker->GetTrueFather()->nr] != -1) && (Walker->GetTrueFather()->AdaptiveOrder+1 > MinimumRingSize[Walker->GetTrueFather()->nr])) {
    44024469    //  *out << Verbose(0) << "Bond order " << Walker->GetTrueFather()->AdaptiveOrder << " of Root " << *Walker << " greater than or equal to Minimum Ring size of " << MinimumRingSize << " found is not allowed." << endl;
    4403     //} else 
     4470    //} else
    44044471    {
    44054472      // increase adaptive order by one
    44064473      Walker->GetTrueFather()->AdaptiveOrder++;
    44074474      Order = Walker->AdaptiveOrder = Walker->GetTrueFather()->AdaptiveOrder;
    4408  
     4475
    44094476      // initialise Order-dependent entries of UniqueFragments structure
    44104477      FragmentSearch.BondsPerSPList = (bond **) Malloc(sizeof(bond *)*Order*2, "molecule::PowerSetGenerator: ***BondsPerSPList");
     
    44134480        FragmentSearch.BondsPerSPList[2*i] = new bond();    // start node
    44144481        FragmentSearch.BondsPerSPList[2*i+1] = new bond();  // end node
    4415         FragmentSearch.BondsPerSPList[2*i]->next = FragmentSearch.BondsPerSPList[2*i+1];     // intertwine these two 
     4482        FragmentSearch.BondsPerSPList[2*i]->next = FragmentSearch.BondsPerSPList[2*i+1];     // intertwine these two
    44164483        FragmentSearch.BondsPerSPList[2*i+1]->previous = FragmentSearch.BondsPerSPList[2*i];
    44174484        FragmentSearch.BondsPerSPCount[i] = 0;
    4418       } 
    4419  
     4485      }
     4486
    44204487      // allocate memory for all lower level orders in this 1D-array of ptrs
    44214488      NumLevels = 1 << (Order-1); // (int)pow(2,Order);
     
    44234490      for (int i=0;i<NumLevels;i++)
    44244491        FragmentLowerOrdersList[RootNr][i] = NULL;
    4425      
     4492
    44264493      // create top order where nothing is reduced
    44274494      *out << Verbose(0) << "==============================================================================================================" << endl;
    44284495      *out << Verbose(0) << "Creating KeySets of Bond Order " << Order << " for " << *Walker << ", " << (RootStack.size()-RootNr) << " Roots remaining." << endl; // , NumLevels is " << NumLevels << "
    4429  
     4496
    44304497      // Create list of Graphs of current Bond Order (i.e. F_{ij})
    44314498      FragmentLowerOrdersList[RootNr][0] =  new Graph;
     
    44404507        // we don't have to dive into suborders! These keysets are all already created on lower orders!
    44414508        // this was all ancient stuff, when we still depended on the TEFactors (and for those the suborders were needed)
    4442        
     4509
    44434510//        if ((NumLevels >> 1) > 0) {
    44444511//          // create lower order fragments
     
    44474514//          for (int source=0;source<(NumLevels >> 1);source++) { // 1-terms don't need any more splitting, that's why only half is gone through (shift again)
    44484515//            // step down to next order at (virtual) boundary of powers of 2 in array
    4449 //            while (source >= (1 << (Walker->AdaptiveOrder-Order))) // (int)pow(2,Walker->AdaptiveOrder-Order))   
     4516//            while (source >= (1 << (Walker->AdaptiveOrder-Order))) // (int)pow(2,Walker->AdaptiveOrder-Order))
    44504517//              Order--;
    44514518//            *out << Verbose(0) << "Current Order is: " << Order << "." << endl;
     
    44544521//              *out << Verbose(0) << "--------------------------------------------------------------------------------------------------------------" << endl;
    44554522//              *out << Verbose(0) << "Current SubOrder is: " << SubOrder << " with source " << source << " to destination " << dest << "." << endl;
    4456 //       
     4523//
    44574524//              // every molecule is split into a list of again (Order - 1) molecules, while counting all molecules
    44584525//              //*out << Verbose(1) << "Splitting the " << (*FragmentLowerOrdersList[RootNr][source]).size() << " molecules of the " << source << "th cell in the array." << endl;
     
    44854552      RootStack.push_back(RootKeyNr); // put back on stack
    44864553      RootNr++;
    4487  
     4554
    44884555      // free Order-dependent entries of UniqueFragments structure for next loop cycle
    44894556      Free((void **)&FragmentSearch.BondsPerSPCount, "molecule::PowerSetGenerator: *BondsPerSPCount");
     
    44914558        delete(FragmentSearch.BondsPerSPList[2*i]);
    44924559        delete(FragmentSearch.BondsPerSPList[2*i+1]);
    4493       } 
     4560      }
    44944561      Free((void **)&FragmentSearch.BondsPerSPList, "molecule::PowerSetGenerator: ***BondsPerSPList");
    44954562    }
     
    45024569  Free((void **)&FragmentSearch.ShortestPathList, "molecule::PowerSetGenerator: *ShortestPathList");
    45034570  delete(FragmentSearch.FragmentSet);
    4504  
    4505   // now, FragmentLowerOrdersList is complete, it looks - for BondOrder 5 - as this (number is the ANOVA Order of the terms therein) 
     4571
     4572  // now, FragmentLowerOrdersList is complete, it looks - for BondOrder 5 - as this (number is the ANOVA Order of the terms therein)
    45064573  // 5433222211111111
    45074574  // 43221111
     
    45234590    RootKeyNr = RootStack.front();
    45244591    RootStack.pop_front();
    4525     Walker = FindAtom(RootKeyNr); 
     4592    Walker = FindAtom(RootKeyNr);
    45264593    NumLevels = 1 << (Walker->AdaptiveOrder - 1);
    45274594    for(int i=0;i<NumLevels;i++) {
     
    45364603  Free((void **)&FragmentLowerOrdersList, "molecule::FragmentBOSSANOVA: ***FragmentLowerOrdersList");
    45374604  Free((void **)&NumMoleculesOfOrder, "molecule::FragmentBOSSANOVA: *NumMoleculesOfOrder");
    4538  
     4605
    45394606  *out << Verbose(0) << "End of FragmentBOSSANOVA." << endl;
    45404607};
     
    45704637  atom *Walker = NULL;
    45714638  bool result = true; // status of comparison
    4572  
    4573   *out << Verbose(3) << "Begin of IsEqualToWithinThreshold." << endl; 
     4639
     4640  *out << Verbose(3) << "Begin of IsEqualToWithinThreshold." << endl;
    45744641  /// first count both their atoms and elements and update lists thereby ...
    45754642  //*out << Verbose(0) << "Counting atoms, updating list" << endl;
     
    46184685    if (CenterOfGravity.Distance(&OtherCenterOfGravity) > threshold) {
    46194686      *out << Verbose(4) << "Centers of gravity don't match." << endl;
    4620       result = false; 
    4621     }
    4622   }
    4623  
     4687      result = false;
     4688    }
     4689  }
     4690
    46244691  /// ... then make a list with the euclidian distance to this center for each atom of both molecules
    46254692  if (result) {
     
    46374704      OtherDistances[Walker->nr] = OtherCenterOfGravity.Distance(&Walker->x);
    46384705    }
    4639  
     4706
    46404707    /// ... sort each list (using heapsort (o(N log N)) from GSL)
    46414708    *out << Verbose(5) << "Sorting distances" << endl;
     
    46484715    for(int i=AtomCount;i--;)
    46494716      PermutationMap[PermMap[i]] = (int) OtherPermMap[i];
    4650    
     4717
    46514718    /// ... and compare them step by step, whether the difference is individiually(!) below \a threshold for all
    46524719    *out << Verbose(4) << "Comparing distances" << endl;
     
    46594726    Free((void **)&PermMap, "molecule::IsEqualToWithinThreshold: *PermMap");
    46604727    Free((void **)&OtherPermMap, "molecule::IsEqualToWithinThreshold: *OtherPermMap");
    4661      
     4728
    46624729    /// free memory
    46634730    Free((void **)&Distances, "molecule::IsEqualToWithinThreshold: Distances");
     
    46674734      result = false;
    46684735    }
    4669   } 
     4736  }
    46704737  /// return pointer to map if all distances were below \a threshold
    46714738  *out << Verbose(3) << "End of IsEqualToWithinThreshold." << endl;
     
    46764743    *out << Verbose(3) << "Result: Not equal." << endl;
    46774744    return NULL;
    4678   } 
     4745  }
    46794746};
    46804747
     
    47314798 * \param *output output stream of temperature file
    47324799 * \return file written (true), failure on writing file (false)
    4733  */ 
     4800 */
    47344801bool molecule::OutputTemperatureFromTrajectories(ofstream *out, int startstep, int endstep, ofstream *output)
    47354802{
     
    47394806  if (output == NULL)
    47404807    return false;
    4741   else 
     4808  else
    47424809    *output << "# Step Temperature [K] Temperature [a.u.]" << endl;
    47434810  for (int step=startstep;step < endstep; step++) { // loop over all time steps
Note: See TracChangeset for help on using the changeset viewer.