67 |
|
using namespace oopse; |
68 |
|
void createMdFile(const std::string&oldMdFileName, |
69 |
|
const std::string&newMdFileName, |
70 |
< |
int components,int* numMol); |
70 |
> |
std::vector<int> numMol); |
71 |
|
|
72 |
|
int main(int argc, char *argv []) { |
73 |
|
|
79 |
|
std::string latticeType; |
80 |
|
std::string inputFileName; |
81 |
|
std::string outPrefix; |
82 |
< |
std::string outMdFileName; |
82 |
> |
std::string outputFileName; |
83 |
|
std::string outInitFileName; |
84 |
|
|
85 |
|
|
90 |
|
int nComponents; |
91 |
|
double latticeConstant; |
92 |
|
std::vector<double> lc; |
93 |
< |
double mass; |
93 |
> |
double mass; |
94 |
> |
|
95 |
|
const double rhoConvertConst = 1.661; |
96 |
|
double density; |
97 |
|
double particleRadius; |
103 |
|
std::vector<Vector3d> latticeOrt; |
104 |
|
int numMolPerCell; |
105 |
|
int nShells; /* Number of shells in nanoparticle*/ |
106 |
< |
int numSites; |
106 |
> |
|
107 |
|
|
108 |
|
DumpWriter *writer; |
109 |
|
|
114 |
|
|
115 |
|
|
116 |
|
/* get lattice type */ |
117 |
< |
latticeType = UpperCase(args_info.latticetype_arg); |
118 |
< |
|
117 |
> |
latticeType = "FCC"; |
118 |
> |
|
119 |
|
/* get input file name */ |
120 |
|
if (args_info.inputs_num) |
121 |
|
inputFileName = args_info.inputs[0]; |
122 |
|
else { |
123 |
< |
std::cerr << "You must specify a input file name.\n" << std::endl; |
123 |
> |
sprintf(painCave.errMsg, "No input .md file name was specified" |
124 |
> |
"on the command line"); |
125 |
> |
painCave.isFatal = 1; |
126 |
|
cmdline_parser_print_help(); |
127 |
< |
exit(1); |
127 |
> |
simError(); |
128 |
|
} |
129 |
|
|
130 |
|
/* parse md file and set up the system */ |
132 |
|
SimInfo* oldInfo = oldCreator.createSim(inputFileName, false); |
133 |
|
|
134 |
|
|
132 |
– |
/*calculate lattice constant (in Angstrom) |
133 |
– |
latticeConstant = pow(rhoConvertConst * numMolPerCell * mass / density, |
134 |
– |
1.0 / 3.0);*/ |
135 |
– |
|
135 |
|
latticeConstant = args_info.latticeCnst_arg; |
136 |
|
particleRadius = args_info.radius_arg; |
137 |
|
Globals* simParams = oldInfo->getSimParams(); |
138 |
|
|
139 |
< |
/* Find out how many different components in this simualtion */ |
141 |
< |
nComponents =simParams->getNComponents(); |
142 |
< |
|
143 |
< |
/*determine the output file names*/ |
144 |
< |
if (args_info.output_given){ |
145 |
< |
outInitFileName = args_info.output_arg; |
146 |
< |
}else{ |
147 |
< |
outInitFileName = getPrefix(inputFileName.c_str()) + ".in"; |
148 |
< |
} |
149 |
< |
|
150 |
< |
std::cout <<"Before build shaped lattice. "<<std::endl; |
151 |
< |
|
139 |
> |
|
140 |
|
/* create Molocators */ |
141 |
|
locator = new MoLocator(oldInfo->getMoleculeStamp(0), oldInfo->getForceField()); |
142 |
|
|
143 |
|
/* Create nanoparticle */ |
144 |
|
shapedLatticeSpherical nanoParticle(latticeConstant,latticeType,particleRadius); |
145 |
|
|
158 |
– |
std::cout <<"Before build getPoints. "<<std::endl; |
146 |
|
/* Build a lattice and get lattice points for this lattice constant */ |
147 |
< |
vector<Vector3d> nanoParticleSites = nanoParticle.getPoints(); |
148 |
< |
|
147 |
> |
vector<Vector3d> sites = nanoParticle.getPoints(); |
148 |
> |
vector<Vector3d> orientations = nanoParticle.getPointsOrt(); |
149 |
> |
|
150 |
> |
std::cout <<"nSites: " << sites.size() << std::endl; |
151 |
> |
|
152 |
|
/* Get number of lattice sites */ |
153 |
< |
numSites = nanoParticleSites.size(); |
153 |
> |
int nSites = sites.size(); |
154 |
|
|
155 |
< |
//std::cout <<"numSites are %d "<<numSites<<std::endl; |
156 |
< |
// std::cout <<"nComponents are %d "<<nComponents<<std::endl; |
157 |
< |
numMol = new int[nComponents]; |
158 |
< |
|
155 |
> |
|
156 |
> |
|
157 |
> |
|
158 |
> |
std::vector<Component*> components = simParams->getComponents(); |
159 |
> |
std::vector<RealType> molFractions; |
160 |
> |
std::vector<RealType> molecularMasses; |
161 |
> |
std::vector<int> nMol; |
162 |
> |
nComponents = components.size(); |
163 |
|
|
164 |
< |
/* Random particle is the default case*/ |
165 |
< |
if (!args_info.ShellRadius_given){ |
166 |
< |
std::cout << "Creating a random nanoparticle" << std::endl; |
167 |
< |
/* Check to see if we have enough components */ |
168 |
< |
if (nComponents != args_info.molFraction_given && nComponents != 1){ |
169 |
< |
std::cerr << "Number of components does not equal molFraction occurances." << std::endl; |
170 |
< |
exit(1); |
164 |
> |
|
165 |
> |
|
166 |
> |
if (nComponents == 1) { |
167 |
> |
molFractions.push_back(1.0); |
168 |
> |
} else { |
169 |
> |
if (args_info.molFraction_given == nComponents) { |
170 |
> |
for (int i = 0; i < nComponents; i++) { |
171 |
> |
molFractions.push_back(args_info.molFraction_arg[i]); |
172 |
> |
} |
173 |
> |
} else if (args_info.molFraction_given == nComponents-1) { |
174 |
> |
RealType remainingFraction = 1.0; |
175 |
> |
for (int i = 0; i < nComponents-1; i++) { |
176 |
> |
molFractions.push_back(args_info.molFraction_arg[i]); |
177 |
> |
remainingFraction -= molFractions[i]; |
178 |
> |
} |
179 |
> |
molFractions.push_back(remainingFraction); |
180 |
> |
} else { |
181 |
> |
sprintf(painCave.errMsg, "nanoparticleBuilder can't figure out molFractions " |
182 |
> |
"for all of the components in the <MetaData> block."); |
183 |
> |
painCave.isFatal = 1; |
184 |
> |
simError(); |
185 |
|
} |
186 |
< |
/* Build the mole fractions and number of molecules of each type */ |
187 |
< |
int totComponents = 0; |
188 |
< |
for (int i = 0;i<nComponents-1;i++){ /* Figure out Percent for each component */ |
189 |
< |
numMol[i] = int((double)numSites * args_info.molFraction_arg[i]); |
190 |
< |
std::cout<<numMol[i]<<std::endl; |
191 |
< |
totComponents += numMol[i]; |
186 |
> |
} |
187 |
> |
|
188 |
> |
RealType totalFraction = 0.0; |
189 |
> |
|
190 |
> |
/* Do some simple sanity checking*/ |
191 |
> |
|
192 |
> |
|
193 |
> |
|
194 |
> |
for (int i = 0; i < nComponents; i++) { |
195 |
> |
if (molFractions.at(i) < 0.0) { |
196 |
> |
sprintf(painCave.errMsg, "One of the requested molFractions was" |
197 |
> |
" less than zero!"); |
198 |
> |
painCave.isFatal = 1; |
199 |
> |
simError(); |
200 |
|
} |
201 |
< |
numMol[nComponents-1] = numSites - totComponents; |
202 |
< |
|
201 |
> |
if (molFractions.at(i) > 1.0) { |
202 |
> |
sprintf(painCave.errMsg, "One of the requested molFractions was" |
203 |
> |
" greater than one!"); |
204 |
> |
painCave.isFatal = 1; |
205 |
> |
simError(); |
206 |
> |
} |
207 |
> |
totalFraction += molFractions.at(i); |
208 |
> |
} |
209 |
> |
if (abs(totalFraction - 1.0) > 1e-6) { |
210 |
> |
sprintf(painCave.errMsg, "The sum of molFractions was not close enough to 1.0"); |
211 |
> |
painCave.isFatal = 1; |
212 |
> |
simError(); |
213 |
> |
} |
214 |
> |
|
215 |
> |
int remaining = nSites; |
216 |
> |
for (int i=0; i < nComponents-1; i++) { |
217 |
> |
nMol.push_back(int((RealType)nSites * molFractions.at(i))); |
218 |
> |
remaining -= nMol.at(i); |
219 |
> |
} |
220 |
> |
nMol.push_back(remaining); |
221 |
> |
|
222 |
> |
|
223 |
> |
|
224 |
> |
// recompute actual mol fractions and perform final sanity check: |
225 |
> |
|
226 |
> |
int totalMolecules = 0; |
227 |
> |
RealType totalMass = 0.0; |
228 |
> |
for (int i=0; i < nComponents; i++) { |
229 |
> |
molFractions[i] = (RealType)(nMol.at(i))/(RealType)nSites; |
230 |
> |
totalMolecules += nMol.at(i); |
231 |
> |
molecularMasses.push_back(getMolMass(oldInfo->getMoleculeStamp(i), |
232 |
> |
oldInfo->getForceField())); |
233 |
> |
totalMass += (RealType)(nMol.at(i)) * molecularMasses.at(i); |
234 |
> |
} |
235 |
> |
RealType avgMass = totalMass / (RealType) totalMolecules; |
236 |
> |
|
237 |
> |
if (totalMolecules != nSites) { |
238 |
> |
sprintf(painCave.errMsg, "Computed total number of molecules is not equal " |
239 |
> |
"to the number of lattice sites!"); |
240 |
> |
painCave.isFatal = 1; |
241 |
> |
simError(); |
242 |
> |
} |
243 |
> |
|
244 |
> |
|
245 |
> |
|
246 |
> |
|
247 |
> |
vector<int> ids; |
248 |
> |
for (int i = 0; i < sites.size(); i++) ids.push_back(i); |
249 |
> |
/* Random particle is the default case*/ |
250 |
> |
if (!args_info.ShellRadius_given){ |
251 |
|
/* do the iPod thing, Shuffle da vector */ |
252 |
< |
std::random_shuffle(nanoParticleSites.begin(), nanoParticleSites.end()); |
252 |
> |
std::random_shuffle(ids.begin(), ids.end()); |
253 |
|
} else{ /*Handle core-shell with multiple components.*/ |
254 |
|
std::cout << "Creating a core-shell nanoparticle." << std::endl; |
255 |
|
if (nComponents != args_info.ShellRadius_given + 1){ |
256 |
< |
std::cerr << "Number of components does not equal ShellRadius occurances." << std::endl; |
257 |
< |
exit(1); |
256 |
> |
sprintf(painCave.errMsg, "Number of .md components " |
257 |
> |
"does not match the number of shell radius specifications"); |
258 |
> |
painCave.isFatal = 1; |
259 |
> |
simError(); |
260 |
|
} |
261 |
|
|
262 |
|
} |
263 |
|
|
264 |
|
|
199 |
– |
//get the orientation of the cell sites |
200 |
– |
//for the same type of molecule in same lattice, it will not change |
201 |
– |
latticeOrt = nanoParticle.getPointsOrt(); |
202 |
– |
std::cout<<"Orientational vector Size: "<< std::endl; |
203 |
– |
std::cout<<latticeOrt.size()<< std::endl; |
265 |
|
|
266 |
|
|
267 |
+ |
outputFileName = args_info.output_arg; |
268 |
+ |
|
269 |
|
|
270 |
< |
// needed for writing out new md file. |
270 |
> |
//creat new .md file on fly which corrects the number of molecule |
271 |
> |
createMdFile(inputFileName, outputFileName, nMol); |
272 |
|
|
209 |
– |
outPrefix = getPrefix(inputFileName.c_str()) + "_" + latticeType; |
210 |
– |
outMdFileName = outPrefix + ".md"; |
211 |
– |
|
212 |
– |
//creat new .md file on fly which corrects the number of molecule |
213 |
– |
createMdFile(inputFileName, outMdFileName, nComponents,numMol); |
214 |
– |
|
273 |
|
if (oldInfo != NULL) |
274 |
|
delete oldInfo; |
275 |
|
|
278 |
|
//parse md file and set up the system |
279 |
|
//SimCreator NewCreator; |
280 |
|
SimCreator newCreator; |
281 |
< |
SimInfo* NewInfo = newCreator.createSim(outMdFileName, false); |
281 |
> |
SimInfo* NewInfo = newCreator.createSim(outputFileName, false); |
282 |
|
|
283 |
|
|
284 |
|
// Place molecules |
286 |
|
SimInfo::MoleculeIterator mi; |
287 |
|
mol = NewInfo->beginMolecule(mi); |
288 |
|
int l = 0; |
289 |
< |
for (mol = NewInfo->beginMolecule(mi); mol != NULL; mol = NewInfo->nextMolecule(mi)) { |
290 |
< |
locator->placeMol(nanoParticleSites[l], latticeOrt[l], mol); |
291 |
< |
l++; |
289 |
> |
|
290 |
> |
for (int i = 0; i < nComponents; i++){ |
291 |
> |
locator = new MoLocator(NewInfo->getMoleculeStamp(i), |
292 |
> |
NewInfo->getForceField()); |
293 |
> |
for (int n = 0; n < nMol.at(i); n++) { |
294 |
> |
mol = NewInfo->getMoleculeByGlobalIndex(l); |
295 |
> |
locator->placeMol(sites[ids[l]], orientations[ids[l]], mol); |
296 |
> |
l++; |
297 |
> |
} |
298 |
|
} |
299 |
< |
|
299 |
> |
|
300 |
|
|
237 |
– |
|
301 |
|
|
302 |
|
//fill Hmat |
303 |
< |
hmat(0, 0)= latticeConstant; |
303 |
> |
hmat(0, 0)= 2.0*particleRadius; |
304 |
|
hmat(0, 1) = 0.0; |
305 |
|
hmat(0, 2) = 0.0; |
306 |
|
|
307 |
|
hmat(1, 0) = 0.0; |
308 |
< |
hmat(1, 1) = latticeConstant; |
308 |
> |
hmat(1, 1) = 2.0*particleRadius; |
309 |
|
hmat(1, 2) = 0.0; |
310 |
|
|
311 |
|
hmat(2, 0) = 0.0; |
312 |
|
hmat(2, 1) = 0.0; |
313 |
< |
hmat(2, 2) = latticeConstant; |
313 |
> |
hmat(2, 2) = 2.0*particleRadius; |
314 |
|
|
315 |
|
//set Hmat |
316 |
|
NewInfo->getSnapshotManager()->getCurrentSnapshot()->setHmat(hmat); |
317 |
|
|
318 |
|
|
319 |
|
//create dumpwriter and write out the coordinates |
320 |
< |
NewInfo->setFinalConfigFileName(outInitFileName); |
258 |
< |
writer = new DumpWriter(NewInfo); |
320 |
> |
writer = new DumpWriter(NewInfo,outputFileName); |
321 |
|
|
322 |
|
if (writer == NULL) { |
323 |
< |
std::cerr << "error in creating DumpWriter" << std::endl; |
324 |
< |
exit(1); |
323 |
> |
sprintf(painCave.errMsg, "Error in creating dumpwrite object "); |
324 |
> |
painCave.isFatal = 1; |
325 |
> |
simError(); |
326 |
|
} |
327 |
|
|
328 |
|
writer->writeDump(); |
329 |
|
std::cout << "new initial configuration file: " << outInitFileName |
330 |
|
<< " is generated." << std::endl; |
331 |
< |
|
332 |
< |
//delete objects |
333 |
< |
|
334 |
< |
//delete oldInfo and oldSimSetup |
335 |
< |
|
336 |
< |
if (NewInfo != NULL) |
337 |
< |
delete NewInfo; |
338 |
< |
|
339 |
< |
if (writer != NULL) |
340 |
< |
delete writer; |
278 |
< |
cmdline_parser_free(&args_info); |
331 |
> |
|
332 |
> |
|
333 |
> |
// deleting the writer will put the closing at the end of the dump file |
334 |
> |
delete writer; |
335 |
> |
|
336 |
> |
// cleanup a by calling sim error..... |
337 |
> |
sprintf(painCave.errMsg, "A new OOPSE MD file called \"%s\" has been " |
338 |
> |
"generated.\n", outputFileName.c_str()); |
339 |
> |
painCave.isFatal = 0; |
340 |
> |
simError(); |
341 |
|
return 0; |
342 |
|
} |
343 |
|
|
344 |
|
void createMdFile(const std::string&oldMdFileName, const std::string&newMdFileName, |
345 |
< |
int components,int* numMol) { |
345 |
> |
std::vector<int> nMol) { |
346 |
|
ifstream oldMdFile; |
347 |
|
ofstream newMdFile; |
348 |
|
const int MAXLEN = 65535; |
359 |
|
|
360 |
|
//correct molecule number |
361 |
|
if (strstr(buffer, "nMol") != NULL) { |
362 |
< |
if(i<components){ |
363 |
< |
sprintf(buffer, "\tnMol = %i;", numMol[i]); |
362 |
> |
if(i<nMol.size()){ |
363 |
> |
sprintf(buffer, "\tnMol = %i;", nMol.at(i)); |
364 |
|
newMdFile << buffer << std::endl; |
365 |
|
i++; |
366 |
|
} |