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 |
> |
|
115 |
> |
//get lattice type |
116 |
> |
latticeType = UpperCase(args_info.latticetype_arg); |
117 |
> |
|
118 |
> |
|
119 |
> |
simpleLat = LatticeFactory::getInstance()->createLattice(latticeType); |
120 |
> |
if (simpleLat == NULL) { |
121 |
> |
sprintf(painCave.errMsg, "Lattice Factory can not create %s lattice\n", |
122 |
> |
latticeType.c_str()); |
123 |
> |
painCave.isFatal = 1; |
124 |
> |
simError(); |
125 |
> |
} |
126 |
> |
|
127 |
> |
//get input file name |
128 |
> |
if (args_info.inputs_num) |
129 |
> |
inputFileName = args_info.inputs[0]; |
130 |
> |
else { |
131 |
> |
std::cerr << "You must specify a input file name.\n" << std::endl; |
132 |
> |
cmdline_parser_print_help(); |
133 |
> |
exit(1); |
134 |
> |
} |
135 |
> |
|
136 |
> |
//parse md file and set up the system |
137 |
> |
SimCreator oldCreator; |
138 |
> |
SimInfo* oldInfo = oldCreator.createSim(inputFileName, false); |
139 |
> |
|
140 |
> |
if (oldInfo->getNMoleculeStamp()> 1) { |
141 |
> |
std::cerr << "can not build nanorod with more than one components" |
142 |
> |
<< std::endl; |
143 |
> |
exit(1); |
144 |
> |
} |
145 |
> |
|
146 |
> |
//get mass of molecule. |
147 |
> |
|
148 |
> |
mass = getMolMass(oldInfo->getMoleculeStamp(0), oldInfo->getForceField()); |
149 |
> |
|
150 |
> |
//creat lattice |
151 |
> |
simpleLat = LatticeFactory::getInstance()->createLattice(latticeType); |
152 |
> |
|
153 |
> |
if (simpleLat == NULL) { |
154 |
> |
std::cerr << "Error in creating lattice" << std::endl; |
155 |
> |
exit(1); |
156 |
> |
} |
157 |
> |
|
158 |
> |
numMolPerCell = simpleLat->getNumSitesPerCell(); |
159 |
> |
|
160 |
> |
//calculate lattice constant (in Angstrom) |
161 |
> |
//latticeConstant = pow(rhoConvertConst * numMolPerCell * mass / density, |
162 |
> |
// 1.0 / 3.0); |
163 |
> |
|
164 |
> |
latticeConstant = args_info.latticeCnst_arg; |
165 |
> |
rodLength = args_info.length_arg; |
166 |
> |
rodDiameter = args_info.width_arg; |
167 |
> |
|
168 |
> |
//set lattice constant |
169 |
> |
lc.push_back(latticeConstant); |
170 |
> |
simpleLat->setLatticeConstant(lc); |
171 |
> |
|
172 |
> |
|
173 |
> |
//determine the output file names |
174 |
> |
if (args_info.output_given) |
175 |
> |
outInitFileName = args_info.output_arg; |
176 |
> |
else |
177 |
> |
outInitFileName = getPrefix(inputFileName.c_str()) + ".in"; |
178 |
> |
|
179 |
> |
//creat Molocator |
180 |
> |
locator = new MoLocator(oldInfo->getMoleculeStamp(0), oldInfo->getForceField()); |
181 |
> |
|
182 |
> |
/* |
183 |
> |
Assume we are carving nanorod out of a cublic block of material and that |
184 |
> |
the shape the material will fit within that block.... |
185 |
> |
The model in geometry builder assumes the long axis is in the y direction and the x-z plane is the |
186 |
> |
diameter of the particle. |
187 |
> |
*/ |
188 |
> |
// Number of Unit Cells in Length first |
189 |
> |
ny = (int)(rodLength/latticeConstant); |
190 |
> |
// Number of unit cells in Width |
191 |
> |
nx = (int)(rodDiameter/latticeConstant); |
192 |
> |
nz = (int)(rodDiameter/latticeConstant); |
193 |
> |
|
194 |
> |
|
195 |
> |
|
196 |
> |
// Create geometry for nanocrystal |
197 |
> |
#ifdef HAVE_GCAL |
198 |
> |
GeometryBuilder myGeometry(rodLength,rodDiameter); |
199 |
> |
#endif |
200 |
> |
|
201 |
> |
/* |
202 |
> |
We have to build the system first to figure out how many molecules |
203 |
> |
there are then create a md file and then actually build the |
204 |
> |
system. |
205 |
> |
*/ |
206 |
> |
|
207 |
> |
//place the molecules |
208 |
> |
|
209 |
> |
curMolIndex = 0; |
210 |
> |
|
211 |
> |
//get the orientation of the cell sites |
212 |
> |
//for the same type of molecule in same lattice, it will not change |
213 |
> |
latticeOrt = simpleLat->getLatticePointsOrt(); |
214 |
> |
|
215 |
> |
|
216 |
> |
/* |
217 |
> |
void BaseLattice::getLatticePointsPos(std::vector<Vector3d>& |
218 |
> |
latticePos, int nx, int ny, int nz){ |
219 |
|
|
220 |
< |
gengetopt_args_info args_info; |
221 |
< |
std::string latticeType; |
222 |
< |
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 |
< |
|
220 |
> |
latticePos.resize(nCellSites); |
221 |
> |
|
222 |
> |
for( int i=0;i < nCellSites;i++){ |
223 |
|
|
224 |
< |
|
225 |
< |
//get lattice type |
226 |
< |
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); |
224 |
> |
latticePos[i][0] = origin[0] + cellSitesPos[i][0] + cellLen[0] * (double(nx) - 0.5); |
225 |
> |
latticePos[i][1] = origin[1] + cellSitesPos[i][1] + cellLen[1] * (double(ny) - 0.5); |
226 |
> |
latticePos[i][2] = origin[2] + cellSitesPos[i][2] + cellLen[2] * (double(nz) - 0.5); |
227 |
|
} |
119 |
– |
|
228 |
|
|
229 |
< |
//get input file name |
230 |
< |
if (args_info.inputs_num) |
231 |
< |
inputFileName = args_info.inputs[0]; |
232 |
< |
else { |
233 |
< |
std::cerr << "You must specify a input file name.\n" << std::endl; |
234 |
< |
cmdline_parser_print_help(); |
235 |
< |
exit(1); |
236 |
< |
} |
229 |
> |
*/ |
230 |
> |
|
231 |
> |
|
232 |
> |
|
233 |
> |
|
234 |
> |
numMol = 0; |
235 |
> |
for(int i = 0; i < nx; i++) { |
236 |
> |
for(int j = 0; j < ny; j++) { |
237 |
> |
for(int k = 0; k < nz; k++) { |
238 |
> |
//if (oldInfo->getNGlobalMolecules() != numMol) { |
239 |
> |
|
240 |
> |
|
241 |
> |
|
242 |
> |
//get the position of the cell sites |
243 |
> |
simpleLat->getLatticePointsPos(latticePos, i, j, k); |
244 |
> |
|
245 |
> |
for(int l = 0; l < numMolPerCell; l++) { |
246 |
|
|
247 |
< |
//parse md file and set up the system |
248 |
< |
SimCreator oldCreator; |
249 |
< |
SimInfo* oldInfo = oldCreator.createSim(inputFileName, false); |
250 |
< |
|
251 |
< |
if (oldInfo->getNMoleculeStamp()> 1) { |
252 |
< |
std::cerr << "can not build nanorod with more than one components" |
253 |
< |
<< std::endl; |
254 |
< |
exit(1); |
247 |
> |
#ifdef HAVE_GCAL |
248 |
> |
if (myGeometry.isInsidePolyhedron(latticePos[l][0],latticePos[l][1],latticePos[l][2])){ |
249 |
> |
numMol++; |
250 |
> |
} |
251 |
> |
#else |
252 |
> |
numMol++; |
253 |
> |
#endif |
254 |
> |
} |
255 |
> |
} |
256 |
|
} |
257 |
< |
|
258 |
< |
//get mass of molecule. |
259 |
< |
|
260 |
< |
mass = getMolMass(oldInfo->getMoleculeStamp(0), oldInfo->getForceField()); |
261 |
< |
|
262 |
< |
//creat lattice |
263 |
< |
simpleLat = LatticeFactory::getInstance()->createLattice(latticeType); |
264 |
< |
|
265 |
< |
if (simpleLat == NULL) { |
266 |
< |
std::cerr << "Error in creating lattice" << std::endl; |
267 |
< |
exit(1); |
268 |
< |
} |
269 |
< |
|
270 |
< |
numMolPerCell = simpleLat->getNumSitesPerCell(); |
271 |
< |
|
272 |
< |
//calculate lattice constant (in Angstrom) |
273 |
< |
//latticeConstant = pow(rhoConvertConst * numMolPerCell * mass / density, |
274 |
< |
// 1.0 / 3.0); |
275 |
< |
|
276 |
< |
latticeConstant = args_info.latticeCnst_arg; |
277 |
< |
rodLength = args_info.length_arg; |
278 |
< |
rodDiameter = args_info.width_arg; |
279 |
< |
|
280 |
< |
//set lattice constant |
281 |
< |
lc.push_back(latticeConstant); |
282 |
< |
simpleLat->setLatticeConstant(lc); |
283 |
< |
|
284 |
< |
|
285 |
< |
//determine the output file names |
286 |
< |
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(); |
257 |
> |
} |
258 |
> |
|
259 |
> |
|
260 |
> |
// needed for writing out new md file. |
261 |
> |
|
262 |
> |
outPrefix = getPrefix(inputFileName.c_str()) + "_" + latticeType; |
263 |
> |
outMdFileName = outPrefix + ".md"; |
264 |
> |
|
265 |
> |
//creat new .md file on fly which corrects the number of molecule |
266 |
> |
createMdFile(inputFileName, outMdFileName, numMol); |
267 |
> |
|
268 |
> |
if (oldInfo != NULL) |
269 |
> |
delete oldInfo; |
270 |
> |
|
271 |
> |
|
272 |
> |
// We need to read in new siminfo object. |
273 |
> |
//parse md file and set up the system |
274 |
> |
//SimCreator NewCreator; |
275 |
> |
|
276 |
> |
SimInfo* NewInfo = oldCreator.createSim(outMdFileName, false); |
277 |
> |
|
278 |
> |
// This was so much fun the first time, lets do it again. |
279 |
> |
|
280 |
> |
Molecule* mol; |
281 |
> |
SimInfo::MoleculeIterator mi; |
282 |
> |
mol = NewInfo->beginMolecule(mi); |
283 |
> |
|
284 |
> |
for(int i = 0; i < nx; i++) { |
285 |
> |
for(int j = 0; j < ny; j++) { |
286 |
> |
for(int k = 0; k < nz; k++) { |
287 |
|
|
288 |
< |
|
289 |
< |
/* |
290 |
< |
void BaseLattice::getLatticePointsPos(std::vector<Vector3d>& latticePos, int nx, int ny, int nz){ |
291 |
< |
|
292 |
< |
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; |
288 |
> |
//get the position of the cell sites |
289 |
> |
simpleLat->getLatticePointsPos(latticePos, i, j, k); |
290 |
> |
|
291 |
> |
for(int l = 0; l < numMolPerCell; l++) { |
292 |
> |
if (mol != NULL) { |
293 |
|
|
294 |
< |
|
295 |
< |
// We need to read in new siminfo object. |
296 |
< |
//parse md file and set up the system |
297 |
< |
//SimCreator NewCreator; |
298 |
< |
|
299 |
< |
SimInfo* NewInfo = oldCreator.createSim(outMdFileName, false); |
300 |
< |
|
301 |
< |
// This was so much fun the first time, lets do it again. |
302 |
< |
|
303 |
< |
Molecule* mol; |
304 |
< |
SimInfo::MoleculeIterator mi; |
305 |
< |
mol = NewInfo->beginMolecule(mi); |
306 |
< |
|
307 |
< |
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 |
< |
} |
294 |
> |
#ifdef HAVE_GCAL |
295 |
> |
if (myGeometry.isInsidePolyhedron(latticePos[l][0],latticePos[l][1],latticePos[l][2])){ |
296 |
> |
locator->placeMol(latticePos[l], latticeOrt[l], mol); |
297 |
> |
} |
298 |
> |
#else |
299 |
> |
|
300 |
> |
locator->placeMol(latticePos[l], latticeOrt[l], mol); |
301 |
> |
#endif |
302 |
> |
} else { |
303 |
> |
std::cerr << std::endl; |
304 |
> |
} |
305 |
> |
mol = NewInfo->nextMolecule(mi); |
306 |
> |
} |
307 |
> |
} |
308 |
|
} |
309 |
< |
|
310 |
< |
|
311 |
< |
|
312 |
< |
//fill Hmat |
313 |
< |
hmat(0, 0)= nx * latticeConstant; |
314 |
< |
hmat(0, 1) = 0.0; |
315 |
< |
hmat(0, 2) = 0.0; |
316 |
< |
|
317 |
< |
hmat(1, 0) = 0.0; |
318 |
< |
hmat(1, 1) = ny * latticeConstant; |
319 |
< |
hmat(1, 2) = 0.0; |
320 |
< |
|
321 |
< |
hmat(2, 0) = 0.0; |
322 |
< |
hmat(2, 1) = 0.0; |
323 |
< |
hmat(2, 2) = nz * latticeConstant; |
324 |
< |
|
325 |
< |
//set Hmat |
326 |
< |
NewInfo->getSnapshotManager()->getCurrentSnapshot()->setHmat(hmat); |
327 |
< |
|
328 |
< |
|
329 |
< |
//create dumpwriter and write out the coordinates |
330 |
< |
NewInfo->setFinalConfigFileName(outInitFileName); |
331 |
< |
writer = new DumpWriter(NewInfo); |
332 |
< |
|
333 |
< |
if (writer == NULL) { |
334 |
< |
std::cerr << "error in creating DumpWriter" << std::endl; |
335 |
< |
exit(1); |
309 |
> |
} |
310 |
> |
|
311 |
> |
|
312 |
> |
|
313 |
> |
//fill Hmat |
314 |
> |
hmat(0, 0)= nx * latticeConstant; |
315 |
> |
hmat(0, 1) = 0.0; |
316 |
> |
hmat(0, 2) = 0.0; |
317 |
> |
|
318 |
> |
hmat(1, 0) = 0.0; |
319 |
> |
hmat(1, 1) = ny * latticeConstant; |
320 |
> |
hmat(1, 2) = 0.0; |
321 |
> |
|
322 |
> |
hmat(2, 0) = 0.0; |
323 |
> |
hmat(2, 1) = 0.0; |
324 |
> |
hmat(2, 2) = nz * latticeConstant; |
325 |
> |
|
326 |
> |
//set Hmat |
327 |
> |
NewInfo->getSnapshotManager()->getCurrentSnapshot()->setHmat(hmat); |
328 |
> |
|
329 |
> |
|
330 |
> |
//create dumpwriter and write out the coordinates |
331 |
> |
NewInfo->setFinalConfigFileName(outInitFileName); |
332 |
> |
writer = new DumpWriter(NewInfo); |
333 |
> |
|
334 |
> |
if (writer == NULL) { |
335 |
> |
std::cerr << "error in creating DumpWriter" << std::endl; |
336 |
> |
exit(1); |
337 |
|
} |
338 |
< |
|
339 |
< |
writer->writeDump(); |
340 |
< |
std::cout << "new initial configuration file: " << outInitFileName |
341 |
< |
<< " is generated." << std::endl; |
342 |
< |
|
343 |
< |
//delete objects |
344 |
< |
|
345 |
< |
//delete oldInfo and oldSimSetup |
346 |
< |
|
347 |
< |
if (NewInfo != NULL) |
348 |
< |
delete NewInfo; |
349 |
< |
|
350 |
< |
if (writer != NULL) |
351 |
< |
delete writer; |
352 |
< |
|
353 |
< |
return 0; |
338 |
> |
|
339 |
> |
writer->writeDump(); |
340 |
> |
std::cout << "new initial configuration file: " << outInitFileName |
341 |
> |
<< " is generated." << std::endl; |
342 |
> |
|
343 |
> |
//delete objects |
344 |
> |
|
345 |
> |
//delete oldInfo and oldSimSetup |
346 |
> |
|
347 |
> |
if (NewInfo != NULL) |
348 |
> |
delete NewInfo; |
349 |
> |
|
350 |
> |
if (writer != NULL) |
351 |
> |
delete writer; |
352 |
> |
delete simpleLat; |
353 |
> |
cmdline_parser_free(&args_info); |
354 |
> |
return 0; |
355 |
|
} |
356 |
|
|
357 |
|
void createMdFile(const std::string&oldMdFileName, const std::string&newMdFileName, |
358 |
|
int numMol) { |
359 |
< |
ifstream oldMdFile; |
360 |
< |
ofstream newMdFile; |
361 |
< |
const int MAXLEN = 65535; |
362 |
< |
char buffer[MAXLEN]; |
363 |
< |
|
364 |
< |
//create new .md file based on old .md file |
365 |
< |
oldMdFile.open(oldMdFileName.c_str()); |
366 |
< |
newMdFile.open(newMdFileName.c_str()); |
367 |
< |
|
359 |
> |
ifstream oldMdFile; |
360 |
> |
ofstream newMdFile; |
361 |
> |
const int MAXLEN = 65535; |
362 |
> |
char buffer[MAXLEN]; |
363 |
> |
|
364 |
> |
//create new .md file based on old .md file |
365 |
> |
oldMdFile.open(oldMdFileName.c_str()); |
366 |
> |
newMdFile.open(newMdFileName.c_str()); |
367 |
> |
|
368 |
> |
oldMdFile.getline(buffer, MAXLEN); |
369 |
> |
|
370 |
> |
while (!oldMdFile.eof()) { |
371 |
> |
|
372 |
> |
//correct molecule number |
373 |
> |
if (strstr(buffer, "nMol") != NULL) { |
374 |
> |
sprintf(buffer, "\tnMol = %i;", numMol); |
375 |
> |
newMdFile << buffer << std::endl; |
376 |
> |
} else |
377 |
> |
newMdFile << buffer << std::endl; |
378 |
> |
|
379 |
|
oldMdFile.getline(buffer, MAXLEN); |
380 |
< |
|
381 |
< |
while (!oldMdFile.eof()) { |
382 |
< |
|
383 |
< |
//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(); |
380 |
> |
} |
381 |
> |
|
382 |
> |
oldMdFile.close(); |
383 |
> |
newMdFile.close(); |
384 |
|
} |
385 |
|
|