Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/moleculelist.cpp

    r274d45 r84c494  
    1212#include "atom.hpp"
    1313#include "bond.hpp"
     14#include "bondgraph.hpp"
    1415#include "boundary.hpp"
    1516#include "config.hpp"
     
    2324#include "periodentafel.hpp"
    2425#include "Helpers/Assert.hpp"
     26#include "Matrix.hpp"
     27#include "Box.hpp"
    2528
    2629#include "Helpers/Assert.hpp"
     
    379382 * bonded to the same atom, then we add for this pair a correction term constructed from a Morse
    380383 * potential function fit to QM calculations with respecting to the interatomic hydrogen distance.
    381  * \param *out output stream for debugging
    382  * \param *path path to file
    383  */
    384 bool MoleculeListClass::AddHydrogenCorrection(char *path)
     384 * \param &path path to file
     385 */
     386bool MoleculeListClass::AddHydrogenCorrection(std::string &path)
    385387{
    386388  bond *Binder = NULL;
     
    400402  // 0a. find dimension of matrices with constants
    401403  line = path;
    402   line.append("/");
    403   line += FRAGMENTPREFIX;
    404404  line += "1";
    405405  line += FITCONSTANTSUFFIX;
    406406  input.open(line.c_str());
    407   if (input == NULL) {
     407  if (input.fail()) {
    408408    DoLog(1) && (Log() << Verbose(1) << endl << "Unable to open " << line << ", is the directory correct?" << endl);
    409409    return false;
     
    569569
    570570/** Store force indices, i.e. the connection between the nuclear index in the total molecule config and the respective atom in fragment config.
    571  * \param *out output stream for debugging
    572  * \param *path path to file
     571 * \param &path path to file
    573572 * \param *SortIndex Index to map from the BFS labeling to the sequence how of Ion_Type in the config
    574573 * \return true - file written successfully, false - writing failed
    575574 */
    576 bool MoleculeListClass::StoreForcesFile(char *path,
    577     int *SortIndex)
     575bool MoleculeListClass::StoreForcesFile(std::string &path, int *SortIndex)
    578576{
    579577  bool status = true;
    580   ofstream ForcesFile;
    581   stringstream line;
     578  string filename(path);
     579  filename += FORCESFILE;
     580  ofstream ForcesFile(filename.c_str());
    582581  periodentafel *periode=World::getInstance().getPeriode();
    583582
    584583  // open file for the force factors
    585584  DoLog(1) && (Log() << Verbose(1) << "Saving  force factors ... ");
    586   line << path << "/" << FRAGMENTPREFIX << FORCESFILE;
    587   ForcesFile.open(line.str().c_str(), ios::out);
    588   if (ForcesFile != NULL) {
     585  if (!ForcesFile.fail()) {
    589586    //Log() << Verbose(1) << "Final AtomicForcesList: ";
    590587    //output << prefix << "Forces" << endl;
     
    611608  } else {
    612609    status = false;
    613     DoLog(1) && (Log() << Verbose(1) << "failed to open file " << line.str() << "." << endl);
     610    DoLog(1) && (Log() << Verbose(1) << "failed to open file " << filename << "." << endl);
    614611  }
    615612  ForcesFile.close();
     
    620617/** Writes a config file for each molecule in the given \a **FragmentList.
    621618 * \param *out output stream for debugging
    622  * \param *configuration standard configuration to attach atoms in fragment molecule to.
     619 * \param &prefix path and prefix to the fragment config files
    623620 * \param *SortIndex Index to map from the BFS labeling to the sequence how of Ion_Type in the config
    624621 * \return true - success (each file was written), false - something went wrong.
    625622 */
    626 bool MoleculeListClass::OutputConfigForListOfFragments(config *configuration, int *SortIndex)
     623bool MoleculeListClass::OutputConfigForListOfFragments(std::string &prefix, int *SortIndex)
    627624{
    628625  ofstream outputFragment;
    629   char FragmentName[MAXSTRINGSIZE];
     626  std::string FragmentName;
    630627  char PathBackup[MAXSTRINGSIZE];
    631628  bool result = true;
     
    636633  int FragmentCounter = 0;
    637634  ofstream output;
    638   double cell_size_backup[6];
    639   double * const cell_size = World::getInstance().getDomain();
    640 
    641   // backup cell_size
    642   for (int i=0;i<6;i++)
    643     cell_size_backup[i] = cell_size[i];
     635  Matrix cell_size = World::getInstance().getDomain().getM();
     636  Matrix cell_size_backup = cell_size;
     637
    644638  // store the fragments as config and as xyz
    645639  for (MoleculeList::iterator ListRunner = ListOfMolecules.begin(); ListRunner != ListOfMolecules.end(); ListRunner++) {
    646640    // save default path as it is changed for each fragment
    647     path = configuration->GetDefaultPath();
     641    path = World::getInstance().getConfig()->GetDefaultPath();
    648642    if (path != NULL)
    649643      strcpy(PathBackup, path);
     
    658652    // output xyz file
    659653    FragmentNumber = FixedDigitNumber(ListOfMolecules.size(), FragmentCounter++);
    660     sprintf(FragmentName, "%s/%s%s.conf.xyz", configuration->configpath, FRAGMENTPREFIX, FragmentNumber);
    661     outputFragment.open(FragmentName, ios::out);
     654    FragmentName = prefix + FragmentNumber + ".conf.xyz";
     655    outputFragment.open(FragmentName.c_str(), ios::out);
    662656    DoLog(2) && (Log() << Verbose(2) << "Saving bond fragment No. " << FragmentNumber << "/" << FragmentCounter - 1 << " as XYZ ...");
    663657    if ((intermediateResult = (*ListRunner)->OutputXYZ(&outputFragment)))
     
    679673    (*ListRunner)->CenterEdge(&BoxDimension);
    680674    (*ListRunner)->SetBoxDimension(&BoxDimension); // update Box of atoms by boundary
    681     int j = -1;
    682675    for (int k = 0; k < NDIM; k++) {
    683       j += k + 1;
    684       BoxDimension[k] = 2.5 * (configuration->GetIsAngstroem() ? 1. : 1. / AtomicLengthToAngstroem);
    685       cell_size[j] = BoxDimension[k] * 2.;
    686     }
     676      BoxDimension[k] = 2.5 * (World::getInstance().getConfig()->GetIsAngstroem() ? 1. : 1. / AtomicLengthToAngstroem);
     677      cell_size.at(k,k) = BoxDimension[k] * 2.;
     678    }
     679    World::getInstance().setDomain(cell_size);
    687680    (*ListRunner)->Translate(&BoxDimension);
    688681
    689682    // also calculate necessary orbitals
    690683    (*ListRunner)->CountElements(); // this is a bugfix, atoms should shoulds actually be added correctly to this fragment
    691     (*ListRunner)->CalculateOrbitals(*configuration);
     684    //(*ListRunner)->CalculateOrbitals(*World::getInstance().getConfig);
    692685
    693686    // change path in config
    694     //strcpy(PathBackup, configuration->configpath);
    695     sprintf(FragmentName, "%s/%s%s/", PathBackup, FRAGMENTPREFIX, FragmentNumber);
    696     configuration->SetDefaultPath(FragmentName);
     687    FragmentName = PathBackup;
     688    FragmentName += "/";
     689    FragmentName += FRAGMENTPREFIX;
     690    FragmentName += FragmentNumber;
     691    FragmentName += "/";
     692    World::getInstance().getConfig()->SetDefaultPath(FragmentName.c_str());
    697693
    698694    // and save as config
    699     sprintf(FragmentName, "%s/%s%s.conf", configuration->configpath, FRAGMENTPREFIX, FragmentNumber);
     695    FragmentName = prefix + FragmentNumber + ".conf";
    700696    DoLog(2) && (Log() << Verbose(2) << "Saving bond fragment No. " << FragmentNumber << "/" << FragmentCounter - 1 << " as config ...");
    701     if ((intermediateResult = configuration->Save(FragmentName, (*ListRunner)->elemente, (*ListRunner))))
     697    if ((intermediateResult = World::getInstance().getConfig()->Save(FragmentName.c_str(), (*ListRunner)->elemente, (*ListRunner))))
    702698      DoLog(0) && (Log() << Verbose(0) << " done." << endl);
    703699    else
     
    706702
    707703    // restore old config
    708     configuration->SetDefaultPath(PathBackup);
     704    World::getInstance().getConfig()->SetDefaultPath(PathBackup);
    709705
    710706    // and save as mpqc input file
    711     sprintf(FragmentName, "%s/%s%s.conf", configuration->configpath, FRAGMENTPREFIX, FragmentNumber);
     707    FragmentName = prefix + FragmentNumber + ".conf";
    712708    DoLog(2) && (Log() << Verbose(2) << "Saving bond fragment No. " << FragmentNumber << "/" << FragmentCounter - 1 << " as mpqc input ...");
    713     if ((intermediateResult = configuration->SaveMPQC(FragmentName, (*ListRunner))))
     709    if ((intermediateResult = World::getInstance().getConfig()->SaveMPQC(FragmentName.c_str(), (*ListRunner))))
    714710      DoLog(2) && (Log() << Verbose(2) << " done." << endl);
    715711    else
     
    727723
    728724  // restore cell_size
    729   for (int i=0;i<6;i++)
    730     cell_size[i] = cell_size_backup[i];
     725  World::getInstance().setDomain(cell_size_backup);
    731726
    732727  return result;
     
    767762
    768763  // 1. dissect the molecule into connected subgraphs
    769   if (!configuration->BG->ConstructBondGraph(mol)) {
    770     World::getInstance().destroyMolecule(mol);
    771     DoeLog(1) && (eLog()<< Verbose(1) << "There are no bonds." << endl);
     764  if (configuration->BG != NULL) {
     765    if (!configuration->BG->ConstructBondGraph(mol)) {
     766      World::getInstance().destroyMolecule(mol);
     767      DoeLog(1) && (eLog()<< Verbose(1) << "There are no bonds." << endl);
     768      return;
     769    }
     770  } else {
     771    DoeLog(1) && (eLog()<< Verbose(1) << "There is no BondGraph class present to create bonds." << endl);
    772772    return;
    773773  }
     
    884884  // center at set box dimensions
    885885  mol->CenterEdge(&center);
    886   World::getInstance().getDomain()[0] = center[0];
    887   World::getInstance().getDomain()[1] = 0;
    888   World::getInstance().getDomain()[2] = center[1];
    889   World::getInstance().getDomain()[3] = 0;
    890   World::getInstance().getDomain()[4] = 0;
    891   World::getInstance().getDomain()[5] = center[2];
     886  Matrix domain;
     887  for(int i =0;i<NDIM;++i)
     888    domain.at(i,i) = center[i];
     889  World::getInstance().setDomain(domain);
    892890  insert(mol);
    893891}
Note: See TracChangeset for help on using the changeset viewer.