OpenMD 3.0
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
openmd.cpp
1/*
2 * Copyright (c) 2004-present, The University of Notre Dame. All rights
3 * reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 *
31 * SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your
32 * research, please cite the appropriate papers when you publish your
33 * work. Good starting points are:
34 *
35 * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).
36 * [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).
37 * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008).
38 * [4] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
39 * [5] Kuang & Gezelter, Mol. Phys., 110, 691-701 (2012).
40 * [6] Lamichhane, Gezelter & Newman, J. Chem. Phys. 141, 134109 (2014).
41 * [7] Lamichhane, Newman & Gezelter, J. Chem. Phys. 141, 134110 (2014).
42 * [8] Bhattarai, Newman & Gezelter, Phys. Rev. B 99, 094106 (2019).
43 */
44
45#include <fstream>
46#include <iostream>
47#include <locale>
48
49#ifdef IS_MPI
50#include <mpi.h>
51#endif
52
53#include "brains/Register.hpp"
54#include "brains/SimCreator.hpp"
55#include "brains/SimInfo.hpp"
56#include "integrators/Integrator.hpp"
60#include "optimization/OptimizationFactory.hpp"
61#include "optimization/PotentialEnergyObjectiveFunction.hpp"
63#include "utils/CaseConversion.hpp"
64#include "utils/Revision.hpp"
65#include "utils/simError.h"
66
67using namespace OpenMD;
68using namespace QuantLib;
69
70int main(int argc, char* argv[]) {
71 // first things first, all of the initializations
72
73#ifdef IS_MPI
74 MPI_Init(&argc, &argv); // the MPI communicators
75#endif
76
77 initSimError(); // the error handler
78
79 Revision r;
80
81#ifdef IS_MPI
82 if (worldRank == 0) {
83#endif
84 std::cout
85 << " "
86 "+------------------------------------------------------------------"
87 "----"
88 "----+\n"
89 << " | ____ __ ___ ____ "
90 " "
91 " |\n"
92 << " | / __ \\____ ___ ____ / |/ // __ \\ The Open Molecular "
93 "Dynamics |\n"
94 << " | / / / / __ \\/ _ \\/ __ \\ / /|_/ // / / / Engine (formerly "
95 "OOPSE). |\n"
96 << " | / /_/ / /_/ / __/ / / // / / // /_/ / "
97 " "
98 " |\n"
99 << " | \\____/ .___/\\___/_/ /_//_/ /_//_____/ Copyright "
100 "2004-2023 by "
101 "the |\n"
102 << " | /_/ University of Notre "
103 "Dame. |\n"
104 << " | http://openmd.org "
105 " "
106 " |\n"
107 << " | "
108 " "
109 " |\n"
110 << " | " << r.getFullRevision() << " |\n"
111 << " | " << r.getBuildDate()
112 << " |\n"
113 << " | "
114 " "
115 " |\n"
116 << " | OpenMD is an OpenScience project. All source code is "
117 "available "
118 "for any |\n"
119 << " | use whatsoever under a BSD-style license. "
120 " "
121 " |\n"
122 << " | "
123 " "
124 " |\n"
125 << " | Support OpenScience! If you use OpenMD or its source code in "
126 "your "
127 " |\n"
128 << " | research, please cite the appropriate papers when you publish "
129 "your "
130 "work. |\n"
131 << " | Good starting points for code and simulation methodology are: "
132 " "
133 " |\n"
134 << " | "
135 " "
136 " |\n"
137 << " | [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). "
138 " "
139 " |\n"
140 << " | [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). "
141 " "
142 " |\n"
143 << " | [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008). "
144 " "
145 " |\n"
146 << " | [4] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, "
147 "834 "
148 "(2011). |\n"
149 << " | [5] Kuang & Gezelter, Mol. Phys., 110, 691-701 (2012). "
150 " "
151 " |\n"
152 << " | [6] Lamichhane, Gezelter & Newman, J. Chem. Phys. 141, 134109 "
153 "(2014). |\n"
154 << " | [7] Lamichhane, Newman & Gezelter, J. Chem. Phys. 141, 134110 "
155 "(2014). |\n"
156 << " | [8] Bhattarai, Newman & Gezelter, Phys. Rev. B 99, 094106 "
157 "(2019). "
158 " |\n"
159 << " "
160 "+------------------------------------------------------------------"
161 "----"
162 "----+\n"
163 << "\n";
164
165 if (argc < 2) {
166 strcpy(painCave.errMsg,
167 "No meta-data file was specified on the command line.\n");
168 painCave.isFatal = 1;
169 simError();
170 }
171#ifdef IS_MPI
172 }
173#endif
174
175 strcpy(checkPointMsg, "Successful number of arguments");
176 errorCheckPoint();
177
178 // register forcefields, integrators and minimizers
179 registerAll();
180
181 // create simulation model
182 SimCreator creator;
183 SimInfo* info = creator.createSim(argv[1]);
184
185 Globals* simParams = info->getSimParams();
186 MinimizerParameters* miniPars = simParams->getMinimizerParameters();
187
188 if (miniPars->getUseMinimizer() && simParams->haveEnsemble()) {
189 snprintf(
190 painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
191 "Ensemble keyword can not co-exist with useMinimizer = \"true\" in the "
192 "minimizer block\n");
193 painCave.isFatal = 1;
194 simError();
195 }
196
197 if (miniPars->getUseMinimizer()) {
198 // create minimizer
199 OptimizationMethod* myMinimizer =
200 OptimizationFactory::getInstance().createOptimization(
201 toUpperCopy(miniPars->getMethod()), info);
202
203 if (myMinimizer == NULL) {
204 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
205 "Optimization Factory can not create %s OptimizationMethod\n",
206 miniPars->getMethod().c_str());
207 painCave.isFatal = 1;
208 simError();
209 }
210
211 ForceManager* fman = new ForceManager(info);
212 fman->initialize();
213
214 PotentialEnergyObjectiveFunction potObjf(info, fman);
215 NoConstraint noConstraint {};
216 DumpStatusFunction dsf(info);
217 DynamicVector<RealType> initCoords = potObjf.setInitialCoords();
218 Problem problem(potObjf, noConstraint, dsf, initCoords);
219
220 int maxIter = miniPars->getMaxIterations();
221 int mssIter = miniPars->getMaxStationaryStateIterations();
222 RealType rEps = miniPars->getRootEpsilon();
223 RealType fEps = miniPars->getFunctionEpsilon();
224 RealType gnEps = miniPars->getGradientNormEpsilon();
225 RealType initialStepSize = miniPars->getInitialStepSize();
226
227 EndCriteria endCriteria(maxIter, mssIter, rEps, fEps, gnEps);
228 myMinimizer->minimize(problem, endCriteria, initialStepSize);
229
230 delete myMinimizer;
231 } else if (simParams->haveEnsemble()) {
232 // create Integrator
233 Integrator* myIntegrator =
234 IntegratorFactory::getInstance().createIntegrator(
235 toUpperCopy(simParams->getEnsemble()), info);
236
237 if (myIntegrator == NULL) {
238 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
239 "Integrator Factory can not create %s Integrator\n",
240 simParams->getEnsemble().c_str());
241 painCave.isFatal = 1;
242 simError();
243 }
244
245 myIntegrator->integrate();
246 delete myIntegrator;
247 } else {
248 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
249 "Integrator Factory can not create %s Integrator\n",
250 simParams->getEnsemble().c_str());
251 painCave.isFatal = 1;
252 simError();
253 }
254
255 delete info;
256
257 strcpy(checkPointMsg, "Great googly moogly! It worked!");
258 errorCheckPoint();
259
260#ifdef IS_MPI
261 MPI_Finalize();
262#endif
263
264 return 0;
265}
Abstract constraint class.
Abstract optimization method class.
Abstract optimization problem class.
ForceManager is responsible for calculating both the short range (bonded) interactions and long range...
static IntegratorFactory & getInstance()
Returns an instance of Integrator factory.
Declaration of the Integrator base class, which all other integrators inherit from.
static OptimizationFactory & getInstance()
Returns an instance of Optimization factory.
The only responsibility of SimCreator is to parse the meta-data file and create a SimInfo instance ba...
One of the heavy-weight classes of OpenMD, SimInfo maintains objects and variables relating to the cu...
Definition SimInfo.hpp:93
Criteria to end optimization process:
Abstract class for constrained optimization method.
Definition Method.hpp:36
Constrained optimization problem.
Definition Problem.hpp:37
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.
void registerAll()
register force fields, integrators and optimizers
Definition Register.cpp:140