7 |
|
#include <map> |
8 |
|
#include <fstream> |
9 |
|
|
10 |
– |
#include "simError.h" |
10 |
|
#include "Globals.hpp" |
11 |
|
#include "SimInfo.hpp" |
12 |
|
#include "SimSetup.hpp" |
13 |
< |
#include "simpleBuilderCmd.hpp" |
13 |
> |
#include "simpleBuilderCmd.h" |
14 |
|
#include "StringUtils.hpp" |
15 |
|
#include "LatticeFactory.hpp" |
16 |
+ |
#include "Vector3d.hpp" |
17 |
+ |
#include "MoLocator.hpp" |
18 |
+ |
#include "Lattice.hpp" |
19 |
|
|
20 |
|
using namespace std; |
21 |
|
|
22 |
+ |
void createMdFile(const string& oldMdFileName, const string& newMdFileName, int numMol); |
23 |
|
|
24 |
|
int main( int argc, char* argv[]){ |
25 |
|
|
36 |
|
BaseLattice* simpleLat; |
37 |
|
int numMol; |
38 |
|
double latticeConstant; |
39 |
+ |
vector<double> lc; |
40 |
|
double mass; |
41 |
|
double density; |
42 |
|
int nx, ny, nz; |
43 |
|
double Hmat[3][3]; |
44 |
|
MoLocator *locator; |
45 |
< |
double* posX; |
46 |
< |
double* posY; |
43 |
< |
double* posZ; |
45 |
> |
vector<Vector3d> latticePos; |
46 |
> |
vector<Vector3d> latticeOrt; |
47 |
|
int numMolPerCell; |
48 |
|
int curMolIndex; |
49 |
|
DumpWriter* writer; |
61 |
|
latticeType = UpperCase(args_info.latticetype_arg); |
62 |
|
if(!LatticeFactory::getInstance()->hasLatticeCreator(latticeType)){ |
63 |
|
cerr << latticeType << " is an invalid lattice type" << endl; |
64 |
< |
cerr << LatticeFactory::getInstance()->oString << endl; |
64 |
> |
cerr << LatticeFactory::getInstance()->toString() << endl; |
65 |
|
exit(1); |
66 |
|
} |
67 |
|
|
68 |
< |
nx = args_info.nx_args; |
68 |
> |
nx = args_info.nx_arg; |
69 |
|
if(nx <= 0){ |
70 |
|
cerr << "The number of unit cell in h direction must be greater than 0" << endl; |
71 |
|
exit(1); |
72 |
|
} |
73 |
|
|
74 |
< |
nx = args_info.nx_args; |
75 |
< |
if(nx <= 0){ |
74 |
> |
ny = args_info.ny_arg; |
75 |
> |
if(ny <= 0){ |
76 |
|
cerr << "The number of unit cell in l direction must be greater than 0" << endl; |
77 |
|
exit(1); |
78 |
|
} |
79 |
|
|
80 |
< |
nx = args_info.nx_args; |
81 |
< |
if(nx <= 0){ |
80 |
> |
nz = args_info.nz_arg; |
81 |
> |
if(nz <= 0){ |
82 |
|
cerr << "The number of unit cell in k direction must be greater than 0" << endl; |
83 |
|
exit(1); |
84 |
|
} |
85 |
|
|
86 |
|
//get input file name |
87 |
< |
if (args_info.inputs_num) { |
87 |
> |
if (args_info.inputs_num) |
88 |
|
inputFileName = args_info.inputs[0]; |
86 |
– |
cerr << in_name << "\n"; } |
89 |
|
else { |
90 |
|
cerr <<"You must specify a input file name.\n" << endl; |
91 |
|
cmdline_parser_print_help(); |
110 |
|
exit(1); |
111 |
|
} |
112 |
|
|
113 |
< |
oldSimSetup = new SimSetup(oldInfo); |
113 |
> |
oldSimSetup = new SimSetup(); |
114 |
|
if(oldSimSetup == NULL){ |
115 |
|
cerr << "error in creating SimSetup" << endl; |
116 |
|
exit(1); |
118 |
|
|
119 |
|
oldSimSetup->setSimInfo(oldInfo ); |
120 |
|
oldSimSetup->parseFile(&inputFileName[0] ); |
119 |
– |
oldSimSetup->createSim(); |
121 |
|
|
122 |
|
|
123 |
< |
if(oldInfo->nComponets >=2){ |
123 |
> |
if(oldInfo->nComponents >=2){ |
124 |
|
cerr << "can not build the system with more than two components" << endl; |
125 |
|
exit(1); |
126 |
|
} |
127 |
|
|
128 |
|
//creat lattice |
129 |
< |
simpleLat = LatticeFactory::getInstance() ->createLattice(latticeType); |
129 |
> |
simpleLat = LatticeFactory::getInstance()->createLattice(latticeType); |
130 |
|
if(simpleLat == NULL){ |
131 |
|
cerr << "Error in creating lattice" << endl; |
132 |
|
exit(1); |
133 |
|
} |
134 |
|
|
135 |
|
|
136 |
< |
numMolPerCell = simpleLat->getNpoints(); |
136 |
> |
numMolPerCell = simpleLat->getNumSitesPerCell(); |
137 |
|
//calculate lattice constant |
138 |
|
latticeConstant = pow(numMolPerCell * mass /density, 1.0/3.0); |
139 |
|
|
140 |
|
//set lattice constant |
141 |
< |
simpleLat->setLatticeConstant(latticeConstant); |
141 |
> |
lc.push_back(latticeConstant); |
142 |
> |
simpleLat->setLatticeConstant(lc); |
143 |
|
|
144 |
|
//calculate the total |
145 |
|
numMol = args_info.nx_arg * args_info.ny_arg * args_info.nz_arg * numMolPerCell; |
167 |
|
exit(1); |
168 |
|
} |
169 |
|
|
170 |
< |
newSimSetup = new SimSetup(newInfo); |
170 |
> |
newSimSetup = new SimSetup(); |
171 |
|
if(newSimSetup == NULL){ |
172 |
|
cerr << "error in creating SimSetup" << endl; |
173 |
|
exit(1); |
177 |
|
newSimSetup->parseFile(&outMdFileName[0] ); |
178 |
|
newSimSetup->createSim(); |
179 |
|
|
180 |
< |
//set Hamt |
180 |
> |
//set Hmat |
181 |
|
newInfo->setBoxM(Hmat); |
182 |
|
|
183 |
|
//allocat memory for storing pos, vel and etc |
184 |
< |
newInfo.getConfiguration()->createArrays(newInfo.n_atoms); |
185 |
< |
for (int i = 0; i < newInfo.n_atoms; i++) |
186 |
< |
newInfo.atoms[i]->setCoords(); |
184 |
> |
newInfo->getConfiguration()->createArrays(newInfo->n_atoms); |
185 |
> |
for (int i = 0; i < newInfo->n_atoms; i++) |
186 |
> |
newInfo->atoms[i]->setCoords(); |
187 |
|
|
188 |
|
//creat Molocator |
189 |
< |
locator = new MoLocator(newInfo->compStamps[0]); |
188 |
< |
|
189 |
< |
//allocate memory for posX, posY, posZ |
190 |
< |
|
191 |
< |
posX = new doule[numMolPerCell]; |
192 |
< |
if(posX == NULL){ |
193 |
< |
cerr << "memory allocation error" << endl; |
194 |
< |
exit(1); |
195 |
< |
} |
189 |
> |
locator = new MoLocator(newInfo->compStamps[0], newSimSetup->getForceField()); |
190 |
|
|
197 |
– |
posY = new doule[numMolPerCell]; |
198 |
– |
if(posX == NULL){ |
199 |
– |
cerr << "memory allocation error" << endl; |
200 |
– |
exit(1); |
201 |
– |
} |
202 |
– |
|
203 |
– |
posZ = new doule[numMolPerCell]; |
204 |
– |
if(posX == NULL){ |
205 |
– |
cerr << "memory allocation error" << endl; |
206 |
– |
exit(1); |
207 |
– |
} |
208 |
– |
|
191 |
|
//place the molecules |
192 |
|
|
193 |
|
curMolIndex = 0; |
194 |
+ |
|
195 |
+ |
//get the orientation of the cell sites |
196 |
+ |
//for the same type of molecule in same lattice, it will not change |
197 |
+ |
latticeOrt = simpleLat->getLatticePointsOrt(); |
198 |
+ |
|
199 |
|
for(int i =0; i < nx; i++){ |
200 |
|
for(int j=0; j < ny; j++){ |
201 |
|
for(int k = 0; k < nz; k++){ |
215 |
– |
|
216 |
– |
simpleLat->getLatticePoints(&posX, &posY, &posZ, i, j, k); |
202 |
|
|
203 |
+ |
//get the position of the cell sites |
204 |
+ |
simpleLat->getLatticePointsPos(latticePos, i, j, k); |
205 |
+ |
|
206 |
|
for(int l = 0; l < numMolPerCell; l++) |
207 |
< |
locator->placeMol(posX[l], posY[l], posZ[l], newInfo->molecules[curMolIndex++]); |
207 |
> |
locator->placeMol(latticePos[l], latticeOrt[l], &(newInfo->molecules[curMolIndex++])); |
208 |
|
} |
209 |
|
} |
210 |
|
} |
215 |
|
cerr << "error in creating DumpWriter" << endl; |
216 |
|
exit(1); |
217 |
|
} |
218 |
< |
writer->writeFinal(); |
218 |
> |
writer->writeFinal(0); |
219 |
|
|
220 |
|
|
221 |
|
//delete objects |
231 |
|
if(!newSimSetup) |
232 |
|
delete newSimSetup; |
233 |
|
|
246 |
– |
if (posX) |
247 |
– |
delete[] posX; |
248 |
– |
|
249 |
– |
if (posY) |
250 |
– |
delete[] posY; |
251 |
– |
|
252 |
– |
if (posZ) |
253 |
– |
delete[] posZ; |
254 |
– |
|
234 |
|
if (writer != NULL) |
235 |
|
delete writer; |
236 |
|
return 0; |
241 |
|
ofstream newMdFile; |
242 |
|
const int MAXLEN = 65535; |
243 |
|
char buffer[MAXLEN]; |
244 |
+ |
string line; |
245 |
|
|
266 |
– |
|
246 |
|
//create new .md file based on old .md file |
247 |
< |
oldMdFile.open(oldMdFileName.c_str()) |
248 |
< |
newMdFile.open(newMdFileName); |
247 |
> |
oldMdFile.open(oldMdFileName.c_str()); |
248 |
> |
newMdFile.open(newMdFileName.c_str()); |
249 |
|
|
250 |
|
oldMdFile.getline(buffer, MAXLEN); |
251 |
|
while(!oldMdFile.eof()){ |
252 |
|
|
253 |
< |
if(line.find("nMol") < line.size()) |
254 |
< |
sprintf(buffer, "nMol = %s;", numMol); |
253 |
> |
if(line.find("nMol") < line.size()){ |
254 |
> |
|
255 |
> |
sprintf(buffer, "\t\tnMol = %d;", numMol); |
256 |
> |
newMdFile << buffer << endl; |
257 |
> |
} |
258 |
|
else |
259 |
|
newMdFile << buffer << endl; |
260 |
|
|