Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/moleculelist.cpp

    r35b698 r274d45  
    1212#include "atom.hpp"
    1313#include "bond.hpp"
    14 #include "bondgraph.hpp"
    1514#include "boundary.hpp"
    1615#include "config.hpp"
     
    380379 * bonded to the same atom, then we add for this pair a correction term constructed from a Morse
    381380 * potential function fit to QM calculations with respecting to the interatomic hydrogen distance.
    382  * \param &path path to file
    383  */
    384 bool MoleculeListClass::AddHydrogenCorrection(std::string &path)
     381 * \param *out output stream for debugging
     382 * \param *path path to file
     383 */
     384bool MoleculeListClass::AddHydrogenCorrection(char *path)
    385385{
    386386  bond *Binder = NULL;
     
    400400  // 0a. find dimension of matrices with constants
    401401  line = path;
     402  line.append("/");
     403  line += FRAGMENTPREFIX;
    402404  line += "1";
    403405  line += FITCONSTANTSUFFIX;
    404406  input.open(line.c_str());
    405   if (input.fail()) {
     407  if (input == NULL) {
    406408    DoLog(1) && (Log() << Verbose(1) << endl << "Unable to open " << line << ", is the directory correct?" << endl);
    407409    return false;
     
    567569
    568570/** Store force indices, i.e. the connection between the nuclear index in the total molecule config and the respective atom in fragment config.
    569  * \param &path path to file
     571 * \param *out output stream for debugging
     572 * \param *path path to file
    570573 * \param *SortIndex Index to map from the BFS labeling to the sequence how of Ion_Type in the config
    571574 * \return true - file written successfully, false - writing failed
    572575 */
    573 bool MoleculeListClass::StoreForcesFile(std::string &path, int *SortIndex)
     576bool MoleculeListClass::StoreForcesFile(char *path,
     577    int *SortIndex)
    574578{
    575579  bool status = true;
    576   string filename(path);
    577   filename += FORCESFILE;
    578   ofstream ForcesFile(filename.c_str());
     580  ofstream ForcesFile;
     581  stringstream line;
    579582  periodentafel *periode=World::getInstance().getPeriode();
    580583
    581584  // open file for the force factors
    582585  DoLog(1) && (Log() << Verbose(1) << "Saving  force factors ... ");
    583   if (!ForcesFile.fail()) {
     586  line << path << "/" << FRAGMENTPREFIX << FORCESFILE;
     587  ForcesFile.open(line.str().c_str(), ios::out);
     588  if (ForcesFile != NULL) {
    584589    //Log() << Verbose(1) << "Final AtomicForcesList: ";
    585590    //output << prefix << "Forces" << endl;
     
    606611  } else {
    607612    status = false;
    608     DoLog(1) && (Log() << Verbose(1) << "failed to open file " << filename << "." << endl);
     613    DoLog(1) && (Log() << Verbose(1) << "failed to open file " << line.str() << "." << endl);
    609614  }
    610615  ForcesFile.close();
     
    615620/** Writes a config file for each molecule in the given \a **FragmentList.
    616621 * \param *out output stream for debugging
    617  * \param &prefix path and prefix to the fragment config files
     622 * \param *configuration standard configuration to attach atoms in fragment molecule to.
    618623 * \param *SortIndex Index to map from the BFS labeling to the sequence how of Ion_Type in the config
    619624 * \return true - success (each file was written), false - something went wrong.
    620625 */
    621 bool MoleculeListClass::OutputConfigForListOfFragments(std::string &prefix, int *SortIndex)
     626bool MoleculeListClass::OutputConfigForListOfFragments(config *configuration, int *SortIndex)
    622627{
    623628  ofstream outputFragment;
    624   std::string FragmentName;
     629  char FragmentName[MAXSTRINGSIZE];
    625630  char PathBackup[MAXSTRINGSIZE];
    626631  bool result = true;
     
    640645  for (MoleculeList::iterator ListRunner = ListOfMolecules.begin(); ListRunner != ListOfMolecules.end(); ListRunner++) {
    641646    // save default path as it is changed for each fragment
    642     path = World::getInstance().getConfig()->GetDefaultPath();
     647    path = configuration->GetDefaultPath();
    643648    if (path != NULL)
    644649      strcpy(PathBackup, path);
     
    653658    // output xyz file
    654659    FragmentNumber = FixedDigitNumber(ListOfMolecules.size(), FragmentCounter++);
    655     FragmentName = prefix + FragmentNumber + ".conf.xyz";
    656     outputFragment.open(FragmentName.c_str(), ios::out);
     660    sprintf(FragmentName, "%s/%s%s.conf.xyz", configuration->configpath, FRAGMENTPREFIX, FragmentNumber);
     661    outputFragment.open(FragmentName, ios::out);
    657662    DoLog(2) && (Log() << Verbose(2) << "Saving bond fragment No. " << FragmentNumber << "/" << FragmentCounter - 1 << " as XYZ ...");
    658663    if ((intermediateResult = (*ListRunner)->OutputXYZ(&outputFragment)))
     
    677682    for (int k = 0; k < NDIM; k++) {
    678683      j += k + 1;
    679       BoxDimension[k] = 2.5 * (World::getInstance().getConfig()->GetIsAngstroem() ? 1. : 1. / AtomicLengthToAngstroem);
     684      BoxDimension[k] = 2.5 * (configuration->GetIsAngstroem() ? 1. : 1. / AtomicLengthToAngstroem);
    680685      cell_size[j] = BoxDimension[k] * 2.;
    681686    }
     
    684689    // also calculate necessary orbitals
    685690    (*ListRunner)->CountElements(); // this is a bugfix, atoms should shoulds actually be added correctly to this fragment
    686     //(*ListRunner)->CalculateOrbitals(*World::getInstance().getConfig);
     691    (*ListRunner)->CalculateOrbitals(*configuration);
    687692
    688693    // change path in config
    689     FragmentName = PathBackup;
    690     FragmentName += "/";
    691     FragmentName += FRAGMENTPREFIX;
    692     FragmentName += FragmentNumber;
    693     FragmentName += "/";
    694     World::getInstance().getConfig()->SetDefaultPath(FragmentName.c_str());
     694    //strcpy(PathBackup, configuration->configpath);
     695    sprintf(FragmentName, "%s/%s%s/", PathBackup, FRAGMENTPREFIX, FragmentNumber);
     696    configuration->SetDefaultPath(FragmentName);
    695697
    696698    // and save as config
    697     FragmentName = prefix + FragmentNumber + ".conf";
     699    sprintf(FragmentName, "%s/%s%s.conf", configuration->configpath, FRAGMENTPREFIX, FragmentNumber);
    698700    DoLog(2) && (Log() << Verbose(2) << "Saving bond fragment No. " << FragmentNumber << "/" << FragmentCounter - 1 << " as config ...");
    699     if ((intermediateResult = World::getInstance().getConfig()->Save(FragmentName.c_str(), (*ListRunner)->elemente, (*ListRunner))))
     701    if ((intermediateResult = configuration->Save(FragmentName, (*ListRunner)->elemente, (*ListRunner))))
    700702      DoLog(0) && (Log() << Verbose(0) << " done." << endl);
    701703    else
     
    704706
    705707    // restore old config
    706     World::getInstance().getConfig()->SetDefaultPath(PathBackup);
     708    configuration->SetDefaultPath(PathBackup);
    707709
    708710    // and save as mpqc input file
    709     FragmentName = prefix + FragmentNumber + ".conf";
     711    sprintf(FragmentName, "%s/%s%s.conf", configuration->configpath, FRAGMENTPREFIX, FragmentNumber);
    710712    DoLog(2) && (Log() << Verbose(2) << "Saving bond fragment No. " << FragmentNumber << "/" << FragmentCounter - 1 << " as mpqc input ...");
    711     if ((intermediateResult = World::getInstance().getConfig()->SaveMPQC(FragmentName.c_str(), (*ListRunner))))
     713    if ((intermediateResult = configuration->SaveMPQC(FragmentName, (*ListRunner))))
    712714      DoLog(2) && (Log() << Verbose(2) << " done." << endl);
    713715    else
     
    765767
    766768  // 1. dissect the molecule into connected subgraphs
    767   if (configuration->BG != NULL) {
    768     if (!configuration->BG->ConstructBondGraph(mol)) {
    769       World::getInstance().destroyMolecule(mol);
    770       DoeLog(1) && (eLog()<< Verbose(1) << "There are no bonds." << endl);
    771       return;
    772     }
    773   } else {
    774     DoeLog(1) && (eLog()<< Verbose(1) << "There is no BondGraph class present to create bonds." << endl);
     769  if (!configuration->BG->ConstructBondGraph(mol)) {
     770    World::getInstance().destroyMolecule(mol);
     771    DoeLog(1) && (eLog()<< Verbose(1) << "There are no bonds." << endl);
    775772    return;
    776773  }
Note: See TracChangeset for help on using the changeset viewer.