Changeset eeec8f for src/parser.cpp
- Timestamp:
- Oct 19, 2008, 1:57:23 PM (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:
- 84fc91
- Parents:
- f731ae
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/parser.cpp
rf731ae reeec8f 56 56 MatrixContainer::MatrixContainer() { 57 57 Indices = NULL; 58 Header = (char * ) Malloc(sizeof(char)*1023, "MatrixContainer::MatrixContainer:*Header");58 Header = (char **) Malloc(sizeof(char)*1, "MatrixContainer::MatrixContainer: **Header"); 59 59 Matrix = (double ***) Malloc(sizeof(double **)*(1), "MatrixContainer::MatrixContainer: ***Matrix"); // one more each for the total molecule 60 60 RowCounter = (int *) Malloc(sizeof(int)*(1), "MatrixContainer::MatrixContainer: *RowCounter"); 61 61 ColumnCounter = (int *) Malloc(sizeof(int)*(1), "MatrixContainer::MatrixContainer: *ColumnCounter"); 62 Header[0] = NULL; 62 63 Matrix[0] = NULL; 63 64 RowCounter[0] = -1; … … 90 91 Free((void **)&Indices, "MatrixContainer::~MatrixContainer: **Indices"); 91 92 92 Free((void **)&Header, "MatrixContainer::~MatrixContainer: *Header"); 93 if (Header != NULL) 94 for(int i=MatrixCounter+1;i--;) 95 Free((void **)&Header[i], "MatrixContainer::~MatrixContainer: *Header[]"); 96 Free((void **)&Header, "MatrixContainer::~MatrixContainer: **Header"); 93 97 Free((void **)&RowCounter, "MatrixContainer::~MatrixContainer: *RowCounter"); 94 98 Free((void **)&ColumnCounter, "MatrixContainer::~MatrixContainer: *RowCounter"); … … 120 124 return false; 121 125 Indices[i] = (int *) Malloc(sizeof(int)*Matrix->RowCounter[i], "MatrixContainer::InitialiseIndices: *Indices[]"); 122 for(int j=Matrix->RowCounter[i];j--;) 126 for(int j=Matrix->RowCounter[i];j--;) { 123 127 Indices[i][j] = Matrix->Indices[i][j]; 128 //cout << Indices[i][j] << "\t"; 129 } 130 //cout << endl; 124 131 } 125 132 } … … 153 160 return false; 154 161 } 155 156 // skip some initial lines 162 163 // parse header 164 Header[MatrixNr] = (char *) Malloc(sizeof(char)*1024, "MatrixContainer::ParseMatrix: *Header[]"); 157 165 for (int m=skiplines+1;m--;) 158 input.getline(Header , 1023);166 input.getline(Header[MatrixNr], 1023); 159 167 160 168 // scan header for number of columns 161 line.str(Header );169 line.str(Header[MatrixNr]); 162 170 for(int k=skipcolumns;k--;) 163 line >> Header ;171 line >> Header[MatrixNr]; 164 172 //cout << line.str() << endl; 165 173 ColumnCounter[MatrixNr]=0; … … 169 177 } 170 178 //cout << line.str() << endl; 171 cout << "ColumnCounter[" << MatrixNr << "]: " << ColumnCounter[MatrixNr] << "." << endl;179 //cout << "ColumnCounter[" << MatrixNr << "]: " << ColumnCounter[MatrixNr] << "." << endl; 172 180 if (ColumnCounter[MatrixNr] == 0) 173 181 cerr << "ColumnCounter[" << MatrixNr << "]: " << ColumnCounter[MatrixNr] << " from file " << name << ", this is probably an error!" << endl; … … 183 191 } 184 192 } 185 cout << "RowCounter[" << MatrixNr << "]: " << RowCounter[MatrixNr] << " from file " << name << "." << endl;193 //cout << "RowCounter[" << MatrixNr << "]: " << RowCounter[MatrixNr] << " from file " << name << "." << endl; 186 194 if (RowCounter[MatrixNr] == 0) 187 195 cerr << "RowCounter[" << MatrixNr << "]: " << RowCounter[MatrixNr] << " from file " << name << ", this is probably an error!" << endl; … … 189 197 // allocate matrix if it's not zero dimension in one direction 190 198 if ((ColumnCounter[MatrixNr] > 0) && (RowCounter[MatrixNr] > -1)) { 191 Matrix[MatrixNr] = (double **) Malloc(sizeof(double *)*(RowCounter[MatrixNr]+1), "MatrixContainer::Parse FragmentMatrix: **Matrix[]");199 Matrix[MatrixNr] = (double **) Malloc(sizeof(double *)*(RowCounter[MatrixNr]+1), "MatrixContainer::ParseMatrix: **Matrix[]"); 192 200 193 201 // parse in each entry for this matrix … … 195 203 input.seekg(ios::beg); 196 204 for (int m=skiplines+1;m--;) 197 input.getline(Header , 1023); // skip header198 line.str(Header );205 input.getline(Header[MatrixNr], 1023); // skip header 206 line.str(Header[MatrixNr]); 199 207 for(int k=skipcolumns;k--;) // skip columns in header too 200 208 line >> filename; 201 strncpy(Header , line.str().c_str(), 1023);209 strncpy(Header[MatrixNr], line.str().c_str(), 1023); 202 210 for(int j=0;j<RowCounter[MatrixNr];j++) { 203 Matrix[MatrixNr][j] = (double *) Malloc(sizeof(double)*ColumnCounter[MatrixNr], "MatrixContainer::Parse FragmentMatrix: *Matrix[][]");211 Matrix[MatrixNr][j] = (double *) Malloc(sizeof(double)*ColumnCounter[MatrixNr], "MatrixContainer::ParseMatrix: *Matrix[][]"); 204 212 input.getline(filename, 1023); 205 213 stringstream lines(filename); … … 212 220 } 213 221 //cout << endl; 214 Matrix[MatrixNr][ RowCounter[MatrixNr] ] = (double *) Malloc(sizeof(double)*ColumnCounter[MatrixNr], "MatrixContainer::Parse FragmentMatrix: *Matrix[RowCounter[MatrixNr]][]");222 Matrix[MatrixNr][ RowCounter[MatrixNr] ] = (double *) Malloc(sizeof(double)*ColumnCounter[MatrixNr], "MatrixContainer::ParseMatrix: *Matrix[RowCounter[MatrixNr]][]"); 215 223 for(int j=ColumnCounter[MatrixNr];j--;) 216 224 Matrix[MatrixNr][ RowCounter[MatrixNr] ][j] = 0.; … … 266 274 267 275 cout << "Parsing through each fragment and retrieving " << prefix << suffix << "." << endl; 276 Header = (char **) ReAlloc(Header, sizeof(char *)*(MatrixCounter+1), "MatrixContainer::ParseFragmentMatrix: **Header"); // one more each for the total molecule 268 277 Matrix = (double ***) ReAlloc(Matrix, sizeof(double **)*(MatrixCounter+1), "MatrixContainer::ParseFragmentMatrix: ***Matrix"); // one more each for the total molecule 269 278 RowCounter = (int *) ReAlloc(RowCounter, sizeof(int)*(MatrixCounter+1), "MatrixContainer::ParseFragmentMatrix: *RowCounter"); … … 271 280 for(int i=MatrixCounter+1;i--;) { 272 281 Matrix[i] = NULL; 282 Header[i] = NULL; 273 283 RowCounter[i] = -1; 274 284 ColumnCounter[i] = -1; … … 287 297 288 298 /** Allocates and resets the memory for a number \a MCounter of matrices. 289 * \param * GivenHeader Header line299 * \param **GivenHeader Header line for each matrix 290 300 * \param MCounter number of matrices 291 301 * \param *RCounter number of rows for each matrix 292 * \param *CCounter number of columns for each matri ces302 * \param *CCounter number of columns for each matrix 293 303 * \return Allocation successful 294 304 */ 295 bool MatrixContainer::AllocateMatrix(char *GivenHeader, int MCounter, int *RCounter, int *CCounter) 296 { 297 Header = (char *) Malloc(sizeof(char)*1024, "MatrixContainer::ParseFragmentMatrix: *EnergyHeader"); 298 strncpy(Header, GivenHeader, 1023); 299 305 bool MatrixContainer::AllocateMatrix(char **GivenHeader, int MCounter, int *RCounter, int *CCounter) 306 { 300 307 MatrixCounter = MCounter; 301 Matrix = (double ***) Malloc(sizeof(double **)*(MatrixCounter+1), "MatrixContainer::ParseFragmentMatrix: ***Matrix"); // one more each for the total molecule 302 RowCounter = (int *) Malloc(sizeof(int)*(MatrixCounter+1), "MatrixContainer::ParseFragmentMatrix: *RowCounter"); 303 ColumnCounter = (int *) Malloc(sizeof(int)*(MatrixCounter+1), "MatrixContainer::ParseFragmentMatrix: *ColumnCounter"); 308 Header = (char **) Malloc(sizeof(char *)*(MatrixCounter+1), "MatrixContainer::AllocateMatrix: *Header"); 309 Matrix = (double ***) Malloc(sizeof(double **)*(MatrixCounter+1), "MatrixContainer::AllocateMatrix: ***Matrix"); // one more each for the total molecule 310 RowCounter = (int *) Malloc(sizeof(int)*(MatrixCounter+1), "MatrixContainer::AllocateMatrix: *RowCounter"); 311 ColumnCounter = (int *) Malloc(sizeof(int)*(MatrixCounter+1), "MatrixContainer::AllocateMatrix: *ColumnCounter"); 304 312 for(int i=MatrixCounter+1;i--;) { 313 Header[i] = (char *) Malloc(sizeof(char)*1024, "MatrixContainer::AllocateMatrix: *Header[i]"); 314 strncpy(Header[i], GivenHeader[i], 1023); 305 315 RowCounter[i] = RCounter[i]; 306 316 ColumnCounter[i] = CCounter[i]; 307 Matrix[i] = (double **) Malloc(sizeof(double *)*(RowCounter[i]+1), "MatrixContainer:: ParseFragmentMatrix: **Matrix[]");317 Matrix[i] = (double **) Malloc(sizeof(double *)*(RowCounter[i]+1), "MatrixContainer::AllocateMatrix: **Matrix[]"); 308 318 for(int j=RowCounter[i]+1;j--;) { 309 Matrix[i][j] = (double *) Malloc(sizeof(double)*ColumnCounter[i], "MatrixContainer:: ParseFragmentMatrix: *Matrix[][]");319 Matrix[i][j] = (double *) Malloc(sizeof(double)*ColumnCounter[i], "MatrixContainer::AllocateMatrix: *Matrix[][]"); 310 320 for(int k=ColumnCounter[i];k--;) 311 321 Matrix[i][j][k] = 0.; … … 385 395 }; 386 396 387 /** Sums the en ergy with each factor and put into last element of \a ***Energies.397 /** Sums the entries with each factor and put into last element of \a ***Matrix. 388 398 * Sums over "E"-terms to create the "F"-terms 389 399 * \param Matrix MatrixContainer with matrices (LevelCounter by *ColumnCounter) with all the energies. … … 462 472 return false; 463 473 } 464 output << Header << endl;474 output << Header[i] << endl; 465 475 for(int j=0;j<RowCounter[i];j++) { 466 476 for(int k=0;k<ColumnCounter[i];k++) … … 491 501 return false; 492 502 } 493 output << Header << endl;503 output << Header[MatrixCounter] << endl; 494 504 for(int j=0;j<RowCounter[MatrixCounter];j++) { 495 505 for(int k=0;k<ColumnCounter[MatrixCounter];k++) … … 765 775 int j = Indices[ FragmentNr ][l]; 766 776 if (j > RowCounter[MatrixCounter]) { 767 cerr << "Current hessian index " << j << " is greater than " << RowCounter[MatrixCounter] << " !" << endl;777 cerr << "Current hessian index " << j << " is greater than " << RowCounter[MatrixCounter] << ", where i=" << i << ", Order=" << Order << ", l=" << l << " and FragmentNr=" << FragmentNr << "!" << endl; 768 778 return false; 769 779 } … … 772 782 int k = Indices[ FragmentNr ][m]; 773 783 if (k > ColumnCounter[MatrixCounter]) { 774 cerr << "Current hessian index " << k << " is greater than " << ColumnCounter[MatrixCounter] << " !" << endl;784 cerr << "Current hessian index " << k << " is greater than " << ColumnCounter[MatrixCounter] << ", where m=" << m << ", j=" << j << ", i=" << i << ", Order=" << Order << ", l=" << l << " and FragmentNr=" << FragmentNr << "!" << endl; 775 785 return false; 776 786 } … … 785 795 }; 786 796 797 /** Constructor for class HessianMatrix. 798 */ 799 HessianMatrix::HessianMatrix() : MatrixContainer() 800 { 801 IsSymmetric = true; 802 } 803 804 /** Sums the hessian entries with each factor and put into last element of \a ***Matrix. 805 * Sums over "E"-terms to create the "F"-terms 806 * \param Matrix MatrixContainer with matrices (LevelCounter by *ColumnCounter) with all the energies. 807 * \param KeySet KeySetContainer with bond Order and association mapping of each fragment to an order 808 * \param Order bond order 809 * \return true if summing was successful 810 */ 811 bool HessianMatrix::SumSubManyBodyTerms(class MatrixContainer &MatrixValues, class KeySetsContainer &KeySet, int Order) 812 { 813 // go through each order 814 for (int CurrentFragment=0;CurrentFragment<KeySet.FragmentsPerOrder[Order];CurrentFragment++) { 815 //cout << "Current Fragment is " << CurrentFragment << "/" << KeySet.OrderSet[Order][CurrentFragment] << "." << endl; 816 // then go per order through each suborder and pick together all the terms that contain this fragment 817 for(int SubOrder=0;SubOrder<=Order;SubOrder++) { // go through all suborders up to the desired order 818 for (int j=0;j<KeySet.FragmentsPerOrder[SubOrder];j++) { // go through all possible fragments of size suborder 819 if (KeySet.Contains(KeySet.OrderSet[Order][CurrentFragment], KeySet.OrderSet[SubOrder][j])) { 820 //cout << "Current other fragment is " << j << "/" << KeySet.OrderSet[SubOrder][j] << "." << endl; 821 // if the fragment's indices are all in the current fragment 822 for(int k=0;k<RowCounter[ KeySet.OrderSet[SubOrder][j] ];k++) { // go through all atoms in this fragment 823 int m = MatrixValues.Indices[ KeySet.OrderSet[SubOrder][j] ][k]; 824 //cout << "Current row index is " << k << "/" << m << "." << endl; 825 if (m != -1) { // if it's not an added hydrogen 826 for (int l=0;l<RowCounter[ KeySet.OrderSet[Order][CurrentFragment] ];l++) { // look for the corresponding index in the current fragment 827 //cout << "Comparing " << m << " with " << MatrixValues.Indices[ KeySet.OrderSet[Order][CurrentFragment] ][l] << "." << endl; 828 if (m == MatrixValues.Indices[ KeySet.OrderSet[Order][CurrentFragment] ][l]) { 829 m = l; 830 break; 831 } 832 } 833 //cout << "Corresponding row index for " << k << " in CurrentFragment is " << m << "." << endl; 834 if (m > RowCounter[ KeySet.OrderSet[Order][CurrentFragment] ]) { 835 cerr << "In fragment No. " << KeySet.OrderSet[Order][CurrentFragment] << " current row index " << m << " is greater than " << RowCounter[ KeySet.OrderSet[Order][CurrentFragment] ] << "!" << endl; 836 return false; 837 } 838 839 for(int l=0;l<ColumnCounter[ KeySet.OrderSet[SubOrder][j] ];l++) { 840 int n = MatrixValues.Indices[ KeySet.OrderSet[SubOrder][j] ][l]; 841 //cout << "Current column index is " << l << "/" << n << "." << endl; 842 if (n != -1) { // if it's not an added hydrogen 843 for (int p=0;p<ColumnCounter[ KeySet.OrderSet[Order][CurrentFragment] ];p++) { // look for the corresponding index in the current fragment 844 //cout << "Comparing " << n << " with " << MatrixValues.Indices[ KeySet.OrderSet[Order][CurrentFragment] ][p] << "." << endl; 845 if (n == MatrixValues.Indices[ KeySet.OrderSet[Order][CurrentFragment] ][p]) { 846 n = p; 847 break; 848 } 849 } 850 //cout << "Corresponding column index for " << l << " in CurrentFragment is " << n << "." << endl; 851 if (n > ColumnCounter[ KeySet.OrderSet[Order][CurrentFragment] ]) { 852 cerr << "In fragment No. " << KeySet.OrderSet[Order][CurrentFragment] << " current column index " << n << " is greater than " << ColumnCounter[ KeySet.OrderSet[Order][CurrentFragment] ] << "!" << endl; 853 return false; 854 } 855 if (Order == SubOrder) { // equal order is always copy from Energies 856 Matrix[ KeySet.OrderSet[Order][CurrentFragment] ][m][n] += MatrixValues.Matrix[ KeySet.OrderSet[SubOrder][j] ][k][l]; 857 } else { 858 Matrix[ KeySet.OrderSet[Order][CurrentFragment] ][m][n] -= Matrix[ KeySet.OrderSet[SubOrder][j] ][k][l]; 859 } 860 } 861 } 862 } 863 //if ((ColumnCounter[ KeySet.OrderSet[SubOrder][j] ]>1) && (RowCounter[0]-1 >= 1)) 864 //cout << "Fragments[ KeySet.OrderSet[" << Order << "][" << CurrentFragment << "]=" << KeySet.OrderSet[Order][CurrentFragment] << " ][" << RowCounter[0]-1 << "][" << 1 << "] = " << Matrix[ KeySet.OrderSet[Order][CurrentFragment] ][RowCounter[0]-1][1] << endl; 865 } 866 } else { 867 //cout << "Fragment " << KeySet.OrderSet[SubOrder][j] << " is not contained in fragment " << KeySet.OrderSet[Order][CurrentFragment] << "." << endl; 868 } 869 } 870 } 871 //cout << "Final Fragments[ KeySet.OrderSet[" << Order << "][" << CurrentFragment << "]=" << KeySet.OrderSet[Order][CurrentFragment] << " ][" << KeySet.AtomCounter[0]-1 << "][" << 1 << "] = " << Matrix[ KeySet.OrderSet[Order][CurrentFragment] ][KeySet.AtomCounter[0]-1][1] << endl; 872 } 873 874 return true; 875 }; 787 876 788 877 /** Calls MatrixContainer::ParseFragmentMatrix() and additionally allocates last plus one matrix.
Note:
See TracChangeset
for help on using the changeset viewer.