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 1390 by gezelter, Wed Nov 25 20:02:06 2009 UTC vs.
Revision 2071 by gezelter, Sat Mar 7 21:41:51 2015 UTC

# Line 35 | Line 35
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]  Vardeman & Gezelter, in progress (2009).                        
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 71 | Line 72 | int main(int argc, char *argv []) {
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 outputFileName;
82
81    MoLocator* locator;
82    int nComponents;
83    double latticeConstant;
86  std::vector<double> lc;
87
84    RealType particleRadius;
89
85    Mat3x3d hmat;
91  std::vector<Vector3d> latticePos;
92  std::vector<Vector3d> latticeOrt;
93
86    DumpWriter *writer;
87    
88    // Parse Command Line Arguments
# Line 126 | Line 118 | int main(int argc, char *argv []) {
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 <  std::vector<int> vacancyTargets;
121 >
122 >
123 >  std::vector<std::size_t> vacancyTargets;
124    vector<bool> isVacancy;
125    
126    Vector3d myLoc;
127    RealType myR;
128  
129 <  for (int i = 0; i < sites.size(); i++)
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.");
134 >      sprintf(painCave.errMsg,
135 >              "vacancyPercent was set to a non-sensical value.");
136        painCave.isFatal = 1;
137        simError();
138      } else {
# Line 156 | Line 151 | int main(int argc, char *argv []) {
151        }
152        if (vIR >= 0.0 && vOR <= particleRadius && vOR >= vIR) {
153          
154 <        for (int i = 0; i < sites.size(); i++) {
154 >        for (std::size_t i = 0; i < sites.size(); i++) {
155            myLoc = sites[i];
156            myR = myLoc.length();
157            if (myR >= vIR && myR <= vOR) {
# Line 173 | Line 168 | int main(int argc, char *argv []) {
168                  "\tsites between %lf and %lf.", (int) vacancyTargets.size(),
169                  vIR, vOR);
170          painCave.isFatal = 0;
171 +        painCave.severity = OPENMD_INFO;
172          simError();
173  
174          isVacancy.clear();
175 <        for (int i = 0; i < sites.size(); i++) {
175 >        for (std::size_t i = 0; i < sites.size(); i++) {
176            bool vac = false;
177 <          for (int j = 0; j < vacancyTargets.size(); j++) {
177 >          for (std::size_t j = 0; j < vacancyTargets.size(); j++) {
178              if (i == vacancyTargets[j]) vac = true;
179            }
180            isVacancy.push_back(vac);
# Line 194 | Line 190 | int main(int argc, char *argv []) {
190    }
191  
192    /* Get number of lattice sites */
193 <  int nSites = sites.size() - vacancyTargets.size();
193 >  std::size_t nSites = sites.size() - vacancyTargets.size();
194  
195    std::vector<Component*> components = simParams->getComponents();
196    std::vector<RealType> molFractions;
197    std::vector<RealType> shellRadii;
202  std::vector<RealType> molecularMasses;
198    std::vector<int> nMol;
199    std::map<int, int> componentFromSite;
200    nComponents = components.size();
# Line 276 | Line 271 | int main(int argc, char *argv []) {
271        totalFraction += molFractions.at(i);
272      }
273      if (abs(totalFraction - 1.0) > 1e-6) {
274 <      sprintf(painCave.errMsg, "The sum of molFractions was not close enough to 1.0");
274 >      sprintf(painCave.errMsg,
275 >              "The sum of molFractions was not close enough to 1.0");
276        painCave.isFatal = 1;
277        simError();
278      }
# Line 290 | Line 286 | int main(int argc, char *argv []) {
286      
287      // recompute actual mol fractions and perform final sanity check:
288      
289 <    int totalMolecules = 0;
289 >    std::size_t totalMolecules = 0;
290      for (int i=0; i < nComponents; i++) {
291        molFractions[i] = (RealType)(nMol.at(i))/(RealType)nSites;
292        totalMolecules += nMol.at(i);
293      }
294      
295      if (totalMolecules != nSites) {
296 <      sprintf(painCave.errMsg, "Computed total number of molecules is not equal "
296 >      sprintf(painCave.errMsg,
297 >              "Computed total number of molecules is not equal "
298                "to the number of lattice sites!");
299        painCave.isFatal = 1;
300        simError();
301      }
302    } else {
303  
304 <    for (int i = 0; i < shellRadii.size(); i++) {
304 >    for (unsigned int i = 0; i < shellRadii.size(); i++) {
305        if (shellRadii.at(i) > particleRadius + 1e-6 ) {
306 <        sprintf(painCave.errMsg, "One of the shellRadius values exceeds the particle Radius.");
306 >        sprintf(painCave.errMsg,
307 >                "One of the shellRadius values exceeds the particle Radius.");
308          painCave.isFatal = 1;
309          simError();
310        }
311        if (shellRadii.at(i) <= 0.0 ) {
312 <        sprintf(painCave.errMsg, "One of the shellRadius values is smaller than zero!");
312 >        sprintf(painCave.errMsg,
313 >                "One of the shellRadius values is smaller than zero!");
314          painCave.isFatal = 1;
315          simError();
316        }
# Line 322 | Line 321 | int main(int argc, char *argv []) {
321    if ((int)args_info.molFraction_given){
322      sprintf(painCave.errMsg, "Creating a randomized spherical nanoparticle.");
323      painCave.isFatal = 0;
324 +    painCave.severity = OPENMD_INFO;
325      simError();
326      /* Random particle is the default case*/
327  
328 <    for (int i = 0; i < sites.size(); i++)
328 >    for (unsigned int i = 0; i < sites.size(); i++)
329        if (!isVacancy[i]) ids.push_back(i);
330      
331      std::random_shuffle(ids.begin(), ids.end());
# Line 333 | Line 333 | int main(int argc, char *argv []) {
333    } else{
334      sprintf(painCave.errMsg, "Creating a core-shell spherical nanoparticle.");
335      painCave.isFatal = 0;
336 +    painCave.severity = OPENMD_INFO;
337      simError();
338  
339      RealType smallestSoFar;
# Line 340 | Line 341 | int main(int argc, char *argv []) {
341      nMol.clear();
342      nMol.resize(nComponents);
343  
344 <    for (int i = 0; i < sites.size(); i++) {
344 >    for (unsigned int i = 0; i < sites.size(); i++) {
345        myLoc = sites[i];
346        myR = myLoc.length();
347        smallestSoFar = particleRadius;      
# Line 364 | Line 365 | int main(int argc, char *argv []) {
365    //creat new .md file on fly which corrects the number of molecule    
366    createMdFile(inputFileName, outputFileName, nMol);
367    
368 <  if (oldInfo != NULL)
368 <    delete oldInfo;
368 >  delete oldInfo;
369    
370    SimCreator newCreator;
371    SimInfo* NewInfo = newCreator.createSim(outputFileName, false);
# Line 376 | Line 376 | int main(int argc, char *argv []) {
376    mol = NewInfo->beginMolecule(mi);
377  
378    int l = 0;
379  int whichSite = 0;
379  
380    for (int i = 0; i < nComponents; i++){
381      locator = new MoLocator(NewInfo->getMoleculeStamp(i),
382                              NewInfo->getForceField());
383      
384      if (!args_info.molFraction_given) {
385 <      for (int n = 0; n < sites.size(); n++) {
385 >      for (unsigned int n = 0; n < sites.size(); n++) {
386          if (!isVacancy[n]) {
387            if (componentFromSite[n] == i) {
388              mol = NewInfo->getMoleculeByGlobalIndex(l);
# Line 437 | Line 436 | int main(int argc, char *argv []) {
436    sprintf(painCave.errMsg, "A new OpenMD file called \"%s\" has been "
437            "generated.\n", outputFileName.c_str());
438    painCave.isFatal = 0;
439 +  painCave.severity = OPENMD_INFO;
440    simError();
441    return 0;
442   }
# Line 454 | Line 454 | void createMdFile(const std::string&oldMdFileName,
454    newMdFile.open(newMdFileName.c_str());
455    oldMdFile.getline(buffer, MAXLEN);
456  
457 <  int i = 0;
457 >  unsigned int i = 0;
458    while (!oldMdFile.eof()) {
459  
460      //correct molecule number

Comparing trunk/src/applications/nanoparticleBuilder/nanoparticleBuilder.cpp (property svn:keywords):
Revision 1390 by gezelter, Wed Nov 25 20:02:06 2009 UTC vs.
Revision 2071 by gezelter, Sat Mar 7 21:41:51 2015 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines