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 |
*/ |
42 |
|
43 |
#ifdef IS_MPI |
44 |
#include <mpi.h> |
45 |
#endif |
46 |
|
47 |
#include <fstream> |
48 |
#include "utils/simError.h" |
49 |
#include "utils/CaseConversion.hpp" |
50 |
#include "brains/Register.hpp" |
51 |
#include "brains/SimCreator.hpp" |
52 |
#include "brains/SimInfo.hpp" |
53 |
#include "constraints/ZconstraintForceManager.hpp" |
54 |
#include "restraints/RestraintForceManager.hpp" |
55 |
#include "integrators/IntegratorFactory.hpp" |
56 |
#include "integrators/Integrator.hpp" |
57 |
#include "optimization/OptimizationFactory.hpp" |
58 |
#include "optimization/Method.hpp" |
59 |
#include "optimization/Constraint.hpp" |
60 |
#include "optimization/Problem.hpp" |
61 |
#include "optimization/PotentialEnergyObjectiveFunction.hpp" |
62 |
#include "restraints/ThermoIntegrationForceManager.hpp" |
63 |
|
64 |
using namespace OpenMD; |
65 |
using namespace QuantLib; |
66 |
|
67 |
int main(int argc,char* argv[]){ |
68 |
|
69 |
// first things first, all of the initializations |
70 |
|
71 |
#ifdef IS_MPI |
72 |
MPI_Init( &argc, &argv ); // the MPI communicators |
73 |
#endif |
74 |
|
75 |
initSimError(); // the error handler |
76 |
srand48( 1337 ); // the random number generator. |
77 |
|
78 |
std::string svnrev; |
79 |
//convert a macro from compiler to a string in c++ |
80 |
STR_DEFINE(svnrev, SVN_REV ); |
81 |
|
82 |
std::string revision; |
83 |
|
84 |
if (!svnrev.empty()) { |
85 |
revision.assign(" Revision: " + svnrev); |
86 |
} |
87 |
|
88 |
revision.resize(19,' '); |
89 |
|
90 |
#ifdef IS_MPI |
91 |
if( worldRank == 0 ){ |
92 |
#endif |
93 |
std::cerr << |
94 |
" +--------------------------------------------------------------------------+\n"<< |
95 |
" | ____ __ ___ ____ |\n"<< |
96 |
" | / __ \\____ ___ ____ / |/ // __ \\ The Open Molecular Dynamics |\n"<< |
97 |
" | / / / / __ \\/ _ \\/ __ \\ / /|_/ // / / / Engine (formerly OOPSE). |\n"<< |
98 |
" | / /_/ / /_/ / __/ / / // / / // /_/ / |\n"<< |
99 |
" | \\____/ .___/\\___/_/ /_//_/ /_//_____/ Copyright 2004-2012 by the |\n"<< |
100 |
" | /_/ University of Notre Dame. |\n"<< |
101 |
" | |\n"<< |
102 |
" | version " << |
103 |
OPENMD_VERSION_MAJOR << "." << OPENMD_VERSION_MINOR << revision << |
104 |
" http://www.openmd.net |\n"<< |
105 |
" | |\n"<< |
106 |
" | OpenMD is an OpenScience project. All source code is available for any |\n"<< |
107 |
" | use whatsoever under a BSD-style license. |\n"<< |
108 |
" | |\n"<< |
109 |
" | Support OpenScience! If you use OpenMD or its source code in your |\n"<< |
110 |
" | research, please cite the appropriate papers when you publish your work |\n"<< |
111 |
" | Good starting points are: |\n"<< |
112 |
" | |\n"<< |
113 |
" | [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). |\n"<< |
114 |
" | [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). |\n"<< |
115 |
" | [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008). |\n"<< |
116 |
" | [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). |\n"<< |
117 |
" | [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). |\n"<< |
118 |
" | [6] Kuang & Gezelter, Mol. Phys., in press (2012). |\n"<< |
119 |
" +--------------------------------------------------------------------------+\n"<< |
120 |
"\n"; |
121 |
|
122 |
if( argc < 2 ){ |
123 |
strcpy( painCave.errMsg, "Error, a meta-data file is needed to run.\n" ); |
124 |
painCave.isFatal = 1; |
125 |
simError(); |
126 |
} |
127 |
#ifdef IS_MPI |
128 |
} |
129 |
#endif |
130 |
|
131 |
strcpy( checkPointMsg, "Successful number of arguments" ); |
132 |
errorCheckPoint(); |
133 |
|
134 |
//register forcefields, integrators and minimizers |
135 |
registerAll(); |
136 |
|
137 |
//create simulation model |
138 |
SimCreator creator; |
139 |
SimInfo* info = creator.createSim(argv[1]); |
140 |
|
141 |
Globals* simParams = info->getSimParams(); |
142 |
|
143 |
if (simParams->haveMinimizer() && simParams->haveEnsemble()) { |
144 |
sprintf(painCave.errMsg, "Minimizer keyword and Ensemble keyword can not exist together\n"); |
145 |
painCave.isFatal = 1; |
146 |
simError(); |
147 |
} |
148 |
|
149 |
|
150 |
if (simParams->haveMinimizer()) { |
151 |
//create minimizer |
152 |
OptimizationMethod* myMinimizer =OptimizationFactory::getInstance()->createOptimization(toUpperCopy(simParams->getMinimizer()), info); |
153 |
|
154 |
if (myMinimizer == NULL) { |
155 |
sprintf(painCave.errMsg, "Optimization Factory can not create %s OptimizationMethod\n", |
156 |
simParams->getMinimizer().c_str()); |
157 |
painCave.isFatal = 1; |
158 |
simError(); |
159 |
} |
160 |
|
161 |
ForceManager* fman = new ForceManager(info); |
162 |
fman->initialize(); |
163 |
|
164 |
PotentialEnergyObjectiveFunction potObjf(info, fman); |
165 |
DumpStatusFunction dsf(info); |
166 |
DynamicVector<RealType> initCoords = potObjf.setInitialCoords(); |
167 |
Problem problem(potObjf, *(new NoConstraint()), dsf, initCoords); |
168 |
EndCriteria endCriteria(1000, 100, 1e-5, 1e-5, 1e-5); |
169 |
|
170 |
myMinimizer->minimize(problem, endCriteria); |
171 |
|
172 |
delete myMinimizer; |
173 |
} else if (simParams->haveEnsemble()) { |
174 |
//create Integrator |
175 |
|
176 |
Integrator* myIntegrator = IntegratorFactory::getInstance()->createIntegrator(toUpperCopy(simParams->getEnsemble()), info); |
177 |
|
178 |
if (myIntegrator == NULL) { |
179 |
sprintf(painCave.errMsg, "Integrator Factory can not create %s Integrator\n", |
180 |
simParams->getEnsemble().c_str()); |
181 |
painCave.isFatal = 1; |
182 |
simError(); |
183 |
} |
184 |
|
185 |
//Thermodynamic Integration Method |
186 |
//set the force manager for thermodynamic integration if specified |
187 |
if (simParams->getUseThermodynamicIntegration()){ |
188 |
ForceManager* fman = new ThermoIntegrationForceManager(info); |
189 |
myIntegrator->setForceManager(fman); |
190 |
} |
191 |
|
192 |
// Restraints |
193 |
if (simParams->getUseRestraints() && !simParams->getUseThermodynamicIntegration()) { |
194 |
ForceManager* fman = new RestraintForceManager(info); |
195 |
myIntegrator->setForceManager(fman); |
196 |
} |
197 |
|
198 |
//Zconstraint-Method |
199 |
if (simParams->getNZconsStamps() > 0) { |
200 |
info->setNZconstraint(simParams->getNZconsStamps()); |
201 |
ForceManager* fman = new ZconstraintForceManager(info); |
202 |
myIntegrator->setForceManager(fman); |
203 |
} |
204 |
|
205 |
myIntegrator->integrate(); |
206 |
delete myIntegrator; |
207 |
}else { |
208 |
sprintf(painCave.errMsg, "Integrator Factory can not create %s Integrator\n", |
209 |
simParams->getEnsemble().c_str()); |
210 |
painCave.isFatal = 1; |
211 |
simError(); |
212 |
} |
213 |
|
214 |
delete info; |
215 |
|
216 |
|
217 |
strcpy( checkPointMsg, "Great googly moogly! It worked!" ); |
218 |
errorCheckPoint(); |
219 |
|
220 |
#ifdef IS_MPI |
221 |
MPI_Finalize(); |
222 |
#endif |
223 |
|
224 |
return 0 ; |
225 |
} |