54#include "brains/Register.hpp"
57#include "io/DumpWriter.hpp"
58#include "lattice/Lattice.hpp"
63#include "utils/MoLocator.hpp"
69void createMdFile(
const std::string& oldMdFileName,
70 const std::string& newMdFileName,
int nMol);
72int main(
int argc,
char* argv[]) {
76 std::string latticeType;
77 std::string inputFileName;
78 std::string outputFileName;
80 RealType latticeConstant;
81 std::vector<RealType> lc;
82 const RealType rhoConvertConst = 1.66053886;
87 std::vector<Vector3d> latticePos;
88 std::vector<Vector3d> latticeOrt;
93 if (cmdline_parser(argc, argv, &args_info) != 0) exit(1);
95 density = args_info.density_arg;
99 if (args_info.lattice_given) { latticeType = args_info.lattice_arg; }
103 if (simpleLat == NULL) {
104 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
105 "Lattice Factory can not create %s lattice\n",
106 latticeType.c_str());
107 painCave.isFatal = 1;
110 nMolPerCell = simpleLat->getNumSitesPerCell();
114 nx = args_info.nx_arg;
117 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
118 "The number of unit cells in the x direction "
119 "must be greater than 0.");
120 painCave.isFatal = 1;
124 ny = args_info.ny_arg;
127 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
128 "The number of unit cells in the y direction "
129 "must be greater than 0.");
130 painCave.isFatal = 1;
134 nz = args_info.nz_arg;
137 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
138 "The number of unit cells in the z direction "
139 "must be greater than 0.");
140 painCave.isFatal = 1;
144 int nSites = nMolPerCell * nx * ny * nz;
147 if (args_info.inputs_num)
148 inputFileName = args_info.inputs[0];
150 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
151 "No input .omd file name was specified "
152 "on the command line");
153 painCave.isFatal = 1;
160 SimInfo* oldInfo = oldCreator.createSim(inputFileName,
false);
164 RealType avgMass = MoLocator::getMolMass(oldInfo->getMoleculeStamp(0),
165 oldInfo->getForceField());
167 latticeConstant = pow(rhoConvertConst * nMolPerCell * avgMass / density,
168 (RealType)(1.0 / 3.0));
172 lc.push_back(latticeConstant);
173 simpleLat->setLatticeConstant(lc);
179 latticeOrt = simpleLat->getLatticePointsOrt();
181 vector<Vector3d> sites;
182 vector<Vector3d> orientations;
184 for (
int i = 0; i < nx; i++) {
185 for (
int j = 0; j < ny; j++) {
186 for (
int k = 0; k < nz; k++) {
189 simpleLat->getLatticePointsPos(latticePos, i, j, k);
191 for (
int l = 0; l < nMolPerCell; l++) {
192 sites.push_back(latticePos[l]);
193 orientations.push_back(latticeOrt[l]);
199 outputFileName = args_info.output_arg;
203 createMdFile(inputFileName, outputFileName, nSites);
211 SimInfo* newInfo = newCreator.createSim(outputFileName,
false);
215 hmat(0, 0) = nx * latticeConstant;
220 hmat(1, 1) = ny * latticeConstant;
225 hmat(2, 2) = nz * latticeConstant;
229 newInfo->getSnapshotManager()->getCurrentSnapshot()->setHmat(hmat);
235 new MoLocator(newInfo->getMoleculeStamp(0), newInfo->getForceField());
236 for (
int n = 0; n < nSites; n++) {
237 mol = newInfo->getMoleculeByGlobalIndex(n);
238 locator->placeMol(sites[n], orientations[n], mol);
243 writer =
new DumpWriter(newInfo, outputFileName);
245 if (writer == NULL) {
246 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
247 "error in creating DumpWriter");
248 painCave.isFatal = 1;
258 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
259 "A new OpenMD file called \"%s\" has been generated.\n",
260 outputFileName.c_str());
261 painCave.isFatal = 0;
262 painCave.severity = OPENMD_INFO;
267void createMdFile(
const std::string& oldMdFileName,
268 const std::string& newMdFileName,
int nMol) {
271 const int MAXLEN = 65535;
275 oldMdFile.open(oldMdFileName.c_str());
276 newMdFile.open(newMdFileName.c_str());
278 oldMdFile.getline(buffer, MAXLEN);
280 while (!oldMdFile.eof()) {
282 if (strstr(buffer,
"nMol") != NULL) {
283 snprintf(buffer, MAXLEN,
"\t\tnMol = %d;", nMol);
284 newMdFile << buffer << std::endl;
286 newMdFile << buffer << std::endl;
288 oldMdFile.getline(buffer, MAXLEN);
static LatticeFactory & getInstance()
Returns an instance of Lattice 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...
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.
void registerLattice()
Register all lattice.
The header file for the command line option parser generated by GNU Gengetopt version 2....
Where the command line options are stored.