--- trunk/src/applications/openmd/openmd.cpp 2010/03/30 15:31:41 1430 +++ trunk/src/applications/openmd/openmd.cpp 2012/09/10 18:38:44 1796 @@ -35,8 +35,10 @@ * * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). * [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). - * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008). - * [4] Vardeman & Gezelter, in progress (2010). + * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008). + * [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). + * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). + * [6] Kuang & Gezelter, Mol. Phys., 110, 691-701 (2012). */ #ifdef IS_MPI @@ -44,6 +46,8 @@ #endif #include +#include +#include #include "utils/simError.h" #include "utils/CaseConversion.hpp" #include "brains/Register.hpp" @@ -53,53 +57,69 @@ #include "restraints/RestraintForceManager.hpp" #include "integrators/IntegratorFactory.hpp" #include "integrators/Integrator.hpp" -#include "minimizers/MinimizerFactory.hpp" -#include "minimizers/Minimizer.hpp" +#include "optimization/OptimizationFactory.hpp" +#include "optimization/Method.hpp" +#include "optimization/Constraint.hpp" +#include "optimization/Problem.hpp" +#include "optimization/PotentialEnergyObjectiveFunction.hpp" #include "restraints/ThermoIntegrationForceManager.hpp" using namespace OpenMD; +using namespace QuantLib; -char* __get_svn_version(); - -int main(int argc,char* argv[]){ +int main(int argc, char* argv[]){ // first things first, all of the initializations #ifdef IS_MPI - MPI_Init( &argc, &argv ); // the MPI communicators + MPI::Init( argc, argv ); // the MPI communicators #endif initSimError(); // the error handler - srand48( 1337 ); // the random number generator. - + //srand48( 1337 ); // the random number generator. + + std::string svnrev; + //convert a macro from compiler to a string in c++ + STR_DEFINE(svnrev, SVN_REV ); + + std::string revision; + + if (!svnrev.empty()) { + revision.assign(" Revision: " + svnrev); + } + + revision.resize(19,' '); + #ifdef IS_MPI if( worldRank == 0 ){ #endif std::cerr << - " +-----------------------------------------------------------------------+\n"<< - " | ____ __ ___ ____ |\n"<< - " | / __ \\____ ___ ____ / |/ // __ \\ The Open Molecular Dynamics |\n"<< - " | / / / / __ \\/ _ \\/ __ \\ / /|_/ // / / / Engine (formerly OOPSE). |\n"<< - " | / /_/ / /_/ / __/ / / // / / // /_/ / |\n"<< - " | \\____/ .___/\\___/_/ /_//_/ /_//_____/ Copyright 2004-2010 by the |\n"<< - " | /_/ University of Notre Dame. |\n"<< - " | |\n"<< - " | version " << - OPENMD_VERSION_MAJOR << "." << OPENMD_VERSION_MINOR << " Revision:" << __get_svn_version() << - " http://www.openmd.net |\n"<< - " | |\n"<< - " | OpenMD is an OpenScience project. All source code is available for |\n"<< - " | any use whatsoever under a BSD-style license. |\n"<< - " | |\n"<< - " | Support OpenScience! If you use OpenMD or its source code in your |\n"<< - " | research, please cite the appropriate papers when you publish your |\n"<< - " | work. Good starting points are: |\n"<< - " | |\n"<< - " | [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). |\n"<< - " | [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). |\n"<< - " | [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008). |\n"<< - " | [4] Vardeman & Gezelter, in progress (2010). |\n"<< - " +-----------------------------------------------------------------------+\n"<< + " +--------------------------------------------------------------------------+\n"<< + " | ____ __ ___ ____ |\n"<< + " | / __ \\____ ___ ____ / |/ // __ \\ The Open Molecular Dynamics |\n"<< + " | / / / / __ \\/ _ \\/ __ \\ / /|_/ // / / / Engine (formerly OOPSE). |\n"<< + " | / /_/ / /_/ / __/ / / // / / // /_/ / |\n"<< + " | \\____/ .___/\\___/_/ /_//_/ /_//_____/ Copyright 2004-2012 by the |\n"<< + " | /_/ University of Notre Dame. |\n"<< + " | |\n"<< + " | version " << + OPENMD_VERSION_MAJOR << "." << OPENMD_VERSION_MINOR << revision << + " http://www.openmd.net |\n"<< + " | |\n"<< + " | OpenMD is an OpenScience project. All source code is available for any |\n"<< + " | use whatsoever under a BSD-style license. |\n"<< + " | |\n"<< + " | Support OpenScience! If you use OpenMD or its source code in your |\n"<< + " | research, please cite the appropriate papers when you publish your work |\n"<< + " | Good starting points are: |\n"<< + " | |\n"<< + " | [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). |\n"<< + " | [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). |\n"<< + " | [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008). |\n"<< + " | [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). |\n"<< + " | [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). |\n"<< + " | [6] Kuang & Gezelter, Mol. Phys., 110, 691-701 (2012). |\n"<< + " +--------------------------------------------------------------------------+\n"<< "\n"; if( argc < 2 ){ @@ -120,26 +140,46 @@ int main(int argc,char* argv[]){ //create simulation model SimCreator creator; SimInfo* info = creator.createSim(argv[1]); + Globals* simParams = info->getSimParams(); + MinimizerParameters* miniPars = simParams->getMinimizerParameters(); - if (simParams->haveMinimizer() && simParams->haveEnsemble()) { - sprintf(painCave.errMsg, "Minimizer keyword and Ensemble keyword can not exist together\n"); + if (miniPars->getUseMinimizer() && simParams->haveEnsemble()) { + sprintf(painCave.errMsg, "Ensemble keyword can not co-exist with useMinimizer = \"true\" in the minimizer block\n"); painCave.isFatal = 1; simError(); } - - if (simParams->haveMinimizer()) { + + if (miniPars->getUseMinimizer()) { //create minimizer - Minimizer* myMinimizer = MinimizerFactory::getInstance()->createMinimizer(toUpperCopy(simParams->getMinimizer()), info); + OptimizationMethod* myMinimizer =OptimizationFactory::getInstance()->createOptimization(toUpperCopy(miniPars->getMethod()), info); if (myMinimizer == NULL) { - sprintf(painCave.errMsg, "Minimizer Factory can not create %s Minimizer\n", - simParams->getMinimizer().c_str()); + sprintf(painCave.errMsg, "Optimization Factory can not create %s OptimizationMethod\n", + miniPars->getMethod().c_str()); painCave.isFatal = 1; simError(); } - myMinimizer->minimize(); + ForceManager* fman = new ForceManager(info); + fman->initialize(); + + PotentialEnergyObjectiveFunction potObjf(info, fman); + DumpStatusFunction dsf(info); + DynamicVector initCoords = potObjf.setInitialCoords(); + Problem problem(potObjf, *(new NoConstraint()), dsf, initCoords); + + + int maxIter = miniPars->getMaxIterations(); + int mssIter = miniPars->getMaxStationaryStateIterations(); + RealType rEps = miniPars->getRootEpsilon(); + RealType fEps = miniPars->getFunctionEpsilon(); + RealType gnEps = miniPars->getGradientNormEpsilon(); + + EndCriteria endCriteria(maxIter, mssIter, rEps, fEps, gnEps); + + myMinimizer->minimize(problem, endCriteria); + delete myMinimizer; } else if (simParams->haveEnsemble()) { //create Integrator @@ -189,19 +229,8 @@ int main(int argc,char* argv[]){ errorCheckPoint(); #ifdef IS_MPI - MPI_Finalize(); + MPI::Finalize(); #endif return 0 ; } - - char svnVersionString[1024]; - char* __get_svn_version(){ - int howMuchToCopy=0; - const char *theVersion="$Revision$"; - howMuchToCopy=strlen(theVersion+11) - 2; - assert(howMuchToCopy>0); - memcpy(svnVersionString, theVersion+11, howMuchToCopy); - svnVersionString[howMuchToCopy] = '\0'; - return svnVersionString; - }