Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/molecule_fragmentation.cpp

    r112b09 rc27778  
    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 *out output stream for debugging
    85  * \param *path path to file
     84 * \param &path path to file
    8685 * \param *FragmentList empty, filled on return
    8786 * \return true - parsing successfully, false - failure on parsing (FragmentList will be NULL)
    8887 */
    89 bool ParseKeySetFile(char *path, Graph *&FragmentList)
     88bool ParseKeySetFile(std::string &path, Graph *&FragmentList)
    9089{
    9190  bool status = true;
     
    9493  GraphTestPair testGraphInsert;
    9594  int NumberOfFragments = 0;
    96   char filename[MAXSTRINGSIZE];
     95  string filename;
    9796
    9897  if (FragmentList == NULL) { // check list pointer
     
    102101  // 1st pass: open file and read
    103102  DoLog(1) && (Log() << Verbose(1) << "Parsing the KeySet file ... " << endl);
    104   sprintf(filename, "%s/%s%s", path, FRAGMENTPREFIX, KEYSETFILE);
    105   InputFile.open(filename);
    106   if (InputFile != NULL) {
     103  filename = path + KEYSETFILE;
     104  InputFile.open(filename.c_str());
     105  if (InputFile.good()) {
    107106    // each line represents a new fragment
    108107    char buffer[MAXSTRINGSIZE];
     
    181180
    182181/** Stores key sets to file.
    183  * \param *out output stream for debugging
    184182 * \param KeySetList Graph with Keysets
    185  * \param *path path to file
     183 * \param &path path to file
    186184 * \return true - file written successfully, false - writing failed
    187185 */
    188 bool StoreKeySetFile(Graph &KeySetList, char *path)
    189 {
    190   ofstream output;
     186bool StoreKeySetFile(Graph &KeySetList, std::string &path)
     187{
    191188  bool status =  true;
    192   string line;
     189  string line = path + KEYSETFILE;
     190  ofstream output(line.c_str());
    193191
    194192  // open KeySet file
    195   line = path;
    196   line.append("/");
    197   line += FRAGMENTPREFIX;
    198   line += KEYSETFILE;
    199   output.open(line.c_str(), ios::out);
    200193  DoLog(1) && (Log() << Verbose(1) << "Saving key sets of the total graph ... ");
    201   if(output != NULL) {
     194  if(output.good()) {
    202195    for(Graph::iterator runner = KeySetList.begin(); runner != KeySetList.end(); runner++) {
    203196      for (KeySet::iterator sprinter = (*runner).first.begin();sprinter != (*runner).first.end(); sprinter++) {
     
    302295
    303296/** Scans the adaptive order file and insert (index, value) into map.
    304  * \param *out output stream for debugging
    305  * \param *path path to ENERGYPERFRAGMENT file (may be NULL if Order is non-negative)
     297 * \param &path path to ENERGYPERFRAGMENT file (may be NULL if Order is non-negative)
    306298 * \param &IndexedKeySetList list to find key set for a given index \a No
    307299 * \return adaptive criteria list from file
    308300 */
    309 map<int, pair<double,int> > * ScanAdaptiveFileIntoMap(char *path, map<int,KeySet> &IndexKeySetList)
     301map<int, pair<double,int> > * ScanAdaptiveFileIntoMap(std::string &path, map<int,KeySet> &IndexKeySetList)
    310302{
    311303  map<int, pair<double,int> > *AdaptiveCriteriaList = new map<int, pair<double,int> >;
     
    313305  double Value = 0.;
    314306  char buffer[MAXSTRINGSIZE];
    315   sprintf(buffer, "%s/%s%s.dat", path, FRAGMENTPREFIX, ENERGYPERFRAGMENT);
    316   ifstream InputFile(buffer, ios::in);
     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  }
    317314
    318315  if (CountLinesinFile(InputFile) > 0) {
     
    419416
    420417/** Checks whether the OrderAtSite is still below \a Order at some site.
    421  * \param *out output stream for debugging
    422418 * \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
    423419 * \param *GlobalKeySetList list of keysets with global ids (valid in "this" molecule) needed for adaptive increase
    424420 * \param Order desired Order if positive, desired exponent in threshold criteria if negative (0 is single-step)
    425421 * \param *MinimumRingSize array of max. possible order to avoid loops
    426  * \param *path path to ENERGYPERFRAGMENT file (may be NULL if Order is non-negative)
     422 * \param path path to ENERGYPERFRAGMENT file (may be NULL if Order is non-negative)
    427423 * \return true - needs further fragmentation, false - does not need fragmentation
    428424 */
    429 bool molecule::CheckOrderAtSite(bool *AtomMask, Graph *GlobalKeySetList, int Order, int *MinimumRingSize, char *path)
     425bool molecule::CheckOrderAtSite(bool *AtomMask, Graph *GlobalKeySetList, int Order, int *MinimumRingSize, std::string path)
    430426{
    431427  bool status = false;
     
    585581 * of vertex indices: Global always means the index in "this" molecule, whereas local refers to the molecule or
    586582 * subgraph in the MoleculeListClass.
    587  * \param *out output stream for debugging
    588583 * \param Order up to how many neighbouring bonds a fragment contains in BondOrderScheme::BottumUp scheme
    589  * \param *configuration configuration for writing config files for each fragment
     584 * \param &prefix path and prefix of the bond order configs to be written
    590585 * \return 1 - continue, 2 - stop (no fragmentation occured)
    591586 */
    592 int molecule::FragmentMolecule(int Order, config *configuration)
     587int molecule::FragmentMolecule(int Order, std::string &prefix)
    593588{
    594589  MoleculeListClass *BondFragments = NULL;
     
    624619
    625620  // === compare it with adjacency file ===
    626   FragmentationToDo = FragmentationToDo && CheckAdjacencyFileAgainstMolecule(configuration->configpath, ListOfAtoms);
     621  FragmentationToDo = FragmentationToDo && CheckAdjacencyFileAgainstMolecule(prefix, ListOfAtoms);
    627622  delete[](ListOfAtoms);
    628623
     
    634629    MinimumRingSize[i] = getAtomCount();
    635630  MolecularWalker = Subgraphs;
     631  const int LeafCount = Subgraphs->next->Count();
    636632  FragmentCounter = 0;
    637633  while (MolecularWalker->next != NULL) {
    638634    MolecularWalker = MolecularWalker->next;
    639635    // fill the bond structure of the individually stored subgraphs
    640     MolecularWalker->FillBondStructureFromReference(this, FragmentCounter, ListOfLocalAtoms, false);  // we want to keep the created ListOfLocalAtoms
     636    ListOfAtoms = NULL;
     637    MolecularWalker->FillBondStructureFromReference(this, ListOfAtoms, false);  // we want to keep the created ListOfLocalAtoms
    641638    DoLog(0) && (Log() << Verbose(0) << "Analysing the cycles of subgraph " << MolecularWalker->Leaf << " with nr. " << FragmentCounter << "." << endl);
    642639    LocalBackEdgeStack = new StackClass<bond *> (MolecularWalker->Leaf->BondCount);
     
    649646//        Log() << Verbose(0) << "\t" << ListOfLocalAtoms[FragmentCounter][i]->Name;
    650647    DoLog(0) && (Log() << Verbose(0) << "Gathering local back edges for subgraph " << MolecularWalker->Leaf << " with nr. " << FragmentCounter << "." << endl);
    651     MolecularWalker->Leaf->PickLocalBackEdges(ListOfLocalAtoms[FragmentCounter++], BackEdgeStack, LocalBackEdgeStack);
     648    MolecularWalker->Leaf->PickLocalBackEdges(ListOfAtoms, BackEdgeStack, LocalBackEdgeStack);
    652649    DoLog(0) && (Log() << Verbose(0) << "Analysing the cycles of subgraph " << MolecularWalker->Leaf << " with nr. " << FragmentCounter << "." << endl);
    653650    MolecularWalker->Leaf->CyclicStructureAnalysis(LocalBackEdgeStack, MinimumRingSize);
    654651    DoLog(0) && (Log() << Verbose(0) << "Done with Analysing the cycles of subgraph " << MolecularWalker->Leaf << " with nr. " << FragmentCounter << "." << endl);
    655652    delete(LocalBackEdgeStack);
     653    delete(ListOfAtoms);
     654    FragmentCounter++;
    656655  }
    657656  delete(BackEdgeStack);
    658657
    659658  // ===== 3. if structure still valid, parse key set file and others =====
    660   FragmentationToDo = FragmentationToDo && ParseKeySetFile(configuration->configpath, ParsedFragmentList);
     659  FragmentationToDo = FragmentationToDo && ParseKeySetFile(prefix, ParsedFragmentList);
    661660
    662661  // ===== 4. check globally whether there's something to do actually (first adaptivity check)
    663   FragmentationToDo = FragmentationToDo && ParseOrderAtSiteFromFile(configuration->configpath);
     662  FragmentationToDo = FragmentationToDo && ParseOrderAtSiteFromFile(prefix);
    664663
    665664  // =================================== Begin of FRAGMENTATION ===============================
    666665  // ===== 6a. assign each keyset to its respective subgraph =====
    667   Subgraphs->next->AssignKeySetsToFragment(this, ParsedFragmentList, ListOfLocalAtoms, FragmentList, (FragmentCounter = 0), true);
     666  ListOfLocalAtoms = new atom **[LeafCount];
     667  for (int i=0;i<LeafCount;i++)
     668    ListOfLocalAtoms[i] = NULL;
     669  FragmentCounter = 0;
     670  Subgraphs->next->AssignKeySetsToFragment(this, ParsedFragmentList, ListOfLocalAtoms, FragmentList, FragmentCounter, true);
     671  delete[](ListOfLocalAtoms);
    668672
    669673  // ===== 6b. prepare and go into the adaptive (Order<0), single-step (Order==0) or incremental (Order>0) cycle
     
    672676  AtomMask[getAtomCount()] = false;
    673677  FragmentationToDo = false;  // if CheckOrderAtSite just ones recommends fragmentation, we will save fragments afterwards
    674   while ((CheckOrder = CheckOrderAtSite(AtomMask, ParsedFragmentList, Order, MinimumRingSize, configuration->configpath))) {
     678  while ((CheckOrder = CheckOrderAtSite(AtomMask, ParsedFragmentList, Order, MinimumRingSize, prefix))) {
    675679    FragmentationToDo = FragmentationToDo || CheckOrder;
    676680    AtomMask[getAtomCount()] = true;   // last plus one entry is used as marker that we have been through this loop once already in CheckOrderAtSite()
     
    701705  delete[](MinimumRingSize);
    702706
    703 
    704707  // ==================================== End of FRAGMENTATION ============================================
    705708
     
    727730    KeySet test = (*runner).first;
    728731    DoLog(0) && (Log() << Verbose(0) << "Fragment No." << (*runner).second.first << " with TEFactor " << (*runner).second.second << "." << endl);
    729     BondFragments->insert(StoreFragmentFromKeySet(test, configuration));
     732    BondFragments->insert(StoreFragmentFromKeySet(test, World::getInstance().getConfig()));
    730733    k++;
    731734  }
     
    739742
    740743    DoLog(1) && (Log() << Verbose(1) << "Writing " << BondFragments->ListOfMolecules.size() << " possible bond fragmentation configs" << endl);
    741     if (BondFragments->OutputConfigForListOfFragments(configuration, SortIndex))
     744    if (BondFragments->OutputConfigForListOfFragments(prefix, SortIndex))
    742745      DoLog(1) && (Log() << Verbose(1) << "All configs written." << endl);
    743746    else
     
    745748
    746749    // store force index reference file
    747     BondFragments->StoreForcesFile(configuration->configpath, SortIndex);
     750    BondFragments->StoreForcesFile(prefix, SortIndex);
    748751
    749752    // store keysets file
    750     StoreKeySetFile(TotalGraph, configuration->configpath);
     753    StoreKeySetFile(TotalGraph, prefix);
    751754
    752755    {
    753756      // store Adjacency file
    754       char filename[MAXSTRINGSIZE];
    755       strcpy(filename, FRAGMENTPREFIX);
    756       strcat(filename, ADJACENCYFILE);
    757       StoreAdjacencyToFile(configuration->configpath, filename);
     757      std::string filename = prefix + ADJACENCYFILE;
     758      StoreAdjacencyToFile(filename);
    758759    }
    759760
    760761    // store Hydrogen saturation correction file
    761     BondFragments->AddHydrogenCorrection(configuration->configpath);
     762    BondFragments->AddHydrogenCorrection(prefix);
    762763
    763764    // store adaptive orders into file
    764     StoreOrderAtSiteFile(configuration->configpath);
     765    StoreOrderAtSiteFile(prefix);
    765766
    766767    // restore orbital and Stop values
    767     CalculateOrbitals(*configuration);
     768    //CalculateOrbitals(*configuration);
    768769
    769770    // free memory for bond part
     
    782783/** Stores pairs (Atom::nr, Atom::AdaptiveOrder) into file.
    783784 * Atoms not present in the file get "-1".
    784  * \param *out output stream for debugging
    785  * \param *path path to file ORDERATSITEFILE
     785 * \param &path path to file ORDERATSITEFILE
    786786 * \return true - file writable, false - not writable
    787787 */
    788 bool molecule::StoreOrderAtSiteFile(char *path)
    789 {
    790   stringstream line;
     788bool molecule::StoreOrderAtSiteFile(std::string &path)
     789{
     790  string line;
    791791  ofstream file;
    792792
    793   line << path << "/" << FRAGMENTPREFIX << ORDERATSITEFILE;
    794   file.open(line.str().c_str());
     793  line = path + ORDERATSITEFILE;
     794  file.open(line.c_str());
    795795  DoLog(1) && (Log() << Verbose(1) << "Writing OrderAtSite " << ORDERATSITEFILE << " ... " << endl);
    796   if (file != NULL) {
     796  if (file.good()) {
    797797    ActOnAllAtoms( &atom::OutputOrder, &file );
    798798    file.close();
     
    800800    return true;
    801801  } else {
    802     DoLog(1) && (Log() << Verbose(1) << "failed to open file " << line.str() << "." << endl);
     802    DoLog(1) && (Log() << Verbose(1) << "failed to open file " << line << "." << endl);
    803803    return false;
    804804  }
     
    807807/** Parses pairs(Atom::nr, Atom::AdaptiveOrder) from file and stores in molecule's Atom's.
    808808 * Atoms not present in the file get "0".
    809  * \param *out output stream for debugging
    810  * \param *path path to file ORDERATSITEFILEe
     809 * \param &path path to file ORDERATSITEFILEe
    811810 * \return true - file found and scanned, false - file not found
    812811 * \sa ParseKeySetFile() and CheckAdjacencyFileAgainstMolecule() as this is meant to be used in conjunction with the two
    813812 */
    814 bool molecule::ParseOrderAtSiteFromFile(char *path)
     813bool molecule::ParseOrderAtSiteFromFile(std::string &path)
    815814{
    816815  unsigned char *OrderArray = new unsigned char[getAtomCount()];
     
    818817  bool status;
    819818  int AtomNr, value;
    820   stringstream line;
     819  string line;
    821820  ifstream file;
    822821
     
    827826
    828827  DoLog(1) && (Log() << Verbose(1) << "Begin of ParseOrderAtSiteFromFile" << endl);
    829   line << path << "/" << FRAGMENTPREFIX << ORDERATSITEFILE;
    830   file.open(line.str().c_str());
    831   if (file != NULL) {
     828  line = path + ORDERATSITEFILE;
     829  file.open(line.c_str());
     830  if (file.good()) {
    832831    while (!file.eof()) { // parse from file
    833832      AtomNr = -1;
     
    850849    status = true;
    851850  } else {
    852     DoLog(1) && (Log() << Verbose(1) << "\t ... failed to open file " << line.str() << "." << endl);
     851    DoLog(1) && (Log() << Verbose(1) << "\t ... failed to open file " << line << "." << endl);
    853852    status = false;
    854853  }
Note: See TracChangeset for help on using the changeset viewer.