OpenMD 3.2
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
equationofstate.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 <cmath>
49#include <fstream>
50#include <iostream>
51#include <string>
52
54#include "brains/Register.hpp"
55#include "brains/SimCreator.hpp"
56#include "brains/SimInfo.hpp"
57#include "brains/Thermo.hpp"
59#include "flucq/FluctuatingChargeDamped.hpp"
60#include "io/DumpReader.hpp"
61#include "io/DumpWriter.hpp"
62#include "types/FluctuatingChargeAdapter.hpp"
63#include "utils/Constants.hpp"
64#include "utils/ProgressBar.hpp"
65#include "utils/simError.h"
66
67using namespace OpenMD;
68using namespace std;
69
70int main(int argc, char* argv[]) {
71 gengetopt_args_info args_info;
72 string omdFileName;
73 string outFileName;
74
75 // parse the command line option
76 if (cmdline_parser(argc, argv, &args_info) != 0) { exit(1); }
77
78 // get the omd file name and meta-data file name
79 if (args_info.input_given) {
80 omdFileName = args_info.input_arg;
81 } else {
82 strcpy(painCave.errMsg, "No input file name was specified.\n");
83 painCave.isFatal = 1;
84 simError();
85 }
86
87 if (args_info.output_given) {
88 outFileName = args_info.output_arg;
89 } else {
90 strcpy(painCave.errMsg, "No output file name was specified.\n");
91 painCave.isFatal = 1;
92 simError();
93 }
94
95 double start_affine = args_info.start_arg;
96 double end_affine = args_info.end_arg;
97 int number = args_info.number_arg;
98
99 RealType affine_step = (end_affine - start_affine) / (number + 1);
100
101 registerAll();
102
103 SimInfo::MoleculeIterator miter;
104 Molecule::IntegrableObjectIterator iiter;
105 Molecule::RigidBodyIterator rbIter;
106 Molecule* mol;
107 StuntDouble* sd;
108 StuntDouble* sdNew;
109 RigidBody* rb;
110 Mat3x3d oldHmat;
111 Mat3x3d newHmat;
112 Snapshot* oldSnap;
113 Snapshot* newSnap;
114 Vector3d oldPos;
115 Vector3d newPos;
116 AtomType* atype;
117
118 // parse omd file and set up the system
119 SimCreator oldCreator;
120 SimInfo* oldInfo = oldCreator.createSim(omdFileName);
121 oldSnap = oldInfo->getSnapshotManager()->getCurrentSnapshot();
122 oldHmat = oldSnap->getHmat();
123
124 // ProgressBarPtr progressBar {nullptr};
125 // progressBar = std::make_unique<ProgressBar>();
126
127 ofstream eos;
128 eos.open(outFileName.c_str());
129
130 RealType current_affine = start_affine;
131 int countStep = 0;
132 std::cout << "Calculation for EOS started." << std::endl;
133 while (current_affine <= end_affine) {
134 // progressBar->setStatus(countStep,number);
135 // progressBar->update();
136 ++countStep;
137 RealType scaling = std::cbrt(current_affine);
138 Mat3x3d scaleMatrix = Mat3x3d(0.0);
139 scaleMatrix(0, 0) = scaling;
140 scaleMatrix(1, 1) = scaling;
141 scaleMatrix(2, 2) = scaling;
142
143 SimInfo* newInfo = oldCreator.createSim(omdFileName);
144 newSnap = newInfo->getSnapshotManager()->getCurrentSnapshot();
145
146 newHmat = scaleMatrix * oldHmat;
147 newSnap->setHmat(newHmat);
148
149 int newIndex = 0;
150 for (mol = oldInfo->beginMolecule(miter); mol != NULL;
151 mol = oldInfo->nextMolecule(miter)) {
152 for (sd = mol->beginIntegrableObject(iiter); sd != NULL;
153 sd = mol->nextIntegrableObject(iiter)) {
154 oldPos = sd->getPos();
155 oldSnap->wrapVector(oldPos);
156 newPos = scaleMatrix * oldPos;
157 sdNew = newInfo->getIOIndexToIntegrableObject(newIndex);
158 sdNew->setPos(newPos);
159 sdNew->setVel(sd->getVel());
160 if (sd->isAtom()) {
161 atype = static_cast<Atom*>(sd)->getAtomType();
163 if (fqa.isFluctuatingCharge()) {
164 RealType charge = sd->getFlucQPos();
165 sdNew->setFlucQPos(charge);
166 RealType cv = sd->getFlucQVel();
167 sdNew->setFlucQVel(cv);
168 }
169 }
170 }
171
172 newIndex++;
173 }
174
175 for (mol = newInfo->beginMolecule(miter); mol != NULL;
176 mol = newInfo->nextMolecule(miter)) {
177 // change the positions of atoms which belong to the rigidbodies
178 for (rb = mol->beginRigidBody(rbIter); rb != NULL;
179 rb = mol->nextRigidBody(rbIter)) {
180 rb->updateAtoms();
181 rb->updateAtomVel();
182 }
183 }
184
185 ForceManager* fman = new ForceManager(newInfo);
186 fman->initialize();
187
189 flucQ->setForceManager(fman);
190 flucQ->initialize();
191
192 fman->calcForces();
193 Thermo thermo(newInfo);
194 RealType totalEnergy(0);
195 totalEnergy = thermo.getTotalEnergy();
196 eos << current_affine << "\t" << totalEnergy << "\n";
197
198 std::cout << countStep << " data generated." << std::endl;
199
200 current_affine += affine_step;
201
202 delete flucQ;
203 delete fman;
204 }
205 eos.close();
206}
AtomType is what OpenMD looks to for unchanging data about an atom.
Definition AtomType.hpp:69
abstract class for propagating fluctuating charge variables
ForceManager is responsible for calculating both the short range (bonded) interactions and long range...
void updateAtoms()
update the positions of atoms belong to this rigidbody
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
Molecule * beginMolecule(MoleculeIterator &i)
Returns the first molecule in this SimInfo and intialize the iterator.
Definition SimInfo.cpp:243
Molecule * nextMolecule(MoleculeIterator &i)
Returns the next avaliable Molecule based on the iterator.
Definition SimInfo.cpp:248
SnapshotManager * getSnapshotManager()
Returns the snapshot manager.
Definition SimInfo.hpp:251
StuntDouble * getIOIndexToIntegrableObject(int index)
return an integral objects by its global index.
Definition SimInfo.cpp:1031
The Snapshot class is a repository storing dynamic data during a Simulation.
Definition Snapshot.hpp:166
Mat3x3d getHmat()
Returns the H-Matrix.
Definition Snapshot.cpp:217
void setHmat(const Mat3x3d &m)
Sets the H-Matrix.
Definition Snapshot.cpp:220
void wrapVector(Vector3d &v)
Wrapping the vector according to periodic boundary condition.
Definition Snapshot.cpp:340
Snapshot * getCurrentSnapshot()
Returns the pointer of current snapshot.
"Don't move, or you're dead! Stand up! Captain, we've got them!"
void setFlucQVel(RealType cvel)
Sets the current charge velocity of this stuntDouble.
Vector3d getVel()
Returns the current velocity of this stuntDouble.
void setFlucQPos(RealType charge)
Sets the current fluctuating charge of this stuntDouble.
Vector3d getPos()
Returns the current position of this stuntDouble.
RealType getFlucQPos()
Returns the current fluctuating charge of this stuntDouble.
void setPos(const Vector3d &pos)
Sets the current position of this stuntDouble.
void setVel(const Vector3d &vel)
Sets the current velocity of this stuntDouble.
bool isAtom()
Tests if this stuntDouble is an atom.
RealType getFlucQVel()
Returns the current charge velocity of this stuntDouble.
The header file for the command line option parser generated by GNU Gengetopt version 2....
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
Where the command line options are stored.
unsigned int output_given
Whether output was given.
char * output_arg
output file name.
int number_arg
number of data points (default='50').
char * input_arg
input dump file.
double start_arg
starting affine scale (default='0.8').
unsigned int input_given
Whether input was given.
double end_arg
ending affine scale (default='1.2').