1 |
/* |
2 |
* Copyright (c) 2010 The University of Notre Dame. All Rights Reserved. |
3 |
* |
4 |
* The University of Notre Dame grants you ("Licensee") a |
5 |
* non-exclusive, royalty free, license to use, modify and |
6 |
* redistribute this software in source and binary code form, provided |
7 |
* that the following conditions are met: |
8 |
* |
9 |
* 1. Redistributions of source code must retain the above copyright |
10 |
* notice, this list of conditions and the following disclaimer. |
11 |
* |
12 |
* 2. Redistributions in binary form must reproduce the above copyright |
13 |
* notice, this list of conditions and the following disclaimer in the |
14 |
* documentation and/or other materials provided with the |
15 |
* distribution. |
16 |
* |
17 |
* This software is provided "AS IS," without a warranty of any |
18 |
* kind. All express or implied conditions, representations and |
19 |
* warranties, including any implied warranty of merchantability, |
20 |
* fitness for a particular purpose or non-infringement, are hereby |
21 |
* excluded. The University of Notre Dame and its licensors shall not |
22 |
* be liable for any damages suffered by licensee as a result of |
23 |
* using, modifying or distributing the software or its |
24 |
* derivatives. In no event will the University of Notre Dame or its |
25 |
* licensors be liable for any lost revenue, profit or data, or for |
26 |
* direct, indirect, special, consequential, incidental or punitive |
27 |
* damages, however caused and regardless of the theory of liability, |
28 |
* arising out of the use of or inability to use software, even if the |
29 |
* University of Notre Dame has been advised of the possibility of |
30 |
* such damages. |
31 |
* |
32 |
* SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your |
33 |
* research, please cite the appropriate papers when you publish your |
34 |
* work. Good starting points are: |
35 |
* |
36 |
* [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). |
37 |
* [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). |
38 |
* [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008). |
39 |
* [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). |
40 |
* [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). |
41 |
* [6] Kuang & Gezelter, Mol. Phys., 110, 691-701 (2012). |
42 |
*/ |
43 |
|
44 |
#ifdef IS_MPI |
45 |
#include <mpi.h> |
46 |
#endif |
47 |
|
48 |
#include <fstream> |
49 |
#include <iostream> |
50 |
#include <locale> |
51 |
#include "utils/simError.h" |
52 |
#include "utils/CaseConversion.hpp" |
53 |
#include "brains/Register.hpp" |
54 |
#include "brains/SimCreator.hpp" |
55 |
#include "brains/SimInfo.hpp" |
56 |
#include "constraints/ZconstraintForceManager.hpp" |
57 |
#include "restraints/RestraintForceManager.hpp" |
58 |
#include "integrators/IntegratorFactory.hpp" |
59 |
#include "integrators/Integrator.hpp" |
60 |
#include "optimization/OptimizationFactory.hpp" |
61 |
#include "optimization/Method.hpp" |
62 |
#include "optimization/Constraint.hpp" |
63 |
#include "optimization/Problem.hpp" |
64 |
#include "optimization/PotentialEnergyObjectiveFunction.hpp" |
65 |
#include "restraints/ThermoIntegrationForceManager.hpp" |
66 |
|
67 |
using namespace OpenMD; |
68 |
using namespace QuantLib; |
69 |
|
70 |
int main(int argc,char* argv[]){ |
71 |
|
72 |
// first things first, all of the initializations |
73 |
|
74 |
#ifdef IS_MPI |
75 |
MPI_Init( &argc, &argv ); // the MPI communicators |
76 |
#endif |
77 |
|
78 |
initSimError(); // the error handler |
79 |
//srand48( 1337 ); // the random number generator. |
80 |
|
81 |
std::string svnrev; |
82 |
//convert a macro from compiler to a string in c++ |
83 |
STR_DEFINE(svnrev, SVN_REV ); |
84 |
|
85 |
std::string revision; |
86 |
|
87 |
if (!svnrev.empty()) { |
88 |
revision.assign(" Revision: " + svnrev); |
89 |
} |
90 |
|
91 |
revision.resize(19,' '); |
92 |
|
93 |
#ifdef IS_MPI |
94 |
if( worldRank == 0 ){ |
95 |
#endif |
96 |
std::cerr << |
97 |
" +--------------------------------------------------------------------------+\n"<< |
98 |
" | ____ __ ___ ____ |\n"<< |
99 |
" | / __ \\____ ___ ____ / |/ // __ \\ The Open Molecular Dynamics |\n"<< |
100 |
" | / / / / __ \\/ _ \\/ __ \\ / /|_/ // / / / Engine (formerly OOPSE). |\n"<< |
101 |
" | / /_/ / /_/ / __/ / / // / / // /_/ / |\n"<< |
102 |
" | \\____/ .___/\\___/_/ /_//_/ /_//_____/ Copyright 2004-2012 by the |\n"<< |
103 |
" | /_/ University of Notre Dame. |\n"<< |
104 |
" | |\n"<< |
105 |
" | version " << |
106 |
OPENMD_VERSION_MAJOR << "." << OPENMD_VERSION_MINOR << revision << |
107 |
" http://www.openmd.net |\n"<< |
108 |
" | |\n"<< |
109 |
" | OpenMD is an OpenScience project. All source code is available for any |\n"<< |
110 |
" | use whatsoever under a BSD-style license. |\n"<< |
111 |
" | |\n"<< |
112 |
" | Support OpenScience! If you use OpenMD or its source code in your |\n"<< |
113 |
" | research, please cite the appropriate papers when you publish your work |\n"<< |
114 |
" | Good starting points are: |\n"<< |
115 |
" | |\n"<< |
116 |
" | [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). |\n"<< |
117 |
" | [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). |\n"<< |
118 |
" | [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008). |\n"<< |
119 |
" | [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). |\n"<< |
120 |
" | [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). |\n"<< |
121 |
" | [6] Kuang & Gezelter, Mol. Phys., 110, 691-701 (2012). |\n"<< |
122 |
" +--------------------------------------------------------------------------+\n"<< |
123 |
"\n"; |
124 |
|
125 |
if( argc < 2 ){ |
126 |
strcpy( painCave.errMsg, "Error, a meta-data file is needed to run.\n" ); |
127 |
painCave.isFatal = 1; |
128 |
simError(); |
129 |
} |
130 |
#ifdef IS_MPI |
131 |
} |
132 |
#endif |
133 |
|
134 |
strcpy( checkPointMsg, "Successful number of arguments" ); |
135 |
errorCheckPoint(); |
136 |
|
137 |
//register forcefields, integrators and minimizers |
138 |
registerAll(); |
139 |
|
140 |
//create simulation model |
141 |
SimCreator creator; |
142 |
SimInfo* info = creator.createSim(argv[1]); |
143 |
|
144 |
Globals* simParams = info->getSimParams(); |
145 |
MinimizerParameters* miniPars = simParams->getMinimizerParameters(); |
146 |
|
147 |
if (miniPars->getUseMinimizer() && simParams->haveEnsemble()) { |
148 |
sprintf(painCave.errMsg, "Ensemble keyword can not co-exist with useMinimizer = \"true\" in the minimizer block\n"); |
149 |
painCave.isFatal = 1; |
150 |
simError(); |
151 |
} |
152 |
|
153 |
if (miniPars->getUseMinimizer()) { |
154 |
//create minimizer |
155 |
OptimizationMethod* myMinimizer =OptimizationFactory::getInstance()->createOptimization(toUpperCopy(miniPars->getMethod()), info); |
156 |
|
157 |
if (myMinimizer == NULL) { |
158 |
sprintf(painCave.errMsg, "Optimization Factory can not create %s OptimizationMethod\n", |
159 |
miniPars->getMethod().c_str()); |
160 |
painCave.isFatal = 1; |
161 |
simError(); |
162 |
} |
163 |
|
164 |
ForceManager* fman = new ForceManager(info); |
165 |
fman->initialize(); |
166 |
|
167 |
PotentialEnergyObjectiveFunction potObjf(info, fman); |
168 |
DumpStatusFunction dsf(info); |
169 |
DynamicVector<RealType> initCoords = potObjf.setInitialCoords(); |
170 |
Problem problem(potObjf, *(new NoConstraint()), dsf, initCoords); |
171 |
|
172 |
|
173 |
int maxIter = miniPars->getMaxIterations(); |
174 |
int mssIter = miniPars->getMaxStationaryStateIterations(); |
175 |
RealType rEps = miniPars->getRootEpsilon(); |
176 |
RealType fEps = miniPars->getFunctionEpsilon(); |
177 |
RealType gnEps = miniPars->getGradientNormEpsilon(); |
178 |
|
179 |
EndCriteria endCriteria(maxIter, mssIter, rEps, fEps, gnEps); |
180 |
|
181 |
myMinimizer->minimize(problem, endCriteria); |
182 |
|
183 |
delete myMinimizer; |
184 |
} else if (simParams->haveEnsemble()) { |
185 |
//create Integrator |
186 |
|
187 |
Integrator* myIntegrator = IntegratorFactory::getInstance()->createIntegrator(toUpperCopy(simParams->getEnsemble()), info); |
188 |
|
189 |
if (myIntegrator == NULL) { |
190 |
sprintf(painCave.errMsg, "Integrator Factory can not create %s Integrator\n", |
191 |
simParams->getEnsemble().c_str()); |
192 |
painCave.isFatal = 1; |
193 |
simError(); |
194 |
} |
195 |
|
196 |
//Thermodynamic Integration Method |
197 |
//set the force manager for thermodynamic integration if specified |
198 |
if (simParams->getUseThermodynamicIntegration()){ |
199 |
ForceManager* fman = new ThermoIntegrationForceManager(info); |
200 |
myIntegrator->setForceManager(fman); |
201 |
} |
202 |
|
203 |
// Restraints |
204 |
if (simParams->getUseRestraints() && !simParams->getUseThermodynamicIntegration()) { |
205 |
ForceManager* fman = new RestraintForceManager(info); |
206 |
myIntegrator->setForceManager(fman); |
207 |
} |
208 |
|
209 |
//Zconstraint-Method |
210 |
if (simParams->getNZconsStamps() > 0) { |
211 |
info->setNZconstraint(simParams->getNZconsStamps()); |
212 |
ForceManager* fman = new ZconstraintForceManager(info); |
213 |
myIntegrator->setForceManager(fman); |
214 |
} |
215 |
|
216 |
myIntegrator->integrate(); |
217 |
delete myIntegrator; |
218 |
}else { |
219 |
sprintf(painCave.errMsg, "Integrator Factory can not create %s Integrator\n", |
220 |
simParams->getEnsemble().c_str()); |
221 |
painCave.isFatal = 1; |
222 |
simError(); |
223 |
} |
224 |
|
225 |
delete info; |
226 |
|
227 |
|
228 |
strcpy( checkPointMsg, "Great googly moogly! It worked!" ); |
229 |
errorCheckPoint(); |
230 |
|
231 |
#ifdef IS_MPI |
232 |
MPI_Finalize(); |
233 |
#endif |
234 |
|
235 |
return 0 ; |
236 |
} |