1 |
< |
/* |
1 |
> |
/* |
2 |
|
* Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. |
3 |
|
* |
4 |
|
* The University of Notre Dame grants you ("Licensee") a |
38 |
|
* University of Notre Dame has been advised of the possibility of |
39 |
|
* such damages. |
40 |
|
*/ |
41 |
< |
|
41 |
> |
|
42 |
|
#include <cstdlib> |
43 |
|
#include <cstdio> |
44 |
|
#include <cstring> |
48 |
|
#include <map> |
49 |
|
#include <fstream> |
50 |
|
|
51 |
+ |
#include "config.h" |
52 |
+ |
|
53 |
|
#include "nanorodBuilderCmd.h" |
54 |
< |
//#include "GeometryBuilder.hpp" |
55 |
< |
#include "applications/simpleBuilder/LatticeFactory.hpp" |
56 |
< |
#include "applications/simpleBuilder/MoLocator.hpp" |
57 |
< |
#include "applications/simpleBuilder/Lattice.hpp" |
54 |
> |
#ifdef HAVE_CGAL |
55 |
> |
#include "GeometryBuilder.hpp" |
56 |
> |
#endif |
57 |
> |
#include "lattice/LatticeFactory.hpp" |
58 |
> |
#include "utils/MoLocator.hpp" |
59 |
> |
#include "lattice/Lattice.hpp" |
60 |
|
#include "brains/Register.hpp" |
61 |
|
#include "brains/SimInfo.hpp" |
62 |
|
#include "brains/SimCreator.hpp" |
67 |
|
|
68 |
|
using namespace std; |
69 |
|
using namespace oopse; |
70 |
< |
void createMdFile(const std::string&oldMdFileName, const std::string&newMdFileName, |
70 |
> |
void createMdFile(const std::string&oldMdFileName, |
71 |
> |
const std::string&newMdFileName, |
72 |
|
int numMol); |
73 |
|
|
74 |
|
int main(int argc, char *argv []) { |
75 |
< |
|
76 |
< |
//register force fields |
77 |
< |
registerForceFields(); |
75 |
> |
|
76 |
> |
//register force fields |
77 |
> |
registerForceFields(); |
78 |
> |
registerLattice(); |
79 |
> |
|
80 |
> |
gengetopt_args_info args_info; |
81 |
> |
std::string latticeType; |
82 |
> |
std::string inputFileName; |
83 |
> |
std::string outPrefix; |
84 |
> |
std::string outMdFileName; |
85 |
> |
std::string outInitFileName; |
86 |
> |
std::string outGeomFileName; |
87 |
> |
|
88 |
> |
|
89 |
> |
Lattice *simpleLat; |
90 |
> |
int numMol; |
91 |
> |
double latticeConstant; |
92 |
> |
std::vector<double> lc; |
93 |
> |
double mass; |
94 |
> |
const double rhoConvertConst = 1.661; |
95 |
> |
double density; |
96 |
> |
double rodLength; |
97 |
> |
double rodDiameter; |
98 |
> |
|
99 |
> |
|
100 |
> |
int nx, ny, nz; |
101 |
> |
Mat3x3d hmat; |
102 |
> |
MoLocator *locator; |
103 |
> |
std::vector<Vector3d> latticePos; |
104 |
> |
std::vector<Vector3d> latticeOrt; |
105 |
> |
int numMolPerCell; |
106 |
> |
int curMolIndex; |
107 |
> |
DumpWriter *writer; |
108 |
> |
|
109 |
> |
// parse command line arguments |
110 |
> |
if (cmdline_parser(argc, argv, &args_info) != 0) |
111 |
> |
exit(1); |
112 |
> |
|
113 |
> |
|
114 |
> |
// Check for lib CGAL, if we don't have it, we should exit.... |
115 |
> |
|
116 |
> |
#ifndef HAVE_CGAL |
117 |
> |
std::cerr << "nanoRodBuilder requires libCGAL to function, please rebuild OOPSE with libCGAL." |
118 |
> |
<< std::endl; |
119 |
> |
exit(1); |
120 |
> |
#endif |
121 |
> |
|
122 |
> |
|
123 |
> |
|
124 |
> |
//get lattice type |
125 |
> |
latticeType = UpperCase(args_info.latticetype_arg); |
126 |
> |
|
127 |
> |
|
128 |
> |
simpleLat = LatticeFactory::getInstance()->createLattice(latticeType); |
129 |
> |
if (simpleLat == NULL) { |
130 |
> |
sprintf(painCave.errMsg, "Lattice Factory can not create %s lattice\n", |
131 |
> |
latticeType.c_str()); |
132 |
> |
painCave.isFatal = 1; |
133 |
> |
simError(); |
134 |
> |
} |
135 |
> |
|
136 |
> |
//get input file name |
137 |
> |
if (args_info.inputs_num) |
138 |
> |
inputFileName = args_info.inputs[0]; |
139 |
> |
else { |
140 |
> |
std::cerr << "You must specify a input file name.\n" << std::endl; |
141 |
> |
cmdline_parser_print_help(); |
142 |
> |
exit(1); |
143 |
> |
} |
144 |
> |
|
145 |
> |
//parse md file and set up the system |
146 |
> |
SimCreator oldCreator; |
147 |
> |
SimInfo* oldInfo = oldCreator.createSim(inputFileName, false); |
148 |
> |
|
149 |
> |
if (oldInfo->getNMoleculeStamp()> 1) { |
150 |
> |
std::cerr << "can not build nanorod with more than one components" |
151 |
> |
<< std::endl; |
152 |
> |
exit(1); |
153 |
> |
} |
154 |
> |
|
155 |
> |
//get mass of molecule. |
156 |
> |
|
157 |
> |
mass = getMolMass(oldInfo->getMoleculeStamp(0), oldInfo->getForceField()); |
158 |
> |
|
159 |
> |
//creat lattice |
160 |
> |
simpleLat = LatticeFactory::getInstance()->createLattice(latticeType); |
161 |
> |
|
162 |
> |
if (simpleLat == NULL) { |
163 |
> |
std::cerr << "Error in creating lattice" << std::endl; |
164 |
> |
exit(1); |
165 |
> |
} |
166 |
> |
|
167 |
> |
numMolPerCell = simpleLat->getNumSitesPerCell(); |
168 |
> |
|
169 |
> |
//calculate lattice constant (in Angstrom) |
170 |
> |
//latticeConstant = pow(rhoConvertConst * numMolPerCell * mass / density, |
171 |
> |
// 1.0 / 3.0); |
172 |
> |
|
173 |
> |
latticeConstant = args_info.latticeCnst_arg; |
174 |
> |
rodLength = args_info.length_arg; |
175 |
> |
rodDiameter = args_info.width_arg; |
176 |
> |
|
177 |
> |
//set lattice constant |
178 |
> |
lc.push_back(latticeConstant); |
179 |
> |
simpleLat->setLatticeConstant(lc); |
180 |
> |
|
181 |
> |
|
182 |
> |
//determine the output file names |
183 |
> |
if (args_info.output_given) |
184 |
> |
outInitFileName = args_info.output_arg; |
185 |
> |
else |
186 |
> |
outInitFileName = getPrefix(inputFileName.c_str()) + ".in"; |
187 |
> |
|
188 |
> |
//creat Molocator |
189 |
> |
locator = new MoLocator(oldInfo->getMoleculeStamp(0), oldInfo->getForceField()); |
190 |
> |
|
191 |
> |
/* |
192 |
> |
Assume we are carving nanorod out of a cublic block of material and that |
193 |
> |
the shape the material will fit within that block.... |
194 |
> |
The model in geometry builder assumes the long axis is in the y direction and the x-z plane is the |
195 |
> |
diameter of the particle. |
196 |
> |
*/ |
197 |
> |
// Number of Unit Cells in Length first |
198 |
> |
ny = (int)(rodLength/latticeConstant); |
199 |
> |
// Number of unit cells in Width |
200 |
> |
nx = (int)(rodDiameter/latticeConstant); |
201 |
> |
nz = (int)(rodDiameter/latticeConstant); |
202 |
> |
|
203 |
> |
|
204 |
> |
|
205 |
> |
// Create geometry for nanocrystal |
206 |
> |
#ifdef HAVE_CGAL |
207 |
> |
GeometryBuilder myGeometry(rodLength,rodDiameter); |
208 |
> |
#endif |
209 |
> |
|
210 |
> |
/* |
211 |
> |
We have to build the system first to figure out how many molecules |
212 |
> |
there are then create a md file and then actually build the |
213 |
> |
system. |
214 |
> |
*/ |
215 |
> |
|
216 |
> |
//place the molecules |
217 |
> |
|
218 |
> |
curMolIndex = 0; |
219 |
> |
|
220 |
> |
//get the orientation of the cell sites |
221 |
> |
//for the same type of molecule in same lattice, it will not change |
222 |
> |
latticeOrt = simpleLat->getLatticePointsOrt(); |
223 |
> |
|
224 |
> |
|
225 |
> |
/* |
226 |
> |
void BaseLattice::getLatticePointsPos(std::vector<Vector3d>& |
227 |
> |
latticePos, int nx, int ny, int nz){ |
228 |
|
|
229 |
< |
gengetopt_args_info args_info; |
230 |
< |
std::string latticeType; |
231 |
< |
std::string inputFileName; |
77 |
< |
std::string outPrefix; |
78 |
< |
std::string outMdFileName; |
79 |
< |
std::string outInitFileName; |
80 |
< |
std::string outGeomFileName; |
81 |
< |
|
82 |
< |
|
83 |
< |
BaseLattice *simpleLat; |
84 |
< |
int numMol; |
85 |
< |
double latticeConstant; |
86 |
< |
std::vector<double> lc; |
87 |
< |
double mass; |
88 |
< |
const double rhoConvertConst = 1.661; |
89 |
< |
double density; |
90 |
< |
double rodLength; |
91 |
< |
double rodDiameter; |
92 |
< |
|
93 |
< |
|
94 |
< |
int nx, |
95 |
< |
ny, |
96 |
< |
nz; |
97 |
< |
Mat3x3d hmat; |
98 |
< |
MoLocator *locator; |
99 |
< |
std::vector<Vector3d> latticePos; |
100 |
< |
std::vector<Vector3d> latticeOrt; |
101 |
< |
int numMolPerCell; |
102 |
< |
int curMolIndex; |
103 |
< |
DumpWriter *writer; |
104 |
< |
|
105 |
< |
// parse command line arguments |
106 |
< |
if (cmdline_parser(argc, argv, &args_info) != 0) |
107 |
< |
exit(1); |
108 |
< |
|
229 |
> |
latticePos.resize(nCellSites); |
230 |
> |
|
231 |
> |
for( int i=0;i < nCellSites;i++){ |
232 |
|
|
233 |
< |
|
234 |
< |
//get lattice type |
235 |
< |
latticeType = UpperCase(args_info.latticetype_arg); |
113 |
< |
|
114 |
< |
if (!LatticeFactory::getInstance()->hasLatticeCreator(latticeType)) { |
115 |
< |
std::cerr << latticeType << " is an invalid lattice type" << std::endl; |
116 |
< |
std::cerr << LatticeFactory::getInstance()->toString() << std::endl; |
117 |
< |
exit(1); |
233 |
> |
latticePos[i][0] = origin[0] + cellSitesPos[i][0] + cellLen[0] * (double(nx) - 0.5); |
234 |
> |
latticePos[i][1] = origin[1] + cellSitesPos[i][1] + cellLen[1] * (double(ny) - 0.5); |
235 |
> |
latticePos[i][2] = origin[2] + cellSitesPos[i][2] + cellLen[2] * (double(nz) - 0.5); |
236 |
|
} |
119 |
– |
|
237 |
|
|
238 |
< |
//get input file name |
239 |
< |
if (args_info.inputs_num) |
240 |
< |
inputFileName = args_info.inputs[0]; |
241 |
< |
else { |
242 |
< |
std::cerr << "You must specify a input file name.\n" << std::endl; |
243 |
< |
cmdline_parser_print_help(); |
244 |
< |
exit(1); |
245 |
< |
} |
238 |
> |
*/ |
239 |
> |
|
240 |
> |
|
241 |
> |
|
242 |
> |
|
243 |
> |
numMol = 0; |
244 |
> |
for(int i = 0; i < nx; i++) { |
245 |
> |
for(int j = 0; j < ny; j++) { |
246 |
> |
for(int k = 0; k < nz; k++) { |
247 |
> |
//if (oldInfo->getNGlobalMolecules() != numMol) { |
248 |
> |
|
249 |
> |
|
250 |
> |
|
251 |
> |
//get the position of the cell sites |
252 |
> |
simpleLat->getLatticePointsPos(latticePos, i, j, k); |
253 |
> |
|
254 |
> |
for(int l = 0; l < numMolPerCell; l++) { |
255 |
|
|
256 |
< |
//parse md file and set up the system |
257 |
< |
SimCreator oldCreator; |
258 |
< |
SimInfo* oldInfo = oldCreator.createSim(inputFileName, false); |
259 |
< |
|
260 |
< |
if (oldInfo->getNMoleculeStamp()> 1) { |
261 |
< |
std::cerr << "can not build nanorod with more than one components" |
262 |
< |
<< std::endl; |
137 |
< |
exit(1); |
256 |
> |
#ifdef HAVE_CGAL |
257 |
> |
if (myGeometry.isInsidePolyhedron(latticePos[l][0],latticePos[l][1],latticePos[l][2])){ |
258 |
> |
numMol++; |
259 |
> |
} |
260 |
> |
#endif |
261 |
> |
} |
262 |
> |
} |
263 |
|
} |
264 |
< |
|
265 |
< |
//get mass of molecule. |
266 |
< |
|
267 |
< |
mass = getMolMass(oldInfo->getMoleculeStamp(0), oldInfo->getForceField()); |
268 |
< |
|
269 |
< |
//creat lattice |
270 |
< |
simpleLat = LatticeFactory::getInstance()->createLattice(latticeType); |
271 |
< |
|
272 |
< |
if (simpleLat == NULL) { |
273 |
< |
std::cerr << "Error in creating lattice" << std::endl; |
274 |
< |
exit(1); |
275 |
< |
} |
276 |
< |
|
277 |
< |
numMolPerCell = simpleLat->getNumSitesPerCell(); |
278 |
< |
|
279 |
< |
//calculate lattice constant (in Angstrom) |
280 |
< |
//latticeConstant = pow(rhoConvertConst * numMolPerCell * mass / density, |
281 |
< |
// 1.0 / 3.0); |
282 |
< |
|
283 |
< |
latticeConstant = args_info.latticeCnst_arg; |
284 |
< |
rodLength = args_info.length_arg; |
285 |
< |
rodDiameter = args_info.width_arg; |
286 |
< |
|
287 |
< |
//set lattice constant |
288 |
< |
lc.push_back(latticeConstant); |
289 |
< |
simpleLat->setLatticeConstant(lc); |
290 |
< |
|
291 |
< |
|
292 |
< |
//determine the output file names |
293 |
< |
if (args_info.output_given) |
169 |
< |
outInitFileName = args_info.output_arg; |
170 |
< |
else |
171 |
< |
outInitFileName = getPrefix(inputFileName.c_str()) + ".in"; |
172 |
< |
|
173 |
< |
//creat Molocator |
174 |
< |
locator = new MoLocator(oldInfo->getMoleculeStamp(0), oldInfo->getForceField()); |
175 |
< |
|
176 |
< |
/* |
177 |
< |
Assume we are carving nanorod out of a cublic block of material and that |
178 |
< |
the shape the material will fit within that block.... |
179 |
< |
The model in geometry builder assumes the long axis is in the y direction and the x-z plane is the |
180 |
< |
diameter of the particle. |
181 |
< |
*/ |
182 |
< |
// Number of Unit Cells in Length first |
183 |
< |
ny = (int)(rodLength/latticeConstant); |
184 |
< |
// Number of unit cells in Width |
185 |
< |
nx = (int)(rodDiameter/latticeConstant); |
186 |
< |
nz = (int)(rodDiameter/latticeConstant); |
187 |
< |
|
188 |
< |
|
189 |
< |
|
190 |
< |
// Create geometry for nanocrystal |
191 |
< |
//GeometryBuilder myGeometry(rodLength,rodDiameter); |
192 |
< |
|
193 |
< |
/* |
194 |
< |
We have to build the system first to figure out how many molecules there are |
195 |
< |
then create a md file and then actually build the system. |
196 |
< |
*/ |
197 |
< |
|
198 |
< |
//place the molecules |
199 |
< |
|
200 |
< |
curMolIndex = 0; |
201 |
< |
|
202 |
< |
//get the orientation of the cell sites |
203 |
< |
//for the same type of molecule in same lattice, it will not change |
204 |
< |
latticeOrt = simpleLat->getLatticePointsOrt(); |
264 |
> |
} |
265 |
> |
|
266 |
> |
|
267 |
> |
// needed for writing out new md file. |
268 |
> |
|
269 |
> |
outPrefix = getPrefix(inputFileName.c_str()) + "_" + latticeType; |
270 |
> |
outMdFileName = outPrefix + ".md"; |
271 |
> |
|
272 |
> |
//creat new .md file on fly which corrects the number of molecule |
273 |
> |
createMdFile(inputFileName, outMdFileName, numMol); |
274 |
> |
|
275 |
> |
if (oldInfo != NULL) |
276 |
> |
delete oldInfo; |
277 |
> |
|
278 |
> |
|
279 |
> |
// We need to read in new siminfo object. |
280 |
> |
//parse md file and set up the system |
281 |
> |
//SimCreator NewCreator; |
282 |
> |
|
283 |
> |
SimInfo* NewInfo = oldCreator.createSim(outMdFileName, false); |
284 |
> |
|
285 |
> |
// This was so much fun the first time, lets do it again. |
286 |
> |
|
287 |
> |
Molecule* mol; |
288 |
> |
SimInfo::MoleculeIterator mi; |
289 |
> |
mol = NewInfo->beginMolecule(mi); |
290 |
> |
|
291 |
> |
for(int i = 0; i < nx; i++) { |
292 |
> |
for(int j = 0; j < ny; j++) { |
293 |
> |
for(int k = 0; k < nz; k++) { |
294 |
|
|
295 |
< |
|
296 |
< |
/* |
297 |
< |
void BaseLattice::getLatticePointsPos(std::vector<Vector3d>& latticePos, int nx, int ny, int nz){ |
298 |
< |
|
299 |
< |
latticePos.resize(nCellSites); |
211 |
< |
|
212 |
< |
for( int i=0;i < nCellSites;i++){ |
213 |
< |
|
214 |
< |
latticePos[i][0] = origin[0] + cellSitesPos[i][0] + cellLen[0] * (double(nx) - 0.5); |
215 |
< |
latticePos[i][1] = origin[1] + cellSitesPos[i][1] + cellLen[1] * (double(ny) - 0.5); |
216 |
< |
latticePos[i][2] = origin[2] + cellSitesPos[i][2] + cellLen[2] * (double(nz) - 0.5); |
217 |
< |
} |
218 |
< |
|
219 |
< |
*/ |
220 |
< |
|
221 |
< |
|
222 |
< |
|
223 |
< |
|
224 |
< |
numMol = 0; |
225 |
< |
for(int i = 0; i < nx; i++) { |
226 |
< |
for(int j = 0; j < ny; j++) { |
227 |
< |
for(int k = 0; k < nz; k++) { |
228 |
< |
//if (oldInfo->getNGlobalMolecules() != numMol) { |
229 |
< |
|
230 |
< |
|
231 |
< |
|
232 |
< |
//get the position of the cell sites |
233 |
< |
simpleLat->getLatticePointsPos(latticePos, i, j, k); |
234 |
< |
|
235 |
< |
for(int l = 0; l < numMolPerCell; l++) { |
236 |
< |
/* |
237 |
< |
if (myGeometry.isInsidePolyhedron(latticePos[l][0],latticePos[l][1],latticePos[l][2])){ |
238 |
< |
numMol++; |
239 |
< |
} |
240 |
< |
*/ |
241 |
< |
numMol++; |
242 |
< |
} |
243 |
< |
} |
244 |
< |
} |
245 |
< |
} |
246 |
< |
|
247 |
< |
|
248 |
< |
// needed for writing out new md file. |
249 |
< |
|
250 |
< |
outPrefix = getPrefix(inputFileName.c_str()) + "_" + latticeType; |
251 |
< |
outMdFileName = outPrefix + ".md"; |
252 |
< |
|
253 |
< |
//creat new .md file on fly which corrects the number of molecule |
254 |
< |
createMdFile(inputFileName, outMdFileName, numMol); |
255 |
< |
|
256 |
< |
if (oldInfo != NULL) |
257 |
< |
delete oldInfo; |
295 |
> |
//get the position of the cell sites |
296 |
> |
simpleLat->getLatticePointsPos(latticePos, i, j, k); |
297 |
> |
|
298 |
> |
for(int l = 0; l < numMolPerCell; l++) { |
299 |
> |
if (mol != NULL) { |
300 |
|
|
301 |
< |
|
302 |
< |
// We need to read in new siminfo object. |
303 |
< |
//parse md file and set up the system |
304 |
< |
//SimCreator NewCreator; |
305 |
< |
|
306 |
< |
SimInfo* NewInfo = oldCreator.createSim(outMdFileName, false); |
307 |
< |
|
308 |
< |
// This was so much fun the first time, lets do it again. |
309 |
< |
|
310 |
< |
Molecule* mol; |
311 |
< |
SimInfo::MoleculeIterator mi; |
312 |
< |
mol = NewInfo->beginMolecule(mi); |
313 |
< |
|
314 |
< |
for(int i = 0; i < nx; i++) { |
273 |
< |
for(int j = 0; j < ny; j++) { |
274 |
< |
for(int k = 0; k < nz; k++) { |
275 |
< |
|
276 |
< |
//get the position of the cell sites |
277 |
< |
simpleLat->getLatticePointsPos(latticePos, i, j, k); |
278 |
< |
|
279 |
< |
for(int l = 0; l < numMolPerCell; l++) { |
280 |
< |
if (mol != NULL) { |
281 |
< |
/* |
282 |
< |
if (myGeometry.isInsidePolyhedron(latticePos[l][0],latticePos[l][1],latticePos[l][2])){ |
283 |
< |
locator->placeMol(latticePos[l], latticeOrt[l], mol); |
284 |
< |
} |
285 |
< |
*/ |
286 |
< |
locator->placeMol(latticePos[l], latticeOrt[l], mol); |
287 |
< |
} else { |
288 |
< |
std::cerr << std::endl; |
289 |
< |
} |
290 |
< |
mol = NewInfo->nextMolecule(mi); |
291 |
< |
} |
292 |
< |
} |
293 |
< |
} |
301 |
> |
#ifdef HAVE_GCAL |
302 |
> |
if (myGeometry.isInsidePolyhedron(latticePos[l][0],latticePos[l][1],latticePos[l][2])){ |
303 |
> |
locator->placeMol(latticePos[l], latticeOrt[l], mol); |
304 |
> |
} |
305 |
> |
#else |
306 |
> |
|
307 |
> |
locator->placeMol(latticePos[l], latticeOrt[l], mol); |
308 |
> |
#endif |
309 |
> |
} else { |
310 |
> |
std::cerr << std::endl; |
311 |
> |
} |
312 |
> |
mol = NewInfo->nextMolecule(mi); |
313 |
> |
} |
314 |
> |
} |
315 |
|
} |
316 |
< |
|
317 |
< |
|
318 |
< |
|
319 |
< |
//fill Hmat |
320 |
< |
hmat(0, 0)= nx * latticeConstant; |
321 |
< |
hmat(0, 1) = 0.0; |
322 |
< |
hmat(0, 2) = 0.0; |
323 |
< |
|
324 |
< |
hmat(1, 0) = 0.0; |
325 |
< |
hmat(1, 1) = ny * latticeConstant; |
326 |
< |
hmat(1, 2) = 0.0; |
327 |
< |
|
328 |
< |
hmat(2, 0) = 0.0; |
329 |
< |
hmat(2, 1) = 0.0; |
330 |
< |
hmat(2, 2) = nz * latticeConstant; |
331 |
< |
|
332 |
< |
//set Hmat |
333 |
< |
NewInfo->getSnapshotManager()->getCurrentSnapshot()->setHmat(hmat); |
334 |
< |
|
335 |
< |
|
336 |
< |
//create dumpwriter and write out the coordinates |
337 |
< |
NewInfo->setFinalConfigFileName(outInitFileName); |
338 |
< |
writer = new DumpWriter(NewInfo); |
339 |
< |
|
340 |
< |
if (writer == NULL) { |
341 |
< |
std::cerr << "error in creating DumpWriter" << std::endl; |
342 |
< |
exit(1); |
343 |
< |
} |
344 |
< |
|
345 |
< |
writer->writeDump(); |
346 |
< |
std::cout << "new initial configuration file: " << outInitFileName |
347 |
< |
<< " is generated." << std::endl; |
348 |
< |
|
349 |
< |
//delete objects |
350 |
< |
|
351 |
< |
//delete oldInfo and oldSimSetup |
352 |
< |
|
353 |
< |
if (NewInfo != NULL) |
354 |
< |
delete NewInfo; |
355 |
< |
|
356 |
< |
if (writer != NULL) |
357 |
< |
delete writer; |
358 |
< |
|
359 |
< |
return 0; |
316 |
> |
} |
317 |
> |
|
318 |
> |
|
319 |
> |
|
320 |
> |
//fill Hmat |
321 |
> |
hmat(0, 0)= nx * latticeConstant; |
322 |
> |
hmat(0, 1) = 0.0; |
323 |
> |
hmat(0, 2) = 0.0; |
324 |
> |
|
325 |
> |
hmat(1, 0) = 0.0; |
326 |
> |
hmat(1, 1) = ny * latticeConstant; |
327 |
> |
hmat(1, 2) = 0.0; |
328 |
> |
|
329 |
> |
hmat(2, 0) = 0.0; |
330 |
> |
hmat(2, 1) = 0.0; |
331 |
> |
hmat(2, 2) = nz * latticeConstant; |
332 |
> |
|
333 |
> |
//set Hmat |
334 |
> |
NewInfo->getSnapshotManager()->getCurrentSnapshot()->setHmat(hmat); |
335 |
> |
|
336 |
> |
|
337 |
> |
//create dumpwriter and write out the coordinates |
338 |
> |
NewInfo->setFinalConfigFileName(outInitFileName); |
339 |
> |
writer = new DumpWriter(NewInfo); |
340 |
> |
|
341 |
> |
if (writer == NULL) { |
342 |
> |
std::cerr << "error in creating DumpWriter" << std::endl; |
343 |
> |
exit(1); |
344 |
> |
} |
345 |
> |
|
346 |
> |
writer->writeDump(); |
347 |
> |
std::cout << "new initial configuration file: " << outInitFileName |
348 |
> |
<< " is generated." << std::endl; |
349 |
> |
|
350 |
> |
//delete objects |
351 |
> |
|
352 |
> |
//delete oldInfo and oldSimSetup |
353 |
> |
|
354 |
> |
if (NewInfo != NULL) |
355 |
> |
delete NewInfo; |
356 |
> |
|
357 |
> |
if (writer != NULL) |
358 |
> |
delete writer; |
359 |
> |
delete simpleLat; |
360 |
> |
cmdline_parser_free(&args_info); |
361 |
> |
return 0; |
362 |
|
} |
363 |
|
|
364 |
|
void createMdFile(const std::string&oldMdFileName, const std::string&newMdFileName, |
365 |
|
int numMol) { |
366 |
< |
ifstream oldMdFile; |
367 |
< |
ofstream newMdFile; |
368 |
< |
const int MAXLEN = 65535; |
369 |
< |
char buffer[MAXLEN]; |
370 |
< |
|
371 |
< |
//create new .md file based on old .md file |
372 |
< |
oldMdFile.open(oldMdFileName.c_str()); |
373 |
< |
newMdFile.open(newMdFileName.c_str()); |
374 |
< |
|
366 |
> |
ifstream oldMdFile; |
367 |
> |
ofstream newMdFile; |
368 |
> |
const int MAXLEN = 65535; |
369 |
> |
char buffer[MAXLEN]; |
370 |
> |
|
371 |
> |
//create new .md file based on old .md file |
372 |
> |
oldMdFile.open(oldMdFileName.c_str()); |
373 |
> |
newMdFile.open(newMdFileName.c_str()); |
374 |
> |
|
375 |
> |
oldMdFile.getline(buffer, MAXLEN); |
376 |
> |
|
377 |
> |
while (!oldMdFile.eof()) { |
378 |
> |
|
379 |
> |
//correct molecule number |
380 |
> |
if (strstr(buffer, "nMol") != NULL) { |
381 |
> |
sprintf(buffer, "\tnMol = %i;", numMol); |
382 |
> |
newMdFile << buffer << std::endl; |
383 |
> |
} else |
384 |
> |
newMdFile << buffer << std::endl; |
385 |
> |
|
386 |
|
oldMdFile.getline(buffer, MAXLEN); |
387 |
< |
|
388 |
< |
while (!oldMdFile.eof()) { |
389 |
< |
|
390 |
< |
//correct molecule number |
357 |
< |
if (strstr(buffer, "nMol") != NULL) { |
358 |
< |
sprintf(buffer, "\tnMol = %i;", numMol); |
359 |
< |
newMdFile << buffer << std::endl; |
360 |
< |
} else |
361 |
< |
newMdFile << buffer << std::endl; |
362 |
< |
|
363 |
< |
oldMdFile.getline(buffer, MAXLEN); |
364 |
< |
} |
365 |
< |
|
366 |
< |
oldMdFile.close(); |
367 |
< |
newMdFile.close(); |
387 |
> |
} |
388 |
> |
|
389 |
> |
oldMdFile.close(); |
390 |
> |
newMdFile.close(); |
391 |
|
} |
392 |
|
|