Changeset 183f35


Ignore:
Timestamp:
Apr 28, 2008, 9:22:38 AM (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:
b0a0c3
Parents:
08f1a0
Message:

FragmentMolecule(): Adjacency store/check and parsing of KeySetFile incorporated

Location:
src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/molecules.cpp

    r08f1a0 r183f35  
    18511851}; 
    18521852
     1853/** Scans a single line for number and puts them into \a KeySet.
     1854 * \param *out output stream for debugging
     1855 * \param *buffer buffer to scan
     1856 * \param &CurrentSet filled KeySet on return
     1857 * \return true - at least one valid atom id parsed, false - CurrentSet is empty
     1858 */
     1859bool molecule::ScanBufferIntoKeySet(ofstream *out, char *buffer, KeySet &CurrentSet)
     1860{
     1861  stringstream line;
     1862  int AtomNr;
     1863  int status = 0;
     1864 
     1865  line.str(buffer);
     1866  while (!line.eof()) {
     1867    line >> AtomNr;
     1868    if ((AtomNr >= 0) && (AtomNr < AtomCount)) {
     1869      CurrentSet.insert(AtomNr);
     1870      status++;
     1871    } // else it's "-1" or else and thus must not be added
     1872  }
     1873  return (status != 0);
     1874};
     1875
     1876/** Parses the KeySet file and fills \a *FragmentList from the known molecule structure.
     1877 * \param *out output stream for debugging
     1878 * \param *filename name of KeySet file
     1879 * \param **ListOfAtoms allocated (molecule::AtomCount) and filled lookup table for ids (Atom::nr) to *Atom
     1880 * \param *FragmentList NULL, filled on return
     1881 * \param IsAngstroem whether we have Ansgtroem or bohrradius
     1882 * \return true - parsing successfully, false - failure on parsing (FragmentList will be NULL)
     1883 */
     1884bool molecule::ParseKeySetFile(ofstream *out, char *filename, atom **ListOfAtoms, MoleculeListClass *&FragmentList, bool IsAngstroem)
     1885{
     1886  bool status = true;
     1887  ifstream KeySetFile;
     1888  stringstream line;
     1889 
     1890  if (FragmentList != NULL) { // check list pointer
     1891    cerr << "Error: FragmentList was not NULL as supposed to be, already atoms present therein?" << endl;
     1892    return false;
     1893  }
     1894  cout << Verbose(1) << "Parsing the KeySet file ... ";
     1895  // open file and read
     1896  KeySetFile.open(filename);
     1897  if (KeySetFile != NULL) {
     1898    // each line represents a new fragment
     1899    int NumberOfFragments = 0;
     1900    char *buffer = (char *) Malloc(sizeof(char)*255, "molecule::ParseKeySetFile - *buffer");
     1901    // 1. scan through file to know number of fragments
     1902    while (!KeySetFile.eof()) {
     1903      KeySetFile.getline(buffer, 255);
     1904      if (strlen(buffer) > 0) // there is at least on possible number on the parsed line
     1905        NumberOfFragments++;
     1906    }
     1907    // 2. allocate the MoleculeListClass accordingly
     1908    FragmentList = new MoleculeListClass(NumberOfFragments, AtomCount);
     1909    // 3. Clear File, go to beginning and parse again, now adding found ids to each keyset and converting into molecules
     1910    KeySetFile.clear();
     1911    KeySetFile.seekg(ios::beg);
     1912    NumberOfFragments = 0;
     1913    while ((!KeySetFile.eof()) && (FragmentList->NumberOfMolecules > NumberOfFragments)) {
     1914      KeySetFile.getline(buffer, 255);
     1915      KeySet CurrentSet;
     1916      if ((strlen(buffer) > 0) && (ScanBufferIntoKeySet(out, buffer, CurrentSet)))  // if at least one valid atom was added, write config
     1917        FragmentList->ListOfMolecules[NumberOfFragments++] = StoreFragmentFromKeySet(out, CurrentSet, IsAngstroem);
     1918    }
     1919    // 4. Free and done
     1920    Free((void **)&buffer, "molecule::ParseKeySetFile - *buffer");
     1921    cout << "done." << endl;
     1922  } else {
     1923    cout << "File not found." << endl;
     1924    status = false;
     1925  }
     1926 
     1927  return status;
     1928};
     1929
    18531930/** Performs a many-body bond order analysis for a given bond order.
    18541931 * Writes for each fragment a config file.
     
    18731950  MoleculeLeafClass *MolecularWalker = NULL;
    18741951  MoleculeLeafClass *Subgraphs = NULL;      // list of subgraphs from DFS analysis
    1875 
     1952  fstream File;
     1953  char *filename = NULL;
     1954  bool status = true;
     1955
     1956  cout << endl;
    18761957#ifdef ADDHYDROGEN
    18771958  cout << Verbose(0) << "I will treat hydrogen special and saturate dangling bonds with it." << endl;
     
    18801961#endif
    18811962
     1963  // fill the adjacency list
    18821964  CreateListOfBondsPerAtom(out);
    18831965
    1884   // first perform a DFS analysis to gather info on cyclic structure and a list of disconnected subgraphs
    1885   Subgraphs = DepthFirstSearchAnalysis((ofstream *)&cout, false, MinimumRingSize);
    1886   MolecularWalker = Subgraphs;
    1887   // fill the bond structure of the individually stored subgraphs
    1888   while (MolecularWalker->next != NULL) {
    1889     MolecularWalker = MolecularWalker->next;
    1890     cout << Verbose(1) << "Creating adjacency list for subgraph " << MolecularWalker << "." << endl;
    1891     MolecularWalker->Leaf->CreateAdjacencyList((ofstream *)&cout, BondDistance);
    1892     MolecularWalker->Leaf->CreateListOfBondsPerAtom((ofstream *)&cout);
    1893   }
    1894   // fragment all subgraphs
    1895   if ((MinimumRingSize != -1) && ((BottomUpOrder >= MinimumRingSize) || (TopDownOrder >= MinimumRingSize))) {
    1896     cout << Verbose(0) << "Bond order greater than or equal to Minimum Ring size of " << MinimumRingSize << " found is not allowed." << endl;
     1966  // === open and compare adjacency file ===
     1967  filename = (char *) Malloc(sizeof(char)*255, "molecule::FragmentMolecule - filename");
     1968  sprintf(filename, "%s/%s%s", configuration->GetDefaultPath(), "BondFragment", "Adjacency.dat");
     1969  File.open(filename, ios::in);
     1970  cout << Verbose(1) << "Looking at bond structure stored in adjacency file and comparing to present one ...";
     1971  if (File != NULL) {
     1972    // allocate storage structure
     1973    atom **ListOfAtoms = (atom **) Malloc(sizeof(atom *)*AtomCount, "molecule::FragmentMolecule - ListOfAtoms"); // will contain the atom ids whose bond partners differ
     1974    int NonMatchNumber = 0;   // will number of atoms with differing bond structure
     1975    int *CurrentBonds = (int *) Malloc(sizeof(int)*8, "molecule::FragmentMolecule - CurrentBonds"); // contains parsed bonds of current atom
     1976    int CurrentBondsOfAtom;
     1977    Walker = start;
     1978    while (Walker->next != end) {
     1979      Walker = Walker->next;
     1980      if ((Walker->nr >= 0) && (Walker->nr < AtomCount)) {
     1981        ListOfAtoms[Walker->nr] = Walker;
     1982      } else
     1983        break;
     1984    }
     1985    if (Walker->next == end) {  // everything went alright
     1986      // Parse the file line by line and count the bonds
     1987      while (!File.eof()) {
     1988        File.getline(filename, 255);
     1989        stringstream line;
     1990        line.str(filename);
     1991        int AtomNr = -1;
     1992        line >> AtomNr;
     1993        CurrentBondsOfAtom = -1; // we count one too far due to line end
     1994        // parse into structure
     1995        if ((AtomNr >= 0) && (AtomNr < AtomCount)) {
     1996          while (!line.eof())
     1997            line >> CurrentBonds[ ++CurrentBondsOfAtom ];
     1998          // compare against present bonds
     1999          Walker = ListOfAtoms[AtomNr];
     2000          //cout << Verbose(2) << "Walker is " << *Walker << ", bond partners: ";
     2001          if (CurrentBondsOfAtom == NumberOfBondsPerAtom[AtomNr]) {
     2002            for(int i=0;i<NumberOfBondsPerAtom[AtomNr];i++) {
     2003              int id = ListOfBondsPerAtom[AtomNr][i]->GetOtherAtom(Walker)->nr;
     2004              int j = 0;
     2005              for (;(j<CurrentBondsOfAtom) && (CurrentBonds[j++] != id);); // check against all parsed bonds
     2006              if (CurrentBonds[j-1] != id) { // no match ? Then mark in ListOfAtoms
     2007                ListOfAtoms[AtomNr] = NULL;
     2008                NonMatchNumber++;
     2009                status = false;
     2010                //cout << "[" << id << "]\t";
     2011              } else {
     2012                //cout << id << "\t";
     2013              }
     2014            }
     2015            //cout << endl;
     2016          } else {
     2017            cout << "Number of bonds for Atom " << *Walker << " does not match, parsed " << CurrentBondsOfAtom << " against " << NumberOfBondsPerAtom[AtomNr] << "." << endl;
     2018            status = false;
     2019          }
     2020        }
     2021      }
     2022      File.close();
     2023      File.clear();
     2024      if (status) { // if equal we parse the KeySetFile
     2025        cout << " done: Equal." << endl;
     2026        sprintf(filename, "%s/%s%s", configuration->GetDefaultPath(), "BondFragment", "KeySets.dat");
     2027        status = ParseKeySetFile(out, filename, ListOfAtoms, FragmentList, configuration->GetIsAngstroem());
     2028      } else
     2029        cout << " done: Not equal by " << NonMatchNumber << " atoms." << endl;
     2030    } else {
     2031      cout << " range of nuclear ids exceeded [0, AtomCount)." << endl;
     2032      status = false;
     2033    }
     2034    Free((void **)&CurrentBonds, "molecule::FragmentMolecule - **CurrentBonds");
     2035    Free((void **)&ListOfAtoms, "molecule::FragmentMolecule - *ListOfAtoms");
    18972036  } else {
    1898     FragmentCounter = 0;
     2037    cout << " Adjacency file not found." << endl;
     2038    status = false;
     2039  }
     2040
     2041  // =================================== Begin of FRAGMENTATION ===============================
     2042  if (!status) {
     2043    // === store Adjacency file ===
     2044    sprintf(filename, "%s/%s%s", configuration->GetDefaultPath(), "BondFragment", "Adjacency.dat");
     2045    File.open(filename, ios::out);
     2046    cout << Verbose(1) << "Saving adjacency list ... ";
     2047    if (File != NULL) {
     2048      Walker = start;
     2049      while(Walker->next != end) {
     2050        Walker = Walker->next;
     2051        File << Walker->nr << "\t";
     2052        for (int i=0;i<NumberOfBondsPerAtom[Walker->nr];i++)
     2053          File << ListOfBondsPerAtom[Walker->nr][i]->GetOtherAtom(Walker)->nr << "\t";
     2054        File << endl;
     2055      }
     2056      File.close();
     2057      cout << "done." << endl;
     2058    } else {
     2059      cout << "failed." << endl;
     2060    }
     2061    Free((void **)&filename, "molecule::FragmentMolecule - filename");
     2062 
     2063    // === first perform a DFS analysis to gather info on cyclic structure and a list of disconnected subgraphs ===
     2064    Subgraphs = DepthFirstSearchAnalysis((ofstream *)&cout, false, MinimumRingSize);
    18992065    MolecularWalker = Subgraphs;
    1900     // count subgraphs
     2066    // fill the bond structure of the individually stored subgraphs
    19012067    while (MolecularWalker->next != NULL) {
    19022068      MolecularWalker = MolecularWalker->next;
    1903       FragmentCounter++;
    1904     }
    1905     BondFragments = (MoleculeListClass **) Malloc(sizeof(MoleculeListClass *)*FragmentCounter, "molecule::FragmentMolecule - **BondFragments");
    1906     // fill the bond fragment list
    1907     FragmentCounter = 0;
    1908     MolecularWalker = Subgraphs;
    1909     while (MolecularWalker->next != NULL) {
    1910       MolecularWalker = MolecularWalker->next;
    1911       cout << Verbose(1) << "Fragmenting subgraph " << MolecularWalker << "." << endl;
    1912       if (MolecularWalker->Leaf->first->next != MolecularWalker->Leaf->last) {
    1913           // output ListOfBondsPerAtom for debugging
    1914         *out << Verbose(0) << endl << "From Contents of ListOfBondsPerAtom, all non-hydrogen atoms:" << endl;
    1915         Walker = MolecularWalker->Leaf->start;
    1916         while (Walker->next != MolecularWalker->Leaf->end) {
    1917           Walker = Walker->next;
    1918 #ifdef ADDHYDROGEN
    1919           if (Walker->type->Z != 1) {   // regard only non-hydrogen
    1920 #endif
    1921             *out << Verbose(0) << "Atom " << Walker->Name << " has Bonds: "<<endl;
    1922             for(int j=0;j<MolecularWalker->Leaf->NumberOfBondsPerAtom[Walker->nr];j++) {
    1923               *out << Verbose(1) << *(MolecularWalker->Leaf->ListOfBondsPerAtom)[Walker->nr][j] << endl;
     2069      cout << Verbose(1) << "Creating adjacency list for subgraph " << MolecularWalker << "." << endl;
     2070      MolecularWalker->Leaf->CreateAdjacencyList((ofstream *)&cout, BondDistance);
     2071      MolecularWalker->Leaf->CreateListOfBondsPerAtom((ofstream *)&cout);
     2072    }
     2073   
     2074    // === fragment all subgraphs ===
     2075    if ((MinimumRingSize != -1) && ((BottomUpOrder >= MinimumRingSize) || (TopDownOrder >= MinimumRingSize))) {
     2076      cout << Verbose(0) << "Bond order greater than or equal to Minimum Ring size of " << MinimumRingSize << " found is not allowed." << endl;
     2077    } else {
     2078      FragmentCounter = 0;
     2079      MolecularWalker = Subgraphs;
     2080      // count subgraphs
     2081      while (MolecularWalker->next != NULL) {
     2082        MolecularWalker = MolecularWalker->next;
     2083        FragmentCounter++;
     2084      }
     2085      BondFragments = (MoleculeListClass **) Malloc(sizeof(MoleculeListClass *)*FragmentCounter, "molecule::FragmentMolecule - **BondFragments");
     2086      // fill the bond fragment list
     2087      FragmentCounter = 0;
     2088      MolecularWalker = Subgraphs;
     2089      while (MolecularWalker->next != NULL) {
     2090        MolecularWalker = MolecularWalker->next;
     2091        cout << Verbose(1) << "Fragmenting subgraph " << MolecularWalker << "." << endl;
     2092        if (MolecularWalker->Leaf->first->next != MolecularWalker->Leaf->last) {
     2093            // output ListOfBondsPerAtom for debugging
     2094          *out << Verbose(0) << endl << "From Contents of ListOfBondsPerAtom, all non-hydrogen atoms:" << endl;
     2095          Walker = MolecularWalker->Leaf->start;
     2096          while (Walker->next != MolecularWalker->Leaf->end) {
     2097            Walker = Walker->next;
     2098  #ifdef ADDHYDROGEN
     2099            if (Walker->type->Z != 1) {   // regard only non-hydrogen
     2100  #endif
     2101              *out << Verbose(0) << "Atom " << Walker->Name << " has Bonds: "<<endl;
     2102              for(int j=0;j<MolecularWalker->Leaf->NumberOfBondsPerAtom[Walker->nr];j++) {
     2103                *out << Verbose(1) << *(MolecularWalker->Leaf->ListOfBondsPerAtom)[Walker->nr][j] << endl;
     2104              }
     2105  #ifdef ADDHYDROGEN
    19242106            }
    1925 #ifdef ADDHYDROGEN
     2107  #endif
    19262108          }
    1927 #endif
     2109          *out << endl;
     2110       
     2111          *out << Verbose(0) << endl << " ========== BOND ENERGY ========================= " << endl;
     2112          *out << Verbose(0) << "Begin of bond fragmentation." << endl;
     2113          BondFragments[FragmentCounter] = NULL;
     2114          if (Scheme == ANOVA) {
     2115            BondFragments[FragmentCounter] = MolecularWalker->Leaf->FragmentBOSSANOVA(out,BottomUpOrder,configuration);
     2116          } 
     2117          if ((Scheme == BottomUp) || (Scheme == Combined)) { // get overlapping subgraphs
     2118            BondFragments[FragmentCounter] = FragmentList = MolecularWalker->Leaf->FragmentBottomUp(out, BottomUpOrder, configuration, CutCyclic);
     2119          }
     2120          if (Scheme == TopDown) { // initialise top level with whole molecule
     2121            *out << Verbose(2) << "Initial memory allocating and initialising for whole molecule." << endl;
     2122            FragmentList = new MoleculeListClass(1, MolecularWalker->Leaf->AtomCount);
     2123            FragmentList->ListOfMolecules[0] = MolecularWalker->Leaf->CopyMolecule();
     2124            FragmentList->TEList[0] = 1.;
     2125          }
     2126          if ((Scheme == Combined) || (Scheme == TopDown)) {
     2127            *out << Verbose(1) << "Calling TopDown." << endl;
     2128            BondFragments[FragmentCounter] = FragmentList->FragmentTopDown(out, TopDownOrder, BondDistance, configuration, CutCyclic);
     2129            // remove this molecule from list again and free wrapper list
     2130            delete(FragmentList);
     2131            FragmentList = NULL;
     2132          }
     2133        } else {
     2134          cout << Verbose(0) << "Connection matrix has not yet been generated!" << endl;
    19282135        }
    1929         *out << endl;
    1930      
    1931         *out << Verbose(0) << endl << " ========== BOND ENERGY ========================= " << endl;
    1932         *out << Verbose(0) << "Begin of bond fragmentation." << endl;
    1933         BondFragments[FragmentCounter] = NULL;
    1934         if (Scheme == ANOVA) {
    1935           BondFragments[FragmentCounter] = MolecularWalker->Leaf->FragmentBOSSANOVA(out,BottomUpOrder,configuration);
    1936         } 
    1937         if ((Scheme == BottomUp) || (Scheme == Combined)) { // get overlapping subgraphs
    1938           BondFragments[FragmentCounter] = FragmentList = MolecularWalker->Leaf->FragmentBottomUp(out, BottomUpOrder, configuration, CutCyclic);
    1939         }
    1940         if (Scheme == TopDown) { // initialise top level with whole molecule
    1941           *out << Verbose(2) << "Initial memory allocating and initialising for whole molecule." << endl;
    1942           FragmentList = new MoleculeListClass(1, MolecularWalker->Leaf->AtomCount);
    1943           FragmentList->ListOfMolecules[0] = MolecularWalker->Leaf->CopyMolecule();
    1944           FragmentList->TEList[0] = 1.;
    1945         }
    1946         if ((Scheme == Combined) || (Scheme == TopDown)) {
    1947           *out << Verbose(1) << "Calling TopDown." << endl;
    1948           BondFragments[FragmentCounter] = FragmentList->FragmentTopDown(out, TopDownOrder, BondDistance, configuration, CutCyclic);
    1949           // remove this molecule from list again and free wrapper list
    1950           delete(FragmentList);
    1951           FragmentList = NULL;
    1952         }
    1953       } else {
    1954         cout << Verbose(0) << "Connection matrix has not yet been generated!" << endl;
    1955       }
    1956       TotalFragmentCounter += BondFragments[FragmentCounter]->NumberOfMolecules;
    1957       FragmentCounter++;  // next fragment list
    1958     }
    1959   }
    1960 
    1961   // combine bond fragments list into a single one
    1962   FragmentList = new MoleculeListClass(TotalFragmentCounter, AtomCount);
    1963   TotalFragmentCounter = 0;
    1964   for (int i=0;i<FragmentCounter;i++) {
    1965     for(int j=0;j<BondFragments[i]->NumberOfMolecules;j++) {
    1966       FragmentList->ListOfMolecules[TotalFragmentCounter] =  BondFragments[i]->ListOfMolecules[j];
    1967       BondFragments[i]->ListOfMolecules[j] = NULL;
    1968       FragmentList->TEList[TotalFragmentCounter++] = BondFragments[i]->TEList[j];
    1969     }
    1970     delete(BondFragments[i]);
    1971   }
    1972   Free((void **)&BondFragments, "molecule::FragmentMolecule - **BondFragments");
    1973  
    1974   // now if there are actually any fragments to save on disk ...
     2136        TotalFragmentCounter += BondFragments[FragmentCounter]->NumberOfMolecules;
     2137        FragmentCounter++;  // next fragment list
     2138      }
     2139    }
     2140 
     2141    // === combine bond fragments list into a single one ===
     2142    FragmentList = new MoleculeListClass(TotalFragmentCounter, AtomCount);
     2143    TotalFragmentCounter = 0;
     2144    for (int i=0;i<FragmentCounter;i++) {
     2145      for(int j=0;j<BondFragments[i]->NumberOfMolecules;j++) {
     2146        FragmentList->ListOfMolecules[TotalFragmentCounter] =  BondFragments[i]->ListOfMolecules[j];
     2147        BondFragments[i]->ListOfMolecules[j] = NULL;
     2148        FragmentList->TEList[TotalFragmentCounter++] = BondFragments[i]->TEList[j];
     2149      }
     2150      delete(BondFragments[i]);
     2151    }
     2152    Free((void **)&BondFragments, "molecule::FragmentMolecule - **BondFragments");
     2153  } else
     2154    cout << Verbose(0) << "Using fragments reconstructed from the KeySetFile." << endl;
     2155  // ==================================== End of FRAGMENTATION ================================
     2156 
     2157  // === Save fragments' configuration to disk ===
    19752158  if (FragmentList != NULL) {
    19762159    // create a SortIndex to map from BFS labels to the sequence in which the atoms are given in the config file
     
    20082191    *out << Verbose(1) << "FragmentList is zero on return, splitting failed." << endl;
    20092192  // free subgraph memory again
    2010   while (Subgraphs->next != NULL) {
    2011     Subgraphs = Subgraphs->next;
    2012     delete(Subgraphs->previous);
    2013   }
    2014   delete(Subgraphs);
     2193  if (Subgraphs != NULL) {
     2194    while (Subgraphs->next != NULL) {
     2195      Subgraphs = Subgraphs->next;
     2196      delete(Subgraphs->previous);
     2197    }
     2198    delete(Subgraphs);
     2199  }
    20152200
    20162201  *out << Verbose(0) << "End of bond fragmentation." << endl;
     
    25532738};
    25542739
    2555 /** Stores a fragment from \a SnakeStack into \a molecule.
     2740/** Stores a fragment from \a KeySet into \a molecule.
    25562741 * First creates the minimal set of atoms from the KeySet, then creates the bond structure from the complete
    25572742 * molecule and adds missing hydrogen where bonds were cut.
    25582743 * \param *out output stream for debugging messages
    25592744 * \param &Leaflet pointer to KeySet structure
    2560  * \param *configuration configuration for writing config files for each fragment
     2745 * \param IsAngstroem whether we have Ansgtroem or bohrradius
    25612746 * \return pointer to constructed molecule
    25622747 */
    2563 molecule * molecule::StoreFragmentFromKeyset(ofstream *&out, KeySet &Leaflet, config *&configuration)
     2748molecule * molecule::StoreFragmentFromKeySet(ofstream *out, KeySet &Leaflet, bool IsAngstroem)
    25642749{
    25652750  atom *Runner = NULL, *FatherOfRunner = NULL, *OtherFather = NULL;
     
    26062791#ifdef ADDHYDROGEN
    26072792          *out << Verbose(3) << "Adding Hydrogen to " << Runner->Name << " and a bond in between." << endl;
    2608           Leaf->AddHydrogenReplacementAtom(out, ListOfBondsPerAtom[FatherOfRunner->nr][i], Runner, FatherOfRunner, OtherFather, ListOfBondsPerAtom[FatherOfRunner->nr],NumberOfBondsPerAtom[FatherOfRunner->nr], configuration->GetIsAngstroem());
     2793          Leaf->AddHydrogenReplacementAtom(out, ListOfBondsPerAtom[FatherOfRunner->nr][i], Runner, FatherOfRunner, OtherFather, ListOfBondsPerAtom[FatherOfRunner->nr],NumberOfBondsPerAtom[FatherOfRunner->nr], IsAngstroem);
    26092794#endif
    26102795          //NumBonds[Runner->nr] += ListOfBondsPerAtom[FatherOfRunner->nr][i]->BondDegree;
     
    35573742  for(Graph::iterator runner = FragmentList->begin(); runner != FragmentList->end(); runner++) {
    35583743    KeySet test = (*runner).first;
    3559     FragmentMoleculeList->ListOfMolecules[k] = StoreFragmentFromKeyset(out, test, configuration);
     3744    FragmentMoleculeList->ListOfMolecules[k] = StoreFragmentFromKeySet(out, test, configuration);
    35603745    FragmentMoleculeList->TEList[k] = ((*runner).second).second;
    35613746    k++;
  • src/molecules.hpp

    r08f1a0 r183f35  
    520520  /// Fragment molecule by two different approaches:
    521521  void FragmentMolecule(ofstream *out, int BottomUpOrder, int TopDownOrder, enum BondOrderScheme Scheme, config *configuration, enum CutCyclicBond CutCyclic);
     522  bool molecule::ParseKeySetFile(ofstream *out, char *filename, atom **ListOfAtoms, MoleculeListClass *&FragmentList, bool IsAngstroem);
     523  bool molecule::ScanBufferIntoKeySet(ofstream *out, char *buffer, KeySet &CurrentSet);
    522524  MoleculeListClass * GetAtomicFragments(ofstream *out, int NumberOfTopAtoms, bool IsAngstroem, double factor, enum CutCyclicBond CutCyclic);
    523525  void BreadthFirstSearchAdd(ofstream *out, molecule *Mol, atom **&AddedAtomList, bond **&AddedBondList, atom *Root, bond *Bond, int BondOrder, bool IsAngstroem, enum CutCyclicBond CutCyclic);
     
    531533        int CreateListOfUniqueFragmentsOfOrder(ofstream *out, int Order, Graph *ListOfGraph, KeySet Fragment, double TEFactor, config *configuration);
    532534  bool BuildInducedSubgraph(ofstream *out, const molecule *Father);
    533   molecule * StoreFragmentFromKeyset(ofstream *&out, KeySet &Leaflet, config *&configuration);
     535  molecule * StoreFragmentFromKeySet(ofstream *out, KeySet &Leaflet, bool IsAngstroem);
    534536  void SPFragmentGenerator(ofstream *out, struct UniqueFragments *FragmentSearch, int RootDistance, bond **BondsSet, int SetDimension, int SubOrder);
    535537  int LookForRemovalCandidate(ofstream *&out, KeySet *&Leaf, int *&ShortestPathList);
Note: See TracChangeset for help on using the changeset viewer.