Changeset 9758f7 for src/Fragmentation/MatrixContainer.cpp
- Timestamp:
- Oct 18, 2011, 8:07:37 AM (14 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:
- 1b145f
- Parents:
- a9b86d
- git-author:
- Frederik Heber <heber@…> (09/16/11 16:24:18)
- git-committer:
- Frederik Heber <heber@…> (10/18/11 08:07:37)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/Fragmentation/MatrixContainer.cpp ¶
ra9b86d r9758f7 35 35 /** Constructor of MatrixContainer class. 36 36 */ 37 MatrixContainer::MatrixContainer() : 38 Indices(NULL) 39 { 40 Header = new char*[1]; 41 Matrix = new double**[1]; // one more each for the total molecule 42 RowCounter = new int[1]; 43 ColumnCounter = new int[1]; 44 Header[0] = NULL; 45 Matrix[0] = NULL; 46 RowCounter[0] = -1; 37 MatrixContainer::MatrixContainer() 38 { 39 Header.resize(1); 40 RowCounter.resize(1); 41 ColumnCounter.resize(1); 42 ColumnCounter[0] = -1; 47 43 MatrixCounter = 0; 48 ColumnCounter[0] = -1;49 44 }; 50 45 51 46 /** Destructor of MatrixContainer class. 52 47 */ 53 MatrixContainer::~MatrixContainer() { 54 if (Matrix != NULL) { 55 // free Matrix[MatrixCounter] 56 if ((ColumnCounter != NULL) && (RowCounter != NULL) && (Matrix[MatrixCounter] != NULL)) 57 for(int j=RowCounter[MatrixCounter]+1;j--;) 58 delete[](Matrix[MatrixCounter][j]); 59 //if (MatrixCounter != 0) 60 delete[](Matrix[MatrixCounter]); 61 // free all matrices but ultimate one 62 for(int i=MatrixCounter;i--;) { 63 if ((ColumnCounter != NULL) && (RowCounter != NULL)) { 64 for(int j=RowCounter[i]+1;j--;) 65 delete[](Matrix[i][j]); 66 delete[](Matrix[i]); 67 } 68 } 69 delete[](Matrix); 70 } 71 // free indices 72 if (Indices != NULL) 73 for(int i=MatrixCounter+1;i--;) { 74 delete[](Indices[i]); 75 } 76 delete[](Indices); 77 78 // free header and counters 79 if (Header != NULL) 80 for(int i=MatrixCounter+1;i--;) 81 delete[](Header[i]); 82 delete[](Header); 83 delete[](RowCounter); 84 delete[](ColumnCounter); 85 }; 48 MatrixContainer::~MatrixContainer() 49 {} 86 50 87 51 /** Either copies index matrix from another MatrixContainer or initialises with trivial mapping if NULL. … … 90 54 * \return true - copy/initialisation sucessful, false - dimension false for copying 91 55 */ 92 bool MatrixContainer::InitialiseIndices(class MatrixContainer * Matrix)56 bool MatrixContainer::InitialiseIndices(class MatrixContainer *_container) 93 57 { 94 58 DoLog(0) && (Log() << Verbose(0) << "Initialising indices"); 95 if ( Matrix== NULL) {59 if (_container == NULL) { 96 60 DoLog(0) && (Log() << Verbose(0) << " with trivial mapping." << endl); 97 Indices = new int*[MatrixCounter + 1];61 Indices.resize(MatrixCounter + 1); 98 62 for(int i=MatrixCounter+1;i--;) { 99 Indices[i] = new int[RowCounter[i]];63 Indices[i].resize(RowCounter[i]); 100 64 for(int j=RowCounter[i];j--;) 101 65 Indices[i][j] = j; … … 103 67 } else { 104 68 DoLog(0) && (Log() << Verbose(0) << " from other MatrixContainer." << endl); 105 if (MatrixCounter != Matrix->MatrixCounter)69 if (MatrixCounter != _container->MatrixCounter) 106 70 return false; 107 Indices = new int*[MatrixCounter + 1];71 Indices.resize(MatrixCounter + 1); 108 72 for(int i=MatrixCounter+1;i--;) { 109 if (RowCounter[i] != Matrix->RowCounter[i])73 if (RowCounter[i] != _container->RowCounter[i]) 110 74 return false; 111 Indices[i] = new int[Matrix->RowCounter[i]];112 for(int j= Matrix->RowCounter[i];j--;) {113 Indices[i][j] = Matrix->Indices[i][j];75 Indices[i].resize(_container->RowCounter[i]); 76 for(int j=_container->RowCounter[i];j--;) { 77 Indices[i][j] = _container->Indices[i][j]; 114 78 //Log() << Verbose(0) << Indices[i][j] << "\t"; 115 79 } … … 133 97 * \return parsing successful 134 98 */ 135 bool MatrixContainer::ParseMatrix(std::istream &input, int skiplines, int skipcolumns, int MatrixNr)99 bool MatrixContainer::ParseMatrix(std::istream &input, int skiplines, int skipcolumns, size_t MatrixNr) 136 100 { 137 101 stringstream line; … … 146 110 147 111 // parse header 148 if (Header[MatrixNr] != NULL) 149 delete[] Header[MatrixNr]; 150 Header[MatrixNr] = new char[1024]; 112 if (Header.size() <= MatrixNr) 113 Header.resize(MatrixNr); 114 Header[MatrixNr] = std::string(""); 115 char dummy[1024]; 151 116 for (int m=skiplines+1;m--;) 152 input.getline(Header[MatrixNr], 1023); 153 154 // scan header for number of columns 155 line.str(Header[MatrixNr]); 117 input.getline(dummy, 1023); 118 line.str(dummy); 156 119 for(int k=skipcolumns;k--;) 157 120 line >> Header[MatrixNr]; 158 121 Log() << Verbose(0) << line.str() << endl; 122 123 // scan header for number of columns 124 if (ColumnCounter.size() <= MatrixNr) 125 ColumnCounter.resize(MatrixNr); 159 126 ColumnCounter[MatrixNr]=0; 160 127 while ( getline(line,token, '\t') ) { … … 170 137 171 138 // scan rest for number of rows/lines 139 if (RowCounter.size() <= MatrixNr) 140 RowCounter.resize(MatrixNr); 172 141 RowCounter[MatrixNr]=-1; // counts one line too much 173 142 while (!input.eof()) { … … 186 155 187 156 // allocate matrix if it's not zero dimension in one direction 188 if ((ColumnCounter[MatrixNr] > 0) && (RowCounter[MatrixNr] > -1)) { 189 if (Matrix[MatrixNr] != NULL) 190 delete[] Matrix[MatrixNr]; 191 Matrix[MatrixNr] = new double*[RowCounter[MatrixNr] + 1]; 192 for(int j=0;j<RowCounter[MatrixNr]+1;j++) 193 Matrix[MatrixNr][j] = 0; 194 195 // parse in each entry for this matrix 196 input.clear(); 197 input.seekg(ios::beg); 198 for (int m=skiplines+1;m--;) 199 input.getline(Header[MatrixNr], 1023); // skip header 200 line.str(Header[MatrixNr]); 201 Log() << Verbose(0) << "Header: " << line.str() << endl; 202 for(int k=skipcolumns;k--;) // skip columns in header too 203 line >> filename; 204 strncpy(Header[MatrixNr], line.str().c_str(), 1023); 205 for(int j=0;j<RowCounter[MatrixNr];j++) { 206 if (Matrix[MatrixNr][j] != NULL) 207 delete[] Matrix[MatrixNr][j]; 208 Matrix[MatrixNr][j] = new double[ColumnCounter[MatrixNr]]; 209 for(int k=0;k<ColumnCounter[MatrixNr];k++) 157 if (Matrix.size() <= MatrixNr) 158 Matrix.resize(MatrixNr+1); 159 if ((Matrix[MatrixNr].size() <= (size_t)RowCounter[MatrixNr] + 1) && (RowCounter[MatrixNr] > -1)) { 160 Matrix[MatrixNr].resize(RowCounter[MatrixNr] + 2); 161 for(int j=0;j<=RowCounter[MatrixNr];j++) { 162 if ((Matrix[MatrixNr][j].size() <= (size_t)ColumnCounter[MatrixNr]) && (ColumnCounter[MatrixNr] > -1)) 163 Matrix[MatrixNr][j].resize(ColumnCounter[MatrixNr]+1); 164 // clear 165 for(int k=0;k<=ColumnCounter[MatrixNr];k++) 210 166 Matrix[MatrixNr][j][k] = 0; 211 212 input.getline(filename, 1023);213 stringstream lines(filename);214 Log() << Verbose(2) << "Matrix at level " << j << ":";// << filename << endl;215 for(int k=skipcolumns;k--;)216 lines >> filename;217 for(int k=0;(k<ColumnCounter[MatrixNr]) && (!lines.eof());k++) {218 lines >> Matrix[MatrixNr][j][k];219 Log() << Verbose(1) << " " << std::setprecision(2) << Matrix[MatrixNr][j][k] << endl;220 }221 if (Matrix[MatrixNr][ RowCounter[MatrixNr] ] != NULL)222 delete[] Matrix[MatrixNr][ RowCounter[MatrixNr] ];223 Matrix[MatrixNr][ RowCounter[MatrixNr] ] = new double[ColumnCounter[MatrixNr]];224 for(int j=ColumnCounter[MatrixNr];j--;)225 Matrix[MatrixNr][ RowCounter[MatrixNr] ][j] = 0.;226 167 } 227 168 } else { 228 DoeLog(1) && (eLog()<< Verbose(1) << "Matrix nr. " << MatrixNr << " has column and row count of (" << ColumnCounter[MatrixNr] << "," << RowCounter[MatrixNr] << "), could not allocate nor parse!" << endl); 229 } 169 ELOG(1, "Matrix nr. " << MatrixNr << " has column and row count of (" << ColumnCounter[MatrixNr] << "," << RowCounter[MatrixNr] << "), could not allocate nor parse!"); 170 return false; 171 } 172 173 // parse in each entry for this matrix 174 input.clear(); 175 input.seekg(ios::beg); 176 for (int m=skiplines+1;m--;) 177 input.getline(dummy, 1023); // skip header 178 line.str(dummy); 179 Log() << Verbose(0) << "Header: " << line.str() << endl; 180 for(int k=skipcolumns;k--;) // skip columns in header too 181 line >> filename; 182 Header[MatrixNr] = line.str(); 183 for(int j=0;j<RowCounter[MatrixNr];j++) { 184 input.getline(filename, 1023); 185 stringstream lines(filename); 186 Log() << Verbose(2) << "Matrix at level " << j << ":";// << filename << endl; 187 for(int k=skipcolumns;k--;) 188 lines >> filename; 189 for(int k=0;(k<ColumnCounter[MatrixNr]) && (!lines.eof());k++) { 190 lines >> Matrix[MatrixNr][j][k]; 191 Log() << Verbose(1) << " " << std::setprecision(2) << Matrix[MatrixNr][j][k] << endl; 192 } 193 } 194 230 195 return true; 231 196 }; … … 249 214 * \return parsing successful 250 215 */ 251 bool MatrixContainer::ParseFragmentMatrix(const char *name, const char *prefix,string suffix, int skiplines, int skipcolumns)216 bool MatrixContainer::ParseFragmentMatrix(const std::string name, const std::string prefix, std::string suffix, int skiplines, int skipcolumns) 252 217 { 253 218 char filename[1023]; … … 274 239 275 240 DoLog(0) && (Log() << Verbose(0) << "Parsing through each fragment and retrieving " << prefix << suffix << "." << endl); 276 delete[](Header); 277 delete[](Matrix); 278 delete[](RowCounter); 279 delete[](ColumnCounter); 280 Header = new char*[MatrixCounter + 1]; // one more each for the total molecule 281 Matrix = new double**[MatrixCounter + 1]; // one more each for the total molecule 282 RowCounter = new int[MatrixCounter + 1]; 283 ColumnCounter = new int[MatrixCounter + 1]; 284 for(int i=MatrixCounter+1;i--;) { 285 Matrix[i] = NULL; 286 Header[i] = NULL; 287 RowCounter[i] = -1; 288 ColumnCounter[i] = -1; 289 } 241 Header.clear(); 242 Matrix.clear(); 243 RowCounter.clear(); 244 ColumnCounter.clear(); 245 Header.resize(MatrixCounter + 1); // one more each for the total molecule 246 Matrix.resize(MatrixCounter + 1); // one more each for the total molecule 247 RowCounter.resize(MatrixCounter + 1); 248 ColumnCounter.resize(MatrixCounter + 1); 290 249 for(int i=0; i < MatrixCounter;i++) { 291 250 // open matrix file … … 312 271 * \return Allocation successful 313 272 */ 314 bool MatrixContainer::AllocateMatrix( char **GivenHeader, int MCounter, int *RCounter, int *CCounter)273 bool MatrixContainer::AllocateMatrix(StringVector GivenHeader, int MCounter, IntVector RCounter, IntVector CCounter) 315 274 { 316 275 MatrixCounter = MCounter; 317 Header = new char*[MatrixCounter + 1];318 Matrix = new double**[MatrixCounter + 1]; // one more each for the total molecule319 RowCounter = new int[MatrixCounter + 1];320 ColumnCounter = new int[MatrixCounter + 1];276 Header.resize(MatrixCounter + 1); 277 Matrix.resize(MatrixCounter + 1); // one more each for the total molecule 278 RowCounter.resize(MatrixCounter + 1); 279 ColumnCounter.resize(MatrixCounter + 1); 321 280 for(int i=MatrixCounter+1;i--;) { 322 Header[i] = new char[1024]; 323 strncpy(Header[i], GivenHeader[i], 1023); 281 Header[i] = GivenHeader[i]; 324 282 RowCounter[i] = RCounter[i]; 325 283 ColumnCounter[i] = CCounter[i]; 326 Matrix[i] = new double*[RowCounter[i] + 1];327 for(int j=RowCounter[i]+1;j--;) {328 Matrix[i][j] = new double[ColumnCounter[i]];329 for(int k=ColumnCounter[i];k--;)330 Matrix[i][j] [k] = 0.;331 }284 if (Matrix[i].size() <= RowCounter[i] + 2) 285 Matrix[i].resize(RowCounter[i] + 1); 286 for(int j=0;j<=RowCounter[i];j++) 287 if (Matrix[i][j].size() <= ColumnCounter[i]+1) 288 Matrix[i][j].resize(ColumnCounter[i]); 289 // allocation with 0 is guaranted by STL 332 290 } 333 291 return true; … … 396 354 * \return true if successful 397 355 */ 398 bool MatrixContainer::SetLastMatrix( double **values, int skipcolumns)356 bool MatrixContainer::SetLastMatrix(const MatrixArray &values, int skipcolumns) 399 357 { 400 358 for(int j=RowCounter[MatrixCounter]+1;j--;) … … 466 424 * \return file was written 467 425 */ 468 bool MatrixContainer::WriteTotalFragments(const char *name, const char *prefix)426 bool MatrixContainer::WriteTotalFragments(const std::string name, const std::string prefix) 469 427 { 470 428 ofstream output; … … 500 458 * \return file was written 501 459 */ 502 bool MatrixContainer::WriteLastMatrix(const char *name, const char *prefix, const char *suffix)460 bool MatrixContainer::WriteLastMatrix(const std::string name, const std::string prefix, const std::string suffix) 503 461 { 504 462 ofstream output;
Note:
See TracChangeset
for help on using the changeset viewer.