Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/molecule_fragmentation.cpp

    r35b698 r112b09  
    8282 * -# Scans TEFactors file and sets the TEFactor of each key set in the temporary graph accordingly
    8383 * Finally, the temporary graph is inserted into the given \a FragmentList for return.
    84  * \param &path path to file
     84 * \param *out output stream for debugging
     85 * \param *path path to file
    8586 * \param *FragmentList empty, filled on return
    8687 * \return true - parsing successfully, false - failure on parsing (FragmentList will be NULL)
    8788 */
    88 bool ParseKeySetFile(std::string &path, Graph *&FragmentList)
     89bool ParseKeySetFile(char *path, Graph *&FragmentList)
    8990{
    9091  bool status = true;
     
    9394  GraphTestPair testGraphInsert;
    9495  int NumberOfFragments = 0;
    95   string filename;
     96  char filename[MAXSTRINGSIZE];
    9697
    9798  if (FragmentList == NULL) { // check list pointer
     
    101102  // 1st pass: open file and read
    102103  DoLog(1) && (Log() << Verbose(1) << "Parsing the KeySet file ... " << endl);
    103   filename = path + KEYSETFILE;
    104   InputFile.open(filename.c_str());
    105   if (InputFile.good()) {
     104  sprintf(filename, "%s/%s%s", path, FRAGMENTPREFIX, KEYSETFILE);
     105  InputFile.open(filename);
     106  if (InputFile != NULL) {
    106107    // each line represents a new fragment
    107108    char buffer[MAXSTRINGSIZE];
     
    180181
    181182/** Stores key sets to file.
     183 * \param *out output stream for debugging
    182184 * \param KeySetList Graph with Keysets
    183  * \param &path path to file
     185 * \param *path path to file
    184186 * \return true - file written successfully, false - writing failed
    185187 */
    186 bool StoreKeySetFile(Graph &KeySetList, std::string &path)
    187 {
     188bool StoreKeySetFile(Graph &KeySetList, char *path)
     189{
     190  ofstream output;
    188191  bool status =  true;
    189   string line = path + KEYSETFILE;
    190   ofstream output(line.c_str());
     192  string line;
    191193
    192194  // open KeySet file
     195  line = path;
     196  line.append("/");
     197  line += FRAGMENTPREFIX;
     198  line += KEYSETFILE;
     199  output.open(line.c_str(), ios::out);
    193200  DoLog(1) && (Log() << Verbose(1) << "Saving key sets of the total graph ... ");
    194   if(output.good()) {
     201  if(output != NULL) {
    195202    for(Graph::iterator runner = KeySetList.begin(); runner != KeySetList.end(); runner++) {
    196203      for (KeySet::iterator sprinter = (*runner).first.begin();sprinter != (*runner).first.end(); sprinter++) {
     
    295302
    296303/** Scans the adaptive order file and insert (index, value) into map.
    297  * \param &path path to ENERGYPERFRAGMENT file (may be NULL if Order is non-negative)
     304 * \param *out output stream for debugging
     305 * \param *path path to ENERGYPERFRAGMENT file (may be NULL if Order is non-negative)
    298306 * \param &IndexedKeySetList list to find key set for a given index \a No
    299307 * \return adaptive criteria list from file
    300308 */
    301 map<int, pair<double,int> > * ScanAdaptiveFileIntoMap(std::string &path, map<int,KeySet> &IndexKeySetList)
     309map<int, pair<double,int> > * ScanAdaptiveFileIntoMap(char *path, map<int,KeySet> &IndexKeySetList)
    302310{
    303311  map<int, pair<double,int> > *AdaptiveCriteriaList = new map<int, pair<double,int> >;
     
    305313  double Value = 0.;
    306314  char buffer[MAXSTRINGSIZE];
    307   string filename = path + ENERGYPERFRAGMENT;
    308   ifstream InputFile(filename.c_str());
    309 
    310   if (InputFile.fail()) {
    311     DoeLog(1) && (eLog() << Verbose(1) << "Cannot find file " << filename << "." << endl);
    312     return AdaptiveCriteriaList;
    313   }
     315  sprintf(buffer, "%s/%s%s.dat", path, FRAGMENTPREFIX, ENERGYPERFRAGMENT);
     316  ifstream InputFile(buffer, ios::in);
    314317
    315318  if (CountLinesinFile(InputFile) > 0) {
     
    416419
    417420/** Checks whether the OrderAtSite is still below \a Order at some site.
     421 * \param *out output stream for debugging
    418422 * \param *AtomMask defines true/false per global Atom::nr to mask in/out each nuclear site, used to activate given number of site to increment order adaptively
    419423 * \param *GlobalKeySetList list of keysets with global ids (valid in "this" molecule) needed for adaptive increase
    420424 * \param Order desired Order if positive, desired exponent in threshold criteria if negative (0 is single-step)
    421425 * \param *MinimumRingSize array of max. possible order to avoid loops
    422  * \param path path to ENERGYPERFRAGMENT file (may be NULL if Order is non-negative)
     426 * \param *path path to ENERGYPERFRAGMENT file (may be NULL if Order is non-negative)
    423427 * \return true - needs further fragmentation, false - does not need fragmentation
    424428 */
    425 bool molecule::CheckOrderAtSite(bool *AtomMask, Graph *GlobalKeySetList, int Order, int *MinimumRingSize, std::string path)
     429bool molecule::CheckOrderAtSite(bool *AtomMask, Graph *GlobalKeySetList, int Order, int *MinimumRingSize, char *path)
    426430{
    427431  bool status = false;
     
    581585 * of vertex indices: Global always means the index in "this" molecule, whereas local refers to the molecule or
    582586 * subgraph in the MoleculeListClass.
     587 * \param *out output stream for debugging
    583588 * \param Order up to how many neighbouring bonds a fragment contains in BondOrderScheme::BottumUp scheme
    584  * \param &prefix path and prefix of the bond order configs to be written
     589 * \param *configuration configuration for writing config files for each fragment
    585590 * \return 1 - continue, 2 - stop (no fragmentation occured)
    586591 */
    587 int molecule::FragmentMolecule(int Order, std::string &prefix)
     592int molecule::FragmentMolecule(int Order, config *configuration)
    588593{
    589594  MoleculeListClass *BondFragments = NULL;
     
    619624
    620625  // === compare it with adjacency file ===
    621   FragmentationToDo = FragmentationToDo && CheckAdjacencyFileAgainstMolecule(prefix, ListOfAtoms);
     626  FragmentationToDo = FragmentationToDo && CheckAdjacencyFileAgainstMolecule(configuration->configpath, ListOfAtoms);
    622627  delete[](ListOfAtoms);
    623628
     
    653658
    654659  // ===== 3. if structure still valid, parse key set file and others =====
    655   FragmentationToDo = FragmentationToDo && ParseKeySetFile(prefix, ParsedFragmentList);
     660  FragmentationToDo = FragmentationToDo && ParseKeySetFile(configuration->configpath, ParsedFragmentList);
    656661
    657662  // ===== 4. check globally whether there's something to do actually (first adaptivity check)
    658   FragmentationToDo = FragmentationToDo && ParseOrderAtSiteFromFile(prefix);
     663  FragmentationToDo = FragmentationToDo && ParseOrderAtSiteFromFile(configuration->configpath);
    659664
    660665  // =================================== Begin of FRAGMENTATION ===============================
     
    667672  AtomMask[getAtomCount()] = false;
    668673  FragmentationToDo = false;  // if CheckOrderAtSite just ones recommends fragmentation, we will save fragments afterwards
    669   while ((CheckOrder = CheckOrderAtSite(AtomMask, ParsedFragmentList, Order, MinimumRingSize, prefix))) {
     674  while ((CheckOrder = CheckOrderAtSite(AtomMask, ParsedFragmentList, Order, MinimumRingSize, configuration->configpath))) {
    670675    FragmentationToDo = FragmentationToDo || CheckOrder;
    671676    AtomMask[getAtomCount()] = true;   // last plus one entry is used as marker that we have been through this loop once already in CheckOrderAtSite()
     
    722727    KeySet test = (*runner).first;
    723728    DoLog(0) && (Log() << Verbose(0) << "Fragment No." << (*runner).second.first << " with TEFactor " << (*runner).second.second << "." << endl);
    724     BondFragments->insert(StoreFragmentFromKeySet(test, World::getInstance().getConfig()));
     729    BondFragments->insert(StoreFragmentFromKeySet(test, configuration));
    725730    k++;
    726731  }
     
    734739
    735740    DoLog(1) && (Log() << Verbose(1) << "Writing " << BondFragments->ListOfMolecules.size() << " possible bond fragmentation configs" << endl);
    736     if (BondFragments->OutputConfigForListOfFragments(prefix, SortIndex))
     741    if (BondFragments->OutputConfigForListOfFragments(configuration, SortIndex))
    737742      DoLog(1) && (Log() << Verbose(1) << "All configs written." << endl);
    738743    else
     
    740745
    741746    // store force index reference file
    742     BondFragments->StoreForcesFile(prefix, SortIndex);
     747    BondFragments->StoreForcesFile(configuration->configpath, SortIndex);
    743748
    744749    // store keysets file
    745     StoreKeySetFile(TotalGraph, prefix);
     750    StoreKeySetFile(TotalGraph, configuration->configpath);
    746751
    747752    {
    748753      // store Adjacency file
    749       std::string filename = prefix + ADJACENCYFILE;
    750       StoreAdjacencyToFile(filename);
     754      char filename[MAXSTRINGSIZE];
     755      strcpy(filename, FRAGMENTPREFIX);
     756      strcat(filename, ADJACENCYFILE);
     757      StoreAdjacencyToFile(configuration->configpath, filename);
    751758    }
    752759
    753760    // store Hydrogen saturation correction file
    754     BondFragments->AddHydrogenCorrection(prefix);
     761    BondFragments->AddHydrogenCorrection(configuration->configpath);
    755762
    756763    // store adaptive orders into file
    757     StoreOrderAtSiteFile(prefix);
     764    StoreOrderAtSiteFile(configuration->configpath);
    758765
    759766    // restore orbital and Stop values
    760     //CalculateOrbitals(*configuration);
     767    CalculateOrbitals(*configuration);
    761768
    762769    // free memory for bond part
     
    775782/** Stores pairs (Atom::nr, Atom::AdaptiveOrder) into file.
    776783 * Atoms not present in the file get "-1".
    777  * \param &path path to file ORDERATSITEFILE
     784 * \param *out output stream for debugging
     785 * \param *path path to file ORDERATSITEFILE
    778786 * \return true - file writable, false - not writable
    779787 */
    780 bool molecule::StoreOrderAtSiteFile(std::string &path)
    781 {
    782   string line;
     788bool molecule::StoreOrderAtSiteFile(char *path)
     789{
     790  stringstream line;
    783791  ofstream file;
    784792
    785   line = path + ORDERATSITEFILE;
    786   file.open(line.c_str());
     793  line << path << "/" << FRAGMENTPREFIX << ORDERATSITEFILE;
     794  file.open(line.str().c_str());
    787795  DoLog(1) && (Log() << Verbose(1) << "Writing OrderAtSite " << ORDERATSITEFILE << " ... " << endl);
    788   if (file.good()) {
     796  if (file != NULL) {
    789797    ActOnAllAtoms( &atom::OutputOrder, &file );
    790798    file.close();
     
    792800    return true;
    793801  } else {
    794     DoLog(1) && (Log() << Verbose(1) << "failed to open file " << line << "." << endl);
     802    DoLog(1) && (Log() << Verbose(1) << "failed to open file " << line.str() << "." << endl);
    795803    return false;
    796804  }
     
    799807/** Parses pairs(Atom::nr, Atom::AdaptiveOrder) from file and stores in molecule's Atom's.
    800808 * Atoms not present in the file get "0".
    801  * \param &path path to file ORDERATSITEFILEe
     809 * \param *out output stream for debugging
     810 * \param *path path to file ORDERATSITEFILEe
    802811 * \return true - file found and scanned, false - file not found
    803812 * \sa ParseKeySetFile() and CheckAdjacencyFileAgainstMolecule() as this is meant to be used in conjunction with the two
    804813 */
    805 bool molecule::ParseOrderAtSiteFromFile(std::string &path)
     814bool molecule::ParseOrderAtSiteFromFile(char *path)
    806815{
    807816  unsigned char *OrderArray = new unsigned char[getAtomCount()];
     
    809818  bool status;
    810819  int AtomNr, value;
    811   string line;
     820  stringstream line;
    812821  ifstream file;
    813822
     
    818827
    819828  DoLog(1) && (Log() << Verbose(1) << "Begin of ParseOrderAtSiteFromFile" << endl);
    820   line = path + ORDERATSITEFILE;
    821   file.open(line.c_str());
    822   if (file.good()) {
     829  line << path << "/" << FRAGMENTPREFIX << ORDERATSITEFILE;
     830  file.open(line.str().c_str());
     831  if (file != NULL) {
    823832    while (!file.eof()) { // parse from file
    824833      AtomNr = -1;
     
    841850    status = true;
    842851  } else {
    843     DoLog(1) && (Log() << Verbose(1) << "\t ... failed to open file " << line << "." << endl);
     852    DoLog(1) && (Log() << Verbose(1) << "\t ... failed to open file " << line.str() << "." << endl);
    844853    status = false;
    845854  }
Note: See TracChangeset for help on using the changeset viewer.