Changeset 390248


Ignore:
Timestamp:
Jul 24, 2008, 2:00:19 PM (16 years ago)
Author:
Frederik Heber <heber@…>
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:
958457
Parents:
c685eb
Message:

BIG change: Hcorrection included and bugfix of analyzer (wrt forces)

  • Hcorrection is supplied via molecuilder which gives correction values if hydrogen atoms are to close and thus already feel each other's influence. This correction energy matrix is also parsed ans subtracted from the approximated energy matrix generated from the fragments. This impacts both on joiner, analyzer and molecuilder
  • Forces were not working which had multiple causes:
    • first, we stepped back down to absolute errors which rather gives a feel about convergence (1e-6 is simply small and neglegible)
    • there may have been bugs where (either in Force or in ForceFragments) adding up took place, this is cleaned up
    • more routines have been abstracted from analyzer into datacreator functions
      • the order of ions had changed, re-run with current molecuilder, calculation and subsequent joining/analyzing brought correct results finally
  • plots were bad still due to wrong axes (two more functions finding max/min values), use of wrong columns in plot file
Location:
src
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • src/analyzer.cpp

    rc685eb r390248  
    2525  periodentafel *periode = NULL; // and a period table of all elements
    2626  EnergyMatrix Energy;
     27  EnergyMatrix Hcorrection;
    2728  ForceMatrix Force;
    2829  ForceMatrix Shielding;
     
    3031  MatrixContainer Time;
    3132  EnergyMatrix EnergyFragments;
     33  EnergyMatrix HcorrectionFragments;
    3234  ForceMatrix ForceFragments;
    3335  ForceMatrix ShieldingFragments;
     
    4547  stringstream Orderxrange;
    4648  stringstream Fragmentxrange;
    47 
     49  stringstream yrange;
     50  char *dir = NULL;
     51  bool Hcorrected = true;
     52  double norm;
     53 
    4854  cout << "ANOVA Analyzer" << endl;
    4955  cout << "==============" << endl;
     
    5763    cout << "[elementsdb]\tpath to elements database, needed for shieldings." << endl;
    5864    return 1;
    59   }
     65  } else {
     66    dir = (char *) Malloc(sizeof(char)*(strlen(argv[2])+2), "main: *dir");
     67    strcpy(dir, "/");
     68    strcat(dir, argv[2]);
     69  }
     70 
    6071  if (argc > 4) {
    6172    cout << "Loading periodentafel." << endl;
     
    7182 
    7283  // ------------- Parse through all Fragment subdirs --------
    73   if (!Energy.ParseMatrix(argv[1], argv[2], EnergySuffix,0,0)) return 1;
    74   if (!Force.ParseMatrix(argv[1], argv[2], ForcesSuffix,0,0)) return 1;
    75   if (!Time.ParseMatrix(argv[1], argv[2], 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;
    7688  if (periode != NULL) { // also look for PAS values
    77     if (!Shielding.ParseMatrix(argv[1], argv[2], ShieldingSuffix, 1, 0)) return 1;
    78     if (!ShieldingPAS.ParseMatrix(argv[1], argv[2], 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;
    7991  }
    8092
    8193  // ---------- Parse the TE Factors into an array -----------------
    8294  if (!Energy.ParseIndices()) return 1;
     95  if (Hcorrected) Hcorrection.ParseIndices();
    8396 
    8497  // ---------- Parse the Force indices into an array ---------------
    8598  if (!Force.ParseIndices(argv[1])) return 1;
     99  if (!ForceFragments.AllocateMatrix(Force.Header, Force.MatrixCounter, Force.RowCounter, Force.ColumnCounter)) return 1;
     100  if (!ForceFragments.ParseIndices(argv[1])) return 1;
    86101
    87102  // ---------- Parse the shielding indices into an array ---------------
     
    96111 
    97112  // ---------- Parse fragment files created by 'joiner' into an array -------------
    98   if (!EnergyFragments.ParseMatrix(argv[1], argv[2], EnergyFragmentSuffix,0,0)) return 1;
    99   if (!ForceFragments.ParseMatrix(argv[1], argv[2], 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;
    100116  if (periode != NULL) { // also look for PAS values
    101     if (!ShieldingFragments.ParseMatrix(argv[1], argv[2], ShieldingSuffix, 1, 0)) return 1;
    102     if (!ShieldingPASFragments.ParseMatrix(argv[1], argv[2], 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;
    103119  }
    104120
     
    143159  }
    144160 
    145   output << endl << "Total Times" << endl << "===============" << endl << Time.Header << endl;
    146   Time.SetLastMatrix(0., 0);
    147   for (int BondOrder=KeySet.Order;BondOrder--;)
    148     for(int i=KeySet.FragmentsPerOrder[BondOrder];i--;)
    149       for(int j=Time.RowCounter[Time.MatrixCounter];j--;)
    150         for(int k=Time.ColumnCounter;k--;) {
    151           Time.Matrix[ Time.MatrixCounter ][j][k] += Time.Matrix[ KeySet.OrderSet[BondOrder][i] ][j][k];
    152         }
    153   for(int j=0;j<Time.RowCounter[Time.MatrixCounter];j++) {
    154     for(int k=0;k<Time.ColumnCounter;k++)
    155       output << scientific << Time.Matrix[ Time.MatrixCounter ][j][k] << "\t";
    156     output << endl;
    157   }
    158   output << endl;
     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//        }
     169//  for(int j=0;j<Time.RowCounter[Time.MatrixCounter];j++) {
     170//    for(int k=0;k<Time.ColumnCounter;k++)
     171//      output << scientific << Time.Matrix[ Time.MatrixCounter ][j][k] << "\t";
     172//    output << endl;
     173//  }
     174//  output << endl;
    159175  output.close();
    160176
     
    165181  // ======================================= Creating the data files ==============================================================
    166182
    167   // +++++++++++++++++++++++++++++++++++++++ Plotting Simtime vs Bond Order
    168   if (!OpenOutputFile(output, argv[3], "SimTime-Order.dat" )) return false;
    169   Time.SetLastMatrix(0., 0);
    170   output << "#Order\tFrag.No.\t" << Time.Header << endl;
    171   for (int BondOrder=0;BondOrder<KeySet.Order;BondOrder++) {
    172     for(int i=KeySet.FragmentsPerOrder[BondOrder];i--;)
    173       for(int j=Time.RowCounter[Time.MatrixCounter];j--;)
    174         for(int k=Time.ColumnCounter;k--;) {
    175           Time.Matrix[ Time.MatrixCounter ][j][k] += Time.Matrix[ KeySet.OrderSet[BondOrder][i] ][j][k];
    176         }
    177     output << BondOrder+1 << "\t" << KeySet.FragmentsPerOrder[BondOrder];
    178     for(int k=0;k<Time.ColumnCounter;k++)
    179       output << "\t" << scientific << Time.Matrix[ Time.MatrixCounter ][1][k];
    180     output << endl;
    181   }
    182   output.close();
     183//  // +++++++++++++++++++++++++++++++++++++++ Plotting Simtime vs Bond Order
     184//  if (!OpenOutputFile(output, argv[3], "SimTime-Order.dat" )) return false;
     185//  Time.SetLastMatrix(0., 0);
     186//  output << "#Order\tFrag.No.\t" << Time.Header << endl;
     187//  for (int BondOrder=0;BondOrder<KeySet.Order;BondOrder++) {
     188//    for(int i=KeySet.FragmentsPerOrder[BondOrder];i--;)
     189//      for(int j=Time.RowCounter[Time.MatrixCounter];j--;)
     190//        for(int k=Time.ColumnCounter;k--;) {
     191//          Time.Matrix[ Time.MatrixCounter ][j][k] += Time.Matrix[ KeySet.OrderSet[BondOrder][i] ][j][k];
     192//        }
     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;
     197//  }
     198//  output.close();
    183199
    184200  // +++++++++++++++++++++++++++++++++++++++ Plotting deviation in energy to full QM
    185   if (!EnergyFragments.SetLastMatrix(Energy.Matrix[Energy.MatrixCounter],0)) return 1;
    186   if (!CreateDataEnergyOrder(Energy, EnergyFragments, KeySet, argv[3], "DeltaEnergies-Order", "Plot of error between approximated and full energies energies versus the Bond Order", datum)) return 1;
     201  if (!CreateDataDeltaEnergyOrder(Energy, EnergyFragments, KeySet, argv[3], "DeltaEnergies-Order", "Plot of error between approximated and full energies energies versus the Bond Order", datum)) return 1;
    187202 
    188203  // +++++++++++++++++++++++++++++++++++Plotting Energies vs. Order
    189   if (!EnergyFragments.SetLastMatrix(1.,0)) return 1;
    190   if (!CreateDataEnergyOrder(Energy, EnergyFragments, KeySet, argv[3], "Energies-Order", "Plot of approximated energies versus the Bond Order", datum)) return 1;
     204  if (!CreateDataEnergyOrder(EnergyFragments, KeySet, argv[3], "Energies-Order", "Plot of approximated energies versus the Bond Order", datum)) return 1;
    191205 
    192206  // +++++++++++++++++++++++++++++++++++++++ Plotting deviation in forces to full QM
    193   if (!ForceFragments.SetLastMatrix(Force.Matrix[Force.MatrixCounter],0)) return 1;
    194   if (!OpenOutputFile(output, argv[3], "DeltaForces-Order.dat" )) return false;
    195   if (!OpenOutputFile(output2, argv[3], "DeltaMinForces-Order.dat" )) return false;
    196   if (!OpenOutputFile(output3, argv[3], "DeltaMeanForces-Order.dat" )) return false;
    197   if (!OpenOutputFile(output4, argv[3], "DeltaMaxForces-Order.dat" )) return false;
    198   cout << "Plot of per atom and min/mean/max error between approximated forces and full forces versus the Bond Order ... " << endl;
    199   output << "# Plot of error between approximated forces and full forces versus the Bond Order, created on " << datum;
    200   output << "# AtomNo" << Force.Header << endl;
    201   output2 << "# Plot of min error between approximated forces and full forces versus the Bond Order, created on " << datum;
    202   output2 << "# Order\tFrag.No.\t" << Force.Header << endl;
    203   output3 << "# Plot of mean error between approximated forces and full forces versus the Bond Order, created on " << datum;
    204   output3 << "# Order\tFrag.No.\t" << Force.Header << endl;
    205   output4 << "# Plot of max error between approximated forces and full forces versus the Bond Order, created on " << datum;
    206   output4 << "# Order\tFrag.No.\t" << Force.Header << endl;
    207   int FragmentCounter = 0;
    208   for (int BondOrder=0;BondOrder<KeySet.Order;BondOrder++) {
    209     for(int i=0;i<KeySet.FragmentsPerOrder[BondOrder];i++) {
    210       for(int l=0;l<Force.RowCounter[ KeySet.OrderSet[BondOrder][i] ];l++) {
    211         int j = Force.Indices[ KeySet.OrderSet[BondOrder][i] ][l];
    212         if (j > Force.RowCounter[Force.MatrixCounter]) {
    213           cerr << "Current force index " << j << " is greater than " << Force.RowCounter[Force.MatrixCounter] << "!" << endl;
    214           return 1;
    215         }
    216         if (j != -1)
    217           for(int k=0;k<Force.ColumnCounter;k++) {
    218             Force.Matrix[Force.MatrixCounter][j][k] -= ForceFragments.Matrix[ KeySet.OrderSet[BondOrder][i] ][l][k];
    219           }
    220       }
    221       FragmentCounter++;
    222     }
    223     // errors per atom
    224     output << "#Order\t" << BondOrder+1 << endl;
    225     for(int j=0;j<Force.RowCounter[ Force.MatrixCounter ];j++) {
    226       output << Force.Indices[Force.MatrixCounter][j] << "\t";
    227       for (int l=0;l<Force.ColumnCounter;l++)
    228         if (fabs(ForceFragments.Matrix[ForceFragments.MatrixCounter][ j ][l]) < MYEPSILON)
    229           output << scientific << Force.Matrix[Force.MatrixCounter][ j ][l] << "\t";
    230         else
    231           output << scientific << (Force.Matrix[Force.MatrixCounter][ j ][l] / ForceFragments.Matrix[ForceFragments.MatrixCounter][ j ][l]) << "\t";
    232       output << endl;
    233     }
    234     output << endl;
    235    
    236     // min error
    237     output2 << BondOrder+1 << "\t" << FragmentCounter;
    238     CreateMinimumForce(Force, Force.MatrixCounter);
    239     for (int l=0;l<Force.ColumnCounter;l++)
    240       if (fabs(ForceFragments.Matrix[ForceFragments.MatrixCounter][ ForceFragments.RowCounter[ForceFragments.MatrixCounter] ][l]) < MYEPSILON)
    241         output2 << scientific << "\t" << Force.Matrix[Force.MatrixCounter][ Force.RowCounter[Force.MatrixCounter] ][l];
    242       else
    243         output2 << scientific << "\t" << (Force.Matrix[Force.MatrixCounter][ Force.RowCounter[Force.MatrixCounter] ][l] / ForceFragments.Matrix[ForceFragments.MatrixCounter][ ForceFragments.RowCounter[ForceFragments.MatrixCounter] ][l]);
    244     output2 << endl;
    245    
    246     // mean error
    247     output3 << BondOrder+1 << "\t" << FragmentCounter;
    248     CreateMeanForce(Force, Force.MatrixCounter);
    249     for (int l=0;l<Force.ColumnCounter;l++)
    250       if (fabs(ForceFragments.Matrix[ForceFragments.MatrixCounter][ ForceFragments.RowCounter[ForceFragments.MatrixCounter] ][l]) < MYEPSILON)
    251         output3 << scientific << "\t" << Force.Matrix[Force.MatrixCounter][ Force.RowCounter[Force.MatrixCounter] ][l];
    252       else
    253         output3 << scientific << "\t" << (Force.Matrix[Force.MatrixCounter][ Force.RowCounter[Force.MatrixCounter] ][l] / ForceFragments.Matrix[ForceFragments.MatrixCounter][ ForceFragments.RowCounter[ForceFragments.MatrixCounter] ][l]);
    254     output3 << endl;
    255    
    256     // max error
    257     output4 << BondOrder+1 << "\t" << FragmentCounter;
    258     CreateMaximumForce(Force, Force.MatrixCounter);
    259     for (int l=0;l<Force.ColumnCounter;l++)
    260       if (fabs(ForceFragments.Matrix[ForceFragments.MatrixCounter][ ForceFragments.RowCounter[ForceFragments.MatrixCounter] ][l]) < MYEPSILON)
    261         output4 << scientific << "\t" << Force.Matrix[Force.MatrixCounter][ Force.RowCounter[Force.MatrixCounter] ][l];
    262       else
    263         output4 << scientific << "\t" << (Force.Matrix[Force.MatrixCounter][ Force.RowCounter[Force.MatrixCounter] ][l] / ForceFragments.Matrix[ForceFragments.MatrixCounter][ ForceFragments.RowCounter[ForceFragments.MatrixCounter] ][l]);
    264     output4 << endl;
    265   }
    266   output.close();
    267   output2.close();
    268   output3.close();
    269   output4.close();
     207  if (!CreateDataDeltaForcesOrderPerAtom(Force, ForceFragments, KeySet, argv[3], "DeltaForces-Order", "Plot of error between approximated forces and full forces versus the Bond Order", datum)) return 1;
     208
     209  // min force
     210  if (!CreateDataDeltaForcesOrder(Force, ForceFragments, KeySet, argv[3], "DeltaMinForces-Order", "Plot of min error between approximated forces and full forces versus the Bond Order", datum, CreateMinimumForce)) return 1;
     211
     212  // mean force
     213  if (!CreateDataDeltaForcesOrder(Force, ForceFragments, KeySet, argv[3], "DeltaMeanForces-Order", "Plot of mean error between approximated forces and full forces versus the Bond Order", datum, CreateMeanForce)) return 1;
     214
     215  // max force
     216  if (!CreateDataDeltaForcesOrder(Force, ForceFragments, KeySet, argv[3], "DeltaMaxForces-Order", "Plot of max error between approximated forces and full forces versus the Bond Order", datum, CreateMaximumForce)) return 1;
    270217
    271218  // ++++++++++++++++++++++++++++++++++++++Plotting Forces vs. Order
    272   if(!OpenOutputFile(output, argv[3], "Forces-Order.dat")) return 1;
    273   cout << "Plot of approximated forces versus the Bond Order ... " << endl;
    274   output << "# Plot of approximated forces versus the Bond Order, created on " << datum;
    275   output << "# AtomNo" << Force.Header << endl;
    276   for (int BondOrder=0;BondOrder<KeySet.Order;BondOrder++) {
    277     for(int i=0;i<KeySet.FragmentsPerOrder[BondOrder];i++) {
    278       for(int l=0;l<Force.RowCounter[ KeySet.OrderSet[BondOrder][i] ];l++) {
    279         int j = Force.Indices[ KeySet.OrderSet[BondOrder][i] ][l];
    280         if (j > Force.RowCounter[Force.MatrixCounter]) {
    281           cerr << "Current force index " << j << " is greater than " << Force.RowCounter[Force.MatrixCounter] << "!" << endl;
    282           return 1;
    283         }
    284         if (j != -1)
    285           for(int k=0;k<Force.ColumnCounter;k++) {
    286             Force.Matrix[Force.MatrixCounter][j][k] -= ForceFragments.Matrix[ KeySet.OrderSet[BondOrder][i] ][l][k];
    287           }
    288       }
    289     }
    290     // errors per atom
    291     output << "#Order\t" << BondOrder+1 << endl;
    292     for(int j=0;j<Force.RowCounter[ Force.MatrixCounter ];j++) {
    293       output << Force.Indices[Force.MatrixCounter][j] << "\t";
    294       for (int l=0;l<Force.ColumnCounter;l++)
    295          output << Force.Matrix[Force.MatrixCounter][ j ][l] << "\t";
    296       output << endl;
    297     }
    298     output << endl;
    299   }
    300   output.close();
    301 
    302   // min force
    303   if (!CreateDataForcesOrder(Force, ForceFragments, KeySet, argv[3], "MinForces-Order", "Plot of min approximated forces versus the Bond Order", datum, CreateMinimumForce)) return 1;
    304 
    305   // mean force
    306   if (!CreateDataForcesOrder(Force, ForceFragments, KeySet, argv[3], "MeanForces-Order", "Plot of mean approximated forces versus the Bond Order", datum, CreateMeanForce)) return 1;
    307 
    308   // max force
    309   if (!CreateDataForcesOrder(Force, ForceFragments, KeySet, argv[3], "MaxForces-Order", "Plot of max approximated forces versus the Bond Order", datum, CreateMaximumForce)) return 1;
     219  if (!CreateDataForcesOrderPerAtom(ForceFragments, KeySet, argv[3], "Forces-Order", "Plot of approximated forces versus the Bond Order", datum)) return 1;
     220
     221  // min force
     222  if (!CreateDataForcesOrder(ForceFragments, KeySet, argv[3], "MinForces-Order", "Plot of min approximated forces versus the Bond Order", datum, CreateMinimumForce)) return 1;
     223
     224  // mean force
     225  if (!CreateDataForcesOrder(ForceFragments, KeySet, argv[3], "MeanForces-Order", "Plot of mean approximated forces versus the Bond Order", datum, CreateMeanForce)) return 1;
     226
     227  // max force
     228  if (!CreateDataForcesOrder(ForceFragments, KeySet, argv[3], "MaxForces-Order", "Plot of max approximated forces versus the Bond Order", datum, CreateMaximumForce)) return 1;
    310229
    311230  // ++++++++++++++++++++++++++++++++++++++Plotting vector sum (should be 0) vs. bond order
    312   if (!CreateDataForcesOrder(Force, ForceFragments, KeySet, argv[3], "VectorSum-Order", "Plot of vector sum of the approximated forces versus the Bond Order", datum, CreateVectorSumForce)) return 1;
     231  if (!CreateDataForcesOrder(ForceFragments, KeySet, argv[3], "VectorSum-Order", "Plot of vector sum of the approximated forces versus the Bond Order", datum, CreateVectorSumForce)) return 1;
    313232
    314233  // +++++++++++++++++++++++++++++++Plotting energyfragments vs. order
     
    342261  Orderxrange << "[1:" << KeySet.Order << "]";
    343262  Fragmentxrange << "[0:" << KeySet.FragmentCounter+1 << "]";
     263  yrange.str("[1e-8:1e+1]");
    344264 
    345265  // +++++++++++++++++++++++++++++++++++++++ Plotting Simtime vs Bond Order
    346   if (!CreatePlotOrder(Time, KeySet, argv[3], "SimTime-Order", 1, "below", "y", "",  1, 1, "bond order k", "Evaluation time [s]", Orderxrange.str().c_str(), "", "1" , "with linespoints", EnergyPlotLine)) return 1;
     266  //if (!CreatePlotOrder(Time, KeySet, argv[3], "SimTime-Order", 1, "below", "y", "",  1, 1, "bond order k", "Evaluation time [s]", Orderxrange.str().c_str(), "", "1" , "with linespoints", EnergyPlotLine)) return 1;
    347267 
    348268  // +++++++++++++++++++++++++++++++++++++++ Plotting deviation in energy to full QM
    349   if (!CreatePlotOrder(Energy, KeySet, argv[3], "DeltaEnergies-Order", 1, "outside", "y", "",  1, 1, "bond order k", "absolute error in energy [Ht]", Orderxrange.str().c_str(), "[1e-8:1e+1]", "1" , "with linespoints", AbsEnergyPlotLine)) return 1;
     269  if (!CreatePlotOrder(Energy, KeySet, argv[3], "DeltaEnergies-Order", 1, "outside", "y", "",  1, 1, "bond order k", "absolute error in energy [Ht]", Orderxrange.str().c_str(), yrange.str().c_str(), "1" , "with linespoints", AbsEnergyPlotLine)) return 1;
    350270 
    351271  // +++++++++++++++++++++++++++++++++++Plotting Energies vs. Order
     
    353273
    354274  // +++++++++++++++++++++++++++++++++++++++ Plotting deviation in forces to full QM
    355   // min force
    356   if (!CreatePlotOrder(Force, KeySet, argv[3], "DeltaMinForces-Order", 2, "top right", "y", "",  1, 1, "bond order k", "absolute error in min force [Ht/a.u.]", Orderxrange.str().c_str(), "[1e-8:1e+0]", "1" , "with linespoints", ForceMagnitudePlotLine)) return 1;
    357 
    358   // mean force
    359   if (!CreatePlotOrder(Force, KeySet, argv[3], "DeltaMeanForces-Order", 2, "top right", "y", "",  1, 1, "bond order k", "absolute error in mean force [Ht/a.u.]", Orderxrange.str().c_str(), "[1e-8:1e+0]", "1" , "with linespoints", AbsFirstForceValuePlotLine)) return 1;
    360 
    361   // max force
    362   if (!CreatePlotOrder(Force, KeySet, argv[3], "DeltaMaxForces-Order", 2, "top right", "y", "",  1, 1, "bond order k", "absolute error in max force [Ht/a.u.]", Orderxrange.str().c_str(), "[1e-8:1e+0]", "1" , "with linespoints", ForceMagnitudePlotLine)) return 1;
     275  yrange.str("[1e-8:1e+0]");
     276  // min force
     277  if (!CreatePlotOrder(Force, KeySet, argv[3], "DeltaMinForces-Order", 2, "top right", "y", "",  1, 1, "bond order k", "absolute error in min force [Ht/a.u.]", Orderxrange.str().c_str(), yrange.str().c_str(), "1" , "with linespoints", ForceMagnitudePlotLine)) return 1;
     278
     279  // mean force
     280  if (!CreatePlotOrder(Force, KeySet, argv[3], "DeltaMeanForces-Order", 2, "top right", "y", "",  1, 1, "bond order k", "absolute error in mean force [Ht/a.u.]", Orderxrange.str().c_str(), yrange.str().c_str(), "1" , "with linespoints", AbsFirstForceValuePlotLine)) return 1;
     281
     282  // max force
     283  if (!CreatePlotOrder(Force, KeySet, argv[3], "DeltaMaxForces-Order", 2, "top right", "y", "",  1, 1, "bond order k", "absolute error in max force [Ht/a.u.]", Orderxrange.str().c_str(), yrange.str().c_str(), "1" , "with linespoints", ForceMagnitudePlotLine)) return 1;
    363284
    364285  // min/mean/max comparison for total force
     
    395316
    396317  // +++++++++++++++++++++++++++++++Plotting energyfragments vs. order
    397   if (!CreatePlotOrder(EnergyFragments, KeySet, argv[3], "Energies-Fragment", 5, "below", "y", "", 1, 5, "fragment number", "Energies of each fragment [Ht]", Fragmentxrange.str().c_str(), "[1e-16:1e+1]", "2" , "with points", AbsEnergyPlotLine)) return 1;
    398   if (!CreatePlotOrder(EnergyFragments, KeySet, argv[3], "Energies-FragmentOrder", 5, "below", "y", "", 1, 1, "bond order", "Energies of each fragment [Ht]", Orderxrange.str().c_str(), "[1e-10:1e+1]", "1" , "with points", AbsEnergyPlotLine)) return 1;
    399   if (!CreatePlotOrder(EnergyFragments, KeySet, argv[3], "MaxEnergies-FragmentOrder", 5, "below", "y", "", 1, 1, "bond order", "Maximum fragment energy [Ht]", Orderxrange.str().c_str(), "[1e-6:1e+1]", "1" , "with linespoints", AbsEnergyPlotLine)) return 1;
    400   if (!CreatePlotOrder(EnergyFragments, KeySet, argv[3], "MinEnergies-FragmentOrder", 5, "below", "y", "", 1, 1, "bond order", "Minimum fragment energy [Ht]", Orderxrange.str().c_str(), "[1e-6:1e+1]", "1" , "with linespoints", AbsEnergyPlotLine)) return 1;
     318  yrange.str("");
     319  yrange << "[" << EnergyFragments.FindMinValue() << ":" << EnergyFragments.FindMaxValue() << "]";
     320  if (!CreatePlotOrder(EnergyFragments, KeySet, argv[3], "Energies-Fragment", 5, "below", "y", "", 1, 5, "fragment number", "Energies of each fragment [Ht]", Fragmentxrange.str().c_str(), yrange.str().c_str(), "2" , "with points", AbsEnergyPlotLine)) return 1;
     321  if (!CreatePlotOrder(EnergyFragments, KeySet, argv[3], "Energies-FragmentOrder", 5, "below", "y", "", 1, 1, "bond order", "Energies of each fragment [Ht]", Orderxrange.str().c_str(), yrange.str().c_str(), "1" , "with points", AbsEnergyPlotLine)) return 1;
     322  if (!CreatePlotOrder(EnergyFragments, KeySet, argv[3], "MaxEnergies-FragmentOrder", 5, "below", "y", "", 1, 1, "bond order", "Maximum fragment energy [Ht]", Orderxrange.str().c_str(), yrange.str().c_str(), "1" , "with linespoints", AbsEnergyPlotLine)) return 1;
     323  if (!CreatePlotOrder(EnergyFragments, KeySet, argv[3], "MinEnergies-FragmentOrder", 5, "below", "y", "", 1, 1, "bond order", "Minimum fragment energy [Ht]", Orderxrange.str().c_str(), yrange.str().c_str(), "1" , "with linespoints", AbsEnergyPlotLine)) return 1;
    401324
    402325  // +++++++++++++++++++++++++++++++=Ploting min/mean/max forces for each fragment
     326  yrange.str("");
     327  yrange << "[" << ForceFragments.FindMinValue() << ":" << ForceFragments.FindMaxValue()<< "]";
    403328  // min
    404   if (!CreatePlotOrder(ForceFragments, KeySet, argv[3], "MinForces-Fragment", 5, "below", "y", "set boxwidth 0.2", 1, 5, "fragment number", "minimum of approximated forces [Ht/a.u.]", Fragmentxrange.str().c_str(), "[1e-16:1e+1]", "2" , "with boxes fillcolor", BoxesForcePlotLine)) return 1;
     329  if (!CreatePlotOrder(ForceFragments, KeySet, argv[3], "MinForces-Fragment", 5, "below", "y", "set boxwidth 0.2", 1, 5, "fragment number", "minimum of approximated forces [Ht/a.u.]", Fragmentxrange.str().c_str(), yrange.str().c_str(), "2" , "with boxes fillcolor", BoxesForcePlotLine)) return 1;
    405330   
    406331  // mean
    407   if (!CreatePlotOrder(ForceFragments, KeySet, argv[3], "MeanForces-Fragment", 5, "below", "y", "set boxwidth 0.2", 1, 5, "fragment number", "mean of approximated forces [Ht/a.u.]", Fragmentxrange.str().c_str(), "[1e-16:1e+1]", "2" , "with boxes fillcolor", BoxesFirstForceValuePlotLine)) return 1;
     332  if (!CreatePlotOrder(ForceFragments, KeySet, argv[3], "MeanForces-Fragment", 5, "below", "y", "set boxwidth 0.2", 1, 5, "fragment number", "mean of approximated forces [Ht/a.u.]", Fragmentxrange.str().c_str(), yrange.str().c_str(), "2" , "with boxes fillcolor", BoxesFirstForceValuePlotLine)) return 1;
    408333   
    409334  // max
    410   if (!CreatePlotOrder(ForceFragments, KeySet, argv[3], "MaxForces-Fragment", 5, "below", "y", "set boxwidth 0.2", 1, 5, "fragment number", "maximum of approximated forces [Ht/a.u.]", Fragmentxrange.str().c_str(), "[1e-16:1e+1]", "2" , "with boxes fillcolor", BoxesForcePlotLine)) return 1;
     335  if (!CreatePlotOrder(ForceFragments, KeySet, argv[3], "MaxForces-Fragment", 5, "below", "y", "set boxwidth 0.2", 1, 5, "fragment number", "maximum of approximated forces [Ht/a.u.]", Fragmentxrange.str().c_str(), yrange.str().c_str(), "2" , "with boxes fillcolor", BoxesForcePlotLine)) return 1;
    411336
    412337  // +++++++++++++++++++++++++++++++=Ploting min/mean/max forces for each fragment per bond order
    413338  // min
    414   if (!CreatePlotOrder(ForceFragments, KeySet, argv[3], "MinForces-FragmentOrder", 5, "below", "y", "set boxwidth 0.2", 1, 1, "bond order", "minimum of approximated forces [Ht/a.u.]", Orderxrange.str().c_str(), "[1e-16:1e+1]", "1" , "with boxes fillcolor", BoxesForcePlotLine)) return 1;
     339  if (!CreatePlotOrder(ForceFragments, KeySet, argv[3], "MinForces-FragmentOrder", 5, "below", "y", "set boxwidth 0.2", 1, 1, "bond order", "minimum of approximated forces [Ht/a.u.]", Orderxrange.str().c_str(), yrange.str().c_str(), "1" , "with boxes fillcolor", BoxesForcePlotLine)) return 1;
    415340   
    416341  // mean
    417   if (!CreatePlotOrder(ForceFragments, KeySet, argv[3], "MeanForces-FragmentOrder", 5, "below", "y", "set boxwidth 0.2", 1, 1, "bond order", "mean of approximated forces [Ht/a.u.]", Orderxrange.str().c_str(), "[1e-16:1e+1]", "1" , "with boxes fillcolor", BoxesFirstForceValuePlotLine)) return 1;
     342  if (!CreatePlotOrder(ForceFragments, KeySet, argv[3], "MeanForces-FragmentOrder", 5, "below", "y", "set boxwidth 0.2", 1, 1, "bond order", "mean of approximated forces [Ht/a.u.]", Orderxrange.str().c_str(), yrange.str().c_str(), "1" , "with boxes fillcolor", BoxesFirstForceValuePlotLine)) return 1;
    418343   
    419344  // max
    420   if (!CreatePlotOrder(ForceFragments, KeySet, argv[3], "MaxForces-FragmentOrder", 5, "below", "y", "set boxwidth 0.2", 1, 1, "bond order", "maximum of approximated forces [Ht/a.u.]", Orderxrange.str().c_str(), "[1e-16:1e+1]", "1" , "with boxes fillcolor", BoxesForcePlotLine)) return 1;
     345  if (!CreatePlotOrder(ForceFragments, KeySet, argv[3], "MaxForces-FragmentOrder", 5, "below", "y", "set boxwidth 0.2", 1, 1, "bond order", "maximum of approximated forces [Ht/a.u.]", Orderxrange.str().c_str(), yrange.str().c_str(), "1" , "with boxes fillcolor", BoxesForcePlotLine)) return 1;
    421346 
    422347  // create Makefile
     
    434359  // ++++++++++++++++ exit ++++++++++++++++++++++++++++++++++
    435360  delete(periode);
     361  Free((void **)&dir, "main: *dir");
    436362  cout << "done." << endl;
    437363  return 0;
  • src/datacreator.cpp

    rc685eb r390248  
    3030
    3131/** Plots an energy vs. order.
    32  * \param Energy EnergyMatrix class containing matrix values (last matrix is created by summing over Fragments)
    33  * \param EnergyFragments EnergyMatrix class containing matrix values
     32 * \param &Fragments EnergyMatrix class containing matrix values
    3433 * \param KeySet KeySetContainer class holding bond KeySetContainer::Order
    3534 * \param *prefix prefix in filename (without ending)
     
    3736 * \return true if file was written successfully
    3837 */
    39 bool CreateDataEnergyOrder(class MatrixContainer &Energy, class MatrixContainer &EnergyFragments, class KeySetsContainer &KeySet, char *dir, char *prefix, char *msg, char *datum)
     38bool CreateDataEnergyOrder(class EnergyMatrix &Fragments, class KeySetsContainer &KeySet, char *dir, char *prefix, char *msg, char *datum)
    4039{
    4140  stringstream filename;
     
    4645  cout << msg << endl;
    4746  output << "# " << msg << ", created on " << datum;
    48   output << "#Order\tFrag.No.\t" << Energy.Header << endl;
     47  output << "#Order\tFrag.No.\t" << Fragments.Header << endl;
    4948  for (int BondOrder=0;BondOrder<KeySet.Order;BondOrder++) {
    5049    for(int i=KeySet.FragmentsPerOrder[BondOrder];i--;) {
    51       for(int j=Energy.RowCounter[ KeySet.OrderSet[BondOrder][i] ];j--;)
    52         for(int k=Energy.ColumnCounter;k--;)
    53           Energy.Matrix[Energy.MatrixCounter][j][k] -= EnergyFragments.Matrix[ KeySet.OrderSet[BondOrder][i] ][j][k];
     50      for(int j=Fragments.RowCounter[ KeySet.OrderSet[BondOrder][i] ];j--;)
     51        for(int k=Fragments.ColumnCounter;k--;)
     52          Fragments.Matrix[Fragments.MatrixCounter][j][k] += Fragments.Matrix[ KeySet.OrderSet[BondOrder][i] ][j][k];
    5453    }
    5554    output << BondOrder+1 << "\t" << KeySet.FragmentsPerOrder[BondOrder];
    56     for (int l=0;l<Energy.ColumnCounter;l++)
    57       if (fabs(EnergyFragments.Matrix[EnergyFragments.MatrixCounter][ EnergyFragments.RowCounter[EnergyFragments.MatrixCounter]-1 ][l]) < MYEPSILON)
    58         output << scientific << "\t" << Energy.Matrix[Energy.MatrixCounter][ Energy.RowCounter[Energy.MatrixCounter]-1 ][l];
     55    for (int l=0;l<Fragments.ColumnCounter;l++)
     56      output << scientific << "\t" << Fragments.Matrix[Fragments.MatrixCounter][ Fragments.RowCounter[Fragments.MatrixCounter]-1 ][l];
     57    output << endl;
     58  }
     59  output.close();
     60  return true;
     61};
     62
     63/** Plots an energy error vs. order.
     64 * \param &Energy EnergyMatrix class containing reference values (in MatrixCounter matrix)
     65 * \param &Fragments EnergyMatrix class containing matrix values
     66 * \param KeySet KeySetContainer class holding bond KeySetContainer::Order
     67 * \param *prefix prefix in filename (without ending)
     68 * \param *msg message to be place in first line as a comment
     69 * \return true if file was written successfully
     70 */
     71bool CreateDataDeltaEnergyOrder(class EnergyMatrix &Energy, class EnergyMatrix &Fragments, class KeySetsContainer &KeySet, char *dir, char *prefix, char *msg, char *datum)
     72{
     73  stringstream filename;
     74  ofstream output;
     75
     76  filename << prefix << ".dat";
     77  if (!OpenOutputFile(output, dir, filename.str().c_str())) return false;
     78  cout << msg << endl;
     79  output << "# " << msg << ", created on " << datum;
     80  output << "#Order\tFrag.No.\t" << Fragments.Header << endl;
     81  Fragments.SetLastMatrix(Energy.Matrix[Energy.MatrixCounter],0);
     82  for (int BondOrder=0;BondOrder<KeySet.Order;BondOrder++) {
     83    for(int i=KeySet.FragmentsPerOrder[BondOrder];i--;) {
     84      for(int j=Fragments.RowCounter[ KeySet.OrderSet[BondOrder][i] ];j--;)
     85        for(int k=Fragments.ColumnCounter;k--;)
     86          Fragments.Matrix[Fragments.MatrixCounter][j][k] -= Fragments.Matrix[ KeySet.OrderSet[BondOrder][i] ][j][k];
     87    }
     88    output << BondOrder+1 << "\t" << KeySet.FragmentsPerOrder[BondOrder];
     89    for (int l=0;l<Fragments.ColumnCounter;l++)
     90      if (fabs(Energy.Matrix[Energy.MatrixCounter][ Energy.RowCounter[Energy.MatrixCounter]-1 ][l]) < MYEPSILON)
     91        output << scientific << "\t" << Fragments.Matrix[Fragments.MatrixCounter][ Fragments.RowCounter[Fragments.MatrixCounter]-1 ][l];
    5992      else
    60         output << scientific << "\t" << (Energy.Matrix[Energy.MatrixCounter][ Energy.RowCounter[Energy.MatrixCounter]-1 ][l] / EnergyFragments.Matrix[EnergyFragments.MatrixCounter][ EnergyFragments.RowCounter[EnergyFragments.MatrixCounter]-1 ][l]);
     93        output << scientific << "\t" << (Fragments.Matrix[Fragments.MatrixCounter][ Fragments.RowCounter[Fragments.MatrixCounter]-1 ][l] / Energy.Matrix[Energy.MatrixCounter][ Energy.RowCounter[Energy.MatrixCounter]-1 ][l]);
    6194    output << endl;
    6295  }
     
    6699
    67100/** Plot forces vs. order.
    68  */
    69 bool CreateDataForcesOrder(class MatrixContainer &Force, class MatrixContainer &ForceFragments, class KeySetsContainer &KeySet, char *dir, char *prefix, char *msg, char *datum, void (*CreateForce)(class MatrixContainer &, int))
     101 * \param &Fragments ForceMatrix class containing matrix values
     102 * \param KeySet KeySetContainer class holding bond KeySetContainer::Order
     103 * \param *prefix prefix in filename (without ending)
     104 * \param *msg message to be place in first line as a comment
     105 * \param *datum current date and time
     106 * \return true if file was written successfully
     107 */
     108bool CreateDataForcesOrder(class ForceMatrix &Fragments, class KeySetsContainer &KeySet, char *dir, char *prefix, char *msg, char *datum, void (*CreateForce)(class MatrixContainer &, int))
    70109{
    71110  stringstream filename;
     
    76115  cout << msg << endl;
    77116  output << "# " << msg << ", created on " << datum;
    78   output << "# Order\tFrag.No.\t" << Force.Header << endl;
    79   for(int j=0;j<=Force.RowCounter[ Force.MatrixCounter ];j++)
    80     for(int k=0;k<Force.ColumnCounter;k++)
    81        Force.Matrix[Force.MatrixCounter][j][k] = 0.;
    82   for (int BondOrder=0;BondOrder<KeySet.Order;BondOrder++) {
    83     for(int i=0;i<KeySet.FragmentsPerOrder[BondOrder];i++) {
    84       for(int l=0;l<Force.RowCounter[ KeySet.OrderSet[BondOrder][i] ];l++) {
    85         int j = Force.Indices[ KeySet.OrderSet[BondOrder][i] ][l];
    86         if (j > Force.RowCounter[Force.MatrixCounter]) {
    87           cerr << "Current force index " << j << " is greater than " << Force.RowCounter[Force.MatrixCounter] << "!" << endl;
    88           return 1;
    89         }
    90         if (j != -1)
    91           for(int k=Force.ColumnCounter;k--;) {
    92             Force.Matrix[Force.MatrixCounter][j][k] += ForceFragments.Matrix[ KeySet.OrderSet[BondOrder][i] ][l][k];
    93           }
     117  output << "# Order\tFrag.No.\t" << Fragments.Header << endl;
     118  Fragments.SetLastMatrix(0.,0);
     119  for (int BondOrder=0;BondOrder<KeySet.Order;BondOrder++) {
     120    Fragments.SumSubForces(Fragments, KeySet, BondOrder, 1.);
     121    output << BondOrder+1 << "\t" << KeySet.FragmentsPerOrder[BondOrder];
     122    CreateForce(Fragments, Fragments.MatrixCounter);
     123    for (int l=0;l<Fragments.ColumnCounter;l++)
     124       output << scientific << "\t" << Fragments.Matrix[Fragments.MatrixCounter][ Fragments.RowCounter[Fragments.MatrixCounter] ][l];
     125    output << endl;
     126  }
     127  output.close();
     128  return true;
     129};
     130
     131/** Plot forces error vs. order.
     132 * \param &Force ForceMatrix containing reference values (in MatrixCounter matrix)
     133 * \param &Fragments ForceMatrix class containing matrix values
     134 * \param KeySet KeySetContainer class holding bond KeySetContainer::Order
     135 * \param *prefix prefix in filename (without ending)
     136 * \param *msg message to be place in first line as a comment
     137 * \param *datum current date and time
     138 * \return true if file was written successfully
     139 */
     140bool CreateDataDeltaForcesOrder(class ForceMatrix &Force, class ForceMatrix &Fragments, class KeySetsContainer &KeySet, char *dir, char *prefix, char *msg, char *datum, void (*CreateForce)(class MatrixContainer &, int))
     141{
     142  stringstream filename;
     143  ofstream output;
     144
     145  filename << prefix << ".dat";
     146  if (!OpenOutputFile(output, dir, filename.str().c_str())) return false;
     147  cout << msg << endl;
     148  output << "# " << msg << ", created on " << datum;
     149  output << "# Order\tFrag.No.\t" << Fragments.Header << endl;
     150  Fragments.SetLastMatrix(Force.Matrix[Force.MatrixCounter],0);
     151  for (int BondOrder=0;BondOrder<KeySet.Order;BondOrder++) {
     152    Fragments.SumSubForces(Fragments, KeySet, BondOrder, -1.);
     153    output << BondOrder+1 << "\t" << KeySet.FragmentsPerOrder[BondOrder];
     154    CreateForce(Fragments, Fragments.MatrixCounter);
     155    for (int l=0;l<Fragments.ColumnCounter;l++)
     156       output << scientific << "\t" << Fragments.Matrix[Fragments.MatrixCounter][ Fragments.RowCounter[Fragments.MatrixCounter] ][l];
     157    output << endl;
     158  }
     159  output.close();
     160  return true;
     161};
     162
     163/** Plot forces error vs. vs atom vs. order.
     164 * \param &Force ForceMatrix containing reference values (in MatrixCounter matrix)
     165 * \param &Fragments ForceMatrix class containing matrix values
     166 * \param KeySet KeySetContainer class holding bond KeySetContainer::Order
     167 * \param *prefix prefix in filename (without ending)
     168 * \param *msg message to be place in first line as a comment
     169 * \param *datum current date and time
     170 * \return true if file was written successfully
     171 */
     172bool CreateDataDeltaForcesOrderPerAtom(class ForceMatrix &Force, class ForceMatrix &Fragments, class KeySetsContainer &KeySet, char *dir, char *prefix, char *msg, char *datum)
     173{
     174  stringstream filename;
     175  ofstream output;
     176  double norm = 0.;
     177
     178  filename << prefix << ".dat";
     179  if (!OpenOutputFile(output, dir, filename.str().c_str())) return false;
     180  cout << msg << endl;
     181  output << "# " << msg << ", created on " << datum;
     182  output << "# AtomNo\t" << Fragments.Header << endl;
     183  Fragments.SetLastMatrix(Force.Matrix[Force.MatrixCounter], 0);
     184  for (int BondOrder=0;BondOrder<KeySet.Order;BondOrder++) {
     185    //cout << "Current order is " << BondOrder << "." << endl;
     186    Fragments.SumSubForces(Fragments, KeySet, BondOrder, -1.);
     187    // errors per atom
     188    output << "#Order\t" << BondOrder+1 << endl;
     189    for(int j=0;j<Fragments.RowCounter[ Fragments.MatrixCounter ];j++) {
     190      output << Fragments.Indices[Fragments.MatrixCounter][j] << "\t";
     191      for (int l=0;l<Fragments.ColumnCounter;l++) {
     192        if (((l+1) % 3) == 0) {
     193          norm = 0.;
     194          for (int m=0;m<NDIM;m++)
     195            norm += Force.Matrix[Force.MatrixCounter][ j ][l+m]*Force.Matrix[Force.MatrixCounter][ j ][l+m];
     196          norm = sqrt(norm);
     197        }                                                                                                           
     198//        if (norm < MYEPSILON)
     199          output << scientific << Fragments.Matrix[Fragments.MatrixCounter][ j ][l] << "\t";
     200//        else
     201//          output << scientific << (Fragments.Matrix[Fragments.MatrixCounter][ j ][l] / norm) << "\t";
    94202      }
    95     }
    96     output << BondOrder+1 << "\t" << KeySet.FragmentsPerOrder[BondOrder];
    97     CreateForce(Force, Force.MatrixCounter);
    98     for (int l=0;l<Force.ColumnCounter;l++)
    99        output << scientific << "\t" << Force.Matrix[Force.MatrixCounter][ Force.RowCounter[Force.MatrixCounter] ][l];
     203      output << endl;
     204    }
     205    output << endl;
     206  }
     207  output.close();
     208  return true;
     209};
     210
     211/** Plot forces error vs. vs atom vs. order.
     212 * \param &Fragments ForceMatrix class containing matrix values
     213 * \param KeySet KeySetContainer class holding bond KeySetContainer::Order
     214 * \param *prefix prefix in filename (without ending)
     215 * \param *msg message to be place in first line as a comment
     216 * \param *datum current date and time
     217 * \return true if file was written successfully
     218 */
     219bool CreateDataForcesOrderPerAtom(class ForceMatrix &Fragments, class KeySetsContainer &KeySet, char *dir, char *prefix, char *msg, char *datum)
     220{
     221  stringstream filename;
     222  ofstream output;
     223
     224  filename << prefix << ".dat";
     225  if (!OpenOutputFile(output, dir, filename.str().c_str())) return false;
     226  cout << msg << endl;
     227  output << "# " << msg << ", created on " << datum;
     228  output << "# AtomNo\t" << Fragments.Header << endl;
     229  for (int BondOrder=0;BondOrder<KeySet.Order;BondOrder++) {
     230    //cout << "Current order is " << BondOrder << "." << endl;
     231    Fragments.SumSubForces(Fragments, KeySet, BondOrder, 1.);
     232    // errors per atom
     233    output << "#Order\t" << BondOrder+1 << endl;
     234    for(int j=0;j<Fragments.RowCounter[ Fragments.MatrixCounter ];j++) {
     235      output << Fragments.Indices[Fragments.MatrixCounter][j] << "\t";
     236      for (int l=0;l<Fragments.ColumnCounter;l++)
     237        output << scientific << Fragments.Matrix[Fragments.MatrixCounter][ j ][l] << "\t";
     238      output << endl;
     239    }
    100240    output << endl;
    101241  }
     
    286426};
    287427
     428/** Leaves the Force.Matrix as it is.
     429 * \param Force ForceMatrix class containing matrix values
     430 * \param MatrixNumber the index for the ForceMatrix::matrix array
     431*/
     432void CreateSameForce(class MatrixContainer &Force, int MatrixNumber)
     433{
     434  // does nothing
     435};
     436
    288437/** Adds vectorwise all forces.
    289438 * Results are stored in the matrix ForceMatrix::MatrixCounter of \a Force.
     
    295444  for (int l=Force.ColumnCounter;l--;)
    296445    Force.Matrix[MatrixNumber][ Force.RowCounter[MatrixNumber] ][l] = 0.;
    297   for (int l=5;l<Force.ColumnCounter;l++) {
     446  for (int l=0;l<Force.ColumnCounter;l++) {
    298447    for (int k=Force.RowCounter[MatrixNumber];k--;)
    299448      Force.Matrix[MatrixNumber][ Force.RowCounter[MatrixNumber] ][l] += Force.Matrix[MatrixNumber][k][l];
     
    375524
    376525  line >> item;
    377   for (int i=3; i< Energy.ColumnCounter;i++) {
    378     line >> item;
    379     output << "'" << prefix << ".dat' title '" << item << "' using " << xargument << ":(abs($" << i+1 << ")) " << uses;
    380     if (i != (Energy.ColumnCounter-1))
     526  for (int i=2; i<= Energy.ColumnCounter;i++) {
     527    line >> item;
     528    output << "'" << prefix << ".dat' title '" << item << "' using " << xargument << ":(abs($" << i+2 << ")) " << uses;
     529    if (i != (Energy.ColumnCounter))
    381530      output << ", \\";
    382531    output << endl;
     
    397546
    398547  line >> item;
    399   for (int i=3; i< Energy.ColumnCounter;i++) {
    400     line >> item;
    401     output << "'" << prefix << ".dat' title '" << item << "' using " << xargument << ":" << i+1 << " " << uses;
    402     if (i != (Energy.ColumnCounter-1))
     548  for (int i=2; i<= Energy.ColumnCounter;i++) {
     549    line >> item;
     550    output << "'" << prefix << ".dat' title '" << item << "' using " << xargument << ":" << i+2 << " " << uses;
     551    if (i != (Energy.ColumnCounter))
    403552      output << ", \\";
    404553    output << endl;
  • src/datacreator.hpp

    rc685eb r390248  
    1919bool OpenOutputFile(ofstream &output, const char *dir, const char *filename);
    2020
    21 bool CreateDataEnergyOrder(class MatrixContainer &Energy, class MatrixContainer &EnergyFragments, class KeySetsContainer &KeySet, char *dir, char *prefix, char *msg, char *datum);
    22 bool CreateDataForcesOrder(class MatrixContainer &Force, class MatrixContainer &ForceFragments, class KeySetsContainer &KeySet, char *dir, char *prefix, char *msg, char *datum, void (*CreateForce)(class MatrixContainer &, int));
     21bool CreateDataEnergyOrder(class EnergyMatrix &Fragments, class KeySetsContainer &KeySet, char *dir, char *prefix, char *msg, char *datum);
     22bool CreateDataDeltaEnergyOrder(class EnergyMatrix &Energy, class EnergyMatrix &Fragments, class KeySetsContainer &KeySet, char *dir, char *prefix, char *msg, char *datum);
     23bool CreateDataForcesOrder(class ForceMatrix &Fragments, class KeySetsContainer &KeySet, char *dir, char *prefix, char *msg, char *datum, void (*CreateForce)(class MatrixContainer &, int));
     24bool CreateDataForcesOrderPerAtom(class ForceMatrix &Fragments, class KeySetsContainer &KeySet, char *dir, char *prefix, char *msg, char *datum);
     25bool CreateDataDeltaForcesOrder(class ForceMatrix &Force, class ForceMatrix &Fragments, class KeySetsContainer &KeySet, char *dir, char *prefix, char *msg, char *datum, void (*CreateForce)(class MatrixContainer &, int));
     26bool CreateDataDeltaForcesOrderPerAtom(class ForceMatrix &Force, class ForceMatrix &Fragments, class KeySetsContainer &KeySet, char *dir, char *prefix, char *msg, char *datum);
    2327bool CreateDataFragment(class MatrixContainer &ForceFragments, class KeySetsContainer &KeySet, char *dir, char *prefix, char *msg, char *datum, void (*CreateForce)(class MatrixContainer &, int));
    2428bool CreateDataFragmentOrder(class MatrixContainer &Fragment, class KeySetsContainer &KeySet, char *dir, char *prefix, char *msg, char *datum, void (*CreateFragmentOrder)(class MatrixContainer &, class KeySetsContainer &, int));
     
    3034void CreateMeanForce(class MatrixContainer &Force, int MatrixNumber);
    3135void CreateMaximumForce(class MatrixContainer &Force, int MatrixNumber);
     36void CreateSameForce(class MatrixContainer &Force, int MatrixNumber);
    3237void CreateVectorSumForce(class MatrixContainer &Force, int MatrixNumber);
    3338
  • src/defs.hpp

    rc685eb r390248  
    4949#define TEFACTORSFILE "TE-Factors.dat"    //!< default filename of BOSSANOVA total energy factors file
    5050#define FORCESFILE "Forces-Factors.dat"    //!< default filename of BOSSANOVA force factors file
     51#define HCORRECTIONSUFFIX "Hcorrection.dat"    //!< default filename of BOSSANOVA H correction file (unwanted saturation interaction)
     52#define FITCONSTANTSUFFIX "FitConstant.dat"   //!< suffix of default filename of BOSSANOVA fit constants file (unwanted saturation interaction)
    5153#define SHIELDINGSUFFIX "sigma_all.csv"                //!< default filename of BOSSANOVA shieldings file
    5254#define SHIELDINGPASSUFFIX "sigma_all_PAS.csv"                 //!< default filename of BOSSANOVA shieldings PAS file
  • src/joiner.cpp

    rc685eb r390248  
    1919  periodentafel *periode = NULL; // and a period table of all elements
    2020  EnergyMatrix Energy;
     21  EnergyMatrix Hcorrection;
    2122  ForceMatrix Force;
    2223  EnergyMatrix EnergyFragments;
     24  EnergyMatrix HcorrectionFragments;
    2325  ForceMatrix ForceFragments;
    2426  ForceMatrix Shielding;
     
    2830  KeySetsContainer KeySet; 
    2931  stringstream prefix;
     32  char *dir = NULL;
     33  bool Hcorrected = true;
    3034
    3135  cout << "Joiner" << endl;
     
    3943    cout << "[elementsdb]\tpath to elements database, needed for shieldings." << endl;
    4044    return 1;
     45  } else {
     46    dir = (char *) Malloc(sizeof(char)*(strlen(argv[2])+2), "main: *dir");
     47    strcpy(dir, "/");
     48    strcat(dir, argv[2]);
    4149  }
    4250  if (argc > 3) {
     
    5260 
    5361  // ------------- Parse through all Fragment subdirs --------
    54   if (!Energy.ParseMatrix(argv[1], argv[2], EnergySuffix, 0,0)) return 1;
    55   if (!Force.ParseMatrix(argv[1], argv[2], ForcesSuffix, 0,0)) return 1;
     62  if (!Energy.ParseMatrix(argv[1], dir, EnergySuffix, 0,0)) return 1;
     63  Hcorrected = Hcorrection.ParseMatrix(argv[1], "", HCORRECTIONSUFFIX, 0,0);
     64  if (!Force.ParseMatrix(argv[1], dir, ForcesSuffix, 0,0)) return 1;
    5665  if (periode != NULL) { // also look for PAS values
    57     if (!Shielding.ParseMatrix(argv[1], argv[2], ShieldingSuffix, 1, 0)) return 1;
    58     if (!ShieldingPAS.ParseMatrix(argv[1], argv[2], ShieldingPASSuffix, 1, 0)) return 1;
     66    if (!Shielding.ParseMatrix(argv[1], dir, ShieldingSuffix, 1, 0)) return 1;
     67    if (!ShieldingPAS.ParseMatrix(argv[1], dir, ShieldingPASSuffix, 1, 0)) return 1;
    5968  }
    6069
    6170  // ---------- Parse the TE Factors into an array -----------------
    6271  if (!Energy.ParseIndices()) return 1;
     72  if (Hcorrected) Hcorrection.ParseIndices();
    6373 
    6474  // ---------- Parse the Force indices into an array ---------------
     
    7686  if (!KeySet.ParseManyBodyTerms()) return 1;
    7787  if (!EnergyFragments.AllocateMatrix(Energy.Header, Energy.MatrixCounter, Energy.RowCounter, Energy.ColumnCounter)) return 1;
     88  if (Hcorrected)  HcorrectionFragments.AllocateMatrix(Hcorrection.Header, Hcorrection.MatrixCounter, Hcorrection.RowCounter, Hcorrection.ColumnCounter);
    7889  if (!ForceFragments.AllocateMatrix(Force.Header, Force.MatrixCounter, Force.RowCounter, Force.ColumnCounter)) return 1;
    7990  if (periode != NULL) { // also look for PAS values
     
    8697  if(!Force.SetLastMatrix(0., 2)) return 1;
    8798  if (periode != NULL) { // also look for PAS values
    88     if(!Shielding.SetLastMatrix(0., 0)) return 1;
     99    if(!Shielding.SetLastMatrix(0., 2)) return 1;
    89100    if(!ShieldingPAS.SetLastMatrix(0., 2)) return 1;
    90101  }
     
    97108    cout << "Summing energy of order " << BondOrder+1 << " ..." << endl;
    98109    if (!EnergyFragments.SumSubManyBodyTerms(Energy, KeySet, BondOrder)) return 1;
    99     if (!Energy.SumSubEnergy(EnergyFragments, KeySet, BondOrder)) return 1;
     110    if (Hcorrected) {
     111      HcorrectionFragments.SumSubManyBodyTerms(Hcorrection, KeySet, BondOrder);
     112      if (!Energy.SumSubEnergy(EnergyFragments, &HcorrectionFragments, KeySet, BondOrder, 1.)) return 1;
     113      if (Hcorrected) Hcorrection.SumSubEnergy(HcorrectionFragments, NULL, KeySet, BondOrder, 1.);
     114    } else
     115      if (!Energy.SumSubEnergy(EnergyFragments, NULL, KeySet, BondOrder, 1.)) return 1;
    100116    // --------- sum up Forces --------------------
    101117    cout << "Summing forces of order " << BondOrder+1 << " ..." << endl;
    102118    if (!ForceFragments.SumSubManyBodyTerms(Force, KeySet, BondOrder)) return 1;
    103     if (!Force.SumSubForces(ForceFragments, KeySet, BondOrder)) return 1;
     119    if (!Force.SumSubForces(ForceFragments, KeySet, BondOrder, 1.)) return 1;
    104120    if (periode != NULL) { // also look for PAS values
    105121      cout << "Summing shieldings of order " << BondOrder+1 << " ..." << endl;
    106122      if (!ShieldingFragments.SumSubManyBodyTerms(Shielding, KeySet, BondOrder)) return 1;
    107       if (!Shielding.SumSubForces(ShieldingFragments, KeySet, BondOrder)) return 1;
     123      if (!Shielding.SumSubForces(ShieldingFragments, KeySet, BondOrder, 1.)) return 1;
    108124      if (!ShieldingPASFragments.SumSubManyBodyTerms(ShieldingPAS, KeySet, BondOrder)) return 1;
    109       if (!ShieldingPAS.SumSubForces(ShieldingPASFragments, KeySet, BondOrder)) return 1;
     125      if (!ShieldingPAS.SumSubForces(ShieldingPASFragments, KeySet, BondOrder, 1.)) return 1;
    110126    }
    111127
    112128    // --------- write the energy and forces file --------------------
    113129    prefix.str(" ");
    114     prefix << argv[2] << OrderSuffix << (BondOrder+1);
     130    prefix << dir << OrderSuffix << (BondOrder+1);
    115131    cout << "Writing files " << argv[1] << prefix.str() << ". ..." << endl;
    116132    // energy
     
    126142  // fragments
    127143  prefix.str(" ");
    128   prefix << argv[2] << EnergyFragmentSuffix;
     144  prefix << dir << EnergyFragmentSuffix;
    129145  if (!EnergyFragments.WriteTotalFragments(argv[1], (prefix.str()).c_str())) return 1;
     146  if (Hcorrected) {
     147    prefix.str(" ");
     148    prefix << dir << HcorrectionFragmentSuffix;
     149    if (!HcorrectionFragments.WriteTotalFragments(argv[1], (prefix.str()).c_str())) return 1;
     150  }
    130151  prefix.str(" ");
    131   prefix << argv[2] << ForceFragmentSuffix;
     152  prefix << dir << ForceFragmentSuffix;
    132153  if (!ForceFragments.WriteTotalFragments(argv[1], (prefix.str()).c_str())) return 1;
    133154  if (!CreateDataFragment(EnergyFragments, KeySet, argv[1], FRAGMENTPREFIX ENERGYPERFRAGMENT, "fragment energy versus the Fragment No", "today", CreateEnergy)) return 1;
    134155  if (periode != NULL) { // also look for PAS values
    135156    prefix.str(" ");
    136     prefix << argv[2] << ShieldingFragmentSuffix;
     157    prefix << dir << ShieldingFragmentSuffix;
    137158    if (!ShieldingFragments.WriteTotalFragments(argv[1], (prefix.str()).c_str())) return 1;
    138159    prefix.str(" ");
    139     prefix << argv[2] << ShieldingPASFragmentSuffix;
     160    prefix << dir << ShieldingPASFragmentSuffix;
    140161    if (!ShieldingPASFragments.WriteTotalFragments(argv[1], (prefix.str()).c_str())) return 1;
    141162  }
    142163
    143164  // write last matrices as fragments into central dir (not subdir as above), for analyzer to know index bounds
    144   if (!Energy.WriteLastMatrix(argv[1], argv[2], EnergyFragmentSuffix)) return 1;
    145   if (!Force.WriteLastMatrix(argv[1], argv[2], ForceFragmentSuffix)) return 1;
     165  if (!Energy.WriteLastMatrix(argv[1], dir, EnergyFragmentSuffix)) return 1;
     166  if (Hcorrected) Hcorrection.WriteLastMatrix(argv[1], dir, HcorrectionFragmentSuffix);
     167  if (!Force.WriteLastMatrix(argv[1], dir, ForceFragmentSuffix)) return 1;
    146168  if (periode != NULL) { // also look for PAS values
    147     if (!Shielding.WriteLastMatrix(argv[1], argv[2], ShieldingFragmentSuffix)) return 1;
    148     if (!ShieldingPAS.WriteLastMatrix(argv[1], argv[2], ShieldingPASFragmentSuffix)) return 1;
     169    if (!Shielding.WriteLastMatrix(argv[1], dir, ShieldingFragmentSuffix)) return 1;
     170    if (!ShieldingPAS.WriteLastMatrix(argv[1], dir, ShieldingPASFragmentSuffix)) return 1;
    149171  }
    150172
    151173  // exit 
    152174  delete(periode);
     175  Free((void **)&dir, "main: *dir");
    153176  cout << "done." << endl;
    154177  return 0;
  • src/moleculelist.cpp

    rc685eb r390248  
    133133};
    134134
     135/** Calculates necessary hydrogen correction due to unwanted interaction between saturated ones.
     136 * If for a pair of two hydrogen atoms a and b, at least is a saturated one, and a and b are not
     137 * bonded to the same atom, then we add for this pair a correction term constructed from a Morse
     138 * potential function fit to QM calculations with respecting to the interatomic hydrogen distance.
     139 * \param *out output stream for debugging
     140 * \param *path path to file
     141 */
     142bool MoleculeListClass::AddHydrogenCorrection(ofstream *out, char *path)
     143{
     144  atom *Walker = NULL;
     145  atom *Runner = NULL;
     146  double ***FitConstant = NULL, **correction = NULL;
     147  int a,b;
     148  ofstream output;
     149  ifstream input;
     150  string line;
     151  stringstream zeile;
     152  double distance;
     153  char ParsedLine[1023];
     154  double tmp;
     155  char *FragmentNumber = NULL;
     156
     157  cout << Verbose(1) << "Saving hydrogen saturation correction ... ";
     158  // 0. parse in fit constant files that should have the same dimension as the final energy files
     159  // 0a. find dimension of matrices with constants
     160  line = path;
     161  line.append("/");
     162  line += FRAGMENTPREFIX;
     163  line += "1";
     164  line += FITCONSTANTSUFFIX;
     165  input.open(line.c_str());
     166  if (input == NULL) {
     167    cerr << endl << "Unable to open " << line << ", is the directory correct?" << endl;
     168    return false;
     169  }
     170  a=0;
     171  b=-1; // we overcount by one
     172  while (!input.eof()) {
     173    input.getline(ParsedLine, 1023);
     174    zeile.str(ParsedLine);
     175    int i=0;
     176    while (!zeile.eof()) {
     177      zeile >> distance;
     178      i++;
     179    }
     180    if (i > a)
     181      a = i;
     182    b++;
     183  }
     184  cout << "I recognized " << a << " columns and " << b << " rows, ";
     185  input.close();
     186 
     187  // 0b. allocate memory for constants
     188  FitConstant = (double ***) Malloc(sizeof(double **)*3, "MoleculeListClass::AddHydrogenCorrection: ***FitConstant");
     189  for (int k=0;k<3;k++) {
     190    FitConstant[k] = (double **) Malloc(sizeof(double *)*a, "MoleculeListClass::AddHydrogenCorrection: **FitConstant[]");
     191    for (int i=a;i--;) {
     192      FitConstant[k][i] = (double *) Malloc(sizeof(double)*b, "MoleculeListClass::AddHydrogenCorrection: *FitConstant[][]");
     193    }
     194  }
     195  // 0c. parse in constants
     196  for (int i=0;i<3;i++) {
     197    line = path;
     198    line.append("/");
     199    line += FRAGMENTPREFIX;
     200    sprintf(ParsedLine, "%d", i+1);
     201    line += ParsedLine;
     202    line += FITCONSTANTSUFFIX;
     203    input.open(line.c_str());
     204    if (input == NULL) {
     205      cerr << endl << "Unable to open " << line << ", is the directory correct?" << endl;
     206      return false;
     207    }
     208    int k = 0,l;
     209    while ((!input.eof()) && (k < b)) {
     210      input.getline(ParsedLine, 1023);
     211      //cout << "Current Line: " << ParsedLine << endl;
     212      zeile.str(ParsedLine);
     213      zeile.clear();
     214      l = 0;
     215      while ((!zeile.eof()) && (l < a)) {
     216        zeile >> FitConstant[i][l][k];
     217        //cout << FitConstant[i][l][k] << "\t";
     218        l++;
     219      }
     220      //cout << endl;
     221      k++;
     222    }
     223    input.close();
     224  }
     225  for(int k=0;k<3;k++) {
     226    cout << "Constants " << k << ":" << endl;
     227    for (int j=0;j<b;j++) {
     228      for (int i=0;i<a;i++) {
     229        cout << FitConstant[k][i][j] << "\t";
     230      }
     231      cout << endl;
     232    }
     233    cout << endl;
     234  }
     235 
     236  // 0d. allocate final correction matrix
     237  correction = (double **) Malloc(sizeof(double *)*a, "MoleculeListClass::AddHydrogenCorrection: **correction");
     238  for (int i=a;i--;)
     239    correction[i] = (double *) Malloc(sizeof(double)*b, "MoleculeListClass::AddHydrogenCorrection: *correction[]");
     240       
     241  // 1a. go through every molecule in the list
     242  for(int i=NumberOfMolecules;i--;) {
     243    // 1b. zero final correction matrix
     244    for (int k=a;k--;)
     245      for (int j=b;j--;)
     246        correction[k][j] = 0.;
     247    // 2. take every hydrogen that is a saturated one
     248    Walker = ListOfMolecules[i]->start;
     249    while (Walker->next != ListOfMolecules[i]->end) {
     250      Walker = Walker->next;
     251      //cout << Verbose(1) << "Walker: " << *Walker << " with first bond " << *ListOfMolecules[i]->ListOfBondsPerAtom[Walker->nr][0] << "." << endl;
     252      if ((Walker->type->Z == 1) && ((Walker->father == NULL) || (Walker->father->type->Z != 1))) { // if it's a hydrogen
     253        Runner = ListOfMolecules[i]->start;
     254        while (Runner->next != ListOfMolecules[i]->end) {
     255          Runner = Runner->next;
     256          //cout << Verbose(2) << "Runner: " << *Runner << " with first bond " << *ListOfMolecules[i]->ListOfBondsPerAtom[Runner->nr][0] << "." << endl;
     257          // 3. take every other hydrogen that is the not the first and not bound to same bonding partner
     258          if ((Runner->type->Z == 1) && (Runner->nr > Walker->nr) && (ListOfMolecules[i]->ListOfBondsPerAtom[Runner->nr][0]->GetOtherAtom(Runner) != ListOfMolecules[i]->ListOfBondsPerAtom[Walker->nr][0]->GetOtherAtom(Walker))) {  // (hydrogens have only one bonding partner!)
     259            // 4. evaluate the morse potential for each matrix component and add up
     260            distance = sqrt(Runner->x.Distance(&Walker->x));
     261            //cout << "Fragment " << i << ": " << *Runner << "<= " << distance << "=>" << *Walker << ":" << endl;
     262            for(int k=0;k<a;k++) {
     263              for (int j=0;j<b;j++) {
     264                switch(k) {
     265                case 1:
     266                case 7:
     267                case 11:
     268                  tmp = pow(FitConstant[0][k][j] * ( 1. - exp(-FitConstant[1][k][j] * (distance - FitConstant[2][k][j]) ) ),2);
     269                  break;
     270                default:
     271                  tmp = FitConstant[0][k][j] * pow( distance,  FitConstant[1][k][j]) + FitConstant[2][k][j];
     272                };
     273                correction[k][j] -= tmp;    // ground state is actually lower (disturbed by additional interaction)
     274                //cout << tmp << "\t";
     275              }
     276              //cout << endl;
     277            }
     278            //cout << endl;
     279          }
     280        }
     281      }
     282    }
     283    // 5. write final matrix to file
     284    line = path;
     285    line.append("/");
     286    line += FRAGMENTPREFIX;
     287    FragmentNumber = FixedDigitNumber(NumberOfMolecules, i);
     288    line += FragmentNumber;
     289    delete(FragmentNumber);
     290    line += HCORRECTIONSUFFIX;
     291    output.open(line.c_str());
     292    output << "Time\t\tTotal\t\tKinetic\t\tNonLocal\tCorrelation\tExchange\tPseudo\t\tHartree\t\t-Gauss\t\tEwald\t\tIonKin\t\tETotal" << endl;
     293    for (int j=0;j<b;j++) {
     294      for(int i=0;i<a;i++)
     295        output << correction[i][j] << "\t";
     296      output << endl;
     297    }
     298    output.close();
     299  }
     300  line = path;
     301  line.append("/");
     302  line += HCORRECTIONSUFFIX;
     303  output.open(line.c_str());
     304  output << "Time\t\tTotal\t\tKinetic\t\tNonLocal\tCorrelation\tExchange\tPseudo\t\tHartree\t\t-Gauss\t\tEwald\t\tIonKin\t\tETotal" << endl;
     305  for (int j=0;j<b;j++) {
     306    for(int i=0;i<a;i++)
     307      output << 0 << "\t";
     308    output << endl;
     309  }
     310  output.close();
     311  // 6. free memory of parsed matrices
     312  FitConstant = (double ***) Malloc(sizeof(double **)*a, "MoleculeListClass::AddHydrogenCorrection: ***FitConstant");
     313  for (int k=0;k<3;k++) {
     314    FitConstant[k] = (double **) Malloc(sizeof(double *)*a, "MoleculeListClass::AddHydrogenCorrection: **FitConstant[]");
     315    for (int i=a;i--;) {
     316      FitConstant[k][i] = (double *) Malloc(sizeof(double)*b, "MoleculeListClass::AddHydrogenCorrection: *FitConstant[][]");
     317    }
     318  }
     319  cout << "done." << endl;
     320  return true;
     321};
    135322
    136323/** Store force indices, i.e. the connection between the nuclear index in the total molecule config and the respective atom in fragment config.
     
    224411    outputFragment.open(FragmentName, ios::out);
    225412    *out << Verbose(2) << "Saving bond fragment No. " << FragmentNumber << "/" << FragmentCounter-1 << " as XYZ ...";
    226     if (intermediateResult = ListOfMolecules[i]->OutputXYZ(&outputFragment))
     413    if ((intermediateResult = ListOfMolecules[i]->OutputXYZ(&outputFragment)))
    227414      *out << " done." << endl;
    228415    else
     
    263450    configuration->SetDefaultPath(FragmentName);
    264451    *out << Verbose(2) << "Saving bond fragment No. " << FragmentNumber << "/" << FragmentCounter-1 << " as config ...";
    265     if (intermediateResult = configuration->Save(&outputFragment, ListOfMolecules[i]->elemente, ListOfMolecules[i]))
     452    if ((intermediateResult = configuration->Save(&outputFragment, ListOfMolecules[i]->elemente, ListOfMolecules[i])))
    266453      *out << " done." << endl;
    267454    else
  • src/molecules.cpp

    rc685eb r390248  
    27072707    StoreAdjacencyToFile(out, configuration->configpath);
    27082708
     2709    // store Hydrogen saturation correction file
     2710    BondFragments->AddHydrogenCorrection(out, configuration->configpath);
     2711   
    27092712    // store adaptive orders into file
    27102713    StoreOrderAtSiteFile(out, configuration->configpath);
  • src/molecules.hpp

    rc685eb r390248  
    289289
    290290  /// Output configs.
     291  bool AddHydrogenCorrection(ofstream *out, char *path);
    291292  bool StoreForcesFile(ofstream *out, char *path, int *SortIndex);
    292293  bool OutputConfigForListOfFragments(ofstream *out, config *configuration, int *SortIndex);
  • src/parser.cpp

    rc685eb r390248  
    146146    file.str(" ");
    147147    if (i != MatrixCounter) 
    148       file << name << FRAGMENTPREFIX << FragmentNumber << "/" << prefix << suffix;
     148      file << name << FRAGMENTPREFIX << FragmentNumber << prefix << suffix;
    149149    else
    150150      file << name << prefix << suffix;
     
    265265};
    266266
     267/** Scans all elements of MatrixContainer::Matrix for greatest absolute value.
     268 * \return greatest value of MatrixContainer::Matrix
     269 */
     270double MatrixContainer::FindMaxValue()
     271{
     272  double max = Matrix[0][0][0];
     273  for(int i=MatrixCounter+1;i--;)
     274    for(int j=RowCounter[i]+1;j--;)
     275      for(int k=ColumnCounter;k--;)
     276        if (fabs(Matrix[i][j][k]) > max)
     277          max = fabs(Matrix[i][j][k]);
     278  if (fabs(max) < MYEPSILON)
     279    max += MYEPSILON;
     280 return max;
     281};
     282
     283/** Scans all elements of MatrixContainer::Matrix for smallest absolute value.
     284 * \return smallest value of MatrixContainer::Matrix
     285 */
     286double MatrixContainer::FindMinValue()
     287{
     288  double min = Matrix[0][0][0];
     289  for(int i=MatrixCounter+1;i--;)
     290    for(int j=RowCounter[i]+1;j--;)
     291      for(int k=ColumnCounter;k--;)
     292        if (fabs(Matrix[i][j][k]) < min)
     293          min = fabs(Matrix[i][j][k]);
     294  if (fabs(min) < MYEPSILON)
     295    min += MYEPSILON;
     296  return min;
     297};
     298
    267299/** Sets all values in the last of MatrixContainer::Matrix to \a value.
    268300 * \param value reset value
     
    333365              }
    334366            }
    335           //if ((ColumnCounter>1) && (RowCounter[0]-1 >= 1))
    336             //cout << "Fragments[ KeySet.OrderSet[" << Order << "][" << CurrentFragment << "]=" << KeySet.OrderSet[Order][CurrentFragment] << " ][" << RowCounter[0]-1 << "][" << 1 << "] = " <<  Matrix[ KeySet.OrderSet[Order][CurrentFragment] ][RowCounter[0]-1][1] << endl;
     367            //if ((ColumnCounter>1) && (RowCounter[0]-1 >= 1))
     368             //cout << "Fragments[ KeySet.OrderSet[" << Order << "][" << CurrentFragment << "]=" << KeySet.OrderSet[Order][CurrentFragment] << " ][" << RowCounter[0]-1 << "][" << 1 << "] = " <<  Matrix[ KeySet.OrderSet[Order][CurrentFragment] ][RowCounter[0]-1][1] << endl;
    337369          }
    338370        } else {
     
    341373      }
    342374    }
    343     //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;
     375   //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;
    344376  }
    345377 
     
    428460 * Sums over the "F"-terms in ANOVA decomposition.
    429461 * \param Matrix MatrixContainer with matrices (LevelCounter by ColumnCounter) with all the energies.
     462 * \param CorrectionFragments MatrixContainer with hydrogen saturation correction per fragments
    430463 * \param KeySet KeySetContainer with bond Order and association mapping of each fragment to an order
    431464 * \param Order bond order
     465 * \parsm sign +1 or -1
    432466 * \return true if summing was successful
    433467 */
    434 bool EnergyMatrix::SumSubEnergy(class EnergyMatrix &Fragments, class KeySetsContainer &KeySet, int Order)
     468bool EnergyMatrix::SumSubEnergy(class EnergyMatrix &Fragments, class EnergyMatrix *CorrectionFragments, class KeySetsContainer &KeySet, int Order, double sign)
    435469{
    436470  // sum energy
    437   for(int i=KeySet.FragmentsPerOrder[Order];i--;)
    438     for(int j=RowCounter[ KeySet.OrderSet[Order][i] ];j--;)
    439       for(int k=ColumnCounter;k--;)
    440         Matrix[MatrixCounter][j][k] += Fragments.Matrix[ KeySet.OrderSet[Order][i] ][j][k];
     471  if (CorrectionFragments == NULL)
     472    for(int i=KeySet.FragmentsPerOrder[Order];i--;)
     473      for(int j=RowCounter[ KeySet.OrderSet[Order][i] ];j--;)
     474        for(int k=ColumnCounter;k--;)
     475          Matrix[MatrixCounter][j][k] += sign*Fragments.Matrix[ KeySet.OrderSet[Order][i] ][j][k];
     476  else
     477    for(int i=KeySet.FragmentsPerOrder[Order];i--;)
     478      for(int j=RowCounter[ KeySet.OrderSet[Order][i] ];j--;)
     479        for(int k=ColumnCounter;k--;)
     480          Matrix[MatrixCounter][j][k] += sign*(Fragments.Matrix[ KeySet.OrderSet[Order][i] ][j][k] + CorrectionFragments->Matrix[ KeySet.OrderSet[Order][i] ][j][k]);
    441481  return true;
    442482};
     
    492532 * \param KeySet KeySetContainer with bond Order and association mapping of each fragment to an order
    493533 * \param Order bond order
     534 *  \param sign +1 or -1
    494535 * \return true if summing was successful
    495536 */
    496 bool ForceMatrix::SumSubForces(class ForceMatrix &Fragments, class KeySetsContainer &KeySet, int Order)
    497 {
     537bool ForceMatrix::SumSubForces(class ForceMatrix &Fragments, class KeySetsContainer &KeySet, int Order, double sign)
     538{
     539  int FragmentNr;
    498540  // sum forces
    499   for(int i=0;i<KeySet.FragmentsPerOrder[Order];i++)
    500     for(int l=0;l<RowCounter[ KeySet.OrderSet[Order][i] ];l++) {
    501       int j = Indices[ KeySet.OrderSet[Order][i] ][l];
     541  for(int i=0;i<KeySet.FragmentsPerOrder[Order];i++) {
     542    FragmentNr = KeySet.OrderSet[Order][i];
     543    for(int l=0;l<RowCounter[ FragmentNr ];l++) {
     544      int j = Indices[ FragmentNr ][l];
    502545      if (j > RowCounter[MatrixCounter]) {
    503546        cerr << "Current force index " << j << " is greater than " << RowCounter[MatrixCounter] << "!" << endl;
    504547        return false;
    505548      }
    506       if (j != -1)
     549      if (j != -1) {
     550        //if (j == 0) cout << "Summing onto ion 0, type 0 from fragment " << FragmentNr << ", ion " << l << "." << endl;
    507551        for(int k=2;k<ColumnCounter;k++)
    508           Matrix[MatrixCounter][j][k] += Fragments.Matrix[ KeySet.OrderSet[Order][i] ][l][k];
    509     }
     552          Matrix[MatrixCounter][j][k] += sign*Fragments.Matrix[ FragmentNr ][l][k];
     553      }
     554    }
     555  }
    510556  return true;
    511557};
     
    571617      KeySets[i][j] = -1;
    572618    FragmentNumber = FixedDigitNumber(FragmentCounter, i);
    573     cout << FRAGMENTPREFIX << FragmentNumber << "[" << AtomCounter[i] << "]:";
     619    //cout << FRAGMENTPREFIX << FragmentNumber << "[" << AtomCounter[i] << "]:";
    574620    Free((void **)&FragmentNumber, "KeySetsContainer::ParseKeySets: *FragmentNumber");
    575621    input.getline(filename, 1023);
     
    577623    for(int j=0;(j<AtomCounter[i]) && (!line.eof());j++) {
    578624      line >> KeySets[i][j];
    579       cout << " " << KeySets[i][j];
    580     }
    581     cout << endl;
     625      //cout << " " << KeySets[i][j];
     626    }
     627    //cout << endl;
    582628  }
    583629  input.close();
  • src/parser.hpp

    rc685eb r390248  
    1919
    2020#define EnergySuffix ".energy.all"
     21#define HcorrectionSuffix ".Hcorrection.all"
    2122#define ForcesSuffix ".forces.all"
    2223#define ShieldingSuffix ".sigma_all.csv"
     
    2627#define TimeSuffix ".speed"
    2728#define EnergyFragmentSuffix ".energyfragment.all"
     29#define HcorrectionFragmentSuffix ".Hcorrectionfragment.all"
    2830#define ForceFragmentSuffix ".forcefragment.all"
    2931#define OrderSuffix ".Order"
     
    5254  bool AllocateMatrix(char *GivenHeader, int MCounter, int *RCounter, int CCounter);
    5355  bool ResetMatrix();
     56  double FindMinValue();
     57  double FindMaxValue();
    5458  bool SetLastMatrix(double value, int skipcolumns);
    5559  bool SetLastMatrix(double **values, int skipcolumns);
     
    6670  public:
    6771    bool ParseIndices();
    68     bool SumSubEnergy(class EnergyMatrix &Fragments, class KeySetsContainer &KeySet, int Order);
     72    bool SumSubEnergy(class EnergyMatrix &Fragments, class EnergyMatrix *CorrectionFragments, class KeySetsContainer &KeySet, int Order, double sign);
    6973};
    7074
     
    7478  public:
    7579    bool ParseIndices(char *name);
    76     bool SumSubForces(class ForceMatrix &Fragments, class KeySetsContainer &KeySet, int Order);
     80    bool SumSubForces(class ForceMatrix &Fragments, class KeySetsContainer &KeySet, int Order, double sign);
    7781};
    7882
Note: See TracChangeset for help on using the changeset viewer.