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 1077 by gezelter, Wed Oct 18 19:35:07 2006 UTC vs.
Revision 2071 by gezelter, Sat Mar 7 21:41:51 2015 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 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                    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 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 170 | Line 165 | int main(int argc, char *argv []) {
165          
166                    
167          sprintf(painCave.errMsg, "Removing %d atoms from randomly-selected\n"
168 <                "\tsites between %lf and %lf.", vacancyTargets.size(),
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 434 | Line 433 | int main(int argc, char *argv []) {
433    delete writer;
434  
435    // cleanup a by calling sim error.....
436 <  sprintf(painCave.errMsg, "A new OOPSE MD file called \"%s\" has been "
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 1077 by gezelter, Wed Oct 18 19:35:07 2006 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