Changeset b0a0c3
- Timestamp:
- Apr 28, 2008, 10:41:40 AM (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:
- 10f641
- Parents:
- 183f35
- Location:
- src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/molecules.cpp
r183f35 rb0a0c3 1876 1876 /** Parses the KeySet file and fills \a *FragmentList from the known molecule structure. 1877 1877 * \param *out output stream for debugging 1878 * \param * filename name of KeySetfile1878 * \param *path path to file 1879 1879 * \param **ListOfAtoms allocated (molecule::AtomCount) and filled lookup table for ids (Atom::nr) to *Atom 1880 1880 * \param *FragmentList NULL, filled on return … … 1882 1882 * \return true - parsing successfully, false - failure on parsing (FragmentList will be NULL) 1883 1883 */ 1884 bool molecule::ParseKeySetFile(ofstream *out, char * filename, atom **ListOfAtoms, MoleculeListClass *&FragmentList, bool IsAngstroem)1884 bool molecule::ParseKeySetFile(ofstream *out, char *path, atom **ListOfAtoms, MoleculeListClass *&FragmentList, bool IsAngstroem) 1885 1885 { 1886 1886 bool status = true; 1887 1887 ifstream KeySetFile; 1888 1888 stringstream line; 1889 char *filename = (char *) Malloc(sizeof(char)*255, "molecule::ParseKeySetFile - filename"); 1889 1890 1890 1891 if (FragmentList != NULL) { // check list pointer … … 1894 1895 cout << Verbose(1) << "Parsing the KeySet file ... "; 1895 1896 // open file and read 1897 sprintf(filename, "%s/%s%s", path, "BondFragment", "KeySets.dat"); 1896 1898 KeySetFile.open(filename); 1897 1899 if (KeySetFile != NULL) { … … 1924 1926 status = false; 1925 1927 } 1928 Free((void **)&filename, "molecule::ParseKeySetFile - filename"); 1929 1930 return status; 1931 }; 1932 1933 /** Storing the bond structure of a molecule to file. 1934 * Simply stores Atom::nr and then the Atom::nr of all bond partners per line. 1935 * \param *out output stream for debugging 1936 * \param *path path to file 1937 * \return true - file written successfully, false - writing failed 1938 */ 1939 bool molecule::StoreAdjacencyToFile(ofstream *out, char *path) 1940 { 1941 ofstream AdjacencyFile; 1942 atom *Walker = NULL; 1943 char *filename = (char *) Malloc(sizeof(char)*255, "molecule::StoreAdjacencyToFile - filename"); 1944 bool status = true; 1945 1946 sprintf(filename, "%s/%s%s", path, "BondFragment", "Adjacency.dat"); 1947 AdjacencyFile.open(filename); 1948 cout << Verbose(1) << "Saving adjacency list ... "; 1949 if (AdjacencyFile != NULL) { 1950 Walker = start; 1951 while(Walker->next != end) { 1952 Walker = Walker->next; 1953 AdjacencyFile << Walker->nr << "\t"; 1954 for (int i=0;i<NumberOfBondsPerAtom[Walker->nr];i++) 1955 AdjacencyFile << ListOfBondsPerAtom[Walker->nr][i]->GetOtherAtom(Walker)->nr << "\t"; 1956 AdjacencyFile << endl; 1957 } 1958 AdjacencyFile.close(); 1959 cout << "done." << endl; 1960 } else { 1961 cout << "failed." << endl; 1962 status = false; 1963 } 1964 Free((void **)&filename, "molecule::StoreAdjacencyToFile - filename"); 1965 1966 return status; 1967 }; 1968 1969 /** Checks contents of adjacency file against bond structure in structure molecule. 1970 * \param *out output stream for debugging 1971 * \param *path path to file 1972 * \param **ListOfAtoms allocated (molecule::AtomCount) and filled lookup table for ids (Atom::nr) to *Atom 1973 * \return true - structure is equal, false - not equivalence 1974 */ 1975 bool molecule::CheckAdjacencyFileAgainstMolecule(ofstream *out, char *path, atom **ListOfAtoms) 1976 { 1977 char *filename = (char *) Malloc(sizeof(char)*255, "molecule::CheckAdjacencyFileAgainstMolecule - filename"); 1978 ifstream File; 1979 bool status = true; 1980 1981 sprintf(filename, "%s/%s%s", path, "BondFragment", "Adjacency.dat"); 1982 File.open(filename); 1983 *out << Verbose(1) << "Looking at bond structure stored in adjacency file and comparing to present one ..."; 1984 if (File != NULL) { 1985 // allocate storage structure 1986 int NonMatchNumber = 0; // will number of atoms with differing bond structure 1987 int *CurrentBonds = (int *) Malloc(sizeof(int)*8, "molecule::CheckAdjacencyFileAgainstMolecule - CurrentBonds"); // contains parsed bonds of current atom 1988 int CurrentBondsOfAtom; 1989 // Parse the file line by line and count the bonds 1990 while (!File.eof()) { 1991 File.getline(filename, 255); 1992 stringstream line; 1993 line.str(filename); 1994 int AtomNr = -1; 1995 line >> AtomNr; 1996 CurrentBondsOfAtom = -1; // we count one too far due to line end 1997 // parse into structure 1998 if ((AtomNr >= 0) && (AtomNr < AtomCount)) { 1999 while (!line.eof()) 2000 line >> CurrentBonds[ ++CurrentBondsOfAtom ]; 2001 // compare against present bonds 2002 //cout << Verbose(2) << "Walker is " << *Walker << ", bond partners: "; 2003 if (CurrentBondsOfAtom == NumberOfBondsPerAtom[AtomNr]) { 2004 for(int i=0;i<NumberOfBondsPerAtom[AtomNr];i++) { 2005 int id = ListOfBondsPerAtom[AtomNr][i]->GetOtherAtom(ListOfAtoms[AtomNr])->nr; 2006 int j = 0; 2007 for (;(j<CurrentBondsOfAtom) && (CurrentBonds[j++] != id);); // check against all parsed bonds 2008 if (CurrentBonds[j-1] != id) { // no match ? Then mark in ListOfAtoms 2009 ListOfAtoms[AtomNr] = NULL; 2010 NonMatchNumber++; 2011 status = false; 2012 //out << "[" << id << "]\t"; 2013 } else { 2014 //out << id << "\t"; 2015 } 2016 } 2017 //out << endl; 2018 } else { 2019 *out << "Number of bonds for Atom " << *ListOfAtoms[AtomNr] << " does not match, parsed " << CurrentBondsOfAtom << " against " << NumberOfBondsPerAtom[AtomNr] << "." << endl; 2020 status = false; 2021 } 2022 } 2023 } 2024 File.close(); 2025 File.clear(); 2026 if (status) { // if equal we parse the KeySetFile 2027 *out << " done: Equal." << endl; 2028 status = true; 2029 } else 2030 *out << " done: Not equal by " << NonMatchNumber << " atoms." << endl; 2031 Free((void **)&CurrentBonds, "molecule::CheckAdjacencyFileAgainstMolecule - **CurrentBonds"); 2032 } else { 2033 *out << " Adjacency file not found." << endl; 2034 status = false; 2035 } 2036 Free((void **)&filename, "molecule::CheckAdjacencyFileAgainstMolecule - filename"); 1926 2037 1927 2038 return status; … … 1951 2062 MoleculeLeafClass *Subgraphs = NULL; // list of subgraphs from DFS analysis 1952 2063 fstream File; 1953 char *filename = NULL;1954 2064 bool status = true; 1955 2065 … … 1964 2074 CreateListOfBondsPerAtom(out); 1965 2075 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"); 2036 } else { 2037 cout << " Adjacency file not found." << endl; 2076 // === compare it with adjacency file === 2077 atom **ListOfAtoms = (atom **) Malloc(sizeof(atom *)*AtomCount, "molecule::FragmentMolecule - **ListOfAtoms"); 2078 Walker = start; 2079 while (Walker->next != end) { // create a lookup table (Atom::nr -> atom) used as a marker table lateron 2080 Walker = Walker->next; 2081 if ((Walker->nr >= 0) && (Walker->nr < AtomCount)) { 2082 ListOfAtoms[Walker->nr] = Walker; 2083 } else 2084 break; 2085 } 2086 if (Walker->next != end) { // everything went alright 2087 *out << " range of nuclear ids exceeded [0, AtomCount)." << endl; 2038 2088 status = false; 2039 2089 } 2090 if (CheckAdjacencyFileAgainstMolecule(out, configuration->GetDefaultPath(), ListOfAtoms)) { // NULL entries in ListOfAtoms contain NonMatches 2091 status = ParseKeySetFile(out, configuration->GetDefaultPath(), ListOfAtoms, FragmentList, configuration->GetIsAngstroem()); 2092 } 2093 Free((void **)&ListOfAtoms, "molecule::FragmentMolecule - **ListOfAtoms"); 2040 2094 2041 2095 // =================================== Begin of FRAGMENTATION =============================== 2042 2096 if (!status) { 2043 2097 // === 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 2098 StoreAdjacencyToFile(out, configuration->GetDefaultPath()); 2099 2063 2100 // === first perform a DFS analysis to gather info on cyclic structure and a list of disconnected subgraphs === 2064 2101 Subgraphs = DepthFirstSearchAnalysis((ofstream *)&cout, false, MinimumRingSize); -
src/molecules.hpp
r183f35 rb0a0c3 520 520 /// Fragment molecule by two different approaches: 521 521 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); 522 bool StoreAdjacencyToFile(ofstream *out, char *path); 523 bool CheckAdjacencyFileAgainstMolecule(ofstream *out, char *path, atom **ListOfAtoms); 524 bool ParseKeySetFile(ofstream *out, char *filename, atom **ListOfAtoms, MoleculeListClass *&FragmentList, bool IsAngstroem); 525 bool ScanBufferIntoKeySet(ofstream *out, char *buffer, KeySet &CurrentSet); 524 526 MoleculeListClass * GetAtomicFragments(ofstream *out, int NumberOfTopAtoms, bool IsAngstroem, double factor, enum CutCyclicBond CutCyclic); 525 527 void BreadthFirstSearchAdd(ofstream *out, molecule *Mol, atom **&AddedAtomList, bond **&AddedBondList, atom *Root, bond *Bond, int BondOrder, bool IsAngstroem, enum CutCyclicBond CutCyclic);
Note:
See TracChangeset
for help on using the changeset viewer.