--- trunk/src/applications/nanoparticleBuilder/nanoparticleBuilder.cpp 2009/11/25 20:02:06 1390 +++ trunk/src/applications/nanoparticleBuilder/nanoparticleBuilder.cpp 2015/03/07 21:41:51 2071 @@ -35,8 +35,9 @@ * * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). * [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). - * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008). - * [4] Vardeman & Gezelter, in progress (2009). + * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008). + * [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). + * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). */ #include @@ -71,26 +72,17 @@ int main(int argc, char *argv []) { int main(int argc, char *argv []) { - //register force fields - registerForceFields(); registerLattice(); gengetopt_args_info args_info; std::string latticeType; std::string inputFileName; std::string outputFileName; - MoLocator* locator; int nComponents; double latticeConstant; - std::vector lc; - RealType particleRadius; - Mat3x3d hmat; - std::vector latticePos; - std::vector latticeOrt; - DumpWriter *writer; // Parse Command Line Arguments @@ -126,18 +118,21 @@ int main(int argc, char *argv []) { /* Build a lattice and get lattice points for this lattice constant */ vector sites = nanoParticle.getSites(); vector orientations = nanoParticle.getOrientations(); - std::vector vacancyTargets; + + + std::vector vacancyTargets; vector isVacancy; Vector3d myLoc; RealType myR; - for (int i = 0; i < sites.size(); i++) + for (unsigned int i = 0; i < sites.size(); i++) isVacancy.push_back(false); if (args_info.vacancyPercent_given) { if (args_info.vacancyPercent_arg < 0.0 || args_info.vacancyPercent_arg > 100.0) { - sprintf(painCave.errMsg, "vacancyPercent was set to a non-sensical value."); + sprintf(painCave.errMsg, + "vacancyPercent was set to a non-sensical value."); painCave.isFatal = 1; simError(); } else { @@ -156,7 +151,7 @@ int main(int argc, char *argv []) { } if (vIR >= 0.0 && vOR <= particleRadius && vOR >= vIR) { - for (int i = 0; i < sites.size(); i++) { + for (std::size_t i = 0; i < sites.size(); i++) { myLoc = sites[i]; myR = myLoc.length(); if (myR >= vIR && myR <= vOR) { @@ -173,12 +168,13 @@ int main(int argc, char *argv []) { "\tsites between %lf and %lf.", (int) vacancyTargets.size(), vIR, vOR); painCave.isFatal = 0; + painCave.severity = OPENMD_INFO; simError(); isVacancy.clear(); - for (int i = 0; i < sites.size(); i++) { + for (std::size_t i = 0; i < sites.size(); i++) { bool vac = false; - for (int j = 0; j < vacancyTargets.size(); j++) { + for (std::size_t j = 0; j < vacancyTargets.size(); j++) { if (i == vacancyTargets[j]) vac = true; } isVacancy.push_back(vac); @@ -194,12 +190,11 @@ int main(int argc, char *argv []) { } /* Get number of lattice sites */ - int nSites = sites.size() - vacancyTargets.size(); + std::size_t nSites = sites.size() - vacancyTargets.size(); std::vector components = simParams->getComponents(); std::vector molFractions; std::vector shellRadii; - std::vector molecularMasses; std::vector nMol; std::map componentFromSite; nComponents = components.size(); @@ -276,7 +271,8 @@ int main(int argc, char *argv []) { totalFraction += molFractions.at(i); } if (abs(totalFraction - 1.0) > 1e-6) { - sprintf(painCave.errMsg, "The sum of molFractions was not close enough to 1.0"); + sprintf(painCave.errMsg, + "The sum of molFractions was not close enough to 1.0"); painCave.isFatal = 1; simError(); } @@ -290,28 +286,31 @@ int main(int argc, char *argv []) { // recompute actual mol fractions and perform final sanity check: - int totalMolecules = 0; + std::size_t totalMolecules = 0; for (int i=0; i < nComponents; i++) { molFractions[i] = (RealType)(nMol.at(i))/(RealType)nSites; totalMolecules += nMol.at(i); } if (totalMolecules != nSites) { - sprintf(painCave.errMsg, "Computed total number of molecules is not equal " + sprintf(painCave.errMsg, + "Computed total number of molecules is not equal " "to the number of lattice sites!"); painCave.isFatal = 1; simError(); } } else { - for (int i = 0; i < shellRadii.size(); i++) { + for (unsigned int i = 0; i < shellRadii.size(); i++) { if (shellRadii.at(i) > particleRadius + 1e-6 ) { - sprintf(painCave.errMsg, "One of the shellRadius values exceeds the particle Radius."); + sprintf(painCave.errMsg, + "One of the shellRadius values exceeds the particle Radius."); painCave.isFatal = 1; simError(); } if (shellRadii.at(i) <= 0.0 ) { - sprintf(painCave.errMsg, "One of the shellRadius values is smaller than zero!"); + sprintf(painCave.errMsg, + "One of the shellRadius values is smaller than zero!"); painCave.isFatal = 1; simError(); } @@ -322,10 +321,11 @@ int main(int argc, char *argv []) { if ((int)args_info.molFraction_given){ sprintf(painCave.errMsg, "Creating a randomized spherical nanoparticle."); painCave.isFatal = 0; + painCave.severity = OPENMD_INFO; simError(); /* Random particle is the default case*/ - for (int i = 0; i < sites.size(); i++) + for (unsigned int i = 0; i < sites.size(); i++) if (!isVacancy[i]) ids.push_back(i); std::random_shuffle(ids.begin(), ids.end()); @@ -333,6 +333,7 @@ int main(int argc, char *argv []) { } else{ sprintf(painCave.errMsg, "Creating a core-shell spherical nanoparticle."); painCave.isFatal = 0; + painCave.severity = OPENMD_INFO; simError(); RealType smallestSoFar; @@ -340,7 +341,7 @@ int main(int argc, char *argv []) { nMol.clear(); nMol.resize(nComponents); - for (int i = 0; i < sites.size(); i++) { + for (unsigned int i = 0; i < sites.size(); i++) { myLoc = sites[i]; myR = myLoc.length(); smallestSoFar = particleRadius; @@ -364,8 +365,7 @@ int main(int argc, char *argv []) { //creat new .md file on fly which corrects the number of molecule createMdFile(inputFileName, outputFileName, nMol); - if (oldInfo != NULL) - delete oldInfo; + delete oldInfo; SimCreator newCreator; SimInfo* NewInfo = newCreator.createSim(outputFileName, false); @@ -376,14 +376,13 @@ int main(int argc, char *argv []) { mol = NewInfo->beginMolecule(mi); int l = 0; - int whichSite = 0; for (int i = 0; i < nComponents; i++){ locator = new MoLocator(NewInfo->getMoleculeStamp(i), NewInfo->getForceField()); if (!args_info.molFraction_given) { - for (int n = 0; n < sites.size(); n++) { + for (unsigned int n = 0; n < sites.size(); n++) { if (!isVacancy[n]) { if (componentFromSite[n] == i) { mol = NewInfo->getMoleculeByGlobalIndex(l); @@ -437,6 +436,7 @@ int main(int argc, char *argv []) { sprintf(painCave.errMsg, "A new OpenMD file called \"%s\" has been " "generated.\n", outputFileName.c_str()); painCave.isFatal = 0; + painCave.severity = OPENMD_INFO; simError(); return 0; } @@ -454,7 +454,7 @@ void createMdFile(const std::string&oldMdFileName, newMdFile.open(newMdFileName.c_str()); oldMdFile.getline(buffer, MAXLEN); - int i = 0; + unsigned int i = 0; while (!oldMdFile.eof()) { //correct molecule number