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

Comparing:
trunk/src/applications/simpleBuilder/simpleBuilder.cpp (file contents), Revision 507 by gezelter, Fri Apr 15 22:04:00 2005 UTC vs.
branches/development/src/applications/simpleBuilder/simpleBuilder.cpp (file contents), Revision 1665 by gezelter, Tue Nov 22 20:38:56 2011 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 61 | Line 62 | using namespace std;
62   #include "utils/StringUtils.hpp"
63  
64   using namespace std;
65 < using namespace oopse;
65 < void createMdFile(const std::string&oldMdFileName, const std::string&newMdFileName,
66 <                  int numMol);
65 > using namespace OpenMD;
66  
67 + void createMdFile(const std::string&oldMdFileName,
68 +                  const std::string&newMdFileName,
69 +                  int nMol);
70 +
71   int main(int argc, char *argv []) {
72  
73 <  //register force fields
73 >  // register force fields
74    registerForceFields();
75    registerLattice();
76      
77    gengetopt_args_info args_info;
78    std::string latticeType;
79    std::string inputFileName;
80 <  std::string outPrefix;
78 <  std::string outMdFileName;
79 <  std::string outInitFileName;
80 >  std::string outputFileName;
81    Lattice *simpleLat;
82 <  int numMol;
83 <  double latticeConstant;
84 <  std::vector<double> lc;
85 <  double mass;
86 <  const double rhoConvertConst = 1.661;
86 <  double density;
87 <  int nx,
88 <    ny,
89 <    nz;
82 >  RealType latticeConstant;
83 >  std::vector<RealType> lc;
84 >  const RealType rhoConvertConst = 1.661;
85 >  RealType density;
86 >  int nx, ny, nz;
87    Mat3x3d hmat;
88    MoLocator *locator;
89    std::vector<Vector3d> latticePos;
90    std::vector<Vector3d> latticeOrt;
91 <  int numMolPerCell;
95 <  int curMolIndex;
91 >  int nMolPerCell;
92    DumpWriter *writer;
93  
94    // parse command line arguments
# Line 102 | Line 98 | int main(int argc, char *argv []) {
98    density = args_info.density_arg;
99  
100    //get lattice type
101 <  latticeType = UpperCase(args_info.latticetype_arg);
101 >  latticeType = "FCC";
102  
103    simpleLat = LatticeFactory::getInstance()->createLattice(latticeType);
104      
# Line 112 | Line 108 | int main(int argc, char *argv []) {
108      painCave.isFatal = 1;
109      simError();
110    }
111 +  nMolPerCell = simpleLat->getNumSitesPerCell();
112  
113 <  //get the number of unit cell
113 >  //get the number of unit cells in each direction:
114 >
115    nx = args_info.nx_arg;
116  
117    if (nx <= 0) {
118 <    std::cerr << "The number of unit cell in h direction must be greater than 0" << std::endl;
119 <    exit(1);
118 >    sprintf(painCave.errMsg, "The number of unit cells in the x direction "
119 >            "must be greater than 0.");
120 >    painCave.isFatal = 1;
121 >    simError();
122    }
123  
124    ny = args_info.ny_arg;
125  
126    if (ny <= 0) {
127 <    std::cerr << "The number of unit cell in l direction must be greater than 0" << std::endl;
128 <    exit(1);
127 >    sprintf(painCave.errMsg, "The number of unit cells in the y direction "
128 >            "must be greater than 0.");
129 >    painCave.isFatal = 1;
130 >    simError();
131    }
132  
133    nz = args_info.nz_arg;
134  
135    if (nz <= 0) {
136 <    std::cerr << "The number of unit cell in k direction must be greater than 0" << std::endl;
137 <    exit(1);
136 >    sprintf(painCave.errMsg, "The number of unit cells in the z direction "
137 >            "must be greater than 0.");
138 >    painCave.isFatal = 1;
139 >    simError();
140    }
141  
142 +  int nSites = nMolPerCell * nx * ny * nz;
143 +
144    //get input file name
145    if (args_info.inputs_num)
146      inputFileName = args_info.inputs[0];
147    else {
148 <    std::cerr << "You must specify a input file name.\n" << std::endl;
149 <    cmdline_parser_print_help();
150 <    exit(1);
148 >    sprintf(painCave.errMsg, "No input .md file name was specified "
149 >            "on the command line");
150 >    painCave.isFatal = 1;
151 >    simError();
152    }
153  
154    //parse md file and set up the system
155 +
156    SimCreator oldCreator;
157    SimInfo* oldInfo = oldCreator.createSim(inputFileName, false);
158 +  Globals* simParams = oldInfo->getSimParams();
159  
160 <  if (oldInfo->getNMoleculeStamp()>= 2) {
152 <    std::cerr << "can not build the system with more than two components"
153 <              << std::endl;
154 <    exit(1);
155 <  }
160 >  // Calculate lattice constant (in Angstroms)
161  
162 <  //get mass of molecule.
162 >  RealType avgMass = getMolMass(oldInfo->getMoleculeStamp(0),
163 >                                  oldInfo->getForceField());
164  
165 <  mass = getMolMass(oldInfo->getMoleculeStamp(0), oldInfo->getForceField());
166 <
167 <  //creat lattice
168 <  simpleLat = LatticeFactory::getInstance()->createLattice(latticeType);
169 <
164 <  if (simpleLat == NULL) {
165 <    std::cerr << "Error in creating lattice" << std::endl;
166 <    exit(1);
167 <  }
168 <
169 <  numMolPerCell = simpleLat->getNumSitesPerCell();
170 <
171 <  //calculate lattice constant (in Angstrom)
172 <  latticeConstant = pow(rhoConvertConst * numMolPerCell * mass / density,
173 <                        1.0 / 3.0);
174 <
175 <  //set lattice constant
165 >  latticeConstant = pow(rhoConvertConst * nMolPerCell * avgMass / density,
166 >                        (RealType)(1.0 / 3.0));
167 >  
168 >  // Set the lattice constant
169 >  
170    lc.push_back(latticeConstant);
171    simpleLat->setLatticeConstant(lc);
172  
173 <  //calculate the total number of molecules
180 <  numMol = nx * ny * nz * numMolPerCell;
173 >  // Calculate the lattice sites and fill the lattice vector.
174  
175 <  if (oldInfo->getNGlobalMolecules() != numMol) {
183 <    outPrefix = getPrefix(inputFileName.c_str()) + "_" + latticeType;
184 <    outMdFileName = outPrefix + ".md";
175 >  // Get the standard orientations of the cell sites
176  
177 <    //creat new .md file on fly which corrects the number of molecule    
178 <    createMdFile(inputFileName, outMdFileName, numMol);
179 <    std::cerr
180 <      << "SimpleBuilder Error: the number of molecule and the density are not matched"
181 <      << std::endl;
182 <    std::cerr << "A new .md file: " << outMdFileName
183 <              << " is generated, use it to rerun the simpleBuilder" << std::endl;
184 <    exit(1);
177 >  latticeOrt = simpleLat->getLatticePointsOrt();
178 >
179 >  vector<Vector3d> sites;
180 >  vector<Vector3d> orientations;
181 >  
182 >  for(int i = 0; i < nx; i++) {
183 >    for(int j = 0; j < ny; j++) {
184 >      for(int k = 0; k < nz; k++) {
185 >
186 >        // Get the position of the cell sites
187 >        
188 >        simpleLat->getLatticePointsPos(latticePos, i, j, k);
189 >        
190 >        for(int l = 0; l < nMolPerCell; l++) {
191 >          sites.push_back(latticePos[l]);
192 >          orientations.push_back(latticeOrt[l]);
193 >        }
194 >      }
195 >    }
196    }
197 +  
198 +  outputFileName = args_info.output_arg;
199 +  
200 +  // create a new .md file on the fly which corrects the number of molecules
201  
202 <  //determine the output file names  
197 <  if (args_info.output_given)
198 <    outInitFileName = args_info.output_arg;
199 <  else
200 <    outInitFileName = getPrefix(inputFileName.c_str()) + ".in";
201 <    
202 <  //creat Molocator
203 <  locator = new MoLocator(oldInfo->getMoleculeStamp(0), oldInfo->getForceField());
202 >  createMdFile(inputFileName, outputFileName, nSites);
203  
204 <  //fill Hmat
205 <  hmat(0, 0)= nx * latticeConstant;
204 >  if (oldInfo != NULL)
205 >    delete oldInfo;
206 >
207 >  // We need to read in the new SimInfo object, then Parse the
208 >  // md file and set up the system
209 >
210 >  SimCreator newCreator;
211 >  SimInfo* newInfo = newCreator.createSim(outputFileName, false);
212 >
213 >  // fill Hmat
214 >
215 >  hmat(0, 0) = nx * latticeConstant;
216    hmat(0, 1) = 0.0;
217    hmat(0, 2) = 0.0;
218  
# Line 215 | Line 224 | int main(int argc, char *argv []) {
224    hmat(2, 1) = 0.0;
225    hmat(2, 2) = nz * latticeConstant;
226  
227 <  //set Hmat
219 <  oldInfo->getSnapshotManager()->getCurrentSnapshot()->setHmat(hmat);
227 >  // Set Hmat
228  
229 <  //place the molecules
229 >  newInfo->getSnapshotManager()->getCurrentSnapshot()->setHmat(hmat);
230  
231 <  curMolIndex = 0;
232 <
225 <  //get the orientation of the cell sites
226 <  //for the same type of molecule in same lattice, it will not change
227 <  latticeOrt = simpleLat->getLatticePointsOrt();
228 <
231 >  // place the molecules
232 >  
233    Molecule* mol;
234 <  SimInfo::MoleculeIterator mi;
235 <  mol = oldInfo->beginMolecule(mi);
236 <  for(int i = 0; i < nx; i++) {
237 <    for(int j = 0; j < ny; j++) {
238 <      for(int k = 0; k < nz; k++) {
235 <
236 <        //get the position of the cell sites
237 <        simpleLat->getLatticePointsPos(latticePos, i, j, k);
238 <
239 <        for(int l = 0; l < numMolPerCell; l++) {
240 <          if (mol != NULL) {
241 <            locator->placeMol(latticePos[l], latticeOrt[l], mol);
242 <          } else {
243 <            std::cerr << std::endl;                    
244 <          }
245 <          mol = oldInfo->nextMolecule(mi);
246 <        }
247 <      }
248 <    }
234 >  locator = new MoLocator(newInfo->getMoleculeStamp(0),
235 >                          newInfo->getForceField());
236 >  for (int n = 0; n < nSites; n++) {
237 >    mol = newInfo->getMoleculeByGlobalIndex(n);
238 >    locator->placeMol(sites[n], orientations[n], mol);
239    }
240 +  
241 +  // Create DumpWriter and write out the coordinates
242  
243 <  //create dumpwriter and write out the coordinates
244 <  oldInfo->setFinalConfigFileName(outInitFileName);
253 <  writer = new DumpWriter(oldInfo);
254 <
243 >  writer = new DumpWriter(newInfo, outputFileName);
244 >  
245    if (writer == NULL) {
246 <    std::cerr << "error in creating DumpWriter" << std::endl;
247 <    exit(1);
246 >    sprintf(painCave.errMsg, "error in creating DumpWriter");
247 >    painCave.isFatal = 1;
248 >    simError();
249    }
250  
251    writer->writeDump();
261  std::cout << "new initial configuration file: " << outInitFileName
262            << " is generated." << std::endl;
252  
253 <  //delete objects
253 >  // deleting the writer will put the closing at the end of the dump file.
254  
255 <  //delete oldInfo and oldSimSetup
267 <  if (oldInfo != NULL)
268 <    delete oldInfo;
255 >  delete writer;
256  
257 <  if (writer != NULL)
258 <    delete writer;
259 <    
260 <  delete simpleLat;
274 <
257 >  sprintf(painCave.errMsg, "A new OpenMD file called \"%s\" has been "
258 >          "generated.\n", outputFileName.c_str());
259 >  painCave.isFatal = 0;
260 >  simError();
261    return 0;
262   }
263  
264 < void createMdFile(const std::string&oldMdFileName, const std::string&newMdFileName,
265 <                  int numMol) {
264 > void createMdFile(const std::string&oldMdFileName,
265 >                  const std::string&newMdFileName,
266 >                  int nMol) {
267    ifstream oldMdFile;
268    ofstream newMdFile;
269    const int MAXLEN = 65535;
# Line 292 | Line 279 | void createMdFile(const std::string&oldMdFileName, con
279  
280      //correct molecule number
281      if (strstr(buffer, "nMol") != NULL) {
282 <      sprintf(buffer, "\t\tnMol = %d;", numMol);
282 >      sprintf(buffer, "\t\tnMol = %d;", nMol);
283        newMdFile << buffer << std::endl;
284      } else
285        newMdFile << buffer << std::endl;

Comparing:
trunk/src/applications/simpleBuilder/simpleBuilder.cpp (property svn:keywords), Revision 507 by gezelter, Fri Apr 15 22:04:00 2005 UTC vs.
branches/development/src/applications/simpleBuilder/simpleBuilder.cpp (property svn:keywords), Revision 1665 by gezelter, Tue Nov 22 20:38:56 2011 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines