Changeset 85d278


Ignore:
Timestamp:
Oct 18, 2008, 2:06:51 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:
f731ae
Parents:
450d63
Message:

Introduced new class HessianMatrix derived from MatrixContainer, which shall contain the hessians calculated by mpqc.

Location:
src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/joiner.cpp

    r450d63 r85d278  
    1919  periodentafel *periode = NULL; // and a period table of all elements
    2020  EnergyMatrix Energy;
     21  EnergyMatrix EnergyFragments;
     22 
    2123  EnergyMatrix Hcorrection;
     24  EnergyMatrix HcorrectionFragments;
     25 
    2226  ForceMatrix Force;
    23   EnergyMatrix EnergyFragments;
    24   EnergyMatrix HcorrectionFragments;
    2527  ForceMatrix ForceFragments;
     28
     29  HessianMatrix Hessian;
     30  HessianMatrix HessianFragments;
     31 
    2632  ForceMatrix Shielding;
    2733  ForceMatrix ShieldingPAS;
     
    3238  char *dir = NULL;
    3339  bool Hcorrected = true;
     40  bool NoHessian = false;
    3441
    3542  cout << "Joiner" << endl;
     
    6370  Hcorrected = Hcorrection.ParseFragmentMatrix(argv[1], "", HCORRECTIONSUFFIX, 0,0);
    6471  if (!Force.ParseFragmentMatrix(argv[1], dir, ForcesSuffix, 0,0)) return 1;
     72  if (!Hessian.ParseFragmentMatrix(argv[1], dir, HessianSuffix, 0,0)) {
     73    NoHessian = true;
     74    cout << "No hessian matrices found, skipping those.";
     75  }
    6576  if (periode != NULL) { // also look for PAS values
    6677    if (!Shielding.ParseFragmentMatrix(argv[1], dir, ShieldingSuffix, 1, 0)) return 1;
     
    7485  // ---------- Parse the Force indices into an array ---------------
    7586  if (!Force.ParseIndices(argv[1])) return 1;
     87
     88  // ---------- Parse the Hessian (=force) indices into an array ---------------
     89  if (!Hessian.ParseIndices(argv[1])) return 1;
    7690
    7791  // ---------- Parse the shielding indices into an array ---------------
     
    88102  if (Hcorrected)  HcorrectionFragments.AllocateMatrix(Hcorrection.Header, Hcorrection.MatrixCounter, Hcorrection.RowCounter, Hcorrection.ColumnCounter);
    89103  if (!ForceFragments.AllocateMatrix(Force.Header, Force.MatrixCounter, Force.RowCounter, Force.ColumnCounter)) return 1;
     104  if (!NoHessian)
     105    if (!HessianFragments.AllocateMatrix(Hessian.Header, Hessian.MatrixCounter, Hessian.RowCounter, Hessian.ColumnCounter)) return 1;
    90106  if (periode != NULL) { // also look for PAS values
    91107    if (!ShieldingFragments.AllocateMatrix(Shielding.Header, Shielding.MatrixCounter, Shielding.RowCounter, Shielding.ColumnCounter)) return 1;
     
    96112  if(!Energy.SetLastMatrix(0., 0)) return 1;
    97113  if(!Force.SetLastMatrix(0., 2)) return 1;
     114  if (!NoHessian)
     115    if (!Hessian.SetLastMatrix(0., 0)) return 1;
    98116  if (periode != NULL) { // also look for PAS values
    99117    if(!Shielding.SetLastMatrix(0., 2)) return 1;
     
    118136    if (!ForceFragments.SumSubManyBodyTerms(Force, KeySet, BondOrder)) return 1;
    119137    if (!Force.SumSubForces(ForceFragments, KeySet, BondOrder, 1.)) return 1;
     138    // --------- sum up Hessian --------------------
     139    if (!NoHessian) {
     140      cout << "Summing Hessian of order " << BondOrder+1 << " ..." << endl;
     141      if (!HessianFragments.SumSubManyBodyTerms(Hessian, KeySet, BondOrder)) return 1;
     142      if (!Hessian.SumSubHessians(HessianFragments, KeySet, BondOrder, 1.)) return 1;
     143    }
    120144    if (periode != NULL) { // also look for PAS values
    121145      cout << "Summing shieldings of order " << BondOrder+1 << " ..." << endl;
     
    134158    // forces
    135159    if (!Force.WriteLastMatrix(argv[1], (prefix.str()).c_str(), ForcesSuffix)) return 1;
     160    // hessian
     161    if (!Hessian.WriteLastMatrix(argv[1], (prefix.str()).c_str(), HessianSuffix)) return 1;
    136162    // shieldings
    137163    if (periode != NULL) { // also look for PAS values
     
    153179  if (!ForceFragments.WriteTotalFragments(argv[1], (prefix.str()).c_str())) return 1;
    154180  if (!CreateDataFragment(EnergyFragments, KeySet, argv[1], FRAGMENTPREFIX ENERGYPERFRAGMENT, "fragment energy versus the Fragment No", "today", CreateEnergy)) return 1;
     181  if (!NoHessian) {
     182    prefix.str(" ");
     183    prefix << dir << HessianFragmentSuffix;
     184    if (!HessianFragments.WriteTotalFragments(argv[1], (prefix.str()).c_str())) return 1;
     185  }
    155186  if (periode != NULL) { // also look for PAS values
    156187    prefix.str(" ");
     
    166197  if (Hcorrected) Hcorrection.WriteLastMatrix(argv[1], dir, HcorrectionFragmentSuffix);
    167198  if (!Force.WriteLastMatrix(argv[1], dir, ForceFragmentSuffix)) return 1;
     199  if (!NoHessian)
     200    if (!Hessian.WriteLastMatrix(argv[1], dir, HessianFragmentSuffix)) return 1;
    168201  if (periode != NULL) { // also look for PAS values
    169202    if (!Shielding.WriteLastMatrix(argv[1], dir, ShieldingFragmentSuffix)) return 1;
  • src/parser.cpp

    r450d63 r85d278  
    673673};
    674674
     675// ======================================= CLASS HessianMatrix =============================
     676
     677/** Parsing force Indices of each fragment
     678 * \param *name directory with \a ForcesFile
     679 * \return parsing successful
     680 */
     681bool HessianMatrix::ParseIndices(char *name)
     682{
     683  ifstream input;
     684  char *FragmentNumber = NULL;
     685  char filename[1023];
     686  stringstream line;
     687 
     688  cout << "Parsing force indices for " << MatrixCounter << " matrices." << endl;
     689  Indices = (int **) Malloc(sizeof(int *)*(MatrixCounter+1), "HessianMatrix::ParseIndices: **Indices");
     690  line << name << FRAGMENTPREFIX << FORCESFILE;
     691  input.open(line.str().c_str(), ios::in);
     692  //cout << "Opening " << line.str() << " ... "  << input << endl;
     693  if (input == NULL) {
     694    cout << endl << "Unable to open " << line.str() << ", is the directory correct?" << endl;
     695    return false;
     696  }
     697  for (int i=0;(i<MatrixCounter) && (!input.eof());i++) {
     698    // get the number of atoms for this fragment
     699    input.getline(filename, 1023);
     700    line.str(filename);
     701    // parse the values
     702    Indices[i] = (int *) Malloc(sizeof(int)*RowCounter[i], "HessianMatrix::ParseIndices: *Indices[]");
     703    FragmentNumber = FixedDigitNumber(MatrixCounter, i);
     704    //cout << FRAGMENTPREFIX << FragmentNumber << "[" << RowCounter[i] << "]:";
     705    Free((void **)&FragmentNumber, "HessianMatrix::ParseIndices: *FragmentNumber");
     706    for(int j=0;(j<RowCounter[i]) && (!line.eof());j++) {
     707      line >> Indices[i][j];
     708      //cout << " " << Indices[i][j];
     709    }
     710    //cout << endl;
     711  }
     712  Indices[MatrixCounter] = (int *) Malloc(sizeof(int)*RowCounter[MatrixCounter], "HessianMatrix::ParseIndices: *Indices[]");
     713  for(int j=RowCounter[MatrixCounter];j--;) {
     714    Indices[MatrixCounter][j] = j;
     715  }
     716  input.close();
     717  return true;
     718};
     719
     720
     721/** Sums the hessian entries and puts into last element of \a HessianMatrix::Matrix.
     722 * \param Matrix MatrixContainer with matrices (LevelCounter by ColumnCounter) with all the energies.
     723 * \param KeySet KeySetContainer with bond Order and association mapping of each fragment to an order
     724 * \param Order bond order
     725 *  \param sign +1 or -1
     726 * \return true if summing was successful
     727 */
     728bool HessianMatrix::SumSubHessians(class HessianMatrix &Fragments, class KeySetsContainer &KeySet, int Order, double sign)
     729{
     730  int FragmentNr;
     731  // sum forces
     732  for(int i=0;i<KeySet.FragmentsPerOrder[Order];i++) {
     733    FragmentNr = KeySet.OrderSet[Order][i];
     734    for(int l=0;l<RowCounter[ FragmentNr ];l++) {
     735      int j = Indices[ FragmentNr ][l];
     736      if (j > RowCounter[MatrixCounter]) {
     737        cerr << "Current hessian index " << j << " is greater than " << RowCounter[MatrixCounter] << "!" << endl;
     738        return false;
     739      }
     740      if (j != -1) {
     741        //for(int m=0;m<ColumnCounter[ FragmentNr ];m++) {
     742        for(int m=0;m<ColumnCounter;m++) {
     743          int k = Indices[ FragmentNr ][m];
     744//          if (k > ColumnCounter[MatrixCounter]) {
     745//            cerr << "Current hessian index " << k << " is greater than " << ColumnCounter[MatrixCounter] << "!" << endl;
     746          if (k > ColumnCounter) {
     747            cerr << "Current hessian index " << k << " is greater than " << ColumnCounter << "!" << endl;
     748            return false;
     749          }
     750          if (k != -1) {
     751            Matrix[MatrixCounter][j][k] += sign*Fragments.Matrix[ FragmentNr ][l][m];
     752          }
     753        }
     754      }
     755    }
     756  }
     757  return true;
     758};
     759
     760
     761/** Calls MatrixContainer::ParseFragmentMatrix() and additionally allocates last plus one matrix.
     762 * \param *name directory with files
     763 * \param *prefix prefix of each matrix file
     764 * \param *suffix suffix of each matrix file
     765 * \param skiplines number of inital lines to skip
     766 * \param skiplines number of inital columns to skip
     767 * \return parsing successful
     768 */
     769bool HessianMatrix::ParseFragmentMatrix(char *name, char *prefix, string suffix, int skiplines, int skipcolumns)
     770{
     771  char filename[1023];
     772  ifstream input;
     773  stringstream file;
     774  int nr;
     775  bool status = MatrixContainer::ParseFragmentMatrix(name, prefix, suffix, skiplines, skipcolumns);
     776
     777  if (status) {
     778    // count number of atoms for last plus one matrix
     779    file << name << FRAGMENTPREFIX << KEYSETFILE;
     780    input.open(file.str().c_str(), ios::in);
     781    if (input == NULL) {
     782      cout << endl << "Unable to open " << file.str() << ", is the directory correct?" << endl;
     783      return false;
     784    }
     785    RowCounter[MatrixCounter] = 0;
     786    while (!input.eof()) {
     787      input.getline(filename, 1023);
     788      stringstream zeile(filename);
     789      while (!zeile.eof()) {
     790        zeile >> nr;
     791        //cout << "Current index: " << nr << "." << endl;
     792        if (nr > RowCounter[MatrixCounter])
     793          RowCounter[MatrixCounter] = nr;
     794      }
     795    }
     796    RowCounter[MatrixCounter]++;    // nr start at 0, count starts at 1
     797    input.close();
     798 
     799    // allocate last plus one matrix
     800    cout << "Allocating last plus one matrix with " << (RowCounter[MatrixCounter]+1) << " rows and " << ColumnCounter << " columns." << endl;
     801    Matrix[MatrixCounter] = (double **) Malloc(sizeof(double *)*(RowCounter[MatrixCounter]+1), "MatrixContainer::ParseFragmentMatrix: **Matrix[]");
     802    for(int j=0;j<=RowCounter[MatrixCounter];j++)
     803      Matrix[MatrixCounter][j] = (double *) Malloc(sizeof(double)*ColumnCounter, "MatrixContainer::ParseFragmentMatrix: *Matrix[][]");
     804
     805    // try independently to parse global forcesuffix file if present
     806    strncpy(filename, name, 1023);
     807    strncat(filename, prefix, 1023-strlen(filename));
     808    strncat(filename, suffix.c_str(), 1023-strlen(filename));
     809    ParseMatrix(filename, skiplines, skipcolumns, MatrixCounter);
     810  }
     811 
     812
     813  return status;
     814};
     815
    675816// ======================================= CLASS KeySetsContainer =============================
    676817
  • src/parser.hpp

    r450d63 r85d278  
    1919
    2020#define EnergySuffix ".energy.all"
     21#define EnergyFragmentSuffix ".energyfragment.all"
     22#define ForcesSuffix ".forces.all"
     23#define ForceFragmentSuffix ".forcefragment.all"
    2124#define HcorrectionSuffix ".Hcorrection.all"
    22 #define ForcesSuffix ".forces.all"
     25#define HcorrectionFragmentSuffix ".Hcorrectionfragment.all"
     26#define HessianSuffix ".hessian_xx.all"
     27#define HessianFragmentSuffix ".hessianfragment_xx.all"
     28#define OrderSuffix ".Order"
    2329#define ShieldingSuffix ".sigma_all.csv"
    2430#define ShieldingPASSuffix ".sigma_all_PAS.csv"
     
    2632#define ShieldingPASFragmentSuffix ".sigma_all_PAS_fragment.all"
    2733#define TimeSuffix ".speed"
    28 #define EnergyFragmentSuffix ".energyfragment.all"
    29 #define HcorrectionFragmentSuffix ".Hcorrectionfragment.all"
    30 #define ForceFragmentSuffix ".forcefragment.all"
    31 #define OrderSuffix ".Order"
    3234
    3335// ======================================= FUNCTIONS ==========================================
     
    8486};
    8587
     88// ======================================= CLASS HessianMatrix =============================
     89
     90class HessianMatrix : public MatrixContainer {
     91  public:
     92    bool ParseIndices(char *name);
     93    bool SumSubHessians(class HessianMatrix &Fragments, class KeySetsContainer &KeySet, int Order, double sign);
     94    bool ParseFragmentMatrix(char *name, char *prefix, string suffix, int skiplines, int skipcolumns);
     95};
     96
    8697// ======================================= CLASS KeySetsContainer =============================
    8798
Note: See TracChangeset for help on using the changeset viewer.