Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/molecule.cpp

    re359a8 ra67d19  
    44 *
    55 */
     6
     7#include <cstring>
    68
    79#include "atom.hpp"
     
    2123#include "tesselation.hpp"
    2224#include "vector.hpp"
     25#include "World.hpp"
    2326
    2427/************************************* Functions for class molecule *********************************/
     
    4346  for(int i=MAX_ELEMENTS;i--;)
    4447    ElementsInMolecule[i] = 0;
    45   cell_size[0] = cell_size[2] = cell_size[5]= 20.;
    46   cell_size[1] = cell_size[3] = cell_size[4]= 0.;
    47   strcpy(name,"none");
     48  strcpy(name,World::get()->DefaultName);
    4849};
    4950
     
    157158  double *matrix = NULL;
    158159  bond *Binder = NULL;
     160  double * const cell_size = World::get()->cell_size;
    159161
    160162//  Log() << Verbose(3) << "Begin of AddHydrogenReplacementAtom." << endl;
     
    192194  BondRescale = TopOrigin->type->HBondDistance[TopBond->BondDegree-1];
    193195  if (BondRescale == -1) {
    194     eLog() << Verbose(1) << "There is no typical hydrogen bond distance in replacing bond (" << TopOrigin->Name << "<->" << TopReplacement->Name << ") of degree " << TopBond->BondDegree << "!" << endl;
     196    DoeLog(1) && (eLog()<< Verbose(1) << "There is no typical hydrogen bond distance in replacing bond (" << TopOrigin->Name << "<->" << TopReplacement->Name << ") of degree " << TopBond->BondDegree << "!" << endl);
    195197    return false;
    196198    BondRescale = bondlength;
     
    235237            SecondOtherAtom = (*Runner)->GetOtherAtom(TopOrigin);
    236238          } else {
    237             eLog() << Verbose(2) << "Detected more than four bonds for atom " << TopOrigin->Name;
     239            DoeLog(2) && (eLog()<< Verbose(2) << "Detected more than four bonds for atom " << TopOrigin->Name);
    238240          }
    239241        }
     
    272274      bondangle = TopOrigin->type->HBondAngle[1];
    273275      if (bondangle == -1) {
    274         eLog() << Verbose(1) << "There is no typical hydrogen bond angle in replacing bond (" << TopOrigin->Name << "<->" << TopReplacement->Name << ") of degree " << TopBond->BondDegree << "!" << endl;
     276        DoeLog(1) && (eLog()<< Verbose(1) << "There is no typical hydrogen bond angle in replacing bond (" << TopOrigin->Name << "<->" << TopReplacement->Name << ") of degree " << TopBond->BondDegree << "!" << endl);
    275277        return false;
    276278        bondangle = 0;
     
    394396      break;
    395397    default:
    396       eLog() << Verbose(1) << "BondDegree does not state single, double or triple bond!" << endl;
     398      DoeLog(1) && (eLog()<< Verbose(1) << "BondDegree does not state single, double or triple bond!" << endl);
    397399      AllWentWell = false;
    398400      break;
     
    427429  input = new istringstream(line);
    428430  *input >> NumberOfAtoms;
    429   Log() << Verbose(0) << "Parsing " << NumberOfAtoms << " atoms in file." << endl;
     431  DoLog(0) && (Log() << Verbose(0) << "Parsing " << NumberOfAtoms << " atoms in file." << endl);
    430432  getline(xyzfile,line,'\n'); // Read comment
    431   Log() << Verbose(1) << "Comment: " << line << endl;
     433  DoLog(1) && (Log() << Verbose(1) << "Comment: " << line << endl);
    432434
    433435  if (MDSteps == 0) // no atoms yet present
     
    445447    Walker->type = elemente->FindElement(shorthand);
    446448    if (Walker->type == NULL) {
    447       eLog() << Verbose(1) << "Could not parse the element at line: '" << line << "', setting to H.";
     449      DoeLog(1) && (eLog()<< Verbose(1) << "Could not parse the element at line: '" << line << "', setting to H.");
    448450      Walker->type = elemente->FindElement(1);
    449451    }
     
    541543    add(Binder, last);
    542544  } else {
    543     eLog() << Verbose(1) << "Could not add bond between " << atom1->Name << " and " << atom2->Name << " as one or both are not present in the molecule." << endl;
     545    DoeLog(1) && (eLog()<< Verbose(1) << "Could not add bond between " << atom1->Name << " and " << atom2->Name << " as one or both are not present in the molecule." << endl);
    544546  }
    545547  return Binder;
     
    553555bool molecule::RemoveBond(bond *pointer)
    554556{
    555   //eLog() << Verbose(1) << "molecule::RemoveBond: Function not implemented yet." << endl;
     557  //DoeLog(1) && (eLog()<< Verbose(1) << "molecule::RemoveBond: Function not implemented yet." << endl);
    556558  pointer->leftatom->RegisterBond(pointer);
    557559  pointer->rightatom->RegisterBond(pointer);
     
    567569bool molecule::RemoveBonds(atom *BondPartner)
    568570{
    569   //eLog() << Verbose(1) << "molecule::RemoveBond: Function not implemented yet." << endl;
     571  //DoeLog(1) && (eLog()<< Verbose(1) << "molecule::RemoveBond: Function not implemented yet." << endl);
    570572  BondList::const_iterator ForeRunner;
    571573  while (!BondPartner->ListOfBonds.empty()) {
     
    587589  else
    588590    molname = filename; // contains no slashes
    589   char *endname = strchr(molname, '.');
     591  const char *endname = strchr(molname, '.');
    590592  if ((endname == NULL) || (endname < molname))
    591593    length = strlen(molname);
     
    601603void molecule::SetBoxDimension(Vector *dim)
    602604{
     605  double * const cell_size = World::get()->cell_size;
    603606  cell_size[0] = dim->x[0];
    604607  cell_size[1] = 0.;
     
    619622    AtomCount--;
    620623  } else
    621     eLog() << Verbose(1) << "Atom " << pointer->Name << " is of element " << pointer->type->Z << " but the entry in the table of the molecule is 0!" << endl;
     624    DoeLog(1) && (eLog()<< Verbose(1) << "Atom " << pointer->Name << " is of element " << pointer->type->Z << " but the entry in the table of the molecule is 0!" << endl);
    622625  if (ElementsInMolecule[pointer->type->Z] == 0)  // was last atom of this element?
    623626    ElementCount--;
     
    637640    ElementsInMolecule[pointer->type->Z]--; // decrease number of atom of this element
    638641  else
    639     eLog() << Verbose(1) << "Atom " << pointer->Name << " is of element " << pointer->type->Z << " but the entry in the table of the molecule is 0!" << endl;
     642    DoeLog(1) && (eLog()<< Verbose(1) << "Atom " << pointer->Name << " is of element " << pointer->type->Z << " but the entry in the table of the molecule is 0!" << endl);
    640643  if (ElementsInMolecule[pointer->type->Z] == 0)  // was last atom of this element?
    641644    ElementCount--;
     
    662665    return walker;
    663666  } else {
    664     Log() << Verbose(0) << "Atom not found in list." << endl;
     667    DoLog(0) && (Log() << Verbose(0) << "Atom not found in list." << endl);
    665668    return NULL;
    666669  }
     
    678681    //mol->Output((ofstream *)&cout);
    679682    //Log() << Verbose(0) << "===============================================" << endl;
    680     Log() << Verbose(0) << text;
     683    DoLog(0) && (Log() << Verbose(0) << text);
    681684    cin >> No;
    682685    ion = this->FindAtom(No);
     
    691694bool molecule::CheckBounds(const Vector *x) const
    692695{
     696  double * const cell_size = World::get()->cell_size;
    693697  bool result = true;
    694698  int j =-1;
     
    766770void molecule::OutputListOfBonds() const
    767771{
    768   Log() << Verbose(2) << endl << "From Contents of ListOfBonds, all non-hydrogen atoms:" << endl;
     772  DoLog(2) && (Log() << Verbose(2) << endl << "From Contents of ListOfBonds, all non-hydrogen atoms:" << endl);
    769773  ActOnAllAtoms (&atom::OutputBondOfAtom );
    770   Log() << Verbose(0) << endl;
     774  DoLog(0) && (Log() << Verbose(0) << endl);
    771775};
    772776
     
    825829  }
    826830  if ((AtomCount == 0) || (i != AtomCount)) {
    827     Log() << Verbose(3) << "Mismatch in AtomCount " << AtomCount << " and recounted number " << i << ", renaming all." << endl;
     831    DoLog(3) && (Log() << Verbose(3) << "Mismatch in AtomCount " << AtomCount << " and recounted number " << i << ", renaming all." << endl);
    828832    AtomCount = i;
    829833
     
    841845        Walker->Name = Malloc<char>(6, "molecule::CountAtoms: *walker->Name");
    842846        sprintf(Walker->Name, "%2s%02d", Walker->type->symbol, Walker->nr+1);
    843         Log() << Verbose(3) << "Naming atom nr. " << Walker->nr << " " << Walker->Name << "." << endl;
     847        DoLog(3) && (Log() << Verbose(3) << "Naming atom nr. " << Walker->nr << " " << Walker->Name << "." << endl);
    844848        i++;
    845849      }
    846850    } else
    847       Log() << Verbose(3) << "AtomCount is still " << AtomCount << ", thus counting nothing." << endl;
     851      DoLog(3) && (Log() << Verbose(3) << "AtomCount is still " << AtomCount << ", thus counting nothing." << endl);
    848852  }
    849853};
     
    905909  bool result = true; // status of comparison
    906910
    907   Log() << Verbose(3) << "Begin of IsEqualToWithinThreshold." << endl;
     911  DoLog(3) && (Log() << Verbose(3) << "Begin of IsEqualToWithinThreshold." << endl);
    908912  /// first count both their atoms and elements and update lists thereby ...
    909913  //Log() << Verbose(0) << "Counting atoms, updating list" << endl;
     
    917921  if (result) {
    918922    if (AtomCount != OtherMolecule->AtomCount) {
    919       Log() << Verbose(4) << "AtomCounts don't match: " << AtomCount << " == " << OtherMolecule->AtomCount << endl;
     923      DoLog(4) && (Log() << Verbose(4) << "AtomCounts don't match: " << AtomCount << " == " << OtherMolecule->AtomCount << endl);
    920924      result = false;
    921925    } else Log() << Verbose(4) << "AtomCounts match: " << AtomCount << " == " << OtherMolecule->AtomCount << endl;
     
    924928  if (result) {
    925929    if (ElementCount != OtherMolecule->ElementCount) {
    926       Log() << Verbose(4) << "ElementCount don't match: " << ElementCount << " == " << OtherMolecule->ElementCount << endl;
     930      DoLog(4) && (Log() << Verbose(4) << "ElementCount don't match: " << ElementCount << " == " << OtherMolecule->ElementCount << endl);
    927931      result = false;
    928932    } else Log() << Verbose(4) << "ElementCount match: " << ElementCount << " == " << OtherMolecule->ElementCount << endl;
     
    936940    }
    937941    if (flag < MAX_ELEMENTS) {
    938       Log() << Verbose(4) << "ElementsInMolecule don't match." << endl;
     942      DoLog(4) && (Log() << Verbose(4) << "ElementsInMolecule don't match." << endl);
    939943      result = false;
    940944    } else Log() << Verbose(4) << "ElementsInMolecule match." << endl;
     
    942946  /// then determine and compare center of gravity for each molecule ...
    943947  if (result) {
    944     Log() << Verbose(5) << "Calculating Centers of Gravity" << endl;
     948    DoLog(5) && (Log() << Verbose(5) << "Calculating Centers of Gravity" << endl);
    945949    DeterminePeriodicCenter(CenterOfGravity);
    946950    OtherMolecule->DeterminePeriodicCenter(OtherCenterOfGravity);
    947     Log() << Verbose(5) << "Center of Gravity: ";
     951    DoLog(5) && (Log() << Verbose(5) << "Center of Gravity: ");
    948952    CenterOfGravity.Output();
    949     Log() << Verbose(0) << endl << Verbose(5) << "Other Center of Gravity: ";
     953    DoLog(0) && (Log() << Verbose(0) << endl << Verbose(5) << "Other Center of Gravity: ");
    950954    OtherCenterOfGravity.Output();
    951     Log() << Verbose(0) << endl;
     955    DoLog(0) && (Log() << Verbose(0) << endl);
    952956    if (CenterOfGravity.DistanceSquared(&OtherCenterOfGravity) > threshold*threshold) {
    953       Log() << Verbose(4) << "Centers of gravity don't match." << endl;
     957      DoLog(4) && (Log() << Verbose(4) << "Centers of gravity don't match." << endl);
    954958      result = false;
    955959    }
     
    958962  /// ... then make a list with the euclidian distance to this center for each atom of both molecules
    959963  if (result) {
    960     Log() << Verbose(5) << "Calculating distances" << endl;
     964    DoLog(5) && (Log() << Verbose(5) << "Calculating distances" << endl);
    961965    Distances = Calloc<double>(AtomCount, "molecule::IsEqualToWithinThreshold: Distances");
    962966    OtherDistances = Calloc<double>(AtomCount, "molecule::IsEqualToWithinThreshold: OtherDistances");
     
    965969
    966970    /// ... sort each list (using heapsort (o(N log N)) from GSL)
    967     Log() << Verbose(5) << "Sorting distances" << endl;
     971    DoLog(5) && (Log() << Verbose(5) << "Sorting distances" << endl);
    968972    PermMap = Calloc<size_t>(AtomCount, "molecule::IsEqualToWithinThreshold: *PermMap");
    969973    OtherPermMap = Calloc<size_t>(AtomCount, "molecule::IsEqualToWithinThreshold: *OtherPermMap");
     
    971975    gsl_heapsort_index (OtherPermMap, OtherDistances, AtomCount, sizeof(double), CompareDoubles);
    972976    PermutationMap = Calloc<int>(AtomCount, "molecule::IsEqualToWithinThreshold: *PermutationMap");
    973     Log() << Verbose(5) << "Combining Permutation Maps" << endl;
     977    DoLog(5) && (Log() << Verbose(5) << "Combining Permutation Maps" << endl);
    974978    for(int i=AtomCount;i--;)
    975979      PermutationMap[PermMap[i]] = (int) OtherPermMap[i];
    976980
    977981    /// ... and compare them step by step, whether the difference is individually(!) below \a threshold for all
    978     Log() << Verbose(4) << "Comparing distances" << endl;
     982    DoLog(4) && (Log() << Verbose(4) << "Comparing distances" << endl);
    979983    flag = 0;
    980984    for (int i=0;i<AtomCount;i++) {
    981       Log() << Verbose(5) << "Distances squared: |" << Distances[PermMap[i]] << " - " << OtherDistances[OtherPermMap[i]] << "| = " << fabs(Distances[PermMap[i]] - OtherDistances[OtherPermMap[i]]) << " ?<? " <<  threshold << endl;
     985      DoLog(5) && (Log() << Verbose(5) << "Distances squared: |" << Distances[PermMap[i]] << " - " << OtherDistances[OtherPermMap[i]] << "| = " << fabs(Distances[PermMap[i]] - OtherDistances[OtherPermMap[i]]) << " ?<? " <<  threshold << endl);
    982986      if (fabs(Distances[PermMap[i]] - OtherDistances[OtherPermMap[i]]) > threshold*threshold)
    983987        flag = 1;
     
    995999  }
    9961000  /// return pointer to map if all distances were below \a threshold
    997   Log() << Verbose(3) << "End of IsEqualToWithinThreshold." << endl;
     1001  DoLog(3) && (Log() << Verbose(3) << "End of IsEqualToWithinThreshold." << endl);
    9981002  if (result) {
    999     Log() << Verbose(3) << "Result: Equal." << endl;
     1003    DoLog(3) && (Log() << Verbose(3) << "Result: Equal." << endl);
    10001004    return PermutationMap;
    10011005  } else {
    1002     Log() << Verbose(3) << "Result: Not equal." << endl;
     1006    DoLog(3) && (Log() << Verbose(3) << "Result: Not equal." << endl);
    10031007    return NULL;
    10041008  }
     
    10151019{
    10161020  atom *Walker = NULL, *OtherWalker = NULL;
    1017   Log() << Verbose(3) << "Begin of GetFatherAtomicMap." << endl;
     1021  DoLog(3) && (Log() << Verbose(3) << "Begin of GetFatherAtomicMap." << endl);
    10181022  int *AtomicMap = Malloc<int>(AtomCount, "molecule::GetAtomicMap: *AtomicMap");
    10191023  for (int i=AtomCount;i--;)
     
    10221026    for (int i=AtomCount;i--;) // no need as -1 means already that there is trivial correspondence
    10231027      AtomicMap[i] = i;
    1024     Log() << Verbose(4) << "Map is trivial." << endl;
     1028    DoLog(4) && (Log() << Verbose(4) << "Map is trivial." << endl);
    10251029  } else {
    1026     Log() << Verbose(4) << "Map is ";
     1030    DoLog(4) && (Log() << Verbose(4) << "Map is ");
    10271031    Walker = start;
    10281032    while (Walker->next != end) {
     
    10411045        }
    10421046      }
    1043       Log() << Verbose(0) << AtomicMap[Walker->nr] << "\t";
    1044     }
    1045     Log() << Verbose(0) << endl;
    1046   }
    1047   Log() << Verbose(3) << "End of GetFatherAtomicMap." << endl;
     1047      DoLog(0) && (Log() << Verbose(0) << AtomicMap[Walker->nr] << "\t");
     1048    }
     1049    DoLog(0) && (Log() << Verbose(0) << endl);
     1050  }
     1051  DoLog(3) && (Log() << Verbose(3) << "End of GetFatherAtomicMap." << endl);
    10481052  return AtomicMap;
    10491053};
Note: See TracChangeset for help on using the changeset viewer.