Changeset 2459b1
- Timestamp:
- May 5, 2008, 4:19:05 PM (17 years ago)
- 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
- Location:
- src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
src/analyzer.cpp
rbd6579 r2459b1 58 58 59 59 // ---------- Parse the TE Factors into an array ----------------- 60 //if (!Energy.ParseIndices()) return 1;60 if (!Energy.ParseIndices()) return 1; 61 61 62 62 // ---------- Parse the Force indices into an array --------------- 63 //if (!Force.ParseIndices(argv[1])) return 1;63 if (!Force.ParseIndices(argv[1])) return 1; 64 64 65 65 // ---------- Parse the KeySets into an array --------------- -
src/defs.hpp
rbd6579 r2459b1 44 44 #define KEYSETFILE "KeySets.dat" 45 45 #define ADJACENCYFILE "Adjacency.dat" 46 #define TEFACTORSFILE "TE-Factors.dat" 47 #define FORCESFILE "Forces-Factors.dat" 46 48 #define ORDERATSITEFILE "OrderAtSite.dat" 47 49 #define FRAGMENTPREFIX "BondFragment" -
src/joiner.cpp
rbd6579 r2459b1 46 46 47 47 // ---------- Parse the TE Factors into an array ----------------- 48 //if (!Energy.ParseIndices()) return 1;48 if (!Energy.ParseIndices()) return 1; 49 49 50 50 // ---------- Parse the Force indices into an array --------------- 51 //if (!Force.ParseIndices(argv[1])) return 1;51 if (!Force.ParseIndices(argv[1])) return 1; 52 52 //if (!ParseForceIndices(argv[1], data.ForcesIndices, data.AtomCounter, data.FragmentCounter)) return 1; 53 53 -
src/moleculelist.cpp
rbd6579 r2459b1 133 133 }; 134 134 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 */ 142 bool 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 135 189 /** Writes a config file for each molecule in the given \a **FragmentList. 136 190 * \param *out output stream for debugging … … 216 270 Free((void **)&FragmentNumber, "MoleculeListClass::OutputConfigForListOfFragments: *FragmentNumber"); 217 271 } 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; 242 273 243 274 // printing final number -
src/molecules.cpp
rbd6579 r2459b1 1249 1249 atom *Walker = NULL, *OtherWalker = NULL; 1250 1250 int No, NoBonds; 1251 bond *Binder = NULL;1252 1251 int NumberCells, divisor[NDIM], n[NDIM], N[NDIM], index, Index, j; 1253 1252 molecule **CellList; … … 1365 1364 if (BondCount != 0) { 1366 1365 NoCyclicBonds = 0; 1367 *out << Verbose(1) << " correct Bond degree of each bond" << endl;1366 *out << Verbose(1) << "Correcting Bond degree of each bond ... "; 1368 1367 do { 1369 1368 No = 0; // No acts as breakup flag (if 1 we still continue) … … 1377 1376 for(j=0;j<NumberOfBondsPerAtom[Walker->nr];j++) 1378 1377 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; 1380 1379 if ((int)(Walker->type->NoValenceOrbitals) > NoBonds) { // we have a mismatch, check NoBonds of other atom 1381 1380 // count valence of second partner … … 1383 1382 for(j=0;j<NumberOfBondsPerAtom[OtherWalker->nr];j++) 1384 1383 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; 1386 1385 if ((int)(OtherWalker->type->NoValenceOrbitals) > NoBonds) // increase bond degree by one 1387 1386 ListOfBondsPerAtom[Walker->nr][i]->BondDegree++; … … 1390 1389 } 1391 1390 } while (No); 1392 1391 *out << " done." << endl; 1393 1392 } else 1394 1393 *out << Verbose(1) << "BondCount is " << BondCount << ", no bonds between any of the " << AtomCount << " atoms." << endl; 1395 1394 *out << Verbose(1) << "I detected " << BondCount << " bonds in the molecule with distance " << bonddistance << "." << endl; 1396 1395 1397 // output bonds for debugging (if bond chain list was correctly installed)1398 *out << Verbose(1) << endl << "From contents of bond chain list:";1399 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; 1405 1404 } else 1406 1405 *out << Verbose(1) << "AtomCount is " << AtomCount << ", thus no bonds, no connections!." << endl; … … 1612 1611 } 1613 1612 1614 // further analysis of the found cycles (print rings, get minimum cycle length)1615 CyclicStructureAnalysis(out, MinimumRingSize);1616 1617 1613 // free all and exit 1618 1614 delete(AtomStack); … … 1880 1876 1881 1877 /** 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. 1882 1882 * \param *out output stream for debugging 1883 1883 * \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 1886 1885 * \param IsAngstroem whether we have Ansgtroem or bohrradius 1887 1886 * \return true - parsing successfully, false - failure on parsing (FragmentList will be NULL) 1888 1887 */ 1889 bool molecule::ParseKeySetFile(ofstream *out, char *path, atom **ListOfAtoms, MoleculeListClass*&FragmentList, bool IsAngstroem)1888 bool molecule::ParseKeySetFile(ofstream *out, char *path, Graph *&FragmentList, bool IsAngstroem) 1890 1889 { 1891 1890 bool status = true; 1892 ifstream KeySetFile;1891 ifstream InputFile; 1893 1892 stringstream line; 1893 GraphTestPair testGraphInsert; 1894 int NumberOfFragments = 0; 1895 double TEFactor; 1894 1896 char *filename = (char *) Malloc(sizeof(char)*MAXSTRINGSIZE, "molecule::ParseKeySetFile - filename"); 1895 1897 1896 if (FragmentList != NULL) { // check list pointer1897 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 read1898 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; 1902 1904 sprintf(filename, "%s/%s%s", path, FRAGMENTPREFIX, KEYSETFILE); 1903 KeySetFile.open(filename);1904 if ( KeySetFile != NULL) {1905 InputFile.open(filename); 1906 if (InputFile != NULL) { 1905 1907 // each line represents a new fragment 1906 int NumberOfFragments = 0;1907 1908 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 1919 1937 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 } 1925 1947 } 1926 1948 // 4. Free and done 1927 Free((void **)&buffer, "molecule::ParseKeySetFile - *buffer");1928 cout<< "done." << endl;1949 InputFile.close(); 1950 *out << Verbose(1) << "done." << endl; 1929 1951 } else { 1930 cout << "Filenot found." << endl;1952 *out << Verbose(1) << "File " << filename << " not found." << endl; 1931 1953 status = false; 1932 1954 } 1955 1933 1956 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 */ 1967 bool 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(); 1934 2010 1935 2011 return status; … … 1946 2022 ofstream AdjacencyFile; 1947 2023 atom *Walker = NULL; 1948 char *filename = (char *) Malloc(sizeof(char)*MAXSTRINGSIZE, "molecule::StoreAdjacencyToFile - filename");2024 stringstream line; 1949 2025 bool status = true; 1950 2026 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 ... "; 1954 2030 if (AdjacencyFile != NULL) { 1955 2031 Walker = start; … … 1962 2038 } 1963 2039 AdjacencyFile.close(); 1964 cout<< "done." << endl;2040 *out << Verbose(1) << "done." << endl; 1965 2041 } else { 1966 cout << "failed." << endl;2042 *out << Verbose(1) << "failed to open file " << line.str() << "." << endl; 1967 2043 status = false; 1968 2044 } 1969 Free((void **)&filename, "molecule::StoreAdjacencyToFile - filename");1970 2045 1971 2046 return status; … … 1980 2055 bool molecule::CheckAdjacencyFileAgainstMolecule(ofstream *out, char *path, atom **ListOfAtoms) 1981 2056 { 1982 char *filename = (char *) Malloc(sizeof(char)*MAXSTRINGSIZE, "molecule::CheckAdjacencyFileAgainstMolecule - filename");1983 2057 ifstream File; 2058 stringstream line; 1984 2059 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; 1989 2065 if (File != NULL) { 1990 2066 // allocate storage structure … … 1995 2071 // Parse the file line by line and count the bonds 1996 2072 while (!File.eof()) { 1997 File.getline( filename, MAXSTRINGSIZE);2073 File.getline(buffer, MAXSTRINGSIZE); 1998 2074 stringstream line; 1999 line.str( filename);2075 line.str(buffer); 2000 2076 int AtomNr = -1; 2001 2077 line >> AtomNr; … … 2031 2107 File.clear(); 2032 2108 if (status) { // if equal we parse the KeySetFile 2033 *out << "done: Equal." << endl;2109 *out << Verbose(1) << "done: Equal." << endl; 2034 2110 status = true; 2035 2111 } else 2036 *out << "done: Not equal by " << NonMatchNumber << " atoms." << endl;2112 *out << Verbose(1) << "done: Not equal by " << NonMatchNumber << " atoms." << endl; 2037 2113 Free((void **)&CurrentBonds, "molecule::CheckAdjacencyFileAgainstMolecule - **CurrentBonds"); 2038 2114 } else { 2039 *out << "Adjacency file not found." << endl;2115 *out << Verbose(1) << "Adjacency file not found." << endl; 2040 2116 status = false; 2041 2117 } 2042 Free((void **)& filename, "molecule::CheckAdjacencyFileAgainstMolecule - filename");2118 Free((void **)&buffer, "molecule::CheckAdjacencyFileAgainstMolecule: *buffer"); 2043 2119 2044 2120 return status; … … 2055 2131 * -# combines the generated molecule lists from all subgraphs 2056 2132 * -# 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. 2057 2136 * \param *out output stream for debugging 2058 2137 * \param Order up to how many neighbouring bonds a fragment contains in BondOrderScheme::BottumUp scheme … … 2061 2140 void molecule::FragmentMolecule(ofstream *out, int Order, config *configuration) 2062 2141 { 2063 MoleculeListClass **BondFragments = NULL; 2064 MoleculeListClass *FragmentList = NULL; 2142 MoleculeListClass *BondFragments = NULL; 2065 2143 atom *Walker = NULL; 2144 atom *OtherWalker = NULL; 2145 bond *Binder = NULL; 2066 2146 int *SortIndex = NULL; 2067 2147 element *runner = NULL; 2068 2148 int AtomNo; 2069 2149 int MinimumRingSize; 2070 int TotalFragmentCounter;2071 2150 int FragmentCounter; 2072 2151 MoleculeLeafClass *MolecularWalker = NULL; … … 2074 2153 fstream File; 2075 2154 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 2077 2163 *out << endl; 2078 2164 #ifdef ADDHYDROGEN … … 2082 2168 #endif 2083 2169 2170 // ===== 1. Check whether bond structure is same as stored in files ==== 2171 2084 2172 // fill the adjacency list 2085 2173 CreateListOfBondsPerAtom(out); 2086 2174 2087 // === compare it with adjacency file ===2175 // create lookup table for Atom::nr 2088 2176 atom **ListOfAtoms = (atom **) Malloc(sizeof(atom *)*AtomCount, "molecule::FragmentMolecule - **ListOfAtoms"); 2089 2177 Walker = start; … … 2099 2187 FragmentationToDo = false; 2100 2188 } 2189 // === compare it with adjacency file === 2101 2190 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; 2104 2247 if (FragmentationToDo) // parse the adaptive order per atom/site/vertex 2105 2248 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; 2110 2255 Walker = start; 2111 while (Walker->next != end) { // create a lookup table (Atom::nr -> atom) used as a marker table lateron2256 while (Walker->next != end) { 2112 2257 Walker = Walker->next; 2113 2258 #ifdef ADDHYDROGEN … … 2115 2260 #endif 2116 2261 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; 2124 2276 MolecularWalker = Subgraphs; 2125 // fill the bond structure of the individually stored subgraphs2277 // count subgraphs and allocate fragments 2126 2278 while (MolecularWalker->next != NULL) { 2127 2279 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"); 2132 2283 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 2137 2292 FragmentCounter = 0; 2138 2293 MolecularWalker = Subgraphs; … … 2140 2295 while (MolecularWalker->next != NULL) { 2141 2296 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 2155 2298 RootStack[FragmentCounter].clear(); 2156 // find first root candidates2157 2299 Walker = MolecularWalker->Leaf->start; 2158 2300 while (Walker->next != MolecularWalker->Leaf->end) { // go through all (non-hydrogen) atoms … … 2166 2308 FragmentCounter++; 2167 2309 } 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 2170 2315 FragmentCounter = 0; 2171 TotalFragmentCounter = 0;2172 2316 MolecularWalker = Subgraphs; 2173 2317 while (MolecularWalker->next != NULL) { 2174 2318 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; 2190 2364 } 2191 #endif 2365 #ifdef ADDHYDROGEN 2192 2366 } 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; 2194 2373 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(); 2216 2384 } 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; 2219 2389 } 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) { 2240 2411 // create a SortIndex to map from BFS labels to the sequence in which the atoms are given in the config file 2241 2412 SortIndex = (int *) Malloc(sizeof(int)*AtomCount, "molecule::FragmentMolecule: *SortIndex"); … … 2255 2426 } 2256 2427 } 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)) 2259 2430 *out << Verbose(1) << "All configs written." << endl; 2260 2431 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); 2263 2436 2264 // === store Adjacency file === 2437 // store keysets file 2438 StoreKeySetFile(out, TotalGraph, configuration->configpath); 2439 2440 // store Adjacency file 2265 2441 StoreAdjacencyToFile(out, configuration->configpath); 2266 2442 2267 // Store adaptive orders into file2443 // store adaptive orders into file 2268 2444 StoreOrderAtSiteFile(out, configuration->configpath); 2269 2445 … … 2275 2451 delete(FragmentList); // remove bond molecule from memory 2276 2452 FragmentList = NULL; 2453 Free((void **)&SortIndex, "molecule::FragmentMolecule: *SortIndex"); 2277 2454 } else 2278 2455 *out << Verbose(1) << "FragmentList is zero on return, splitting failed." << endl; 2279 2456 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"); 2280 2461 // free subgraph memory again 2462 delete(TempFragmentList); 2281 2463 if (Subgraphs != NULL) { 2282 2464 while (Subgraphs->next != NULL) { … … 2303 2485 line << path << "/" << FRAGMENTPREFIX << ORDERATSITEFILE; 2304 2486 file.open(line.str().c_str()); 2305 *out << Verbose( 0) << "Writing OrderAtSite " << ORDERATSITEFILE << " ... " << endl;2487 *out << Verbose(1) << "Writing OrderAtSite " << ORDERATSITEFILE << " ... " << endl; 2306 2488 if (file != NULL) { 2307 2489 atom *Walker = start; … … 2312 2494 } 2313 2495 file.close(); 2496 *out << Verbose(1) << "done." << endl; 2314 2497 return true; 2315 2498 } else { 2499 *out << Verbose(1) << "failed to open file " << line.str() << "." << endl; 2316 2500 return false; 2317 2501 } … … 2355 2539 } 2356 2540 file.close(); 2541 *out << Verbose(1) << "done." << endl; 2357 2542 status = true; 2358 2543 } else { 2544 *out << Verbose(1) << "failed to open file " << line.str() << "." << endl; 2359 2545 status = false; 2360 2546 } … … 2938 3124 int CurrentIndex; 2939 3125 int *Labels; 3126 double TEFactor; 2940 3127 int *ShortestPathList; 2941 3128 bool **UsedList; … … 3083 3270 * with SP of 2, then those with SP of 3, then those with SP of 4 and so on. 3084 3271 * \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 into3272 * \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 3087 3274 * \param RestrictedKeySet Restricted vertex set to use in context of molecule 3088 * \param RootKeyNr Atom::nr of the atom acting as current fragment root3089 3275 * \return number of inserted fragments 3090 3276 * \note ShortestPathList in FragmentSearch structure is probably due to NumberOfAtomsSPLevel and SP not needed anymore 3091 3277 */ 3092 int molecule::PowerSetGenerator(ofstream *out, int Order, Graph *ReturnKeySets, KeySet RestrictedKeySet, int RootKeyNr)3278 int molecule::PowerSetGenerator(ofstream *out, int Order, struct UniqueFragments &FragmentSearch, KeySet RestrictedKeySet) 3093 3279 { 3094 3280 int SP, UniqueIndex, AtomKeyNr; … … 3100 3286 atom **PredecessorList = (atom **) Malloc(sizeof(atom *)*AtomCount, "molecule::PowerSetGenerator: **PredecessorList"); 3101 3287 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 3114 3291 for (int i=0;i<AtomCount;i++) { 3115 FragmentSearch.Labels[i] = -1;3116 FragmentSearch.ShortestPathList[i] = -1;3117 3292 PredecessorList[i] = NULL; 3118 3293 } 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 3127 3295 *out << endl; 3128 3296 *out << Verbose(0) << "Begin of PowerSetGenerator with order " << Order << " at Root " << *FragmentSearch.Root << "." << endl; … … 3183 3351 *out << Verbose(3) << "Label is already " << FragmentSearch.Labels[OtherWalker->nr] << "." << endl; 3184 3352 } 3185 if ((OtherWalker != PredecessorList[AtomKeyNr]) && ( FragmentSearch.Labels[OtherWalker->nr] > FragmentSearch.Labels[RootKeyNr])) { // only pass through those with label bigger than Root's3353 if ((OtherWalker != PredecessorList[AtomKeyNr]) && (OtherWalker->nr > RootKeyNr)) { // only pass through those with label bigger than Root's 3186 3354 FragmentSearch.ShortestPathList[OtherWalker->nr] = SP+1; 3187 3355 *out << Verbose(3) << "Set Shortest Path to " << FragmentSearch.ShortestPathList[OtherWalker->nr] << "." << endl; … … 3204 3372 } else *out << Verbose(3) << "Not putting on atom stack, nor adding bond, as " << *OtherWalker << "'s SP is shorter than Walker's." << endl; 3205 3373 } 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 re tstricted 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; 3208 3376 } 3209 3377 } … … 3271 3439 } 3272 3440 3273 /*// as FragmentSearch structure is used only once, we don't have to clean it anymore3441 // as FragmentSearch structure is used only once, we don't have to clean it anymore 3274 3442 // remove root from stack 3275 3443 *out << Verbose(0) << "Removing root again from stack." << endl; … … 3292 3460 *out << "cleaned." << endl; 3293 3461 } 3294 */ 3462 3295 3463 // free allocated memory 3296 3464 Free((void **)&NumberOfAtomsSPLevel, "molecule::PowerSetGenerator: *SPLevelCount"); 3297 3465 Free((void **)&PredecessorList, "molecule::PowerSetGenerator: **PredecessorList"); 3298 for(int i=0;i<Order;i++) { // delete start and end of each list3299 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);3307 3466 3308 3467 // return list 3309 3468 *out << Verbose(0) << "End of PowerSetGenerator." << endl; 3310 return FragmentSearch.FragmentCounter;3469 return (FragmentSearch.FragmentCounter - Counter); 3311 3470 }; 3312 3471 … … 3459 3618 GraphTestPair testGraphInsert; 3460 3619 3461 testGraphInsert = Fragment->Leaflet->insert(GraphPair (*Fragment->FragmentSet,pair<int,double>(Fragment->FragmentCounter, 1))); // store fragment number and current factor3620 testGraphInsert = Fragment->Leaflet->insert(GraphPair (*Fragment->FragmentSet,pair<int,double>(Fragment->FragmentCounter,Fragment->TEFactor))); // store fragment number and current factor 3462 3621 if (testGraphInsert.second) { 3463 3622 *out << Verbose(2) << "KeySet " << Fragment->FragmentCounter << " successfully inserted." << endl; … … 3465 3624 } else { 3466 3625 *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" counter3626 ((*(testGraphInsert.first)).second).second += Fragment->TEFactor; // increase the "created" counter 3468 3627 *out << Verbose(2) << "New factor is " << ((*(testGraphInsert.first)).second).second << "." << endl; 3469 3628 } … … 3513 3672 * as these copies are filtered out via use of the hash table (KeySet). 3514 3673 * \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) 3515 3676 * \return pointer to Graph list 3516 3677 */ 3517 Graph * molecule::FragmentBOSSANOVA(ofstream *out, KeyStack &RootStack)3518 { 3519 Graph * FragmentList = NULL, ***FragmentLowerOrdersList = NULL;3678 void molecule::FragmentBOSSANOVA(ofstream *out, Graph *&FragmentList, KeyStack &RootStack) 3679 { 3680 Graph ***FragmentLowerOrdersList = NULL; 3520 3681 int Order, NumLevels, NumMolecules, TotalNumMolecules = 0, *NumMoleculesOfOrder = NULL; 3521 3682 int counter = 0; … … 3523 3684 KeyStack FragmentRootStack; 3524 3685 int RootKeyNr, RootNr; 3686 struct UniqueFragments FragmentSearch; 3525 3687 3526 3688 *out << Verbose(0) << "Begin of FragmentBOSSANOVA." << endl; … … 3530 3692 NumMoleculesOfOrder = (int *) Malloc(sizeof(int)*UpgradeCount, "molecule::FragmentBOSSANOVA: *NumMoleculesOfOrder"); 3531 3693 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 } 3532 3707 3533 3708 // Construct the complete KeySet which we need for topmost level only (but for all Roots) … … 3551 3726 Walker->GetTrueFather()->AdaptiveOrder++; 3552 3727 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 3554 3740 // 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); 3556 3742 FragmentLowerOrdersList[RootNr] = (Graph **) Malloc(sizeof(Graph *)*NumLevels, "molecule::FragmentBOSSANOVA: **FragmentLowerOrdersList[]"); 3557 3743 3558 3744 // create top order where nothing is reduced 3559 3745 *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; 3561 3747 3562 3748 // Create list of Graphs of current Bond Order (i.e. F_{ij}) 3563 3749 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); 3565 3754 *out << Verbose(1) << "Number of resulting KeySets is: " << NumMoleculesOfOrder[RootNr] << "." << endl; 3566 3755 NumMolecules = 0; … … 3575 3764 Order--; 3576 3765 *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))); 3579 3768 *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; 3581 3770 3582 3771 // every molecule is split into a list of again (Order - 1) molecules, while counting all molecules … … 3586 3775 for(Graph::iterator runner = (*FragmentLowerOrdersList[RootNr][source]).begin();runner != (*FragmentLowerOrdersList[RootNr][source]).end(); runner++) { 3587 3776 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); 3590 3782 // insert new keysets FragmentList into FragmentLowerOrdersList[Walker->AdaptiveOrder-1][dest] 3591 3783 *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); 3594 3785 } 3595 3786 } … … 3601 3792 //NumMoleculesOfOrder[Walker->AdaptiveOrder-1] = NumMolecules; 3602 3793 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; 3604 3795 RootStack.push_back(RootKeyNr); // put back on stack 3605 3796 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"); 3606 3805 } 3607 3806 *out << Verbose(0) << "==============================================================================================================" << endl; 3608 3807 *out << Verbose(1) << "Total number of resulting molecules is: " << TotalNumMolecules << "." << endl; 3609 3808 *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 3610 3815 // now, FragmentLowerOrdersList is complete, it looks - for BondOrder 5 - as this (number is the ANOVA Order of the terms therein) 3611 3816 // 5433222211111111 … … 3614 3819 // 21 3615 3820 // 1 3821 3616 3822 // Subsequently, we combine all into a single list (FragmentList) 3617 3823 3618 3824 *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 } 3620 3831 RootNr = 0; 3621 3832 while (!RootStack.empty()) { … … 3635 3846 3636 3847 *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. 3641 3851 * \param *a 3642 3852 * \param *b -
src/molecules.hpp
rbd6579 r2459b1 525 525 bool ParseOrderAtSiteFromFile(ofstream *out, char *path); 526 526 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); 528 530 bool ScanBufferIntoKeySet(ofstream *out, char *buffer, KeySet &CurrentSet); 529 531 void BreadthFirstSearchAdd(ofstream *out, molecule *Mol, atom **&AddedAtomList, bond **&AddedBondList, atom *Root, bond *Bond, int BondOrder, bool IsAngstroem); 530 532 /// -# 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); 533 535 bool BuildInducedSubgraph(ofstream *out, const molecule *Father); 534 536 molecule * StoreFragmentFromKeySet(ofstream *out, KeySet &Leaflet, bool IsAngstroem); … … 563 565 564 566 /// Output configs. 567 bool StoreForcesFile(ofstream *out, char *path, int *SortIndex); 565 568 bool OutputConfigForListOfFragments(ofstream *out, config *configuration, int *SortIndex); 566 569 void Output(ofstream *out); -
src/parser.cpp
rbd6579 r2459b1 43 43 stringstream line; 44 44 45 //line << argv[1] << FRAGMENTPREFIX << TEFACTORSFILE;45 line << argv[1] << FRAGMENTPREFIX << KEYSETFILE; 46 46 return FilePresent(line.str().c_str()); 47 47 }; … … 114 114 } 115 115 while (!input.eof()) { 116 input >> tmp;116 input.getline(filename, 1023); 117 117 MatrixCounter++; 118 118 }
Note:
See TracChangeset
for help on using the changeset viewer.