Changeset d392067 for src/bin/mpqc


Ignore:
Timestamp:
Jul 10, 2012, 1:15:51 PM (13 years ago)
Author:
Frederik Heber <heber@…>
Children:
bab0b1
Parents:
ad2befa
git-author:
Frederik Heber <heber@…> (07/06/12 20:03:47)
git-committer:
Frederik Heber <heber@…> (07/10/12 13:15:51)
Message:

Extracted performing gradient calculation into own function.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/bin/mpqc/mpqc.cc

    rad2befa rd392067  
    919919}
    920920
     921/** Performs gradient calculation.
     922 *
     923 * \param mole molecular energy object
     924 */
     925void performGradientCalculation(
     926    Ref<MolecularEnergy> &mole
     927    )
     928{
     929  mole->do_gradient(1);
     930  ExEnv::out0() << endl << indent
     931       << scprintf("Value of the MolecularEnergy: %15.10f",
     932                   mole->energy())
     933       << endl;
     934  if (mole->value_result().actual_accuracy()
     935      > mole->value_result().desired_accuracy()) {
     936    ExEnv::out0() << indent
     937         << "WARNING: desired accuracy not achieved in energy" << endl;
     938  }
     939  ExEnv::out0() << endl;
     940  // Use result_noupdate since the energy might not have converged
     941  // to the desired accuracy in which case grabbing the result will
     942  // start up the calculation again.  However the gradient might
     943  // not have been computed (if we are restarting and the gradient
     944  // isn't in the save file for example).
     945  RefSCVector grad;
     946  if (mole->gradient_result().computed()) {
     947    grad = mole->gradient_result().result_noupdate();
     948  }
     949  else {
     950    grad = mole->gradient();
     951  }
     952  if (grad.nonnull()) {
     953    grad.print("Gradient of the MolecularEnergy:");
     954    if (mole->gradient_result().actual_accuracy()
     955        > mole->gradient_result().desired_accuracy()) {
     956      ExEnv::out0() << indent
     957           << "WARNING: desired accuracy not achieved in gradient" << endl;
     958    }
     959  }
     960}
     961
    921962int
    922963try_main(int argc, char *argv[])
     
    10371078       << " by default for molecular integrals evaluation" << endl << endl;
    10381079 
    1039   // check for a molecular energy and optimizer
     1080  // create some filenames for molecule, checkpoint, basename of output
    10401081  const char *basename = SCFormIO::default_basename();
    10411082  KeyValValueString molnamedef(basename);
     
    11451186
    11461187    } else if (do_grad && mole->gradient_implemented()) {
    1147       mole->do_gradient(1);
    1148       ExEnv::out0() << endl << indent
    1149            << scprintf("Value of the MolecularEnergy: %15.10f",
    1150                        mole->energy())
    1151            << endl;
    1152       if (mole->value_result().actual_accuracy()
    1153           > mole->value_result().desired_accuracy()) {
    1154         ExEnv::out0() << indent
    1155              << "WARNING: desired accuracy not achieved in energy" << endl;
    1156       }
    1157       ExEnv::out0() << endl;
    1158       // Use result_noupdate since the energy might not have converged
    1159       // to the desired accuracy in which case grabbing the result will
    1160       // start up the calculation again.  However the gradient might
    1161       // not have been computed (if we are restarting and the gradient
    1162       // isn't in the save file for example).
    1163       RefSCVector grad;
    1164       if (mole->gradient_result().computed()) {
    1165         grad = mole->gradient_result().result_noupdate();
    1166       }
    1167       else {
    1168         grad = mole->gradient();
    1169       }
    1170       if (grad.nonnull()) {
    1171         grad.print("Gradient of the MolecularEnergy:");
    1172         if (mole->gradient_result().actual_accuracy()
    1173             > mole->gradient_result().desired_accuracy()) {
    1174           ExEnv::out0() << indent
    1175                << "WARNING: desired accuracy not achieved in gradient" << endl;
    1176         }
    1177       }
     1188
     1189      performGradientCalculation(mole);
     1190
    11781191    } else if (do_energy && mole->value_implemented()) {
    11791192      ExEnv::out0() << endl << indent
     
    11841197  }
    11851198
     1199  // stop timing of calculations
    11861200  if (tim.nonnull()) tim->exit("calc");
    11871201
Note: See TracChangeset for help on using the changeset viewer.