Changeset 2459b1


Ignore:
Timestamp:
May 5, 2008, 4:19:05 PM (17 years ago)
Author:
Frederik Heber <heber@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
Children:
3c4b08
Parents:
bd6579
Message:

ForcesFile and TEFactors are _needed_, reincorporated. UniqueFragments structure is now in BOSSANOVA

ForcesFile is again written, as we need it for the hydrogen not coming saturation (forces!)
TEFactors are back, as despite my notion they are needed in the evaluation
UniqueFragments structure is shifted from PowerSetGenerator to FragmentBOSSANOVA. Actually only for the labels - however, the if was changed to test the real indices (which are also always the same, which is better for adaptive runs) - but might be more useful there still.
analyzer and joiner again parse indices.

Location:
src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • src/analyzer.cpp

    rbd6579 r2459b1  
    5858
    5959  // ---------- Parse the TE Factors into an array -----------------
    60   //if (!Energy.ParseIndices()) return 1;
     60  if (!Energy.ParseIndices()) return 1;
    6161 
    6262  // ---------- Parse the Force indices into an array ---------------
    63   //if (!Force.ParseIndices(argv[1])) return 1;
     63  if (!Force.ParseIndices(argv[1])) return 1;
    6464
    6565  // ---------- Parse the KeySets into an array ---------------
  • src/defs.hpp

    rbd6579 r2459b1  
    4444#define KEYSETFILE "KeySets.dat"
    4545#define ADJACENCYFILE "Adjacency.dat"
     46#define TEFACTORSFILE "TE-Factors.dat"
     47#define FORCESFILE "Forces-Factors.dat"
    4648#define ORDERATSITEFILE "OrderAtSite.dat"
    4749#define FRAGMENTPREFIX "BondFragment"
  • src/joiner.cpp

    rbd6579 r2459b1  
    4646
    4747  // ---------- Parse the TE Factors into an array -----------------
    48   //if (!Energy.ParseIndices()) return 1;
     48  if (!Energy.ParseIndices()) return 1;
    4949 
    5050  // ---------- Parse the Force indices into an array ---------------
    51   //if (!Force.ParseIndices(argv[1])) return 1;
     51  if (!Force.ParseIndices(argv[1])) return 1;
    5252  //if (!ParseForceIndices(argv[1], data.ForcesIndices, data.AtomCounter, data.FragmentCounter)) return 1;
    5353
  • src/moleculelist.cpp

    rbd6579 r2459b1  
    133133};
    134134
     135
     136/** Store force indices, i.e. the connection between the nuclear index in the total molecule config and the respective atom in fragment config.
     137 * \param *out output stream for debugging
     138 * \param *path path to file
     139 * \param *SortIndex Index to map from the BFS labeling to the sequence how of Ion_Type in the config
     140 * \return true - file written successfully, false - writing failed
     141 */
     142bool MoleculeListClass::StoreForcesFile(ofstream *out, char *path, int *SortIndex)
     143{
     144  bool status = true;
     145  ofstream ForcesFile;
     146  stringstream line;
     147  atom *Walker = NULL;
     148  element *runner = NULL;
     149
     150  // open file for the force factors
     151  *out << Verbose(1) << "Saving  force factors ... ";
     152  line << path << "/" << FRAGMENTPREFIX << FORCESFILE;
     153  ForcesFile.open(line.str().c_str(), ios::out);
     154  if (ForcesFile != NULL) {
     155    //cout << Verbose(1) << "Final AtomicForcesList: ";
     156    //output << prefix << "Forces" << endl;
     157    for(int j=0;j<NumberOfMolecules;j++) {
     158      //if (TEList[j] != 0) {
     159      runner = ListOfMolecules[j]->elemente->start;
     160      while (runner->next != ListOfMolecules[j]->elemente->end) { // go through every element
     161        runner = runner->next;
     162        if (ListOfMolecules[j]->ElementsInMolecule[runner->Z]) { // if this element got atoms
     163          Walker = ListOfMolecules[j]->start;
     164          while (Walker->next != ListOfMolecules[j]->end) { // go through every atom of this element
     165            Walker = Walker->next;
     166            if (Walker->type->Z == runner->Z) {
     167              if ((Walker->GetTrueFather() != NULL) && (Walker->GetTrueFather() != Walker)) {// if there is a rea
     168                //cout << "Walker is " << *Walker << " with true father " << *( Walker->GetTrueFather()) << ", it
     169                ForcesFile <<  SortIndex[Walker->GetTrueFather()->nr] << "\t";
     170                } else  // otherwise a -1 to indicate an added saturation hydrogen
     171                  ForcesFile << "-1\t";
     172              }
     173            }
     174          }
     175      }
     176      ForcesFile << endl;
     177    }
     178    ForcesFile.close();
     179    *out << Verbose(1) << "done." << endl;
     180  } else {
     181    status = false;
     182    *out << Verbose(1) << "failed to open file " << line.str() << "." << endl;
     183  }
     184  ForcesFile.close();
     185 
     186  return status;
     187};
     188
    135189/** Writes a config file for each molecule in the given \a **FragmentList.
    136190 * \param *out output stream for debugging
     
    216270    Free((void **)&FragmentNumber, "MoleculeListClass::OutputConfigForListOfFragments: *FragmentNumber");
    217271  }
    218 
    219   // open KeySet file
    220   sprintf(FragmentName, "%s/%s%s", configuration->configpath,  FRAGMENTPREFIX , KEYSETFILE);
    221   output.open(FragmentName, ios::out);
    222   *out << Verbose(2) << "Saving " << FRAGMENTPREFIX << " key sets of each subgraph ...";
    223   for(int j=0;j<NumberOfMolecules;j++) {
    224     Walker = ListOfMolecules[j]->start;
    225     while(Walker->next != ListOfMolecules[j]->end) {
    226       Walker = Walker->next;       
    227 #ifdef ADDHYDROGEN
    228       if ((Walker->GetTrueFather() != NULL) && (Walker->type->Z != 1)) // if there is a real father, prints its index
    229 #else
    230       if ((Walker->GetTrueFather() != NULL)) // if there is a real father, prints its index
    231 #endif
    232         output <<  Walker->GetTrueFather()->nr << "\t";
    233 #ifdef ADDHYDROGEN
    234       else  // otherwise a -1 to indicate an added saturation hydrogen
    235         output << "-1\t";
    236 #endif
    237     }
    238     output << endl;
    239   }
    240   output.close();
    241   *out << " done." << endl;
     272  cout << " done." << endl;
    242273 
    243274  // printing final number
  • src/molecules.cpp

    rbd6579 r2459b1  
    12491249  atom *Walker = NULL, *OtherWalker = NULL;
    12501250  int No, NoBonds;
    1251   bond *Binder = NULL;
    12521251  int NumberCells, divisor[NDIM], n[NDIM], N[NDIM], index, Index, j;
    12531252  molecule **CellList;
     
    13651364                if (BondCount != 0) {
    13661365      NoCyclicBonds = 0;
    1367                   *out << Verbose(1) << "correct Bond degree of each bond" << endl;
     1366                  *out << Verbose(1) << "Correcting Bond degree of each bond ... ";
    13681367                  do {
    13691368                    No = 0; // No acts as breakup flag (if 1 we still continue)
     
    13771376            for(j=0;j<NumberOfBondsPerAtom[Walker->nr];j++)
    13781377              NoBonds += ListOfBondsPerAtom[Walker->nr][j]->BondDegree;
    1379                   *out << Verbose(3) << "Walker: " << (int)Walker->type->NoValenceOrbitals << " > " << NoBonds << "?" << endl;
     1378                  //*out << Verbose(3) << "Walker: " << (int)Walker->type->NoValenceOrbitals << " > " << NoBonds << "?" << endl;
    13801379                  if ((int)(Walker->type->NoValenceOrbitals) > NoBonds) { // we have a mismatch, check NoBonds of other atom
    13811380                    // count valence of second partner
     
    13831382              for(j=0;j<NumberOfBondsPerAtom[OtherWalker->nr];j++)
    13841383                NoBonds += ListOfBondsPerAtom[OtherWalker->nr][j]->BondDegree;
    1385               *out << Verbose(3) << "OtherWalker: " << (int)OtherWalker->type->NoValenceOrbitals << " > " << NoBonds << "?" << endl;
     1384              //*out << Verbose(3) << "OtherWalker: " << (int)OtherWalker->type->NoValenceOrbitals << " > " << NoBonds << "?" << endl;
    13861385                    if ((int)(OtherWalker->type->NoValenceOrbitals) > NoBonds) // increase bond degree by one
    13871386                ListOfBondsPerAtom[Walker->nr][i]->BondDegree++;
     
    13901389                    }
    13911390                  } while (No);
    1392                
     1391                *out << " done." << endl;
    13931392                } else
    13941393                        *out << Verbose(1) << "BondCount is " << BondCount << ", no bonds between any of the " << AtomCount << " atoms." << endl;
    13951394          *out << Verbose(1) << "I detected " << BondCount << " bonds in the molecule with distance " << bonddistance << "." << endl;
    13961395               
    1397           // output bonds for debugging (if bond chain list was correctly installed)
    1398           *out << Verbose(1) << endl << "From contents of bond chain list:";
    1399     Binder = first;
    1400     while(Binder->next != last) {
    1401       Binder = Binder->next;
    1402                         *out << *Binder << "\t" << endl;
    1403     }
    1404     *out << endl;
     1396//        // output bonds for debugging (if bond chain list was correctly installed)
     1397//        *out << Verbose(1) << endl << "From contents of bond chain list:";
     1398//        bond *Binder = first;
     1399//    while(Binder->next != last) {
     1400//      Binder = Binder->next;
     1401//                      *out << *Binder << "\t" << endl;
     1402//    }
     1403//    *out << endl;
    14051404  } else
    14061405        *out << Verbose(1) << "AtomCount is " << AtomCount << ", thus no bonds, no connections!." << endl;
     
    16121611  }
    16131612
    1614   // further analysis of the found cycles (print rings, get minimum cycle length)
    1615   CyclicStructureAnalysis(out, MinimumRingSize);
    1616  
    16171613  // free all and exit
    16181614  delete(AtomStack);
     
    18801876
    18811877/** Parses the KeySet file and fills \a *FragmentList from the known molecule structure.
     1878 * Does two-pass scanning:
     1879 * -# Scans the keyset file and initialises a temporary graph
     1880 * -# Scans TEFactors file and sets the TEFactor of each key set in the temporary graph accordingly
     1881 * Finally, the temporary graph is inserted into the given \a FragmentList for return.
    18821882 * \param *out output stream for debugging
    18831883 * \param *path path to file
    1884  * \param **ListOfAtoms allocated (molecule::AtomCount) and filled lookup table for ids (Atom::nr) to *Atom
    1885  * \param *FragmentList NULL, filled on return
     1884 * \param *FragmentList empty, filled on return
    18861885 * \param IsAngstroem whether we have Ansgtroem or bohrradius
    18871886 * \return true - parsing successfully, false - failure on parsing (FragmentList will be NULL)
    18881887 */
    1889 bool molecule::ParseKeySetFile(ofstream *out, char *path, atom **ListOfAtoms, MoleculeListClass *&FragmentList, bool IsAngstroem)
     1888bool molecule::ParseKeySetFile(ofstream *out, char *path, Graph *&FragmentList, bool IsAngstroem)
    18901889{
    18911890  bool status = true;
    1892   ifstream KeySetFile;
     1891  ifstream InputFile;
    18931892  stringstream line;
     1893  GraphTestPair testGraphInsert;
     1894  int NumberOfFragments = 0;
     1895  double TEFactor;
    18941896  char *filename = (char *) Malloc(sizeof(char)*MAXSTRINGSIZE, "molecule::ParseKeySetFile - filename");
    18951897 
    1896   if (FragmentList != NULL) { // check list pointer
    1897     cerr << "Error: FragmentList was not NULL as supposed to be, already atoms present therein?" << endl;
    1898     return false;
    1899   }
    1900   cout << Verbose(1) << "Parsing the KeySet file ... " << endl;
    1901   // open file and read
     1898  if (FragmentList == NULL) { // check list pointer
     1899    FragmentList = new Graph;
     1900  }
     1901 
     1902  // 1st pass: open file and read
     1903  *out << Verbose(1) << "Parsing the KeySet file ... " << endl;
    19021904  sprintf(filename, "%s/%s%s", path, FRAGMENTPREFIX, KEYSETFILE);
    1903   KeySetFile.open(filename);
    1904   if (KeySetFile != NULL) {
     1905  InputFile.open(filename);
     1906  if (InputFile != NULL) {
    19051907    // each line represents a new fragment
    1906     int NumberOfFragments = 0;
    19071908    char *buffer = (char *) Malloc(sizeof(char)*MAXSTRINGSIZE, "molecule::ParseKeySetFile - *buffer");
    1908     // 1. scan through file to know number of fragments
    1909     while (!KeySetFile.eof()) {
    1910       KeySetFile.getline(buffer, MAXSTRINGSIZE);
    1911       if (strlen(buffer) > 0) // there is at least on possible number on the parsed line
    1912         NumberOfFragments++;
    1913     }
    1914     // 2. allocate the MoleculeListClass accordingly
    1915     FragmentList = new MoleculeListClass(NumberOfFragments, AtomCount);
    1916     // 3. Clear File, go to beginning and parse again, now adding found ids to each keyset and converting into molecules
    1917     KeySetFile.clear();
    1918     KeySetFile.seekg(ios::beg);
     1909    // 1. parse keysets and insert into temp. graph
     1910    while (!InputFile.eof()) {
     1911      InputFile.getline(buffer, MAXSTRINGSIZE);
     1912      KeySet CurrentSet;
     1913      if ((strlen(buffer) > 0) && (ScanBufferIntoKeySet(out, buffer, CurrentSet))) {  // if at least one valid atom was added, write config
     1914        testGraphInsert = FragmentList->insert(GraphPair (CurrentSet,pair<int,double>(NumberOfFragments++,1)));  // store fragment number and current factor
     1915        if (!testGraphInsert.second) {
     1916          cerr << "KeySet file must be corrupt as there are two equal key sets therein!" << endl;
     1917        }
     1918        //FragmentList->ListOfMolecules[NumberOfFragments++] = StoreFragmentFromKeySet(out, CurrentSet, IsAngstroem);
     1919      }
     1920    }
     1921    // 2. Free and done
     1922    InputFile.close();
     1923    InputFile.clear();
     1924    Free((void **)&buffer, "molecule::ParseKeySetFile - *buffer");
     1925    *out << Verbose(1) << "done." << endl;
     1926  } else {
     1927    *out << Verbose(1) << "File " << filename << " not found." << endl;
     1928    status = false;
     1929  }
     1930 
     1931  // 2nd pass: open TEFactors file and read
     1932  *out << Verbose(1) << "Parsing the TEFactors file ... " << endl;
     1933  sprintf(filename, "%s/%s%s", path, FRAGMENTPREFIX, TEFACTORSFILE);
     1934  InputFile.open(filename);
     1935  if (InputFile != NULL) {
     1936    // 3. add found TEFactors to each keyset
    19191937    NumberOfFragments = 0;
    1920     while ((!KeySetFile.eof()) && (FragmentList->NumberOfMolecules > NumberOfFragments)) {
    1921       KeySetFile.getline(buffer, MAXSTRINGSIZE);
    1922       KeySet CurrentSet;
    1923       if ((strlen(buffer) > 0) && (ScanBufferIntoKeySet(out, buffer, CurrentSet)))  // if at least one valid atom was added, write config
    1924         FragmentList->ListOfMolecules[NumberOfFragments++] = StoreFragmentFromKeySet(out, CurrentSet, IsAngstroem);
     1938    for(Graph::iterator runner = FragmentList->begin();runner != FragmentList->end(); runner++) {
     1939      if (!InputFile.eof()) {
     1940        InputFile >> TEFactor;
     1941        (*runner).second.second = TEFactor;
     1942        *out << Verbose(2) << "Setting " << ++NumberOfFragments << " fragment's TEFactor to " << (*runner).second.second << "." << endl;
     1943      } else {
     1944        status = false;
     1945        break;
     1946      }
    19251947    }
    19261948    // 4. Free and done
    1927     Free((void **)&buffer, "molecule::ParseKeySetFile - *buffer");
    1928     cout << "done." << endl;
     1949    InputFile.close();
     1950    *out << Verbose(1) << "done." << endl;
    19291951  } else {
    1930     cout << "File not found." << endl;
     1952    *out << Verbose(1) << "File " << filename << " not found." << endl;
    19311953    status = false;
    19321954  }
     1955
    19331956  Free((void **)&filename, "molecule::ParseKeySetFile - filename");
     1957
     1958  return status;
     1959};
     1960
     1961/** Stores keysets and TEFactors to file.
     1962 * \param *out output stream for debugging
     1963 * \param KeySetList Graph with Keysets and factors
     1964 * \param *path path to file
     1965 * \return true - file written successfully, false - writing failed
     1966 */
     1967bool molecule::StoreKeySetFile(ofstream *out, Graph &KeySetList, char *path)
     1968{
     1969  ofstream output;
     1970  bool status =  true;
     1971  string line;
     1972  string::iterator ende;
     1973
     1974  // open KeySet file
     1975  line = path;
     1976  line.append("/");
     1977  line += FRAGMENTPREFIX;
     1978  ende = line.end();
     1979  line += KEYSETFILE;
     1980  output.open(line.c_str(), ios::out);
     1981  *out << Verbose(1) << "Saving key sets of the total graph ... ";
     1982  if(output != NULL) {
     1983    for(Graph::iterator runner = KeySetList.begin(); runner != KeySetList.end(); runner++) {
     1984      for (KeySet::iterator sprinter = (*runner).first.begin();sprinter != (*runner).first.end(); sprinter++)
     1985        output << *sprinter << "\t";
     1986      output << endl;
     1987    }
     1988    *out << "done." << endl;
     1989  } else {
     1990    cerr << "Unable to open " << line << " for writing keysets!" << endl;
     1991    status = false;
     1992  }
     1993  output.close();
     1994  output.clear();
     1995
     1996  // open TEFactors file
     1997  line.erase(ende, line.end());
     1998  line += TEFACTORSFILE;
     1999  output.open(line.c_str(), ios::out);
     2000  *out << Verbose(1) << "Saving TEFactors of the total graph ... ";
     2001  if(output != NULL) {
     2002    for(Graph::iterator runner = KeySetList.begin(); runner != KeySetList.end(); runner++)
     2003      output << (*runner).second.second << endl;
     2004    *out << Verbose(1) << "done." << endl;
     2005  } else {
     2006    *out << Verbose(1) << "failed to open file" << line << "." << endl;
     2007    status = false;
     2008  }
     2009  output.close();
    19342010
    19352011  return status;
     
    19462022  ofstream AdjacencyFile;
    19472023  atom *Walker = NULL;
    1948   char *filename = (char *) Malloc(sizeof(char)*MAXSTRINGSIZE, "molecule::StoreAdjacencyToFile - filename");
     2024  stringstream line;
    19492025  bool status = true;
    19502026
    1951   sprintf(filename, "%s/%s%s", path, FRAGMENTPREFIX, ADJACENCYFILE);
    1952   AdjacencyFile.open(filename);
    1953   cout << Verbose(1) << "Saving adjacency list ... ";
     2027  line << path << "/" << FRAGMENTPREFIX << ADJACENCYFILE;
     2028  AdjacencyFile.open(line.str().c_str(), ios::out);
     2029  *out << Verbose(1) << "Saving adjacency list ... ";
    19542030  if (AdjacencyFile != NULL) {
    19552031    Walker = start;
     
    19622038    }
    19632039    AdjacencyFile.close();
    1964     cout << "done." << endl;
     2040    *out << Verbose(1) << "done." << endl;
    19652041  } else {
    1966     cout << "failed." << endl;
     2042    *out << Verbose(1) << "failed to open file " << line.str() << "." << endl;
    19672043    status = false;
    19682044  }
    1969   Free((void **)&filename, "molecule::StoreAdjacencyToFile - filename");
    19702045 
    19712046  return status;
     
    19802055bool molecule::CheckAdjacencyFileAgainstMolecule(ofstream *out, char *path, atom **ListOfAtoms)
    19812056{
    1982   char *filename = (char *) Malloc(sizeof(char)*MAXSTRINGSIZE, "molecule::CheckAdjacencyFileAgainstMolecule - filename");
    19832057  ifstream File;
     2058  stringstream line;
    19842059  bool status = true;
    1985  
    1986   sprintf(filename, "%s/%s%s", path, FRAGMENTPREFIX, ADJACENCYFILE);
    1987   File.open(filename);
    1988   *out << Verbose(1) << "Looking at bond structure stored in adjacency file and comparing to present one ...";
     2060  char *buffer = (char *) Malloc(sizeof(char)*MAXSTRINGSIZE, "molecule::CheckAdjacencyFileAgainstMolecule: *buffer");
     2061 
     2062  line << path << "/" << FRAGMENTPREFIX << ADJACENCYFILE;
     2063  File.open(line.str().c_str(), ios::out);
     2064  *out << Verbose(1) << "Looking at bond structure stored in adjacency file and comparing to present one ... " << endl;
    19892065  if (File != NULL) {
    19902066    // allocate storage structure
     
    19952071    // Parse the file line by line and count the bonds
    19962072    while (!File.eof()) {
    1997       File.getline(filename, MAXSTRINGSIZE);
     2073      File.getline(buffer, MAXSTRINGSIZE);
    19982074      stringstream line;
    1999       line.str(filename);
     2075      line.str(buffer);
    20002076      int AtomNr = -1;
    20012077      line >> AtomNr;
     
    20312107    File.clear();
    20322108    if (status) { // if equal we parse the KeySetFile
    2033       *out << " done: Equal." << endl;
     2109      *out << Verbose(1) << "done: Equal." << endl;
    20342110      status = true;
    20352111    } else
    2036       *out << " done: Not equal by " << NonMatchNumber << " atoms." << endl;
     2112      *out << Verbose(1) << "done: Not equal by " << NonMatchNumber << " atoms." << endl;
    20372113    Free((void **)&CurrentBonds, "molecule::CheckAdjacencyFileAgainstMolecule - **CurrentBonds");
    20382114  } else {
    2039     *out << " Adjacency file not found." << endl;
     2115    *out << Verbose(1) << "Adjacency file not found." << endl;
    20402116    status = false;
    20412117  }
    2042   Free((void **)&filename, "molecule::CheckAdjacencyFileAgainstMolecule - filename");
     2118  Free((void **)&buffer, "molecule::CheckAdjacencyFileAgainstMolecule: *buffer");
    20432119 
    20442120  return status;
     
    20552131 * -# combines the generated molecule lists from all subgraphs
    20562132 * -# saves to disk: fragment configs, adjacency, orderatsite, keyset files
     2133 * Note that as we split "this" molecule up into a list of subgraphs, i.e. a MoleculeListClass, we have two sets
     2134 * of vertex indices: Global always means the index in "this" molecule, whereas local refers to the molecule or
     2135 * subgraph in the MoleculeListClass.
    20572136 * \param *out output stream for debugging
    20582137 * \param Order up to how many neighbouring bonds a fragment contains in BondOrderScheme::BottumUp scheme
     
    20612140void molecule::FragmentMolecule(ofstream *out, int Order, config *configuration)
    20622141{
    2063         MoleculeListClass **BondFragments = NULL;
    2064   MoleculeListClass *FragmentList = NULL;
     2142        MoleculeListClass *BondFragments = NULL;
    20652143  atom *Walker = NULL;
     2144  atom *OtherWalker = NULL;
     2145  bond *Binder = NULL;
    20662146  int *SortIndex = NULL;
    20672147  element *runner = NULL;
    20682148  int AtomNo;
    20692149  int MinimumRingSize;
    2070   int TotalFragmentCounter;
    20712150  int FragmentCounter;
    20722151  MoleculeLeafClass *MolecularWalker = NULL;
     
    20742153  fstream File;
    20752154  bool FragmentationToDo = true;
    2076 
     2155  Graph **FragmentList = NULL;
     2156  Graph *TempFragmentList = NULL;
     2157  Graph TotalGraph;     // graph with all keysets however local numbers
     2158  KeySet *TempSet = NULL;
     2159  int TotalNumberOfKeySets = 0;
     2160  int KeySetCounter = 0;
     2161  atom ***ListOfLocalAtoms = NULL;
     2162 
    20772163  *out << endl;
    20782164#ifdef ADDHYDROGEN
     
    20822168#endif
    20832169
     2170  // ===== 1. Check whether bond structure is same as stored in files ====
     2171 
    20842172  // fill the adjacency list
    20852173  CreateListOfBondsPerAtom(out);
    20862174
    2087   // === compare it with adjacency file ===
     2175  // create lookup table for Atom::nr
    20882176  atom **ListOfAtoms = (atom **) Malloc(sizeof(atom *)*AtomCount, "molecule::FragmentMolecule - **ListOfAtoms");
    20892177  Walker = start;
     
    20992187    FragmentationToDo = false;
    21002188  }
     2189  // === compare it with adjacency file ===
    21012190  FragmentationToDo = FragmentationToDo && CheckAdjacencyFileAgainstMolecule(out, configuration->configpath, ListOfAtoms);
    2102   if (FragmentationToDo)  // NULL entries in ListOfAtoms contain NonMatches
    2103     FragmentationToDo = FragmentationToDo && ParseKeySetFile(out, configuration->configpath, ListOfAtoms, FragmentList, configuration->GetIsAngstroem());
     2191  Free((void **)&ListOfAtoms, "molecule::FragmentMolecule - **ListOfAtoms");
     2192
     2193  // ===== 2. perform a DFS analysis to gather info on cyclic structure and a list of disconnected subgraphs =====
     2194  Subgraphs = DepthFirstSearchAnalysis((ofstream *)&*out, false, MinimumRingSize);
     2195 
     2196  // fill index lookup list for each subgraph from global nr to local pointer
     2197  ListOfLocalAtoms = (atom ***) Malloc(sizeof(atom **)*FragmentCounter, "molecule::FragmentMolecule - **ListOfLocalAtoms");
     2198  for (int i=0;i<FragmentCounter;i++) {
     2199    ListOfLocalAtoms[i] = (atom **) Malloc(sizeof(atom *)*AtomCount, "molecule::FragmentMolecule - *ListOfLocalAtoms[]");
     2200    for(int j=0;j<AtomCount;j++)
     2201      ListOfLocalAtoms[i][j] = NULL;
     2202  }
     2203  FragmentCounter = 0;
     2204  MolecularWalker = Subgraphs;
     2205  while (MolecularWalker->next != NULL) {
     2206    MolecularWalker = MolecularWalker->next;
     2207    Walker = MolecularWalker->Leaf->start;
     2208    while (Walker->next != MolecularWalker->Leaf->end) {
     2209      Walker = Walker->next;
     2210#ifdef ADDHYDROGEN
     2211      if (Walker->type->Z != 1) // skip hydrogen
     2212#endif
     2213        ListOfLocalAtoms[FragmentCounter][Walker->GetTrueFather()->nr] = Walker;  // set present global id index to the local pointer
     2214    }
     2215    FragmentCounter++;
     2216  }
     2217
     2218  // fill the bond structure of the individually stored subgraphs
     2219  FragmentCounter = 0;
     2220  MolecularWalker = Subgraphs;
     2221  while (MolecularWalker->next != NULL) {
     2222    MolecularWalker = MolecularWalker->next;
     2223    *out << Verbose(1) << "Creating adjacency list for subgraph " << MolecularWalker << "." << endl;
     2224    Walker = MolecularWalker->Leaf->start;
     2225    while (Walker->next != MolecularWalker->Leaf->end) {
     2226      Walker = Walker->next;
     2227      AtomNo = Walker->father->nr;  // global id of the current walker
     2228      for(int i=0;i<NumberOfBondsPerAtom[AtomNo];i++) { // go through father's bonds and copy them all
     2229        Binder = ListOfBondsPerAtom[AtomNo][i];
     2230        OtherWalker = ListOfLocalAtoms[FragmentCounter][Binder->GetOtherAtom(Walker->father)->nr];    // local copy of current bond partner of walker
     2231        if ((OtherWalker != NULL) && (OtherWalker->nr > Walker->nr))
     2232          MolecularWalker->Leaf->AddBond(Walker, OtherWalker, Binder->BondDegree);
     2233      }
     2234    }
     2235    //MolecularWalker->Leaf->CreateAdjacencyList(out, BondDistance);
     2236    MolecularWalker->Leaf->CreateListOfBondsPerAtom(out);
     2237    FragmentCounter++;
     2238  }
     2239
     2240  // ===== 3. if structure still valid, parse key set file and others =====
     2241  if (FragmentationToDo) {
     2242    // parse key sets into new graph
     2243    TempFragmentList = new Graph;
     2244    FragmentationToDo = FragmentationToDo && ParseKeySetFile(out, configuration->configpath, TempFragmentList, configuration->GetIsAngstroem());
     2245  } else
     2246    *out << Verbose(1) << "Creation of lookup table Atom::nr <-> Atom failed!" << endl;
    21042247  if (FragmentationToDo)  // parse the adaptive order per atom/site/vertex
    21052248    FragmentationToDo = FragmentationToDo && ParseOrderAtSiteFromFile(out, configuration->configpath);
    2106   Free((void **)&ListOfAtoms, "molecule::FragmentMolecule - **ListOfAtoms");
    2107 
    2108   // =================================== Begin of FRAGMENTATION ===============================
    2109   if (FragmentationToDo) { // if we parsed Adjacancy, check whether OrderAtSite is above Order everywhere
     2249  else
     2250     *out << Verbose(1) << "Parsing keyset file failed" << endl;
     2251 
     2252  // ===== 4. check globally whether there's something to do actually (first adaptivity check)
     2253  if (FragmentationToDo) { // check whether OrderAtSite is above Order everywhere
     2254    FragmentationToDo = false;
    21102255    Walker = start;
    2111     while (Walker->next != end) { // create a lookup table (Atom::nr -> atom) used as a marker table lateron
     2256    while (Walker->next != end) {
    21122257      Walker = Walker->next;
    21132258#ifdef ADDHYDROGEN
     
    21152260#endif
    21162261        if (Walker->AdaptiveOrder < Order)
    2117           FragmentationToDo = false;
    2118     }
    2119   }
    2120  
    2121   if (!FragmentationToDo) { // if we have still do something, FragmentationToDo will be false
    2122     // === first perform a DFS analysis to gather info on cyclic structure and a list of disconnected subgraphs ===
    2123     Subgraphs = DepthFirstSearchAnalysis((ofstream *)&*out, false, MinimumRingSize);
     2262          FragmentationToDo = true;
     2263    }
     2264  } else
     2265    *out << Verbose(1) << "Parsing order at site file failed" << endl;
     2266 
     2267  if (!FragmentationToDo)
     2268    *out << Verbose(0) << "Order at every site is already equal or above desired order " << Order << "." << endl;
     2269
     2270  // =================================== Begin of FRAGMENTATION ===============================
     2271  // check cyclic lengths
     2272  if ((MinimumRingSize != -1) && (Order >= MinimumRingSize)) {
     2273    *out << Verbose(0) << "Bond order " << Order << " greater than or equal to Minimum Ring size of " << MinimumRingSize << " found is not allowed." << endl;
     2274  } else {
     2275    FragmentCounter = 0;
    21242276    MolecularWalker = Subgraphs;
    2125     // fill the bond structure of the individually stored subgraphs
     2277    // count subgraphs and allocate fragments
    21262278    while (MolecularWalker->next != NULL) {
    21272279      MolecularWalker = MolecularWalker->next;
    2128       *out << Verbose(1) << "Creating adjacency list for subgraph " << MolecularWalker << "." << endl;
    2129       MolecularWalker->Leaf->CreateAdjacencyList(out, BondDistance);
    2130       MolecularWalker->Leaf->CreateListOfBondsPerAtom(out);
    2131     }
     2280      FragmentCounter++;
     2281    }
     2282    FragmentList = (Graph **) Malloc(sizeof(Graph *)*FragmentCounter, "molecule::FragmentMolecule - **BondFragments");
    21322283   
    2133     // === fragment all subgraphs ===
    2134     if ((MinimumRingSize != -1) && (Order >= MinimumRingSize)) {
    2135       *out << Verbose(0) << "Bond order greater than or equal to Minimum Ring size of " << MinimumRingSize << " found is not allowed." << endl;
    2136     } else {
     2284    // ===== 6a. fill RootStack for each subgraph (second adaptivity check) =====
     2285    // NOTE: (keep this extern of following while loop, as lateron we may here look for which site to add to which subgraph)
     2286    // fill the root stack
     2287    KeyStack RootStack[FragmentCounter];
     2288
     2289    if (Order == -1) {  // means we want to increase order adaptively
     2290      cerr << "Adaptive chosing of sites not yet implemented!" << endl;
     2291    } else {  // means we just want to increase it at every site by one
    21372292      FragmentCounter = 0;
    21382293      MolecularWalker = Subgraphs;
     
    21402295      while (MolecularWalker->next != NULL) {
    21412296        MolecularWalker = MolecularWalker->next;
    2142         FragmentCounter++;
    2143       }
    2144       BondFragments = (MoleculeListClass **) Malloc(sizeof(MoleculeListClass *)*FragmentCounter, "molecule::FragmentMolecule - **BondFragments");
    2145      
    2146       // create RootStack for each Subgraph
    2147       // NOTE: (keep this extern of following while loop, as lateron we may here look for which site to add to which subgraph)
    2148       KeyStack RootStack[FragmentCounter];
    2149 
    2150       FragmentCounter = 0;
    2151       MolecularWalker = Subgraphs;
    2152       // count subgraphs and allocate fragments
    2153       while (MolecularWalker->next != NULL) {
    2154         MolecularWalker = MolecularWalker->next;
     2297        // find first root candidates 
    21552298        RootStack[FragmentCounter].clear(); 
    2156         // find first root candidates 
    21572299        Walker = MolecularWalker->Leaf->start;
    21582300        while (Walker->next != MolecularWalker->Leaf->end) { // go through all (non-hydrogen) atoms
     
    21662308        FragmentCounter++;
    21672309      }
    2168      
    2169       // fill the bond fragment list
     2310    }
     2311
     2312   // ===== 6b. assign each keyset to its respective subgraph =====
     2313    if ((TempFragmentList != NULL) && (TempFragmentList->size() != 0)) { // if there are some scanned keysets at all
     2314      // spread the keysets
    21702315      FragmentCounter = 0;
    2171       TotalFragmentCounter = 0;
    21722316      MolecularWalker = Subgraphs;
    21732317      while (MolecularWalker->next != NULL) {
    21742318        MolecularWalker = MolecularWalker->next;
    2175         *out << Verbose(1) << "Fragmenting subgraph " << MolecularWalker << "." << endl;
    2176         if (MolecularWalker->Leaf->first->next != MolecularWalker->Leaf->last) {
    2177             // output ListOfBondsPerAtom for debugging
    2178           *out << Verbose(0) << endl << "From Contents of ListOfBondsPerAtom, all non-hydrogen atoms:" << endl;
    2179           Walker = MolecularWalker->Leaf->start;
    2180           while (Walker->next != MolecularWalker->Leaf->end) {
    2181             Walker = Walker->next;
    2182   #ifdef ADDHYDROGEN
    2183             if (Walker->type->Z != 1) {   // regard only non-hydrogen
    2184   #endif
    2185               *out << Verbose(0) << "Atom " << Walker->Name << " has Bonds: "<<endl;
    2186               for(int j=0;j<MolecularWalker->Leaf->NumberOfBondsPerAtom[Walker->nr];j++) {
    2187                 *out << Verbose(1) << *(MolecularWalker->Leaf->ListOfBondsPerAtom)[Walker->nr][j] << endl;
    2188               }
    2189   #ifdef ADDHYDROGEN
     2319        // assign scanned keysets
     2320        FragmentList[FragmentCounter] = new Graph;
     2321        TempSet = new KeySet;
     2322        KeySetCounter = 0;
     2323        for(Graph::iterator runner = TempFragmentList->begin();runner != TempFragmentList->end(); runner++) { // key sets contain global numbers!
     2324          if ( ListOfLocalAtoms[FragmentCounter][FindAtom(*((*runner).first.begin()))->nr]->nr != -1) {// as we may assume that that bond structure is unchanged, we only test the first key in each set
     2325            // translate keyset to local numbers
     2326            for(KeySet::iterator sprinter = (*runner).first.begin(); sprinter != (*runner).first.end(); sprinter++)
     2327              TempSet->insert(ListOfLocalAtoms[FragmentCounter][FindAtom(*sprinter)->nr]->nr);
     2328            // insert into FragmentList
     2329            FragmentList[FragmentCounter]->insert(GraphPair (*TempSet, pair<int,double>(KeySetCounter++, (*runner).second.second)));
     2330          }
     2331          TempSet->clear();
     2332        }
     2333        delete(TempSet);
     2334        if (KeySetCounter == 0)
     2335          delete(FragmentList[FragmentCounter]);
     2336        else
     2337          *out << Verbose(1) << KeySetCounter << " atoms were put into subgraph " << FragmentCounter << "." << endl;
     2338        FragmentCounter++;
     2339      }
     2340    } else  // otherwise make sure all lists are initialised to NULL
     2341      for(int i=0;i<FragmentCounter;i++)
     2342        FragmentList[i] = NULL;
     2343   
     2344
     2345   // ===== 7. fill the bond fragment list =====
     2346    FragmentCounter = 0;
     2347    TotalNumberOfKeySets = 0;
     2348    MolecularWalker = Subgraphs;
     2349    while (MolecularWalker->next != NULL) {
     2350      MolecularWalker = MolecularWalker->next;
     2351      *out << Verbose(1) << "Fragmenting subgraph " << MolecularWalker << "." << endl;
     2352      if (MolecularWalker->Leaf->first->next != MolecularWalker->Leaf->last) {
     2353          // output ListOfBondsPerAtom for debugging
     2354        *out << Verbose(0) << endl << "From Contents of ListOfBondsPerAtom, all non-hydrogen atoms:" << endl;
     2355        Walker = MolecularWalker->Leaf->start;
     2356        while (Walker->next != MolecularWalker->Leaf->end) {
     2357          Walker = Walker->next;
     2358#ifdef ADDHYDROGEN
     2359          if (Walker->type->Z != 1) {   // regard only non-hydrogen
     2360#endif
     2361            *out << Verbose(0) << "Atom " << Walker->Name << " has Bonds: "<<endl;
     2362            for(int j=0;j<MolecularWalker->Leaf->NumberOfBondsPerAtom[Walker->nr];j++) {
     2363              *out << Verbose(1) << *(MolecularWalker->Leaf->ListOfBondsPerAtom)[Walker->nr][j] << endl;
    21902364            }
    2191   #endif
     2365#ifdef ADDHYDROGEN
    21922366          }
    2193           *out << endl;
     2367#endif
     2368        }
     2369        *out << endl;
     2370     
     2371        *out << Verbose(0) << endl << " ========== BOND ENERGY of subgraph " << FragmentCounter << " ========================= " << endl;
     2372        *out << Verbose(0) << "Begin of bond fragmentation." << endl;
    21942373       
    2195           *out << Verbose(0) << endl << " ========== BOND ENERGY ========================= " << endl;
    2196           *out << Verbose(0) << "Begin of bond fragmentation." << endl;
    2197           BondFragments[FragmentCounter] = NULL;
    2198           // call BOSSANOVA method
    2199           Graph *FragmentList = MolecularWalker->Leaf->FragmentBOSSANOVA(out, RootStack[FragmentCounter]);
    2200 
    2201           // allocate memory for the pointer array and transmorph graphs into full molecular fragments
    2202           int TotalNumberOfMolecules = 0;
    2203           for(Graph::iterator runner = FragmentList->begin(); runner != FragmentList->end(); runner++)
    2204             TotalNumberOfMolecules++;
    2205           BondFragments[FragmentCounter] = new MoleculeListClass(TotalNumberOfMolecules, AtomCount);
    2206           int k=0;
    2207           for(Graph::iterator runner = FragmentList->begin(); runner != FragmentList->end(); runner++) {
    2208             KeySet test = (*runner).first;
    2209             *out << "Fragment No." << (*runner).second.first << " was created " << (int)(*runner).second.second << " time(s)." << endl;
    2210             BondFragments[FragmentCounter]->ListOfMolecules[k] = MolecularWalker->Leaf->StoreFragmentFromKeySet(out, test, configuration);
    2211             k++;
    2212           }
    2213           *out << k << "/" << BondFragments[FragmentCounter]->NumberOfMolecules << " fragments generated from the keysets." << endl;
    2214         } else {
    2215           *out << Verbose(0) << "Connection matrix has not yet been generated!" << endl;
     2374        // call BOSSANOVA method
     2375        MolecularWalker->Leaf->FragmentBOSSANOVA(out, FragmentList[FragmentCounter], RootStack[FragmentCounter]);
     2376       
     2377        // translate list into global numbers (i.e. valid in "this" molecule, not in MolecularWalker->Leaf)
     2378        KeySet *TempSet = new KeySet;
     2379        for(Graph::iterator runner = FragmentList[FragmentCounter]->begin(); runner != FragmentList[FragmentCounter]->end(); runner++) {
     2380          for(KeySet::iterator sprinter = (*runner).first.begin(); sprinter != (*runner).first.end(); sprinter++)
     2381            TempSet->insert((MolecularWalker->Leaf->FindAtom(*sprinter))->GetTrueFather()->nr);
     2382          TotalGraph.insert(GraphPair(*TempSet, pair<int,double>(TotalNumberOfKeySets++, (*runner).second.second)));
     2383          TempSet->clear();
    22162384        }
    2217         TotalFragmentCounter += BondFragments[FragmentCounter]->NumberOfMolecules;
    2218         FragmentCounter++;  // next fragment list
     2385        delete(TempSet);
     2386        delete(FragmentList[FragmentCounter]);
     2387      } else {
     2388        cerr << "Subgraph " << MolecularWalker << " has no atoms!" << endl;
    22192389      }
    2220     }
    2221  
    2222     // === combine bond fragments list into a single one ===
    2223     FragmentList = new MoleculeListClass(TotalFragmentCounter, AtomCount);
    2224     TotalFragmentCounter = 0;
    2225     for (int i=0;i<FragmentCounter;i++) {
    2226       for(int j=0;j<BondFragments[i]->NumberOfMolecules;j++) {
    2227         FragmentList->ListOfMolecules[TotalFragmentCounter] =  BondFragments[i]->ListOfMolecules[j];
    2228         BondFragments[i]->ListOfMolecules[j] = NULL;
    2229         TotalFragmentCounter++;
    2230       }
    2231       delete(BondFragments[i]);
    2232     }
    2233     Free((void **)&BondFragments, "molecule::FragmentMolecule - **BondFragments");
    2234   } else
    2235     *out << Verbose(0) << "Nothing to do, using only fragments reconstructed from the KeySetFile." << endl;
    2236   // ==================================== End of FRAGMENTATION ================================
    2237  
    2238   // === Save fragments' configuration to disk ===
    2239   if (FragmentList != NULL) {
     2390      FragmentCounter++;  // next fragment list
     2391    }
     2392  }
     2393  Free((void **)&FragmentList, "molecule::FragmentMolecule - **FragmentList");
     2394
     2395  // ===== 8. gather keyset lists (graphs) from all subgraphs and transform into MoleculeListClass =====
     2396  // allocate memory for the pointer array and transmorph graphs into full molecular fragments
     2397  BondFragments = new MoleculeListClass(TotalGraph.size(), AtomCount);
     2398  int k=0;
     2399  for(Graph::iterator runner = TotalGraph.begin(); runner != TotalGraph.end(); runner++) {
     2400    KeySet test = (*runner).first;
     2401    *out << "Fragment No." << (*runner).second.first << " with TEFactor " << (*runner).second.second << "." << endl;
     2402    BondFragments->ListOfMolecules[k] = StoreFragmentFromKeySet(out, test, configuration);
     2403    k++;
     2404  }
     2405  *out << k << "/" << BondFragments->NumberOfMolecules << " fragments generated from the keysets." << endl;
     2406
     2407 // ==================================== End of FRAGMENTATION ================================
     2408 
     2409  // ===== 10. Save fragments' configuration and keyset files et al to disk ===
     2410  if (BondFragments->NumberOfMolecules != 0) {
    22402411    // create a SortIndex to map from BFS labels to the sequence in which the atoms are given in the config file
    22412412    SortIndex = (int *) Malloc(sizeof(int)*AtomCount, "molecule::FragmentMolecule: *SortIndex");
     
    22552426      }
    22562427    }
    2257     *out << Verbose(1) << "Writing " << FragmentList->NumberOfMolecules << " possible bond fragmentation configs" << endl;
    2258     if (FragmentList->OutputConfigForListOfFragments(out, configuration, SortIndex))
     2428    *out << Verbose(1) << "Writing " << BondFragments->NumberOfMolecules << " possible bond fragmentation configs" << endl;
     2429    if (BondFragments->OutputConfigForListOfFragments(out, configuration, SortIndex))
    22592430      *out << Verbose(1) << "All configs written." << endl;
    22602431    else
    2261       *out << Verbose(1) << "Some configs' writing failed." << endl;
    2262     Free((void **)&SortIndex, "molecule::FragmentMolecule: *SortIndex");
     2432      *out << Verbose(1) << "Some config writing failed." << endl;
     2433
     2434    // store force index reference file
     2435    BondFragments->StoreForcesFile(out, configuration->configpath, SortIndex);
    22632436   
    2264     // === store Adjacency file ===
     2437    // store keysets file
     2438    StoreKeySetFile(out, TotalGraph, configuration->configpath);
     2439
     2440    // store Adjacency file
    22652441    StoreAdjacencyToFile(out, configuration->configpath);
    22662442
    2267     // Store adaptive orders into file
     2443    // store adaptive orders into file
    22682444    StoreOrderAtSiteFile(out, configuration->configpath);
    22692445   
     
    22752451    delete(FragmentList); // remove bond molecule from memory
    22762452    FragmentList = NULL;
     2453    Free((void **)&SortIndex, "molecule::FragmentMolecule: *SortIndex");
    22772454  } else
    22782455    *out << Verbose(1) << "FragmentList is zero on return, splitting failed." << endl;
    22792456 
     2457  // free the index lookup list
     2458  for (int i=0;i<FragmentCounter;i++)
     2459    Free((void **)&ListOfLocalAtoms[i], "molecule::FragmentMolecule - *ListOfLocalAtoms[]");
     2460  Free((void **)&ListOfLocalAtoms, "molecule::FragmentMolecule - **ListOfLocalAtoms");
    22802461  // free subgraph memory again
     2462  delete(TempFragmentList);
    22812463  if (Subgraphs != NULL) {
    22822464    while (Subgraphs->next != NULL) {
     
    23032485  line << path << "/" << FRAGMENTPREFIX << ORDERATSITEFILE;
    23042486  file.open(line.str().c_str());
    2305   *out << Verbose(0) << "Writing OrderAtSite " << ORDERATSITEFILE << " ... " << endl;
     2487  *out << Verbose(1) << "Writing OrderAtSite " << ORDERATSITEFILE << " ... " << endl;
    23062488  if (file != NULL) {
    23072489    atom *Walker = start;
     
    23122494    }
    23132495    file.close();
     2496    *out << Verbose(1) << "done." << endl;
    23142497    return true;
    23152498  } else {
     2499    *out << Verbose(1) << "failed to open file " << line.str() << "." << endl;
    23162500    return false;
    23172501  }
     
    23552539    }
    23562540    file.close();
     2541    *out << Verbose(1) << "done." << endl;
    23572542    status = true;
    23582543  } else {
     2544    *out << Verbose(1) << "failed to open file " << line.str() << "." << endl;
    23592545    status = false;
    23602546  }
     
    29383124  int CurrentIndex;
    29393125  int *Labels;
     3126  double TEFactor;
    29403127  int *ShortestPathList;
    29413128  bool **UsedList;
     
    30833270 * with SP of 2, then those with SP of 3, then those with SP of 4 and so on.
    30843271 * \param *out output stream for debugging
    3085  * \param Order bond order (limits BFS exploration and "number of digits" in power set generation 
    3086  * \param *ReturnKeySets Graph structure to insert found keysets/fragments into
     3272 * \param Order bond order (limits BFS exploration and "number of digits" in power set generation
     3273 * \param FragmentSearch UniqueFragments structure containing TEFactor, root atom and so on
    30873274 * \param RestrictedKeySet Restricted vertex set to use in context of molecule
    3088  * \param RootKeyNr Atom::nr of the atom acting as current fragment root
    30893275 * \return number of inserted fragments
    30903276 * \note ShortestPathList in FragmentSearch structure is probably due to NumberOfAtomsSPLevel and SP not needed anymore
    30913277 */
    3092 int molecule::PowerSetGenerator(ofstream *out, int Order, Graph *ReturnKeySets, KeySet RestrictedKeySet, int RootKeyNr)
     3278int molecule::PowerSetGenerator(ofstream *out, int Order, struct UniqueFragments &FragmentSearch, KeySet RestrictedKeySet)
    30933279{
    30943280  int SP, UniqueIndex, AtomKeyNr;
     
    31003286  atom **PredecessorList = (atom **) Malloc(sizeof(atom *)*AtomCount, "molecule::PowerSetGenerator: **PredecessorList");
    31013287  KeySet::iterator runner;
    3102   //int Count = RestrictedKeySet.size();
    3103 
    3104   // initialise the fragments structure
    3105   struct UniqueFragments FragmentSearch;
    3106   FragmentSearch.BondsPerSPList = (bond **) Malloc(sizeof(bond *)*Order*2, "molecule::PowerSetGenerator: ***BondsPerSPList");
    3107   FragmentSearch.BondsPerSPCount = (int *) Malloc(sizeof(int)*Order, "molecule::PowerSetGenerator: *BondsPerSPCount");
    3108   FragmentSearch.ShortestPathList = (int *) Malloc(sizeof(int)*AtomCount, "molecule::PowerSetGenerator: *ShortestPathList");
    3109   FragmentSearch.Labels = (int *) Malloc(sizeof(int)*AtomCount, "molecule::PowerSetGenerator: *Labels");
    3110   FragmentSearch.FragmentCounter = 0;
    3111   FragmentSearch.FragmentSet = new KeySet;
    3112   FragmentSearch.Leaflet = ReturnKeySets;      // set to insertion graph
    3113   FragmentSearch.Root = FindAtom(RootKeyNr);
     3288  int RootKeyNr = FragmentSearch.Root->nr;
     3289  int Counter = FragmentSearch.FragmentCounter;
     3290
    31143291  for (int i=0;i<AtomCount;i++) {
    3115     FragmentSearch.Labels[i] = -1;
    3116     FragmentSearch.ShortestPathList[i] = -1;
    31173292    PredecessorList[i] = NULL;
    31183293  }
    3119   for (int i=0;i<Order;i++) {
    3120     FragmentSearch.BondsPerSPList[2*i] = new bond();    // start node
    3121     FragmentSearch.BondsPerSPList[2*i+1] = new bond();  // end node
    3122     FragmentSearch.BondsPerSPList[2*i]->next = FragmentSearch.BondsPerSPList[2*i+1];     // intertwine these two
    3123     FragmentSearch.BondsPerSPList[2*i+1]->previous = FragmentSearch.BondsPerSPList[2*i];
    3124     FragmentSearch.BondsPerSPCount[i] = 0;
    3125   } 
    3126  
     3294
    31273295  *out << endl;
    31283296  *out << Verbose(0) << "Begin of PowerSetGenerator with order " << Order << " at Root " << *FragmentSearch.Root << "." << endl;
     
    31833351          *out << Verbose(3) << "Label is already " << FragmentSearch.Labels[OtherWalker->nr] << "." << endl;
    31843352        }
    3185         if ((OtherWalker != PredecessorList[AtomKeyNr]) && (FragmentSearch.Labels[OtherWalker->nr] > FragmentSearch.Labels[RootKeyNr])) { // only pass through those with label bigger than Root's
     3353        if ((OtherWalker != PredecessorList[AtomKeyNr]) && (OtherWalker->nr > RootKeyNr)) { // only pass through those with label bigger than Root's
    31863354          FragmentSearch.ShortestPathList[OtherWalker->nr] = SP+1;
    31873355          *out << Verbose(3) << "Set Shortest Path to " << FragmentSearch.ShortestPathList[OtherWalker->nr] << "." << endl;
     
    32043372            } else *out << Verbose(3) << "Not putting on atom stack, nor adding bond, as " << *OtherWalker << "'s SP is shorter than Walker's." << endl;
    32053373          } else *out << Verbose(3) << "Not continuing, as " << *OtherWalker << " is out of reach of order " << Order << "." << endl;
    3206         } else *out << Verbose(3) << "Not passing on, as label of " << *OtherWalker << " " << FragmentSearch.Labels[OtherWalker->nr] << " is smaller than that of Root " << FragmentSearch.Labels[RootKeyNr] << " or this is my predecessor." << endl;
    3207       } else *out << Verbose(2) << "Is not in the retstricted keyset or skipping hydrogen " << *OtherWalker << "." << endl;
     3374        } else *out << Verbose(3) << "Not passing on, as index of " << *OtherWalker << " " << OtherWalker->nr << " is smaller than that of Root " << RootKeyNr << " or this is my predecessor." << endl;
     3375      } else *out << Verbose(2) << "Is not in the restricted keyset or skipping hydrogen " << *OtherWalker << "." << endl;
    32083376    }
    32093377  }
     
    32713439  }
    32723440
    3273 /*  // as FragmentSearch structure is used only once, we don't have to clean it anymore
     3441  // as FragmentSearch structure is used only once, we don't have to clean it anymore
    32743442  // remove root from stack
    32753443  *out << Verbose(0) << "Removing root again from stack." << endl;
     
    32923460    *out << "cleaned." << endl;
    32933461  }
    3294 */
     3462
    32953463  // free allocated memory
    32963464  Free((void **)&NumberOfAtomsSPLevel, "molecule::PowerSetGenerator: *SPLevelCount");
    32973465  Free((void **)&PredecessorList, "molecule::PowerSetGenerator: **PredecessorList");
    3298   for(int i=0;i<Order;i++) { // delete start and end of each list
    3299     delete(FragmentSearch.BondsPerSPList[2*i]);
    3300     delete(FragmentSearch.BondsPerSPList[2*i+1]);
    3301   }
    3302   Free((void **)&FragmentSearch.BondsPerSPList, "molecule::PowerSetGenerator: ***BondsPerSPList");
    3303   Free((void **)&FragmentSearch.BondsPerSPCount, "molecule::PowerSetGenerator: *BondsPerSPCount");
    3304   Free((void **)&FragmentSearch.ShortestPathList, "molecule::PowerSetGenerator: *ShortestPathList");
    3305   Free((void **)&FragmentSearch.Labels, "molecule::PowerSetGenerator: *Labels");
    3306   delete(FragmentSearch.FragmentSet);
    33073466 
    33083467  // return list 
    33093468  *out << Verbose(0) << "End of PowerSetGenerator." << endl;
    3310   return FragmentSearch.FragmentCounter;
     3469  return (FragmentSearch.FragmentCounter - Counter);
    33113470};
    33123471
     
    34593618  GraphTestPair testGraphInsert;
    34603619
    3461   testGraphInsert = Fragment->Leaflet->insert(GraphPair (*Fragment->FragmentSet,pair<int,double>(Fragment->FragmentCounter,1)));  // store fragment number and current factor
     3620  testGraphInsert = Fragment->Leaflet->insert(GraphPair (*Fragment->FragmentSet,pair<int,double>(Fragment->FragmentCounter,Fragment->TEFactor)));  // store fragment number and current factor
    34623621  if (testGraphInsert.second) {
    34633622    *out << Verbose(2) << "KeySet " << Fragment->FragmentCounter << " successfully inserted." << endl;
     
    34653624  } else {
    34663625    *out << Verbose(2) << "KeySet " << Fragment->FragmentCounter << " failed to insert, present fragment is " << ((*(testGraphInsert.first)).second).first << endl;
    3467     ((*(testGraphInsert.first)).second).second ++;  // increase the "created" counter
     3626    ((*(testGraphInsert.first)).second).second += Fragment->TEFactor;  // increase the "created" counter
    34683627    *out << Verbose(2) << "New factor is " << ((*(testGraphInsert.first)).second).second << "." << endl;
    34693628  }
     
    35133672 * as these copies are filtered out via use of the hash table (KeySet).
    35143673 * \param *out output stream for debugging
     3674 * \param Fragment&*List list of already present keystacks (adaptive scheme) or empty list
     3675 * \param &RootStack stack with all root candidates (unequal to each atom in complete molecule if adaptive scheme is applied)
    35153676 * \return pointer to Graph list
    35163677 */
    3517 Graph * molecule::FragmentBOSSANOVA(ofstream *out, KeyStack &RootStack)
    3518 {
    3519   Graph *FragmentList = NULL, ***FragmentLowerOrdersList = NULL;
     3678void molecule::FragmentBOSSANOVA(ofstream *out, Graph *&FragmentList, KeyStack &RootStack)
     3679{
     3680  Graph ***FragmentLowerOrdersList = NULL;
    35203681  int Order, NumLevels, NumMolecules, TotalNumMolecules = 0, *NumMoleculesOfOrder = NULL;
    35213682  int counter = 0;
     
    35233684  KeyStack FragmentRootStack;
    35243685  int RootKeyNr, RootNr;
     3686  struct UniqueFragments FragmentSearch;
    35253687 
    35263688  *out << Verbose(0) << "Begin of FragmentBOSSANOVA." << endl;
     
    35303692  NumMoleculesOfOrder = (int *) Malloc(sizeof(int)*UpgradeCount, "molecule::FragmentBOSSANOVA: *NumMoleculesOfOrder");
    35313693  FragmentLowerOrdersList = (Graph ***) Malloc(sizeof(Graph **)*UpgradeCount, "molecule::FragmentBOSSANOVA: ***FragmentLowerOrdersList");
     3694
     3695  // initialise the fragments structure
     3696  FragmentSearch.BondsPerSPList = (bond **) Malloc(sizeof(bond *)*Order*2, "molecule::PowerSetGenerator: ***BondsPerSPList");
     3697  FragmentSearch.BondsPerSPCount = (int *) Malloc(sizeof(int)*Order, "molecule::PowerSetGenerator: *BondsPerSPCount");
     3698  FragmentSearch.ShortestPathList = (int *) Malloc(sizeof(int)*AtomCount, "molecule::PowerSetGenerator: *ShortestPathList");
     3699  FragmentSearch.Labels = (int *) Malloc(sizeof(int)*AtomCount, "molecule::PowerSetGenerator: *Labels");
     3700  FragmentSearch.FragmentCounter = 0;
     3701  FragmentSearch.FragmentSet = new KeySet;
     3702  FragmentSearch.Root = FindAtom(RootKeyNr);
     3703  for (int i=0;i<AtomCount;i++) {
     3704    FragmentSearch.Labels[i] = -1;
     3705    FragmentSearch.ShortestPathList[i] = -1;
     3706  }
    35323707
    35333708  // Construct the complete KeySet which we need for topmost level only (but for all Roots)
     
    35513726    Walker->GetTrueFather()->AdaptiveOrder++;
    35523727    Order = Walker->AdaptiveOrder = Walker->GetTrueFather()->AdaptiveOrder;
    3553    
     3728
     3729    // initialise Order-dependent entries of UniqueFragments structure
     3730    FragmentSearch.BondsPerSPList = (bond **) Malloc(sizeof(bond *)*Order*2, "molecule::PowerSetGenerator: ***BondsPerSPList");
     3731    FragmentSearch.BondsPerSPCount = (int *) Malloc(sizeof(int)*Order, "molecule::PowerSetGenerator: *BondsPerSPCount");
     3732    for (int i=0;i<Order;i++) {
     3733      FragmentSearch.BondsPerSPList[2*i] = new bond();    // start node
     3734      FragmentSearch.BondsPerSPList[2*i+1] = new bond();  // end node
     3735      FragmentSearch.BondsPerSPList[2*i]->next = FragmentSearch.BondsPerSPList[2*i+1];     // intertwine these two
     3736      FragmentSearch.BondsPerSPList[2*i+1]->previous = FragmentSearch.BondsPerSPList[2*i];
     3737      FragmentSearch.BondsPerSPCount[i] = 0;
     3738    } 
     3739
    35543740    // allocate memory for all lower level orders in this 1D-array of ptrs
    3555     NumLevels = 1 << (Order); // (int)pow(2,Order);
     3741    NumLevels = 1 << (Order-1); // (int)pow(2,Order);
    35563742    FragmentLowerOrdersList[RootNr] = (Graph **) Malloc(sizeof(Graph *)*NumLevels, "molecule::FragmentBOSSANOVA: **FragmentLowerOrdersList[]");
    35573743 
    35583744    // create top order where nothing is reduced
    35593745    *out << Verbose(0) << "==============================================================================================================" << endl;
    3560     *out << Verbose(0) << "Creating KeySets of Bond Order " << Order << " for " << *Walker << ", NumLevels is " << NumLevels << ", " << RootStack.size() << " Roots remaining." << endl;
     3746    *out << Verbose(0) << "Creating KeySets of Bond Order " << Order << " for " << *Walker << ", NumLevels is " << NumLevels << ", " << (RootStack.size()-RootNr-1) << " Roots remaining." << endl;
    35613747
    35623748    // Create list of Graphs of current Bond Order (i.e. F_{ij})
    35633749    FragmentLowerOrdersList[RootNr][0] =  new Graph;
    3564     NumMoleculesOfOrder[RootNr] = PowerSetGenerator(out, Walker->AdaptiveOrder, FragmentLowerOrdersList[RootNr][0], CompleteMolecule, RootKeyNr);
     3750    FragmentSearch.TEFactor = 1.;
     3751    FragmentSearch.Leaflet = FragmentLowerOrdersList[RootNr][0];      // set to insertion graph
     3752    FragmentSearch.Root = Walker;
     3753    NumMoleculesOfOrder[RootNr] = PowerSetGenerator(out, Walker->AdaptiveOrder, FragmentSearch, CompleteMolecule);
    35653754    *out << Verbose(1) << "Number of resulting KeySets is: " << NumMoleculesOfOrder[RootNr] << "." << endl;
    35663755    NumMolecules = 0;
     
    35753764          Order--;
    35763765        *out << Verbose(0) << "Current Order is: " << Order << "." << endl;
    3577         for (int SubOrder=Order;SubOrder>1;SubOrder--) {
    3578           int dest = source + (1 << (Walker->AdaptiveOrder-SubOrder));
     3766        for (int SubOrder=Order-1;SubOrder>0;SubOrder--) {
     3767          int dest = source + (1 << (Walker->AdaptiveOrder-(SubOrder+1)));
    35793768          *out << Verbose(0) << "--------------------------------------------------------------------------------------------------------------" << endl;
    3580           *out << Verbose(0) << "Current SubOrder is: " << SubOrder-1 << " with source " << source << " to destination " << dest << "." << endl;
     3769          *out << Verbose(0) << "Current SubOrder is: " << SubOrder << " with source " << source << " to destination " << dest << "." << endl;
    35813770   
    35823771          // every molecule is split into a list of again (Order - 1) molecules, while counting all molecules
     
    35863775          for(Graph::iterator runner = (*FragmentLowerOrdersList[RootNr][source]).begin();runner != (*FragmentLowerOrdersList[RootNr][source]).end(); runner++) {
    35873776            for (KeySet::iterator sprinter = (*runner).first.begin();sprinter != (*runner).first.end(); sprinter++) {
    3588               FragmentList = new Graph();
    3589               PowerSetGenerator(out, SubOrder-1, FragmentList, (*runner).first, *sprinter);
     3777              Graph TempFragmentList;
     3778              FragmentSearch.TEFactor = -(*runner).second.second;
     3779              FragmentSearch.Leaflet = &TempFragmentList;      // set to insertion graph
     3780              FragmentSearch.Root = FindAtom(*sprinter);
     3781              NumMoleculesOfOrder[RootNr] += PowerSetGenerator(out, SubOrder, FragmentSearch, (*runner).first);
    35903782              // insert new keysets FragmentList into FragmentLowerOrdersList[Walker->AdaptiveOrder-1][dest]
    35913783              *out << Verbose(1) << "Merging resulting key sets with those present in destination " << dest << "." << endl;
    3592               InsertGraphIntoGraph(out, *FragmentLowerOrdersList[RootNr][dest], *FragmentList, &NumMolecules);
    3593               delete(FragmentList);
     3784              InsertGraphIntoGraph(out, *FragmentLowerOrdersList[RootNr][dest], TempFragmentList, &NumMolecules);
    35943785            }
    35953786          }
     
    36013792    //NumMoleculesOfOrder[Walker->AdaptiveOrder-1] = NumMolecules;
    36023793    TotalNumMolecules += NumMoleculesOfOrder[RootNr];
    3603     *out << Verbose(1) << "Number of resulting molecules for Order " << Walker->AdaptiveOrder << " is: " << NumMoleculesOfOrder[RootNr] << "." << endl;
     3794    *out << Verbose(1) << "Number of resulting molecules for Order " << (int)Walker->GetTrueFather()->AdaptiveOrder << " is: " << NumMoleculesOfOrder[RootNr] << "." << endl;
    36043795    RootStack.push_back(RootKeyNr); // put back on stack
    36053796    RootNr++;
     3797
     3798    // free Order-dependent entries of UniqueFragments structure for next loop cycle
     3799    Free((void **)&FragmentSearch.BondsPerSPCount, "molecule::PowerSetGenerator: *BondsPerSPCount");
     3800    for (int i=0;i<Order;i++) {
     3801      delete(FragmentSearch.BondsPerSPList[2*i]);
     3802      delete(FragmentSearch.BondsPerSPList[2*i+1]);
     3803    } 
     3804    Free((void **)&FragmentSearch.BondsPerSPList, "molecule::PowerSetGenerator: ***BondsPerSPList");
    36063805  }
    36073806  *out << Verbose(0) << "==============================================================================================================" << endl;
    36083807  *out << Verbose(1) << "Total number of resulting molecules is: " << TotalNumMolecules << "." << endl;
    36093808  *out << Verbose(0) << "==============================================================================================================" << endl;
     3809
     3810  // cleanup FragmentSearch structure
     3811  Free((void **)&FragmentSearch.ShortestPathList, "molecule::PowerSetGenerator: *ShortestPathList");
     3812  Free((void **)&FragmentSearch.Labels, "molecule::PowerSetGenerator: *Labels");
     3813  delete(FragmentSearch.FragmentSet);
     3814 
    36103815  // now, FragmentLowerOrdersList is complete, it looks - for BondOrder 5 - as this (number is the ANOVA Order of the terms therein)
    36113816  // 5433222211111111
     
    36143819  // 21
    36153820  // 1
     3821
    36163822  // Subsequently, we combine all into a single list (FragmentList)
    36173823
    36183824  *out << Verbose(0) << "Combining the lists of all orders per order and finally into a single one." << endl;
    3619   FragmentList = new Graph;
     3825  if (FragmentList == NULL) {
     3826    FragmentList = new Graph;
     3827    counter = 0;
     3828  } else {
     3829    counter = FragmentList->size();
     3830  }
    36203831  RootNr = 0;
    36213832  while (!RootStack.empty()) {
     
    36353846 
    36363847  *out << Verbose(0) << "End of FragmentBOSSANOVA." << endl;
    3637   return FragmentList;
    3638 };
    3639 
    3640 /** Comparision function for GSL heapsort on distances in two molecules.
     3848};
     3849
     3850/** Comparison function for GSL heapsort on distances in two molecules.
    36413851 * \param *a
    36423852 * \param *b
  • src/molecules.hpp

    rbd6579 r2459b1  
    525525  bool ParseOrderAtSiteFromFile(ofstream *out, char *path);
    526526  bool StoreOrderAtSiteFile(ofstream *out, char *path);
    527   bool ParseKeySetFile(ofstream *out, char *filename, atom **ListOfAtoms, MoleculeListClass *&FragmentList, bool IsAngstroem);
     527  bool ParseKeySetFile(ofstream *out, char *filename, Graph *&FragmentList, bool IsAngstroem);
     528  bool StoreKeySetFile(ofstream *out, Graph &KeySetList, char *path);
     529  bool StoreForcesFile(ofstream *out, MoleculeListClass *BondFragments, char *path, int *SortIndex);
    528530  bool ScanBufferIntoKeySet(ofstream *out, char *buffer, KeySet &CurrentSet);
    529531  void BreadthFirstSearchAdd(ofstream *out, molecule *Mol, atom **&AddedAtomList, bond **&AddedBondList, atom *Root, bond *Bond, int BondOrder, bool IsAngstroem);
    530532  /// -# BOSSANOVA
    531   Graph * FragmentBOSSANOVA(ofstream *out, KeyStack &RootStack);
    532         int PowerSetGenerator(ofstream *out, int Order, Graph *ReturnKeySets, KeySet RestrictedKeySet, int RootKeyNr);
     533  void FragmentBOSSANOVA(ofstream *out, Graph *&FragmentList, KeyStack &RootStack);
     534        int PowerSetGenerator(ofstream *out, int Order, struct UniqueFragments &FragmentSearch, KeySet RestrictedKeySet);
    533535  bool BuildInducedSubgraph(ofstream *out, const molecule *Father);
    534536  molecule * StoreFragmentFromKeySet(ofstream *out, KeySet &Leaflet, bool IsAngstroem);
     
    563565
    564566  /// Output configs.
     567  bool StoreForcesFile(ofstream *out, char *path, int *SortIndex);
    565568  bool OutputConfigForListOfFragments(ofstream *out, config *configuration, int *SortIndex);
    566569  void Output(ofstream *out);
  • src/parser.cpp

    rbd6579 r2459b1  
    4343  stringstream line;
    4444
    45   //line << argv[1] << FRAGMENTPREFIX << TEFACTORSFILE;
     45  line << argv[1] << FRAGMENTPREFIX << KEYSETFILE;
    4646  return FilePresent(line.str().c_str());
    4747};
     
    114114  }
    115115  while (!input.eof()) {
    116     input >> tmp;
     116    input.getline(filename, 1023);
    117117    MatrixCounter++;
    118118  }
Note: See TracChangeset for help on using the changeset viewer.