ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/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.
Revision 1977 by gezelter, Wed Mar 12 21:35:23 2014 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, 234107 (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    
74  //register force fields
75  registerForceFields();
75    registerLattice();
76    
77    gengetopt_args_info args_info;
78    std::string latticeType;
79    std::string inputFileName;
80 <  std::string outPrefix;
81 <  std::string outMdFileName;
82 <  std::string outInitFileName;
84 <
85 <  
86 <  
87 <  Lattice *simpleLat;
88 <  int numMol;
80 >  std::string outputFileName;
81 >  MoLocator* locator;
82 >  int nComponents;
83    double latticeConstant;
84 <  std::vector<double> lc;
91 <  double mass;
92 <  const double rhoConvertConst = 1.661;
93 <  double density;
94 <  
95 <  
96 <
84 >  RealType particleRadius;
85    Mat3x3d hmat;
98  MoLocator *locator;
99  sphericalNanoparticle *nanoparticle;
100  std::vector<Vector3d> latticePos;
101  std::vector<Vector3d> latticeOrt;
102  int numMolPerCell;
103  int nShells; /* Number of shells in nanoparticle*/
104  int numSites;
105  
86    DumpWriter *writer;
87    
88 <  // parse command line arguments
88 >  // Parse Command Line Arguments
89    if (cmdline_parser(argc, argv, &args_info) != 0)
90      exit(1);
91 <  
112 <        
113 <        
91 >        
92    /* get lattice type */
93 <  latticeType = UpperCase(args_info.latticetype_arg);
94 <    
93 >  latticeType = "FCC";
94 >
95    /* get input file name */
96    if (args_info.inputs_num)
97      inputFileName = args_info.inputs[0];
98    else {
99 <    std::cerr << "You must specify a input file name.\n" << std::endl;
99 >    sprintf(painCave.errMsg, "No input .md file name was specified "
100 >            "on the command line");
101 >    painCave.isFatal = 1;
102      cmdline_parser_print_help();
103 <    exit(1);
103 >    simError();
104    }
105    
106    /* parse md file and set up the system */
107    SimCreator oldCreator;
108    SimInfo* oldInfo = oldCreator.createSim(inputFileName, false);
109    
110 <  nShells = 0;
111 <  if (args_info.coreShellRadius_given){
112 <    nShells = args_info.coreShellRadius_given;
133 <  }
110 >  latticeConstant = args_info.latticeConstant_arg;
111 >  particleRadius = args_info.radius_arg;
112 >  Globals* simParams = oldInfo->getSimParams();
113    
114 <  nComponents = oldInfo->getNMoleculeStamp();
114 >  /* Create nanoparticle */
115 >  shapedLatticeSpherical nanoParticle(latticeConstant, latticeType,
116 >                                      particleRadius);
117    
118 <  /* Check to see if we have enough components to build that many shells. */
119 <  if (nShells){
120 <    if (oldInfo->getNMoleculeStamp() != nShells) {
121 <      std::cerr << "Not enough components present in MD file to build specified number of shells"
122 <      << std::endl;
123 <      exit(1);
118 >  /* Build a lattice and get lattice points for this lattice constant */
119 >  vector<Vector3d> sites = nanoParticle.getSites();
120 >  vector<Vector3d> orientations = nanoParticle.getOrientations();
121 >
122 >
123 >  std::vector<int> vacancyTargets;
124 >  vector<bool> isVacancy;
125 >  
126 >  Vector3d myLoc;
127 >  RealType myR;
128 >
129 >  for (unsigned int i = 0; i < sites.size(); i++)
130 >    isVacancy.push_back(false);
131 >
132 >  if (args_info.vacancyPercent_given) {
133 >    if (args_info.vacancyPercent_arg < 0.0 || args_info.vacancyPercent_arg > 100.0) {
134 >      sprintf(painCave.errMsg, "vacancyPercent was set to a non-sensical value.");
135 >      painCave.isFatal = 1;
136 >      simError();
137 >    } else {
138 >      RealType vF = args_info.vacancyPercent_arg / 100.0;
139 >      RealType vIR;
140 >      RealType vOR;
141 >      if (args_info.vacancyInnerRadius_given) {
142 >        vIR = args_info.vacancyInnerRadius_arg;
143 >      } else {
144 >        vIR = 0.0;
145 >      }
146 >      if (args_info.vacancyOuterRadius_given) {
147 >        vOR = args_info.vacancyOuterRadius_arg;
148 >      } else {
149 >        vOR = particleRadius;
150 >      }
151 >      if (vIR >= 0.0 && vOR <= particleRadius && vOR >= vIR) {
152 >        
153 >        for (unsigned int i = 0; i < sites.size(); i++) {
154 >          myLoc = sites[i];
155 >          myR = myLoc.length();
156 >          if (myR >= vIR && myR <= vOR) {
157 >            vacancyTargets.push_back(i);
158 >          }          
159 >        }
160 >        std::random_shuffle(vacancyTargets.begin(), vacancyTargets.end());
161 >        
162 >        int nTargets = vacancyTargets.size();
163 >        vacancyTargets.resize((int)(vF * nTargets));
164 >        
165 >                  
166 >        sprintf(painCave.errMsg, "Removing %d atoms from randomly-selected\n"
167 >                "\tsites between %lf and %lf.", (int) vacancyTargets.size(),
168 >                vIR, vOR);
169 >        painCave.isFatal = 0;
170 >        painCave.severity = OPENMD_INFO;
171 >        simError();
172 >
173 >        isVacancy.clear();
174 >        for (unsigned int i = 0; i < sites.size(); i++) {
175 >          bool vac = false;
176 >          for (unsigned int j = 0; j < vacancyTargets.size(); j++) {
177 >            if (i == vacancyTargets[j]) vac = true;
178 >          }
179 >          isVacancy.push_back(vac);
180 >        }
181 >              
182 >      } else {
183 >        sprintf(painCave.errMsg, "Something is strange about the vacancy\n"
184 >                "\tinner or outer radii.  Check their values.");
185 >        painCave.isFatal = 1;
186 >        simError();
187 >      }
188      }
189    }
190 <  
191 <  
192 <  //creat lattice
193 <  simpleLat = LatticeFactory::getInstance()->createLattice(latticeType);
194 <  
195 <  if (simpleLat == NULL) {
196 <    std::cerr << "Error in creating lattice" << std::endl;
197 <    exit(1);
190 >
191 >  /* Get number of lattice sites */
192 >  int nSites = sites.size() - vacancyTargets.size();
193 >
194 >  std::vector<Component*> components = simParams->getComponents();
195 >  std::vector<RealType> molFractions;
196 >  std::vector<RealType> shellRadii;
197 >  std::vector<int> nMol;
198 >  std::map<int, int> componentFromSite;
199 >  nComponents = components.size();
200 >
201 >  if (args_info.molFraction_given && args_info.shellRadius_given) {
202 >    sprintf(painCave.errMsg, "Specify either molFraction or shellRadius "
203 >            "arguments, but not both!");
204 >    painCave.isFatal = 1;
205 >    simError();
206    }
207    
208 <  numMolPerCell = simpleLat->getNumSitesPerCell();
209 <  
210 <  /*calculate lattice constant (in Angstrom)
211 <  latticeConstant = pow(rhoConvertConst * numMolPerCell * mass / density,
212 <                        1.0 / 3.0);*/
213 <  
214 <  latticeConstant = args_info.latticeCnst_arg;
215 <  particleRadius = args_info.radius_arg;
216 <  particleDiameter = 2.0 * particleRadius;
217 <  
218 <  /* set lattice constant */
219 <  lc.push_back(latticeConstant);
220 <  simpleLat->setLatticeConstant(lc);
221 <  
222 <  
223 <  /*determine the output file names*/
224 <  if (args_info.output_given)
225 <    outInitFileName = args_info.output_arg;
226 <  else
227 <    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;
208 >  if (nComponents == 1) {
209 >    molFractions.push_back(1.0);    
210 >    shellRadii.push_back(particleRadius);
211 >  } else if (args_info.molFraction_given) {
212 >    if ((int)args_info.molFraction_given == nComponents) {
213 >      for (int i = 0; i < nComponents; i++) {
214 >        molFractions.push_back(args_info.molFraction_arg[i]);
215 >      }
216 >    } else if ((int)args_info.molFraction_given == nComponents-1) {
217 >      RealType remainingFraction = 1.0;
218 >      for (int i = 0; i < nComponents-1; i++) {
219 >        molFractions.push_back(args_info.molFraction_arg[i]);
220 >        remainingFraction -= molFractions[i];
221 >      }
222 >      molFractions.push_back(remainingFraction);
223 >    } else {    
224 >      sprintf(painCave.errMsg, "nanoparticleBuilder can't figure out molFractions "
225 >              "for all of the components in the <MetaData> block.");
226 >      painCave.isFatal = 1;
227 >      simError();
228      }
229 <    int totComponents = 0;
230 <    for (int i = 0;i<nComponents-2;i++){ /* Figure out Percent for each component */
231 <      numMol[i] = int((double)numSites * args_info.molFraction_arg[i]);
232 <      totComponents += numMol[i];
233 <    }
234 <    numMol[nComponents-1] = numSites - totComponents;
235 <
236 <  } else{ /*Handle core-shell with multiple components.*/
237 <    std::cout << "Creating a core-shell nanoparticle." << std::endl;
238 <    if (nComponents != args_info.ShellRadius_given + 1){
239 <      std::cerr << "Number of components does not equal ShellRadius occurances." << std::endl;
240 <      exit 1;
229 >  } else if ((int)args_info.shellRadius_given) {
230 >    if ((int)args_info.shellRadius_given == nComponents) {
231 >      for (int i = 0; i < nComponents; i++) {
232 >        shellRadii.push_back(args_info.shellRadius_arg[i]);
233 >      }
234 >    } else if ((int)args_info.shellRadius_given == nComponents-1) {
235 >      for (int i = 0; i < nComponents-1; i++) {
236 >        shellRadii.push_back(args_info.shellRadius_arg[i]);
237 >      }
238 >      shellRadii.push_back(particleRadius);
239 >    } else {    
240 >      sprintf(painCave.errMsg, "nanoparticleBuilder can't figure out the\n"
241 >              "\tshell radii for all of the components in the <MetaData> block.");
242 >      painCave.isFatal = 1;
243 >      simError();
244      }
245 +  } else {
246 +    sprintf(painCave.errMsg, "You have a multi-component <MetaData> block,\n"
247 +            "\tbut have not specified either molFraction or shellRadius arguments.");
248 +    painCave.isFatal = 1;
249 +    simError();
250 +  }
251      
252 +  if (args_info.molFraction_given) {
253 +    RealType totalFraction = 0.0;
254      
255 +    /* Do some simple sanity checking*/
256      
257 +    for (int i = 0; i < nComponents; i++) {
258 +      if (molFractions.at(i) < 0.0) {
259 +        sprintf(painCave.errMsg, "One of the requested molFractions was"
260 +                " less than zero!");
261 +        painCave.isFatal = 1;
262 +        simError();
263 +      }
264 +      if (molFractions.at(i) > 1.0) {
265 +        sprintf(painCave.errMsg, "One of the requested molFractions was"
266 +                " greater than one!");
267 +        painCave.isFatal = 1;
268 +        simError();
269 +      }
270 +      totalFraction += molFractions.at(i);
271 +    }
272 +    if (abs(totalFraction - 1.0) > 1e-6) {
273 +      sprintf(painCave.errMsg, "The sum of molFractions was not close enough to 1.0");
274 +      painCave.isFatal = 1;
275 +      simError();
276 +    }
277 +    
278 +    int remaining = nSites;
279 +    for (int i=0; i < nComponents-1; i++) {    
280 +      nMol.push_back(int((RealType)nSites * molFractions.at(i)));
281 +      remaining -= nMol.at(i);
282 +    }
283 +    nMol.push_back(remaining);
284 +    
285 +    // recompute actual mol fractions and perform final sanity check:
286 +    
287 +    int totalMolecules = 0;
288 +    for (int i=0; i < nComponents; i++) {
289 +      molFractions[i] = (RealType)(nMol.at(i))/(RealType)nSites;
290 +      totalMolecules += nMol.at(i);
291 +    }
292 +    
293 +    if (totalMolecules != nSites) {
294 +      sprintf(painCave.errMsg, "Computed total number of molecules is not equal "
295 +              "to the number of lattice sites!");
296 +      painCave.isFatal = 1;
297 +      simError();
298 +    }
299 +  } else {
300 +
301 +    for (unsigned int i = 0; i < shellRadii.size(); i++) {
302 +      if (shellRadii.at(i) > particleRadius + 1e-6 ) {
303 +        sprintf(painCave.errMsg, "One of the shellRadius values exceeds the particle Radius.");
304 +        painCave.isFatal = 1;
305 +        simError();
306 +      }
307 +      if (shellRadii.at(i) <= 0.0 ) {
308 +        sprintf(painCave.errMsg, "One of the shellRadius values is smaller than zero!");
309 +        painCave.isFatal = 1;
310 +        simError();
311 +      }
312 +    }
313    }
314  
315 <   //get the orientation of the cell sites
316 <  //for the same type of molecule in same lattice, it will not change
317 <   latticeOrt = simpleLat->getLatticePointsOrt();
315 >  vector<int> ids;          
316 >  if ((int)args_info.molFraction_given){
317 >    sprintf(painCave.errMsg, "Creating a randomized spherical nanoparticle.");
318 >    painCave.isFatal = 0;
319 >    painCave.severity = OPENMD_INFO;
320 >    simError();
321 >    /* Random particle is the default case*/
322 >
323 >    for (unsigned int i = 0; i < sites.size(); i++)
324 >      if (!isVacancy[i]) ids.push_back(i);
325 >    
326 >    std::random_shuffle(ids.begin(), ids.end());
327 >    
328 >  } else{
329 >    sprintf(painCave.errMsg, "Creating a core-shell spherical nanoparticle.");
330 >    painCave.isFatal = 0;
331 >    painCave.severity = OPENMD_INFO;
332 >    simError();
333 >
334 >    RealType smallestSoFar;
335 >    int myComponent = -1;
336 >    nMol.clear();
337 >    nMol.resize(nComponents);
338 >
339 >    for (unsigned int i = 0; i < sites.size(); i++) {
340 >      myLoc = sites[i];
341 >      myR = myLoc.length();
342 >      smallestSoFar = particleRadius;      
343 >      if (!isVacancy[i]) {
344 >        for (int j = 0; j < nComponents; j++) {
345 >          if (myR <= shellRadii[j]) {
346 >            if (shellRadii[j] <= smallestSoFar) {
347 >              smallestSoFar = shellRadii[j];
348 >              myComponent = j;
349 >            }
350 >          }
351 >        }
352 >        componentFromSite[i] = myComponent;
353 >        nMol[myComponent]++;
354 >      }
355 >    }      
356 >  }
357    
358 +  outputFileName = args_info.output_arg;
359 +  
360 +  //creat new .md file on fly which corrects the number of molecule    
361 +  createMdFile(inputFileName, outputFileName, nMol);
362    
363 +  delete oldInfo;
364    
365 <  // needed for writing out new md file.
366 <  
367 <    outPrefix = getPrefix(inputFileName.c_str()) + "_" + latticeType;
368 <    outMdFileName = outPrefix + ".md";
227 <  
228 <    //creat new .md file on fly which corrects the number of molecule    
229 <    createMdFile(inputFileName, outMdFileName, numcomponents,numMol);
230 <  
231 <  if (oldInfo != NULL)
232 <    delete oldInfo;
233 <  
234 <  
235 <  // We need to read in new siminfo object.    
236 <  //parse md file and set up the system
237 <  //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 <  
365 >  SimCreator newCreator;
366 >  SimInfo* NewInfo = newCreator.createSim(outputFileName, false);
367 >    
368 >  // Place molecules
369    Molecule* mol;
370    SimInfo::MoleculeIterator mi;
371    mol = NewInfo->beginMolecule(mi);
372  
373 +  int l = 0;
374  
375 <  for(int i = -nx; i < nx; i++) {
376 <     for(int j = -ny; j < ny; j++) {
377 <        for(int k = -nz; k < nz; k++) {
378 <          
379 <           //get the position of the cell sites
380 <           simpleLat->getLatticePointsPos(latticePos, i, j, k);
381 <          
382 <           for(int l = 0; l < numMolPerCell; l++) {
383 < #ifdef HAVE_CGAL              
384 <              if (myGeometry->isInsidePolyhedron(latticePos[l][0],latticePos[l][1],latticePos[l][2])){
385 < #endif                              
386 <                 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 <           }
375 >  for (int i = 0; i < nComponents; i++){
376 >    locator = new MoLocator(NewInfo->getMoleculeStamp(i),
377 >                            NewInfo->getForceField());
378 >    
379 >    if (!args_info.molFraction_given) {
380 >      for (unsigned int n = 0; n < sites.size(); n++) {
381 >        if (!isVacancy[n]) {
382 >          if (componentFromSite[n] == i) {
383 >            mol = NewInfo->getMoleculeByGlobalIndex(l);
384 >            locator->placeMol(sites[n], orientations[n], mol);
385 >            l++;
386 >          }
387          }
388 <     }
388 >      }
389 >    } else {
390 >      for (int n = 0; n < nMol.at(i); n++) {
391 >        mol = NewInfo->getMoleculeByGlobalIndex(l);
392 >        locator->placeMol(sites[ids[l]], orientations[ids[l]], mol);
393 >        l++;
394 >      }
395 >    }
396    }
397    
273
274  
398    //fill Hmat
399 <  hmat(0, 0)= nx * latticeConstant;
399 >  hmat(0, 0)=  10.0*particleRadius;
400    hmat(0, 1) = 0.0;
401    hmat(0, 2) = 0.0;
402    
403    hmat(1, 0) = 0.0;
404 <  hmat(1, 1) = ny * latticeConstant;
404 >  hmat(1, 1) =  10.0*particleRadius;
405    hmat(1, 2) = 0.0;
406    
407    hmat(2, 0) = 0.0;
408    hmat(2, 1) = 0.0;
409 <  hmat(2, 2) = nz * latticeConstant;
409 >  hmat(2, 2) =  10.0*particleRadius;
410    
411    //set Hmat
412    NewInfo->getSnapshotManager()->getCurrentSnapshot()->setHmat(hmat);
413    
414    
415    //create dumpwriter and write out the coordinates
416 <  NewInfo->setFinalConfigFileName(outInitFileName);
294 <  writer = new DumpWriter(NewInfo);
416 >  writer = new DumpWriter(NewInfo, outputFileName);
417    
418    if (writer == NULL) {
419 <    std::cerr << "error in creating DumpWriter" << std::endl;
420 <    exit(1);
419 >    sprintf(painCave.errMsg, "Error in creating dumpwriter object ");
420 >    painCave.isFatal = 1;
421 >    simError();
422    }
423    
424    writer->writeDump();
425 <  std::cout << "new initial configuration file: " << outInitFileName
426 <            << " is generated." << std::endl;
427 <  
428 <  //delete objects
429 <  
430 <  //delete oldInfo and oldSimSetup
431 <  
432 <  if (NewInfo != NULL)
433 <    delete NewInfo;
434 <  
435 <  if (writer != NULL)
313 <    delete writer;
314 <  delete simpleLat;    
315 <  cmdline_parser_free(&args_info);
425 >
426 >  // deleting the writer will put the closing at the end of the dump file
427 >
428 >  delete writer;
429 >
430 >  // cleanup a by calling sim error.....
431 >  sprintf(painCave.errMsg, "A new OpenMD file called \"%s\" has been "
432 >          "generated.\n", outputFileName.c_str());
433 >  painCave.isFatal = 0;
434 >  painCave.severity = OPENMD_INFO;
435 >  simError();
436    return 0;
437   }
438  
439 < void createMdFile(const std::string&oldMdFileName, const std::string&newMdFileName,
440 <                  int components,int &nummol) {
439 > void createMdFile(const std::string&oldMdFileName,
440 >                  const std::string&newMdFileName,
441 >                  std::vector<int> nMol) {
442    ifstream oldMdFile;
443    ofstream newMdFile;
444    const int MAXLEN = 65535;
# Line 326 | Line 447 | void createMdFile(const std::string&oldMdFileName, con
447    //create new .md file based on old .md file
448    oldMdFile.open(oldMdFileName.c_str());
449    newMdFile.open(newMdFileName.c_str());
329  
450    oldMdFile.getline(buffer, MAXLEN);
451 <  
451 >
452 >  unsigned int i = 0;
453    while (!oldMdFile.eof()) {
454 <    
454 >
455      //correct molecule number
456      if (strstr(buffer, "nMol") != NULL) {
457 <      sprintf(buffer, "\tnMol = %i;", numMol);                          
458 <      newMdFile << buffer << std::endl;
457 >      if(i<nMol.size()){
458 >        sprintf(buffer, "\tnMol = %i;", nMol.at(i));
459 >        newMdFile << buffer << std::endl;
460 >        i++;
461 >      }
462      } else
463        newMdFile << buffer << std::endl;
464      
# Line 343 | Line 467 | void createMdFile(const std::string&oldMdFileName, con
467    
468    oldMdFile.close();
469    newMdFile.close();
470 +
471 +  if (i != nMol.size()) {
472 +    sprintf(painCave.errMsg, "Couldn't replace the correct number of nMol\n"
473 +            "\tstatements in component blocks.  Make sure that all\n"
474 +            "\tcomponents in the template file have nMol=1");
475 +    painCave.isFatal = 1;
476 +    simError();
477 +  }
478 +    
479   }
480  

Comparing trunk/src/applications/nanoparticleBuilder/nanoparticleBuilder.cpp (property svn:keywords):
Revision 653 by chuckv, Tue Oct 11 21:57:22 2005 UTC vs.
Revision 1977 by gezelter, Wed Mar 12 21:35:23 2014 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines