OpenMD 3.2
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 following paper when you publish your work:
33 *
34 * [1] Drisko et al., J. Open Source Softw. 9, 7004 (2024).
35 *
36 * Good starting points for code and simulation methodology are:
37 *
38 * [2] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).
39 * [3] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).
40 * [4] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008).
41 * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
42 * [6] Kuang & Gezelter, Mol. Phys., 110, 691-701 (2012).
43 * [7] Lamichhane, Gezelter & Newman, J. Chem. Phys. 141, 134109 (2014).
44 * [8] Bhattarai, Newman & Gezelter, Phys. Rev. B 99, 094106 (2019).
45 * [9] Drisko & Gezelter, J. Chem. Theory Comput. 20, 4986-4997 (2024).
46 */
47
48#include <fstream>
49#include <iostream>
50#include <locale>
51
52#ifdef IS_MPI
53#include <mpi.h>
54#endif
55
56#include "brains/Register.hpp"
57#include "brains/SimCreator.hpp"
58#include "brains/SimInfo.hpp"
59#include "integrators/Integrator.hpp"
63#include "optimization/OptimizationFactory.hpp"
64#include "optimization/PotentialEnergyObjectiveFunction.hpp"
66#include "utils/CaseConversion.hpp"
67#include "utils/Revision.hpp"
68#include "utils/simError.h"
69
70using namespace OpenMD;
71using namespace QuantLib;
72
73int main(int argc, char* argv[]) {
74 // first things first, all of the initializations
75
76#ifdef IS_MPI
77 MPI_Init(&argc, &argv); // the MPI communicators
78#endif
79
80 initSimError(); // the error handler
81
82 Revision r;
83
84#ifdef IS_MPI
85 if (worldRank == 0) {
86#endif
87 std::cout
88 << " +--------------------------------------------------------------------------+\n"
89 << " | ____ __ ___ ____ |\n"
90 << " | / __ \\____ ___ ____ / |/ // __ \\ The Open Molecular Dynamics |\n"
91 << " | / / / / __ \\/ _ \\/ __ \\ / /|_/ // / / / Engine: openmd.org |\n"
92 << " | / /_/ / /_/ / __/ / / // / / // /_/ / |\n"
93 << " | \\____/ /___/\\___/_/ /_//_/ /_//_____/ Copyright 2004-2024 by the |\n"
94 << " | /_/ University of Notre Dame |\n"
95 << " | |\n"
96 << " | " << r.getHalfRevision() << " |\n"
97 << " | |\n"
98 << " | All source code is available under a BSD 3-Clause License. If you use |\n"
99 << " | OpenMD or its source code in your research, please cite the following |\n"
100 << " | paper when you publish your work: |\n"
101 << " | |\n"
102 << " | [1] Drisko et al., J. Open Source Softw. 9, 7004 (2024). |\n"
103 << " | |\n"
104 << " | Good starting points for code and simulation methodology are: |\n"
105 << " | |\n"
106 << " | [2] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). |\n"
107 << " | [3] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). |\n"
108 << " | [4] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008). |\n"
109 << " | [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). |\n"
110 << " | [6] Kuang & Gezelter, Mol. Phys., 110, 691-701 (2012). |\n"
111 << " | [7] Lamichhane, Gezelter & Newman, J. Chem. Phys. 141, 134109 (2014). |\n"
112 << " | [8] Bhattarai, Newman & Gezelter, Phys. Rev. B 99, 094106 (2019). |\n"
113 << " | [9] Drisko & Gezelter, J. Chem. Theory Comput. 20, 4986-4997 (2024). |\n"
114 << " +--------------------------------------------------------------------------+\n"
115 << "\n";
116
117 if (argc < 2) {
118 strcpy(painCave.errMsg,
119 "No meta-data file was specified on the command line.\n");
120 painCave.isFatal = 1;
121 simError();
122 }
123#ifdef IS_MPI
124 }
125#endif
126
127 strcpy(checkPointMsg, "Successful number of arguments");
128 errorCheckPoint();
129
130 // register forcefields, integrators and minimizers
131 registerAll();
132
133 // create simulation model
134 SimCreator creator;
135 SimInfo* info = creator.createSim(argv[1]);
136
137 Globals* simParams = info->getSimParams();
138 MinimizerParameters* miniPars = simParams->getMinimizerParameters();
139
140 if (miniPars->getUseMinimizer() && simParams->haveEnsemble()) {
141 snprintf(
142 painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
143 "Ensemble keyword can not co-exist with useMinimizer = \"true\" in the "
144 "minimizer block\n");
145 painCave.isFatal = 1;
146 simError();
147 }
148
149 if (miniPars->getUseMinimizer()) {
150 // create minimizer
151 OptimizationMethod* myMinimizer =
153 toUpperCopy(miniPars->getMethod()), info);
154
155 if (myMinimizer == NULL) {
156 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
157 "Optimization Factory can not create %s OptimizationMethod\n",
158 miniPars->getMethod().c_str());
159 painCave.isFatal = 1;
160 simError();
161 }
162
163 ForceManager* fman = new ForceManager(info);
164 fman->initialize();
165
166 PotentialEnergyObjectiveFunction potObjf(info, fman);
167 NoConstraint noConstraint {};
168 DumpStatusFunction dsf(info);
169 DynamicVector<RealType> initCoords = potObjf.setInitialCoords();
170 Problem problem(potObjf, noConstraint, dsf, initCoords);
171
172 int maxIter = miniPars->getMaxIterations();
173 int mssIter = miniPars->getMaxStationaryStateIterations();
174 RealType rEps = miniPars->getRootEpsilon();
175 RealType fEps = miniPars->getFunctionEpsilon();
176 RealType gnEps = miniPars->getGradientNormEpsilon();
177 RealType initialStepSize = miniPars->getInitialStepSize();
178
179 EndCriteria endCriteria(maxIter, mssIter, rEps, fEps, gnEps);
180 myMinimizer->minimize(problem, endCriteria, initialStepSize);
181
182 delete myMinimizer;
183 } else if (simParams->haveEnsemble()) {
184 // create Integrator
185 Integrator* myIntegrator =
187 toUpperCopy(simParams->getEnsemble()), info);
188
189 if (myIntegrator == NULL) {
190 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
191 "Integrator Factory can not create %s Integrator\n",
192 simParams->getEnsemble().c_str());
193 painCave.isFatal = 1;
194 simError();
195 }
196
197 myIntegrator->integrate();
198 delete myIntegrator;
199 } else {
200 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
201 "Integrator Factory can not create %s Integrator\n",
202 simParams->getEnsemble().c_str());
203 painCave.isFatal = 1;
204 simError();
205 }
206
207 delete info;
208
209 strcpy(checkPointMsg, "Great googly moogly! It worked!");
210 errorCheckPoint();
211
212#ifdef IS_MPI
213 MPI_Finalize();
214#endif
215
216 return 0;
217}
Abstract constraint class.
Abstract optimization method class.
Abstract optimization problem class.
Dynamically-sized vector class.
ForceManager is responsible for calculating both the short range (bonded) interactions and long range...
Integrator * createIntegrator(const std::string &id, SimInfo *info)
Looks up the type identifier in the internal map.
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.
QuantLib::OptimizationMethod * createOptimization(const std::string &id, SimInfo *info)
Looks up the type identifier in the internal map.
The only responsibility of SimCreator is to parse the meta-data file and create a SimInfo instance ba...
SimInfo * createSim(const std::string &mdFileName, bool loadInitCoords=true)
Setup Simulation.
One of the heavy-weight classes of OpenMD, SimInfo maintains objects and variables relating to the cu...
Definition SimInfo.hpp:96
Criteria to end optimization process:
Abstract class for constrained optimization method.
Definition Method.hpp:36
virtual EndCriteria::Type minimize(Problem &P, const EndCriteria &endCriteria, RealType initialStepSize)=0
minimize the optimization problem P
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:143