- Timestamp:
- Aug 18, 2008, 8:35:11 AM (16 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:
- f05407
- Parents:
- f3dc4c
- Location:
- src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/analyzer.cpp
rf3dc4c r8f019c 29 29 ForceMatrix Shielding; 30 30 ForceMatrix ShieldingPAS; 31 EnergyMatrixTime;31 MatrixContainer Time; 32 32 EnergyMatrix EnergyFragments; 33 33 EnergyMatrix HcorrectionFragments; … … 51 51 bool Hcorrected = true; 52 52 double norm; 53 int counter;54 53 55 54 cout << "ANOVA Analyzer" << endl; … … 83 82 84 83 // ------------- Parse through all Fragment subdirs -------- 85 if (!Energy.Parse FragmentMatrix(argv[1], dir, EnergySuffix,0,0)) return 1;86 Hcorrected = Hcorrection.Parse FragmentMatrix(argv[1], "", HCORRECTIONSUFFIX,0,0);87 if (!Force.Parse FragmentMatrix(argv[1], dir, ForcesSuffix,0,0)) return 1;88 if (!Time.Parse FragmentMatrix(argv[1], dir, TimeSuffix, 10,1)) return 1;84 if (!Energy.ParseMatrix(argv[1], dir, EnergySuffix,0,0)) return 1; 85 Hcorrected = Hcorrection.ParseMatrix(argv[1], "", HCORRECTIONSUFFIX,0,0); 86 if (!Force.ParseMatrix(argv[1], dir, ForcesSuffix,0,0)) return 1; 87 if (!Time.ParseMatrix(argv[1], dir, TimeSuffix, 10,1)) return 1; 89 88 if (periode != NULL) { // also look for PAS values 90 if (!Shielding.Parse FragmentMatrix(argv[1], dir, ShieldingSuffix, 1, 0)) return 1;91 if (!ShieldingPAS.Parse FragmentMatrix(argv[1], dir, ShieldingPASSuffix, 1, 0)) return 1;89 if (!Shielding.ParseMatrix(argv[1], dir, ShieldingSuffix, 1, 0)) return 1; 90 if (!ShieldingPAS.ParseMatrix(argv[1], dir, ShieldingPASSuffix, 1, 0)) return 1; 92 91 } 93 92 … … 112 111 113 112 // ---------- Parse fragment files created by 'joiner' into an array ------------- 114 if (!EnergyFragments.Parse FragmentMatrix(argv[1], dir, EnergyFragmentSuffix,0,0)) return 1;115 if (Hcorrected) HcorrectionFragments.Parse FragmentMatrix(argv[1], dir, HcorrectionFragmentSuffix,0,0);116 if (!ForceFragments.Parse FragmentMatrix(argv[1], dir, ForceFragmentSuffix,0,0)) return 1;113 if (!EnergyFragments.ParseMatrix(argv[1], dir, EnergyFragmentSuffix,0,0)) return 1; 114 if (Hcorrected) HcorrectionFragments.ParseMatrix(argv[1], dir, HcorrectionFragmentSuffix,0,0); 115 if (!ForceFragments.ParseMatrix(argv[1], dir, ForceFragmentSuffix,0,0)) return 1; 117 116 if (periode != NULL) { // also look for PAS values 118 if (!ShieldingFragments.Parse FragmentMatrix(argv[1], dir, ShieldingSuffix, 1, 0)) return 1;119 if (!ShieldingPASFragments.Parse FragmentMatrix(argv[1], dir, ShieldingPASSuffix, 1, 0)) return 1;117 if (!ShieldingFragments.ParseMatrix(argv[1], dir, ShieldingSuffix, 1, 0)) return 1; 118 if (!ShieldingPASFragments.ParseMatrix(argv[1], dir, ShieldingPASSuffix, 1, 0)) return 1; 120 119 } 121 120 … … 161 160 162 161 output << endl << "Total Times" << endl << "===============" << endl << Time.Header << endl; 162 Time.SetLastMatrix(0., 0); 163 for (int BondOrder=KeySet.Order;BondOrder--;) 164 for(int i=KeySet.FragmentsPerOrder[BondOrder];i--;) 165 for(int j=Time.RowCounter[Time.MatrixCounter];j--;) 166 for(int k=Time.ColumnCounter;k--;) { 167 Time.Matrix[ Time.MatrixCounter ][j][k] += Time.Matrix[ KeySet.OrderSet[BondOrder][i] ][j][k]; 168 } 163 169 for(int j=0;j<Time.RowCounter[Time.MatrixCounter];j++) { 164 for(int k=0;k<Time.ColumnCounter;k++) {170 for(int k=0;k<Time.ColumnCounter;k++) 165 171 output << scientific << Time.Matrix[ Time.MatrixCounter ][j][k] << "\t"; 166 }167 172 output << endl; 168 173 } 169 174 output << endl; 170 175 output.close(); 171 for(int k=0;k<Time.ColumnCounter;k++)172 Time.Matrix[ Time.MatrixCounter ][ Time.RowCounter[Time.MatrixCounter] ][k] = Time.Matrix[ Time.MatrixCounter ][Time.RowCounter[Time.MatrixCounter]-1][k];173 176 174 177 // +++++++++++++++ ANALYZING ++++++++++++++++++++++++++++++ … … 179 182 180 183 // +++++++++++++++++++++++++++++++++++++++ Plotting Simtime vs Bond Order 181 // +++++++++++++++++++++++++++++++++++++++ Plotting Delta Simtime vs Bond Order182 184 if (!OpenOutputFile(output, argv[3], "SimTime-Order.dat" )) return false; 183 if (!OpenOutputFile(output2, argv[3], "DeltaSimTime-Order.dat" )) return false; 184 for(int j=Time.RowCounter[Time.MatrixCounter];j--;) 185 for(int k=Time.ColumnCounter;k--;) { 186 Time.Matrix[ Time.MatrixCounter ][j][k] = 0.; 187 } 188 counter = 0; 185 Time.SetLastMatrix(0., 0); 189 186 output << "#Order\tFrag.No.\t" << Time.Header << endl; 190 output2 << "#Order\tFrag.No.\t" << Time.Header << endl;191 187 for (int BondOrder=0;BondOrder<KeySet.Order;BondOrder++) { 192 188 for(int i=KeySet.FragmentsPerOrder[BondOrder];i--;) … … 195 191 Time.Matrix[ Time.MatrixCounter ][j][k] += Time.Matrix[ KeySet.OrderSet[BondOrder][i] ][j][k]; 196 192 } 197 counter += KeySet.FragmentsPerOrder[BondOrder]; 198 output << BondOrder+1 << "\t" << counter; 199 output2 << BondOrder+1 << "\t" << counter; 200 for(int k=0;k<Time.ColumnCounter;k++) { 201 output << "\t" << scientific << Time.Matrix[ Time.MatrixCounter ][ Time.RowCounter[Time.MatrixCounter]-1 ][k]; 202 if (fabs(Time.Matrix[ Time.MatrixCounter ][ Time.RowCounter[Time.MatrixCounter] ][k]) > MYEPSILON) 203 output2 << "\t" << scientific << Time.Matrix[ Time.MatrixCounter ][ Time.RowCounter[Time.MatrixCounter]-1 ][k] / Time.Matrix[ Time.MatrixCounter ][ Time.RowCounter[Time.MatrixCounter] ][k]; 204 else 205 output2 << "\t" << scientific << Time.Matrix[ Time.MatrixCounter ][ Time.RowCounter[Time.MatrixCounter]-1 ][k]; 206 } 207 output << endl; 208 output2 << endl; 193 output << BondOrder+1 << "\t" << KeySet.FragmentsPerOrder[BondOrder]; 194 for(int k=0;k<Time.ColumnCounter;k++) 195 output << "\t" << scientific << Time.Matrix[ Time.MatrixCounter ][1][k]; 196 output << endl; 209 197 } 210 198 output.close(); 211 output2.close();212 213 199 214 200 // +++++++++++++++++++++++++++++++++++++++ Plotting deviation in energy to full QM -
src/helpers.cpp
rf3dc4c r8f019c 73 73 void *buffer = NULL; 74 74 if (OldPointer == NULL) 75 cout << Verbose(0) << "ReAlloc impossible - old is NULL: " << output << endl; 76 buffer = (void *)realloc(OldPointer, size); // alloc 75 //cout << Verbose(0) << "ReAlloc impossible - old is NULL: " << output << endl; 76 buffer = (void *)malloc(size); // malloc 77 else 78 buffer = (void *)realloc(OldPointer, size); // realloc 77 79 if (buffer == NULL) 78 80 cout << Verbose(0) << "ReAlloc failed - new is NULL: " << output << endl; -
src/joiner.cpp
rf3dc4c r8f019c 60 60 61 61 // ------------- Parse through all Fragment subdirs -------- 62 if (!Energy.Parse Matrix(argv[1], dir, EnergySuffix, 0,0)) return 1;63 Hcorrected = Hcorrection.Parse Matrix(argv[1], "", HCORRECTIONSUFFIX, 0,0);64 if (!Force.Parse Matrix(argv[1], dir, ForcesSuffix, 0,0)) return 1;62 if (!Energy.ParseFragmentMatrix(argv[1], dir, EnergySuffix, 0,0)) return 1; 63 Hcorrected = Hcorrection.ParseFragmentMatrix(argv[1], "", HCORRECTIONSUFFIX, 0,0); 64 if (!Force.ParseFragmentMatrix(argv[1], dir, ForcesSuffix, 0,0)) return 1; 65 65 if (periode != NULL) { // also look for PAS values 66 if (!Shielding.Parse Matrix(argv[1], dir, ShieldingSuffix, 1, 0)) return 1;67 if (!ShieldingPAS.Parse Matrix(argv[1], dir, ShieldingPASSuffix, 1, 0)) return 1;66 if (!Shielding.ParseFragmentMatrix(argv[1], dir, ShieldingSuffix, 1, 0)) return 1; 67 if (!ShieldingPAS.ParseFragmentMatrix(argv[1], dir, ShieldingPASSuffix, 1, 0)) return 1; 68 68 } 69 69 -
src/parser.cpp
rf3dc4c r8f019c 55 55 */ 56 56 MatrixContainer::MatrixContainer() { 57 Matrix = NULL;58 57 Indices = NULL; 59 Header = NULL; 58 Header = (char *) Malloc(sizeof(char)*1023, "MatrixContainer::MatrixContainer: *Header"); 59 Matrix = (double ***) Malloc(sizeof(double **)*(1), "MatrixContainer::MatrixContainer: ***Matrix"); // one more each for the total molecule 60 RowCounter = (int *) Malloc(sizeof(int)*(1), "MatrixContainer::MatrixContainer: *RowCounter"); 61 Matrix[0] = NULL; 62 RowCounter[0] = -1; 60 63 MatrixCounter = 0; 61 RowCounter = NULL;62 64 ColumnCounter = 0; 63 65 }; … … 89 91 Free((void **)&Header, "MatrixContainer::~MatrixContainer: *Header"); 90 92 Free((void **)&RowCounter, "MatrixContainer::~MatrixContainer: *RowCounter"); 93 }; 94 95 96 /** Parsing a number of matrices. 97 * -# open the matrix file 98 * -# skip some lines (\a skiplines) 99 * -# scan header lines for number of columns 100 * -# scan lines for number of rows 101 * -# allocate matrix 102 * -# loop over found column and row counts and parse in each entry 103 * \param *name directory with files 104 * \param skiplines number of inital lines to skip 105 * \param skiplines number of inital columns to skip 106 * \param MatrixNr index number in Matrix array to parse into 107 * \return parsing successful 108 */ 109 bool MatrixContainer::ParseMatrix(const char *name, int skiplines, int skipcolumns, int MatrixNr) 110 { 111 ifstream input; 112 stringstream line; 113 string token; 114 char filename[1023]; 115 116 input.open(name, ios::in); 117 //cout << "Opening " << name << " ... " << input << endl; 118 if (input == NULL) { 119 cerr << endl << "Unable to open " << name << ", is the directory correct?" << endl; 120 return false; 121 } 122 123 // skip some initial lines 124 for (int m=skiplines+1;m--;) 125 input.getline(Header, 1023); 126 127 // scan header for number of columns 128 line.str(Header); 129 for(int k=skipcolumns;k--;) 130 line >> Header; 131 //cout << line.str() << endl; 132 ColumnCounter=0; 133 while ( getline(line,token, '\t') ) { 134 if (token.length() > 0) 135 ColumnCounter++; 136 } 137 //cout << line.str() << endl; 138 //cout << "ColumnCounter: " << ColumnCounter << "." << endl; 139 if (ColumnCounter == 0) 140 cerr << "ColumnCounter: " << ColumnCounter << " from file " << name << ", this is probably an error!" << endl; 141 142 // scan rest for number of rows/lines 143 RowCounter[MatrixNr]=-1; // counts one line too much 144 while (!input.eof()) { 145 input.getline(filename, 1023); 146 //cout << "Comparing: " << strncmp(filename,"MeanForce",9) << endl; 147 RowCounter[MatrixNr]++; // then line was not last MeanForce 148 if (strncmp(filename,"MeanForce", 9) == 0) { 149 break; 150 } 151 } 152 //cout << "RowCounter[" << MatrixNr << "]: " << RowCounter[MatrixNr] << " from file " << name << "." << endl; 153 if (RowCounter[MatrixNr] == 0) 154 cerr << "RowCounter[" << MatrixNr << "]: " << RowCounter[MatrixNr] << " from file " << name << ", this is probably an error!" << endl; 155 156 // allocate matrix if it's not zero dimension in one direction 157 if ((ColumnCounter > 0) && (RowCounter[MatrixNr] > -1)) { 158 Matrix[MatrixNr] = (double **) Malloc(sizeof(double *)*(RowCounter[MatrixNr]+1), "MatrixContainer::ParseFragmentMatrix: **Matrix[]"); 159 160 // parse in each entry for this matrix 161 input.clear(); 162 input.seekg(ios::beg); 163 for (int m=skiplines+1;m--;) 164 input.getline(Header, 1023); // skip header 165 line.str(Header); 166 for(int k=skipcolumns;k--;) // skip columns in header too 167 line >> filename; 168 strncpy(Header, line.str().c_str(), 1023); 169 for(int j=0;j<RowCounter[MatrixNr];j++) { 170 Matrix[MatrixNr][j] = (double *) Malloc(sizeof(double)*ColumnCounter, "MatrixContainer::ParseFragmentMatrix: *Matrix[][]"); 171 input.getline(filename, 1023); 172 stringstream lines(filename); 173 //cout << "Matrix at level " << j << ":";// << filename << endl; 174 for(int k=skipcolumns;k--;) 175 lines >> filename; 176 for(int k=0;(k<ColumnCounter) && (!lines.eof());k++) { 177 lines >> Matrix[MatrixNr][j][k]; 178 //cout << " " << setprecision(2) << Matrix[MatrixNr][j][k];; 179 } 180 //cout << endl; 181 Matrix[MatrixNr][ RowCounter[MatrixNr] ] = (double *) Malloc(sizeof(double)*ColumnCounter, "MatrixContainer::ParseFragmentMatrix: *Matrix[RowCounter[MatrixNr]][]"); 182 for(int j=ColumnCounter;j--;) 183 Matrix[MatrixNr][ RowCounter[MatrixNr] ][j] = 0.; 184 } 185 } else { 186 cerr << "ERROR: Matrix nr. " << MatrixNr << " has column and row count of (" << ColumnCounter << "," << RowCounter[MatrixNr] << "), could not allocate nor parse!" << endl; 187 } 188 input.close(); 189 return true; 91 190 }; 92 191 … … 109 208 * \return parsing successful 110 209 */ 111 bool MatrixContainer::Parse Matrix(char *name, char *prefix, string suffix, int skiplines, int skipcolumns)210 bool MatrixContainer::ParseFragmentMatrix(char *name, char *prefix, string suffix, int skiplines, int skipcolumns) 112 211 { 113 212 char filename[1023]; … … 117 216 string token; 118 217 119 Header = (char *) Malloc(sizeof(char)*1023, "MatrixContainer::ParseMatrix: *EnergyHeader");120 121 218 // count the number of matrices 122 219 MatrixCounter = -1; // we count one too much … … 129 226 while (!input.eof()) { 130 227 input.getline(filename, 1023); 228 stringstream zeile(filename); 131 229 MatrixCounter++; 132 230 } 133 input.close(); 231 input.close(); 134 232 cout << "Determined " << MatrixCounter << " fragments." << endl; 135 233 136 234 cout << "Parsing through each fragment and retrieving " << prefix << suffix << "." << endl; 137 Matrix = (double ***) Malloc(sizeof(double **)*(MatrixCounter+1), "MatrixContainer::ParseMatrix: ***Matrix"); // one more each for the total molecule138 RowCounter = (int *) Malloc(sizeof(int)*(MatrixCounter+1), "MatrixContainer::ParseMatrix: *RowCounter");235 Matrix = (double ***) ReAlloc(Matrix, sizeof(double **)*(MatrixCounter+1), "MatrixContainer::ParseFragmentMatrix: ***Matrix"); // one more each for the total molecule 236 RowCounter = (int *) ReAlloc(RowCounter, sizeof(int)*(MatrixCounter+1), "MatrixContainer::ParseFragmentMatrix: *RowCounter"); 139 237 for(int i=MatrixCounter+1;i--;) { 140 238 Matrix[i] = NULL; 141 239 RowCounter[i] = -1; 142 240 } 143 for(int i= MatrixCounter+1;i--;) {241 for(int i=0; i < MatrixCounter;i++) { 144 242 // open matrix file 145 stringstream line;146 243 FragmentNumber = FixedDigitNumber(MatrixCounter, i); 147 244 file.str(" "); 148 if (i != MatrixCounter) 149 file << name << FRAGMENTPREFIX << FragmentNumber << prefix << suffix; 150 else 151 file << name << prefix << suffix; 152 Free((void **)&FragmentNumber, "MatrixContainer::ParseMatrix: *FragmentNumber"); 153 input.open(file.str().c_str(), ios::in); 154 //cout << "Opening " << file.str() << " ... " << input << endl; 155 if (input == NULL) { 156 cerr << endl << "Unable to open " << file.str() << ", is the directory correct?" << endl; 245 file << name << FRAGMENTPREFIX << FragmentNumber << prefix << suffix; 246 if (!ParseMatrix(file.str().c_str(), skiplines, skipcolumns, i)) 157 247 return false; 158 } 159 160 // skip some initial lines 161 for (int m=skiplines+1;m--;) 162 input.getline(Header, 1023); 163 164 // scan header for number of columns 165 line.str(Header); 166 for(int k=skipcolumns;k--;) 167 line >> Header; 168 //cout << line.str() << endl; 169 ColumnCounter=0; 170 while ( getline(line,token, '\t') ) { 171 if (token.length() > 0) 172 ColumnCounter++; 173 } 174 //cout << line.str() << endl; 175 //cout << "ColumnCounter: " << ColumnCounter << endl; 176 177 // scan rest for number of rows/lines 178 RowCounter[i]=-1; // counts one line too much 179 while (!input.eof()) { 180 input.getline(filename, 1023); 181 //cout << "Comparing: " << strncmp(filename,"MeanForce",9) << endl; 182 RowCounter[i]++; // then line was not last MeanForce 183 if (strncmp(filename,"MeanForce", 9) == 0) { 184 break; 185 } 186 } 187 //cout << "RowCounter[" << i << "]: " << RowCounter[i] << " from file " << file.str() << "." << endl; 188 189 // allocate matrix if it's not zero dimension in one direction 190 if ((ColumnCounter > 0) && (RowCounter[i] > -1)) { 191 Matrix[i] = (double **) Malloc(sizeof(double *)*(RowCounter[i]+1), "MatrixContainer::ParseMatrix: **Matrix[]"); 192 193 // parse in each entry for this matrix 194 input.clear(); 195 input.seekg(ios::beg); 196 for (int m=skiplines+1;m--;) 197 input.getline(Header, 1023); // skip header 198 line.str(Header); 199 for(int k=skipcolumns;k--;) // skip columns in header too 200 line >> filename; 201 strncpy(Header, line.str().c_str(), 1023); 202 for(int j=0;j<RowCounter[i];j++) { 203 Matrix[i][j] = (double *) Malloc(sizeof(double)*ColumnCounter, "MatrixContainer::ParseMatrix: *Matrix[][]"); 204 input.getline(filename, 1023); 205 stringstream lines(filename); 206 //cout << "Matrix at level " << j << ":";// << filename << endl; 207 for(int k=skipcolumns;k--;) 208 lines >> filename; 209 for(int k=0;(k<ColumnCounter) && (!lines.eof());k++) { 210 lines >> Matrix[i][j][k]; 211 //cout << " " << setprecision(2) << Matrix[i][j][k];; 212 } 213 //cout << endl; 214 Matrix[i][ RowCounter[i] ] = (double *) Malloc(sizeof(double)*ColumnCounter, "MatrixContainer::ParseMatrix: *Matrix[RowCounter[i]][]"); 215 for(int j=ColumnCounter;j--;) 216 Matrix[i][ RowCounter[i] ][j] = 0.; 217 } 218 } else { 219 cerr << "ERROR: Matrix nr. " << i << " has column and row count of (" << ColumnCounter << "," << RowCounter[i] << "), could not allocate nor parse!" << endl; 220 } 221 input.close(); 248 Free((void **)&FragmentNumber, "MatrixContainer::ParseFragmentMatrix: *FragmentNumber"); 222 249 } 223 250 return true; … … 233 260 bool MatrixContainer::AllocateMatrix(char *GivenHeader, int MCounter, int *RCounter, int CCounter) 234 261 { 235 Header = (char *) Malloc(sizeof(char)*1024, "MatrixContainer::Parse Matrix: *EnergyHeader");262 Header = (char *) Malloc(sizeof(char)*1024, "MatrixContainer::ParseFragmentMatrix: *EnergyHeader"); 236 263 strncpy(Header, GivenHeader, 1023); 237 264 238 265 MatrixCounter = MCounter; 239 266 ColumnCounter = CCounter; 240 Matrix = (double ***) Malloc(sizeof(double **)*(MatrixCounter+1), "MatrixContainer::Parse Matrix: ***Matrix"); // one more each for the total molecule241 RowCounter = (int *) Malloc(sizeof(int)*(MatrixCounter+1), "MatrixContainer::Parse Matrix: *RowCounter");267 Matrix = (double ***) Malloc(sizeof(double **)*(MatrixCounter+1), "MatrixContainer::ParseFragmentMatrix: ***Matrix"); // one more each for the total molecule 268 RowCounter = (int *) Malloc(sizeof(int)*(MatrixCounter+1), "MatrixContainer::ParseFragmentMatrix: *RowCounter"); 242 269 for(int i=MatrixCounter+1;i--;) { 243 270 RowCounter[i] = RCounter[i]; 244 Matrix[i] = (double **) Malloc(sizeof(double *)*(RowCounter[i]+1), "MatrixContainer::Parse Matrix: **Matrix[]");271 Matrix[i] = (double **) Malloc(sizeof(double *)*(RowCounter[i]+1), "MatrixContainer::ParseFragmentMatrix: **Matrix[]"); 245 272 for(int j=RowCounter[i]+1;j--;) { 246 Matrix[i][j] = (double *) Malloc(sizeof(double)*ColumnCounter, "MatrixContainer::Parse Matrix: *Matrix[][]");273 Matrix[i][j] = (double *) Malloc(sizeof(double)*ColumnCounter, "MatrixContainer::ParseFragmentMatrix: *Matrix[][]"); 247 274 for(int k=ColumnCounter;k--;) 248 275 Matrix[i][j][k] = 0.; … … 481 508 }; 482 509 510 /** Calls MatrixContainer::ParseFragmentMatrix() and additionally allocates last plus one matrix. 511 * \param *name directory with files 512 * \param *prefix prefix of each matrix file 513 * \param *suffix suffix of each matrix file 514 * \param skiplines number of inital lines to skip 515 * \param skiplines number of inital columns to skip 516 * \return parsing successful 517 */ 518 bool EnergyMatrix::ParseFragmentMatrix(char *name, char *prefix, string suffix, int skiplines, int skipcolumns) 519 { 520 char filename[1024]; 521 bool status = MatrixContainer::ParseFragmentMatrix(name, prefix, suffix, skiplines, skipcolumns); 522 523 if (status) { 524 // count maximum of columns 525 RowCounter[MatrixCounter] = 0; 526 for(int j=0; j < MatrixCounter;j++) // (energy matrix might be bigger than number of atoms in terms of rows) 527 if (RowCounter[j] > RowCounter[MatrixCounter]) 528 RowCounter[MatrixCounter] = RowCounter[j]; 529 // allocate last plus one matrix 530 cout << "Allocating last plus one matrix with " << (RowCounter[MatrixCounter]+1) << " rows and " << ColumnCounter << " columns." << endl; 531 Matrix[MatrixCounter] = (double **) Malloc(sizeof(double *)*(RowCounter[MatrixCounter]+1), "MatrixContainer::ParseFragmentMatrix: **Matrix[]"); 532 for(int j=0;j<=RowCounter[MatrixCounter];j++) 533 Matrix[MatrixCounter][j] = (double *) Malloc(sizeof(double)*ColumnCounter, "MatrixContainer::ParseFragmentMatrix: *Matrix[][]"); 534 535 // try independently to parse global energysuffix file if present 536 strncpy(filename, name, 1023); 537 strncat(filename, prefix, 1023-strlen(filename)); 538 strncat(filename, suffix.c_str(), 1023-strlen(filename)); 539 ParseMatrix(filename, skiplines, skipcolumns, MatrixCounter); 540 } 541 return status; 542 }; 543 483 544 // ======================================= CLASS ForceMatrix ============================= 484 545 … … 556 617 }; 557 618 619 620 /** Calls MatrixContainer::ParseFragmentMatrix() and additionally allocates last plus one matrix. 621 * \param *name directory with files 622 * \param *prefix prefix of each matrix file 623 * \param *suffix suffix of each matrix file 624 * \param skiplines number of inital lines to skip 625 * \param skiplines number of inital columns to skip 626 * \return parsing successful 627 */ 628 bool ForceMatrix::ParseFragmentMatrix(char *name, char *prefix, string suffix, int skiplines, int skipcolumns) 629 { 630 char filename[1023]; 631 ifstream input; 632 stringstream file; 633 int nr; 634 bool status = MatrixContainer::ParseFragmentMatrix(name, prefix, suffix, skiplines, skipcolumns); 635 636 if (status) { 637 // count number of atoms for last plus one matrix 638 file << name << FRAGMENTPREFIX << KEYSETFILE; 639 input.open(file.str().c_str(), ios::in); 640 if (input == NULL) { 641 cout << endl << "Unable to open " << file.str() << ", is the directory correct?" << endl; 642 return false; 643 } 644 RowCounter[MatrixCounter] = 0; 645 while (!input.eof()) { 646 input.getline(filename, 1023); 647 stringstream zeile(filename); 648 while (!zeile.eof()) { 649 zeile >> nr; 650 //cout << "Current index: " << nr << "." << endl; 651 if (nr > RowCounter[MatrixCounter]) 652 RowCounter[MatrixCounter] = nr; 653 } 654 } 655 RowCounter[MatrixCounter]++; // nr start at 0, count starts at 1 656 input.close(); 657 658 // allocate last plus one matrix 659 cout << "Allocating last plus one matrix with " << (RowCounter[MatrixCounter]+1) << " rows and " << ColumnCounter << " columns." << endl; 660 Matrix[MatrixCounter] = (double **) Malloc(sizeof(double *)*(RowCounter[MatrixCounter]+1), "MatrixContainer::ParseFragmentMatrix: **Matrix[]"); 661 for(int j=0;j<=RowCounter[MatrixCounter];j++) 662 Matrix[MatrixCounter][j] = (double *) Malloc(sizeof(double)*ColumnCounter, "MatrixContainer::ParseFragmentMatrix: *Matrix[][]"); 663 664 // try independently to parse global forcesuffix file if present 665 strncpy(filename, name, 1023); 666 strncat(filename, prefix, 1023-strlen(filename)); 667 strncat(filename, suffix.c_str(), 1023-strlen(filename)); 668 ParseMatrix(filename, skiplines, skipcolumns, MatrixCounter); 669 } 670 671 672 return status; 673 }; 558 674 559 675 // ======================================= CLASS KeySetsContainer ============================= -
src/parser.hpp
rf3dc4c r8f019c 51 51 ~MatrixContainer(); 52 52 53 bool ParseMatrix(char *name, char *prefix, string suffix, int skiplines, int skipcolumns); 53 bool ParseMatrix(const char *name, int skiplines, int skipcolumns, int MatrixNr); 54 virtual bool ParseFragmentMatrix(char *name, char *prefix, string suffix, int skiplines, int skipcolumns); 54 55 bool AllocateMatrix(char *GivenHeader, int MCounter, int *RCounter, int CCounter); 55 56 bool ResetMatrix(); … … 71 72 bool ParseIndices(); 72 73 bool SumSubEnergy(class EnergyMatrix &Fragments, class EnergyMatrix *CorrectionFragments, class KeySetsContainer &KeySet, int Order, double sign); 74 bool ParseFragmentMatrix(char *name, char *prefix, string suffix, int skiplines, int skipcolumns); 73 75 }; 74 76 … … 79 81 bool ParseIndices(char *name); 80 82 bool SumSubForces(class ForceMatrix &Fragments, class KeySetsContainer &KeySet, int Order, double sign); 83 bool ParseFragmentMatrix(char *name, char *prefix, string suffix, int skiplines, int skipcolumns); 81 84 }; 82 85
Note:
See TracChangeset
for help on using the changeset viewer.