57#include "brains/Register.hpp"
60#include "io/DumpWriter.hpp"
61#include "lattice/Lattice.hpp"
66#include "utils/MoLocator.hpp"
72void createMdFile(
const std::string& oldMdFileName,
73 const std::string& newMdFileName,
int nMol);
75int main(
int argc,
char* argv[]) {
79 std::string latticeType;
80 std::string inputFileName;
81 std::string outputFileName;
83 RealType latticeConstant;
84 std::vector<RealType> lc;
85 const RealType rhoConvertConst = 1.66053886;
90 std::vector<Vector3d> latticePos;
91 std::vector<Vector3d> latticeOrt;
96 if (cmdline_parser(argc, argv, &args_info) != 0) exit(1);
106 if (simpleLat == NULL) {
107 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
108 "Lattice Factory can not create %s lattice\n",
109 latticeType.c_str());
110 painCave.isFatal = 1;
113 nMolPerCell = simpleLat->getNumSitesPerCell();
120 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
121 "The number of unit cells in the x direction "
122 "must be greater than 0.");
123 painCave.isFatal = 1;
130 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
131 "The number of unit cells in the y direction "
132 "must be greater than 0.");
133 painCave.isFatal = 1;
140 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
141 "The number of unit cells in the z direction "
142 "must be greater than 0.");
143 painCave.isFatal = 1;
147 int nSites = nMolPerCell * nx * ny * nz;
151 inputFileName = args_info.
inputs[0];
153 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
154 "No input .omd file name was specified "
155 "on the command line");
156 painCave.isFatal = 1;
170 latticeConstant = pow(rhoConvertConst * nMolPerCell * avgMass / density,
171 (RealType)(1.0 / 3.0));
175 lc.push_back(latticeConstant);
176 simpleLat->setLatticeConstant(lc);
182 latticeOrt = simpleLat->getLatticePointsOrt();
184 vector<Vector3d> sites;
185 vector<Vector3d> orientations;
187 for (
int i = 0; i < nx; i++) {
188 for (
int j = 0; j < ny; j++) {
189 for (
int k = 0; k < nz; k++) {
192 simpleLat->getLatticePointsPos(latticePos, i, j, k);
194 for (
int l = 0; l < nMolPerCell; l++) {
195 sites.push_back(latticePos[l]);
196 orientations.push_back(latticeOrt[l]);
206 createMdFile(inputFileName, outputFileName, nSites);
218 hmat(0, 0) = nx * latticeConstant;
223 hmat(1, 1) = ny * latticeConstant;
228 hmat(2, 2) = nz * latticeConstant;
239 for (
int n = 0; n < nSites; n++) {
241 locator->placeMol(sites[n], orientations[n], mol);
246 writer =
new DumpWriter(newInfo, outputFileName);
248 if (writer == NULL) {
249 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
250 "error in creating DumpWriter");
251 painCave.isFatal = 1;
261 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
262 "A new OpenMD file called \"%s\" has been generated.\n",
263 outputFileName.c_str());
264 painCave.isFatal = 0;
265 painCave.severity = OPENMD_INFO;
270void createMdFile(
const std::string& oldMdFileName,
271 const std::string& newMdFileName,
int nMol) {
274 const int MAXLEN = 65535;
278 oldMdFile.open(oldMdFileName.c_str());
279 newMdFile.open(newMdFileName.c_str());
281 oldMdFile.getline(buffer, MAXLEN);
283 while (!oldMdFile.eof()) {
285 if (strstr(buffer,
"nMol") != NULL) {
286 snprintf(buffer, MAXLEN,
"\t\tnMol = %d;", nMol);
287 newMdFile << buffer << std::endl;
289 newMdFile << buffer << std::endl;
291 oldMdFile.getline(buffer, MAXLEN);
Lattice * createLattice(const std::string &id)
Looks up the type identifier in the internal map.
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...
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...
Molecule * getMoleculeByGlobalIndex(int index)
Finds a molecule with a specified global index.
ForceField * getForceField()
Returns the force field.
MoleculeStamp * getMoleculeStamp(int id)
Returns the molecule stamp.
SnapshotManager * getSnapshotManager()
Returns the snapshot manager.
void setHmat(const Mat3x3d &m)
Sets the H-Matrix.
Snapshot * getCurrentSnapshot()
Returns the pointer of current snapshot.
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.
unsigned inputs_num
unamed options number
unsigned int lattice_given
Whether lattice was given.
char * output_arg
output file name.
char ** inputs
unamed options (options without names)
int ny_arg
number of unit cells in y.
int nz_arg
number of unit cells in z.
double density_arg
density (g/cm^3).
int nx_arg
number of unit cells in x.
char * lattice_arg
Lattice Type.