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);
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();
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;
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;
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;
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;
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]);
203 createMdFile(inputFileName, outputFileName, nSites);
215 hmat(0, 0) = nx * latticeConstant;
220 hmat(1, 1) = ny * latticeConstant;
225 hmat(2, 2) = nz * latticeConstant;
236 for (
int n = 0; n < nSites; 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);
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.