ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/applications/nanoparticleBuilder/nanoparticleBuilder.cpp
(Generate patch)

Comparing:
trunk/src/applications/nanoparticleBuilder/nanoparticleBuilder.cpp (file contents), Revision 653 by chuckv, Tue Oct 11 21:57:22 2005 UTC vs.
branches/development/src/applications/nanoparticleBuilder/nanoparticleBuilder.cpp (file contents), Revision 1704 by gezelter, Tue Apr 24 20:40:04 2012 UTC

# Line 6 | Line 6
6   * redistribute this software in source and binary code form, provided
7   * that the following conditions are met:
8   *
9 < * 1. Acknowledgement of the program authors must be made in any
10 < *    publication of scientific results based in part on use of the
11 < *    program.  An acceptable form of acknowledgement is citation of
12 < *    the article in which the program was described (Matthew
13 < *    A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher
14 < *    J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented
15 < *    Parallel Simulation Engine for Molecular Dynamics,"
16 < *    J. Comput. Chem. 26, pp. 252-271 (2005))
17 < *
18 < * 2. Redistributions of source code must retain the above copyright
9 > * 1. Redistributions of source code must retain the above copyright
10   *    notice, this list of conditions and the following disclaimer.
11   *
12 < * 3. Redistributions in binary form must reproduce the above copyright
12 > * 2. Redistributions in binary form must reproduce the above copyright
13   *    notice, this list of conditions and the following disclaimer in the
14   *    documentation and/or other materials provided with the
15   *    distribution.
# Line 37 | Line 28
28   * arising out of the use of or inability to use software, even if the
29   * University of Notre Dame has been advised of the possibility of
30   * such damages.
31 + *
32 + * SUPPORT OPEN SCIENCE!  If you use OpenMD or its source code in your
33 + * research, please cite the appropriate papers when you publish your
34 + * work.  Good starting points are:
35 + *                                                                      
36 + * [1]  Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).            
37 + * [2]  Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).          
38 + * [3]  Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008).          
39 + * [4]  Kuang & Gezelter,  J. Chem. Phys. 133, 164101 (2010).
40 + * [5]  Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
41   */
42  
43   #include <cstdlib>
# Line 47 | Line 48
48   #include <string>
49   #include <map>
50   #include <fstream>
51 + #include <algorithm>
52  
53   #include "config.h"
54 <
54 > #include "shapedLatticeSpherical.hpp"
55   #include "nanoparticleBuilderCmd.h"
54 #include "sphericalNanoparticle.hpp"
56   #include "lattice/LatticeFactory.hpp"
57   #include "utils/MoLocator.hpp"
58   #include "lattice/Lattice.hpp"
# Line 64 | Line 65 | using namespace std;
65   #include "utils/StringUtils.hpp"
66  
67   using namespace std;
68 < using namespace oopse;
68 > using namespace OpenMD;
69   void createMdFile(const std::string&oldMdFileName,
70                    const std::string&newMdFileName,
71 <                  int numMol);
71 >                  std::vector<int> numMol);
72  
73   int main(int argc, char *argv []) {
74    
# Line 78 | Line 79 | int main(int argc, char *argv []) {
79    gengetopt_args_info args_info;
80    std::string latticeType;
81    std::string inputFileName;
82 <  std::string outPrefix;
82 <  std::string outMdFileName;
83 <  std::string outInitFileName;
82 >  std::string outputFileName;
83  
84 <  
85 <  
87 <  Lattice *simpleLat;
88 <  int numMol;
84 >  MoLocator* locator;
85 >  int nComponents;
86    double latticeConstant;
87    std::vector<double> lc;
91  double mass;
92  const double rhoConvertConst = 1.661;
93  double density;
94  
95  
88  
89 +  RealType particleRadius;
90 +
91    Mat3x3d hmat;
98  MoLocator *locator;
99  sphericalNanoparticle *nanoparticle;
92    std::vector<Vector3d> latticePos;
93    std::vector<Vector3d> latticeOrt;
94 <  int numMolPerCell;
103 <  int nShells; /* Number of shells in nanoparticle*/
104 <  int numSites;
105 <  
94 >
95    DumpWriter *writer;
96    
97 <  // parse command line arguments
97 >  // Parse Command Line Arguments
98    if (cmdline_parser(argc, argv, &args_info) != 0)
99      exit(1);
100 <  
112 <        
113 <        
100 >        
101    /* get lattice type */
102 <  latticeType = UpperCase(args_info.latticetype_arg);
103 <    
102 >  latticeType = "FCC";
103 >
104    /* get input file name */
105    if (args_info.inputs_num)
106      inputFileName = args_info.inputs[0];
107    else {
108 <    std::cerr << "You must specify a input file name.\n" << std::endl;
108 >    sprintf(painCave.errMsg, "No input .md file name was specified "
109 >            "on the command line");
110 >    painCave.isFatal = 1;
111      cmdline_parser_print_help();
112 <    exit(1);
112 >    simError();
113    }
114    
115    /* parse md file and set up the system */
116    SimCreator oldCreator;
117    SimInfo* oldInfo = oldCreator.createSim(inputFileName, false);
118    
119 <  nShells = 0;
120 <  if (args_info.coreShellRadius_given){
121 <    nShells = args_info.coreShellRadius_given;
133 <  }
119 >  latticeConstant = args_info.latticeConstant_arg;
120 >  particleRadius = args_info.radius_arg;
121 >  Globals* simParams = oldInfo->getSimParams();
122    
123 <  nComponents = oldInfo->getNMoleculeStamp();
123 >  /* Create nanoparticle */
124 >  shapedLatticeSpherical nanoParticle(latticeConstant, latticeType,
125 >                                      particleRadius);
126    
127 <  /* Check to see if we have enough components to build that many shells. */
128 <  if (nShells){
129 <    if (oldInfo->getNMoleculeStamp() != nShells) {
130 <      std::cerr << "Not enough components present in MD file to build specified number of shells"
131 <      << std::endl;
132 <      exit(1);
127 >  /* Build a lattice and get lattice points for this lattice constant */
128 >  vector<Vector3d> sites = nanoParticle.getSites();
129 >  vector<Vector3d> orientations = nanoParticle.getOrientations();
130 >
131 >
132 >  std::vector<int> vacancyTargets;
133 >  vector<bool> isVacancy;
134 >  
135 >  Vector3d myLoc;
136 >  RealType myR;
137 >
138 >  for (int i = 0; i < sites.size(); i++)
139 >    isVacancy.push_back(false);
140 >
141 >  if (args_info.vacancyPercent_given) {
142 >    if (args_info.vacancyPercent_arg < 0.0 || args_info.vacancyPercent_arg > 100.0) {
143 >      sprintf(painCave.errMsg, "vacancyPercent was set to a non-sensical value.");
144 >      painCave.isFatal = 1;
145 >      simError();
146 >    } else {
147 >      RealType vF = args_info.vacancyPercent_arg / 100.0;
148 >      RealType vIR;
149 >      RealType vOR;
150 >      if (args_info.vacancyInnerRadius_given) {
151 >        vIR = args_info.vacancyInnerRadius_arg;
152 >      } else {
153 >        vIR = 0.0;
154 >      }
155 >      if (args_info.vacancyOuterRadius_given) {
156 >        vOR = args_info.vacancyOuterRadius_arg;
157 >      } else {
158 >        vOR = particleRadius;
159 >      }
160 >      if (vIR >= 0.0 && vOR <= particleRadius && vOR >= vIR) {
161 >        
162 >        for (int i = 0; i < sites.size(); i++) {
163 >          myLoc = sites[i];
164 >          myR = myLoc.length();
165 >          if (myR >= vIR && myR <= vOR) {
166 >            vacancyTargets.push_back(i);
167 >          }          
168 >        }
169 >        std::random_shuffle(vacancyTargets.begin(), vacancyTargets.end());
170 >        
171 >        int nTargets = vacancyTargets.size();
172 >        vacancyTargets.resize((int)(vF * nTargets));
173 >        
174 >                  
175 >        sprintf(painCave.errMsg, "Removing %d atoms from randomly-selected\n"
176 >                "\tsites between %lf and %lf.", (int) vacancyTargets.size(),
177 >                vIR, vOR);
178 >        painCave.isFatal = 0;
179 >        simError();
180 >
181 >        isVacancy.clear();
182 >        for (int i = 0; i < sites.size(); i++) {
183 >          bool vac = false;
184 >          for (int j = 0; j < vacancyTargets.size(); j++) {
185 >            if (i == vacancyTargets[j]) vac = true;
186 >          }
187 >          isVacancy.push_back(vac);
188 >        }
189 >              
190 >      } else {
191 >        sprintf(painCave.errMsg, "Something is strange about the vacancy\n"
192 >                "\tinner or outer radii.  Check their values.");
193 >        painCave.isFatal = 1;
194 >        simError();
195 >      }
196      }
197    }
198 <  
199 <  
200 <  //creat lattice
201 <  simpleLat = LatticeFactory::getInstance()->createLattice(latticeType);
202 <  
203 <  if (simpleLat == NULL) {
204 <    std::cerr << "Error in creating lattice" << std::endl;
205 <    exit(1);
198 >
199 >  /* Get number of lattice sites */
200 >  int nSites = sites.size() - vacancyTargets.size();
201 >
202 >  std::vector<Component*> components = simParams->getComponents();
203 >  std::vector<RealType> molFractions;
204 >  std::vector<RealType> shellRadii;
205 >  std::vector<RealType> molecularMasses;
206 >  std::vector<int> nMol;
207 >  std::map<int, int> componentFromSite;
208 >  nComponents = components.size();
209 >
210 >  if (args_info.molFraction_given && args_info.shellRadius_given) {
211 >    sprintf(painCave.errMsg, "Specify either molFraction or shellRadius "
212 >            "arguments, but not both!");
213 >    painCave.isFatal = 1;
214 >    simError();
215    }
216    
217 <  numMolPerCell = simpleLat->getNumSitesPerCell();
218 <  
219 <  /*calculate lattice constant (in Angstrom)
220 <  latticeConstant = pow(rhoConvertConst * numMolPerCell * mass / density,
221 <                        1.0 / 3.0);*/
222 <  
223 <  latticeConstant = args_info.latticeCnst_arg;
224 <  particleRadius = args_info.radius_arg;
225 <  particleDiameter = 2.0 * particleRadius;
226 <  
227 <  /* set lattice constant */
228 <  lc.push_back(latticeConstant);
229 <  simpleLat->setLatticeConstant(lc);
230 <  
231 <  
232 <  /*determine the output file names*/
233 <  if (args_info.output_given)
234 <    outInitFileName = args_info.output_arg;
235 <  else
236 <    outInitFileName = getPrefix(inputFileName.c_str()) + ".in";
175 <  
176 <  
177 <        
178 <  
179 <  
180 <  
181 <  /* create Molocators */
182 <  locator = new MoLocator(oldInfo->getMoleculeStamp(0), oldInfo->getForceField());
183 <  
184 <  /* create a new spherical nanoparticle */
185 <  nanoparticle = new sphericalNanoparticle(particleRadius,latticeConstant);
186 <  /* Build a nanoparticle to see how many sites are there */
187 <  numSites = new int[nComponents]
188 <  nanoparticle.getNMol(numSites);
189 <  
190 <  numMol = new int[nComponents];
191 <  /* Random particle is the default case*/
192 <  if (!args_info.ShellRadius_given){
193 <    std::cout << "Creating a random nanoparticle" << std::endl;
194 <    /* Check to see if we have enough components */
195 <    if (nComponents != args_info.molFraction_given + 1){
196 <      std::cerr << "Number of components does not equal molFraction occurances." << std::endl;
197 <      exit 1;
217 >  if (nComponents == 1) {
218 >    molFractions.push_back(1.0);    
219 >    shellRadii.push_back(particleRadius);
220 >  } else if (args_info.molFraction_given) {
221 >    if ((int)args_info.molFraction_given == nComponents) {
222 >      for (int i = 0; i < nComponents; i++) {
223 >        molFractions.push_back(args_info.molFraction_arg[i]);
224 >      }
225 >    } else if ((int)args_info.molFraction_given == nComponents-1) {
226 >      RealType remainingFraction = 1.0;
227 >      for (int i = 0; i < nComponents-1; i++) {
228 >        molFractions.push_back(args_info.molFraction_arg[i]);
229 >        remainingFraction -= molFractions[i];
230 >      }
231 >      molFractions.push_back(remainingFraction);
232 >    } else {    
233 >      sprintf(painCave.errMsg, "nanoparticleBuilder can't figure out molFractions "
234 >              "for all of the components in the <MetaData> block.");
235 >      painCave.isFatal = 1;
236 >      simError();
237      }
238 <    int totComponents = 0;
239 <    for (int i = 0;i<nComponents-2;i++){ /* Figure out Percent for each component */
240 <      numMol[i] = int((double)numSites * args_info.molFraction_arg[i]);
241 <      totComponents += numMol[i];
242 <    }
243 <    numMol[nComponents-1] = numSites - totComponents;
244 <
245 <  } else{ /*Handle core-shell with multiple components.*/
246 <    std::cout << "Creating a core-shell nanoparticle." << std::endl;
247 <    if (nComponents != args_info.ShellRadius_given + 1){
248 <      std::cerr << "Number of components does not equal ShellRadius occurances." << std::endl;
249 <      exit 1;
238 >  } else if ((int)args_info.shellRadius_given) {
239 >    if ((int)args_info.shellRadius_given == nComponents) {
240 >      for (int i = 0; i < nComponents; i++) {
241 >        shellRadii.push_back(args_info.shellRadius_arg[i]);
242 >      }
243 >    } else if ((int)args_info.shellRadius_given == nComponents-1) {
244 >      for (int i = 0; i < nComponents-1; i++) {
245 >        shellRadii.push_back(args_info.shellRadius_arg[i]);
246 >      }
247 >      shellRadii.push_back(particleRadius);
248 >    } else {    
249 >      sprintf(painCave.errMsg, "nanoparticleBuilder can't figure out the\n"
250 >              "\tshell radii for all of the components in the <MetaData> block.");
251 >      painCave.isFatal = 1;
252 >      simError();
253      }
254 +  } else {
255 +    sprintf(painCave.errMsg, "You have a multi-component <MetaData> block,\n"
256 +            "\tbut have not specified either molFraction or shellRadius arguments.");
257 +    painCave.isFatal = 1;
258 +    simError();
259 +  }
260      
261 +  if (args_info.molFraction_given) {
262 +    RealType totalFraction = 0.0;
263      
264 +    /* Do some simple sanity checking*/
265      
266 +    for (int i = 0; i < nComponents; i++) {
267 +      if (molFractions.at(i) < 0.0) {
268 +        sprintf(painCave.errMsg, "One of the requested molFractions was"
269 +                " less than zero!");
270 +        painCave.isFatal = 1;
271 +        simError();
272 +      }
273 +      if (molFractions.at(i) > 1.0) {
274 +        sprintf(painCave.errMsg, "One of the requested molFractions was"
275 +                " greater than one!");
276 +        painCave.isFatal = 1;
277 +        simError();
278 +      }
279 +      totalFraction += molFractions.at(i);
280 +    }
281 +    if (abs(totalFraction - 1.0) > 1e-6) {
282 +      sprintf(painCave.errMsg, "The sum of molFractions was not close enough to 1.0");
283 +      painCave.isFatal = 1;
284 +      simError();
285 +    }
286 +    
287 +    int remaining = nSites;
288 +    for (int i=0; i < nComponents-1; i++) {    
289 +      nMol.push_back(int((RealType)nSites * molFractions.at(i)));
290 +      remaining -= nMol.at(i);
291 +    }
292 +    nMol.push_back(remaining);
293 +    
294 +    // recompute actual mol fractions and perform final sanity check:
295 +    
296 +    int totalMolecules = 0;
297 +    for (int i=0; i < nComponents; i++) {
298 +      molFractions[i] = (RealType)(nMol.at(i))/(RealType)nSites;
299 +      totalMolecules += nMol.at(i);
300 +    }
301 +    
302 +    if (totalMolecules != nSites) {
303 +      sprintf(painCave.errMsg, "Computed total number of molecules is not equal "
304 +              "to the number of lattice sites!");
305 +      painCave.isFatal = 1;
306 +      simError();
307 +    }
308 +  } else {
309 +
310 +    for (int i = 0; i < shellRadii.size(); i++) {
311 +      if (shellRadii.at(i) > particleRadius + 1e-6 ) {
312 +        sprintf(painCave.errMsg, "One of the shellRadius values exceeds the particle Radius.");
313 +        painCave.isFatal = 1;
314 +        simError();
315 +      }
316 +      if (shellRadii.at(i) <= 0.0 ) {
317 +        sprintf(painCave.errMsg, "One of the shellRadius values is smaller than zero!");
318 +        painCave.isFatal = 1;
319 +        simError();
320 +      }
321 +    }
322    }
323  
324 <   //get the orientation of the cell sites
325 <  //for the same type of molecule in same lattice, it will not change
326 <   latticeOrt = simpleLat->getLatticePointsOrt();
324 >  vector<int> ids;          
325 >  if ((int)args_info.molFraction_given){
326 >    sprintf(painCave.errMsg, "Creating a randomized spherical nanoparticle.");
327 >    painCave.isFatal = 0;
328 >    simError();
329 >    /* Random particle is the default case*/
330 >
331 >    for (int i = 0; i < sites.size(); i++)
332 >      if (!isVacancy[i]) ids.push_back(i);
333 >    
334 >    std::random_shuffle(ids.begin(), ids.end());
335 >    
336 >  } else{
337 >    sprintf(painCave.errMsg, "Creating a core-shell spherical nanoparticle.");
338 >    painCave.isFatal = 0;
339 >    simError();
340 >
341 >    RealType smallestSoFar;
342 >    int myComponent = -1;
343 >    nMol.clear();
344 >    nMol.resize(nComponents);
345 >
346 >    for (int i = 0; i < sites.size(); i++) {
347 >      myLoc = sites[i];
348 >      myR = myLoc.length();
349 >      smallestSoFar = particleRadius;      
350 >      if (!isVacancy[i]) {
351 >        for (int j = 0; j < nComponents; j++) {
352 >          if (myR <= shellRadii[j]) {
353 >            if (shellRadii[j] <= smallestSoFar) {
354 >              smallestSoFar = shellRadii[j];
355 >              myComponent = j;
356 >            }
357 >          }
358 >        }
359 >        componentFromSite[i] = myComponent;
360 >        nMol[myComponent]++;
361 >      }
362 >    }      
363 >  }
364    
365 +  outputFileName = args_info.output_arg;
366 +  
367 +  //creat new .md file on fly which corrects the number of molecule    
368 +  createMdFile(inputFileName, outputFileName, nMol);
369    
222  
223  // needed for writing out new md file.
224  
225    outPrefix = getPrefix(inputFileName.c_str()) + "_" + latticeType;
226    outMdFileName = outPrefix + ".md";
227  
228    //creat new .md file on fly which corrects the number of molecule    
229    createMdFile(inputFileName, outMdFileName, numcomponents,numMol);
230  
370    if (oldInfo != NULL)
371      delete oldInfo;
372    
373 <  
374 <  // We need to read in new siminfo object.    
375 <  //parse md file and set up the system
376 <  //SimCreator NewCreator;
238 <  
239 <  SimInfo* NewInfo = oldCreator.createSim(outMdFileName, false);
240 <  
241 <  // This was so much fun the first time, lets do it again.
242 <  
373 >  SimCreator newCreator;
374 >  SimInfo* NewInfo = newCreator.createSim(outputFileName, false);
375 >    
376 >  // Place molecules
377    Molecule* mol;
378    SimInfo::MoleculeIterator mi;
379    mol = NewInfo->beginMolecule(mi);
380  
381 +  int l = 0;
382 +  int whichSite = 0;
383  
384 <  for(int i = -nx; i < nx; i++) {
385 <     for(int j = -ny; j < ny; j++) {
386 <        for(int k = -nz; k < nz; k++) {
387 <          
388 <           //get the position of the cell sites
389 <           simpleLat->getLatticePointsPos(latticePos, i, j, k);
390 <          
391 <           for(int l = 0; l < numMolPerCell; l++) {
392 < #ifdef HAVE_CGAL              
393 <              if (myGeometry->isInsidePolyhedron(latticePos[l][0],latticePos[l][1],latticePos[l][2])){
394 < #endif                              
395 <                 if (mol != NULL) {
260 <                    locator->placeMol(latticePos[l], latticeOrt[l], mol);
261 <                 } else {
262 <                    std::cerr<<"Error in placing molecule " << std::endl;                    
263 <                 }
264 <                 mol = NewInfo->nextMolecule(mi);
265 < #ifdef HAVE_CGAL                
266 <              }
267 < #endif              
268 <           }
384 >  for (int i = 0; i < nComponents; i++){
385 >    locator = new MoLocator(NewInfo->getMoleculeStamp(i),
386 >                            NewInfo->getForceField());
387 >    
388 >    if (!args_info.molFraction_given) {
389 >      for (int n = 0; n < sites.size(); n++) {
390 >        if (!isVacancy[n]) {
391 >          if (componentFromSite[n] == i) {
392 >            mol = NewInfo->getMoleculeByGlobalIndex(l);
393 >            locator->placeMol(sites[n], orientations[n], mol);
394 >            l++;
395 >          }
396          }
397 <     }
397 >      }
398 >    } else {
399 >      for (int n = 0; n < nMol.at(i); n++) {
400 >        mol = NewInfo->getMoleculeByGlobalIndex(l);
401 >        locator->placeMol(sites[ids[l]], orientations[ids[l]], mol);
402 >        l++;
403 >      }
404 >    }
405    }
406    
273
274  
407    //fill Hmat
408 <  hmat(0, 0)= nx * latticeConstant;
408 >  hmat(0, 0)=  10.0*particleRadius;
409    hmat(0, 1) = 0.0;
410    hmat(0, 2) = 0.0;
411    
412    hmat(1, 0) = 0.0;
413 <  hmat(1, 1) = ny * latticeConstant;
413 >  hmat(1, 1) =  10.0*particleRadius;
414    hmat(1, 2) = 0.0;
415    
416    hmat(2, 0) = 0.0;
417    hmat(2, 1) = 0.0;
418 <  hmat(2, 2) = nz * latticeConstant;
418 >  hmat(2, 2) =  10.0*particleRadius;
419    
420    //set Hmat
421    NewInfo->getSnapshotManager()->getCurrentSnapshot()->setHmat(hmat);
422    
423    
424    //create dumpwriter and write out the coordinates
425 <  NewInfo->setFinalConfigFileName(outInitFileName);
294 <  writer = new DumpWriter(NewInfo);
425 >  writer = new DumpWriter(NewInfo, outputFileName);
426    
427    if (writer == NULL) {
428 <    std::cerr << "error in creating DumpWriter" << std::endl;
429 <    exit(1);
428 >    sprintf(painCave.errMsg, "Error in creating dumpwriter object ");
429 >    painCave.isFatal = 1;
430 >    simError();
431    }
432    
433    writer->writeDump();
434 <  std::cout << "new initial configuration file: " << outInitFileName
435 <            << " is generated." << std::endl;
436 <  
437 <  //delete objects
438 <  
439 <  //delete oldInfo and oldSimSetup
440 <  
441 <  if (NewInfo != NULL)
442 <    delete NewInfo;
443 <  
312 <  if (writer != NULL)
313 <    delete writer;
314 <  delete simpleLat;    
315 <  cmdline_parser_free(&args_info);
434 >
435 >  // deleting the writer will put the closing at the end of the dump file
436 >
437 >  delete writer;
438 >
439 >  // cleanup a by calling sim error.....
440 >  sprintf(painCave.errMsg, "A new OpenMD file called \"%s\" has been "
441 >          "generated.\n", outputFileName.c_str());
442 >  painCave.isFatal = 0;
443 >  simError();
444    return 0;
445   }
446  
447 < void createMdFile(const std::string&oldMdFileName, const std::string&newMdFileName,
448 <                  int components,int &nummol) {
447 > void createMdFile(const std::string&oldMdFileName,
448 >                  const std::string&newMdFileName,
449 >                  std::vector<int> nMol) {
450    ifstream oldMdFile;
451    ofstream newMdFile;
452    const int MAXLEN = 65535;
# Line 326 | Line 455 | void createMdFile(const std::string&oldMdFileName, con
455    //create new .md file based on old .md file
456    oldMdFile.open(oldMdFileName.c_str());
457    newMdFile.open(newMdFileName.c_str());
329  
458    oldMdFile.getline(buffer, MAXLEN);
459 <  
459 >
460 >  int i = 0;
461    while (!oldMdFile.eof()) {
462 <    
462 >
463      //correct molecule number
464      if (strstr(buffer, "nMol") != NULL) {
465 <      sprintf(buffer, "\tnMol = %i;", numMol);                          
466 <      newMdFile << buffer << std::endl;
465 >      if(i<nMol.size()){
466 >        sprintf(buffer, "\tnMol = %i;", nMol.at(i));
467 >        newMdFile << buffer << std::endl;
468 >        i++;
469 >      }
470      } else
471        newMdFile << buffer << std::endl;
472      
# Line 343 | Line 475 | void createMdFile(const std::string&oldMdFileName, con
475    
476    oldMdFile.close();
477    newMdFile.close();
478 +
479 +  if (i != nMol.size()) {
480 +    sprintf(painCave.errMsg, "Couldn't replace the correct number of nMol\n"
481 +            "\tstatements in component blocks.  Make sure that all\n"
482 +            "\tcomponents in the template file have nMol=1");
483 +    painCave.isFatal = 1;
484 +    simError();
485 +  }
486 +    
487   }
488  

Comparing:
trunk/src/applications/nanoparticleBuilder/nanoparticleBuilder.cpp (property svn:keywords), Revision 653 by chuckv, Tue Oct 11 21:57:22 2005 UTC vs.
branches/development/src/applications/nanoparticleBuilder/nanoparticleBuilder.cpp (property svn:keywords), Revision 1704 by gezelter, Tue Apr 24 20:40:04 2012 UTC

# Line 0 | Line 1
1 + Author Id Revision Date

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines