ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-3.0/src/applications/simpleBuilder/simpleBuilder.cpp
(Generate patch)

Comparing branches/new_design/OOPSE-3.0/src/applications/simpleBuilder/simpleBuilder.cpp (file contents):
Revision 1902 by tim, Wed Dec 15 22:34:41 2004 UTC vs.
Revision 1903 by tim, Thu Jan 6 00:16:07 2005 UTC

# Line 7 | Line 7
7   #include <map>
8   #include <fstream>
9  
10 #include "io/Globals.hpp"
11 #include "brains/SimInfo.hpp"
12 #include "brains/SimSetup.hpp"
10   #include "applications/simpleBuilder/simpleBuilderCmd.h"
14 #include "utils/StringUtils.hpp"
11   #include "applications/simpleBuilder/LatticeFactory.hpp"
16 #include "math/Vector3.hpp"
12   #include "applications/simpleBuilder/MoLocator.hpp"
13   #include "applications/simpleBuilder/Lattice.hpp"
14 + #include "brains/SimInfo.hpp"
15 + #include "brains/SimCreator.hpp"
16 + #include "io/DumpWriter.hpp"
17 + #include "math/Vector3.hpp"
18 + #include "math/SquareMatrix3.hpp"
19 + #include "utils/StringUtils.hpp"
20 + #include "UseTheForce/DUFF.hpp"
21 + #include "UseTheForce/EAM.hpp"
22 + #include "UseTheForce/ForceFieldCreator.hpp"
23  
24 + using namespace std;
25   using namespace oopse;
21
26   void createMdFile(const std::string&oldMdFileName, const std::string&newMdFileName,
27                    int numMol);
24 double getMolMass(MoleculeStamp * molStamp, ForceFields * myFF);
28  
29   int main(int argc, char *argv []) {
30 +
31 +    ForceFieldBuilder<DUFF> DUFFCreator("DUFF");
32 +    ForceFieldBuilder<DUFF> WATERCreator("WATER");
33 +    ForceFieldBuilder<DUFF> LJCreator("LJ");
34 +    //in theory, EAM can also be merged
35 +    ForceFieldBuilder<EAM> EAMCreator("EAM");
36 +    
37      gengetopt_args_info args_info;
38 <     std::string latticeType;
39 <     std::string inputFileName;
40 <     std::string outPrefix;
41 <     std::string outMdFileName;
42 <     std::string outInitFileName;
33 <    SimInfo *oldInfo;
34 <    SimSetup *oldSimSetup;
38 >    std::string latticeType;
39 >    std::string inputFileName;
40 >    std::string outPrefix;
41 >    std::string outMdFileName;
42 >    std::string outInitFileName;
43      BaseLattice *simpleLat;
44      int numMol;
45      double latticeConstant;
46 <    vector < double > lc;
46 >    std::vector<double> lc;
47      double mass;
48      const double rhoConvertConst = 1.661;
49      double density;
50      int nx,
51      ny,
52      nz;
53 <    double Hmat[3][3];
53 >    Mat3x3d hmat;
54      MoLocator *locator;
55 <    vector < Vector3d > latticePos;
56 <    vector < Vector3d > latticeOrt;
55 >    std::vector<Vector3d> latticePos;
56 >    std::vector<Vector3d> latticeOrt;
57      int numMolPerCell;
58      int curMolIndex;
59      DumpWriter *writer;
# Line 69 | Line 77 | int main(int argc, char *argv []) {
77      nx = args_info.nx_arg;
78  
79      if (nx <= 0) {
80 <        std::cerr << "The number of unit cell in h direction must be greater than 0"
73 <            << std::endl;
80 >        std::cerr << "The number of unit cell in h direction must be greater than 0" << std::endl;
81          exit(1);
82      }
83  
84      ny = args_info.ny_arg;
85  
86      if (ny <= 0) {
87 <        std::cerr << "The number of unit cell in l direction must be greater than 0"
81 <            << std::endl;
87 >        std::cerr << "The number of unit cell in l direction must be greater than 0" << std::endl;
88          exit(1);
89      }
90  
91      nz = args_info.nz_arg;
92  
93      if (nz <= 0) {
94 <        std::cerr << "The number of unit cell in k direction must be greater than 0"
89 <            << std::endl;
94 >        std::cerr << "The number of unit cell in k direction must be greater than 0" << std::endl;
95          exit(1);
96      }
97  
# Line 100 | Line 105 | int main(int argc, char *argv []) {
105      }
106  
107      //parse md file and set up the system
108 <    oldInfo = new SimInfo;
108 >    SimCreator oldCreator;
109 >    SimInfo* oldInfo = oldCreator.createSim(inputFileName, false);
110  
111 <    if (oldInfo == NULL) {
106 <        std::cerr << "error in creating SimInfo" << std::endl;
107 <        exit(1);
108 <    }
109 <
110 <    oldSimSetup = new SimSetup();
111 <
112 <    if (oldSimSetup == NULL) {
113 <        std::cerr << "error in creating SimSetup" << std::endl;
114 <        exit(1);
115 <    }
116 <
117 <    oldSimSetup->suspendInit();
118 <    oldSimSetup->setSimInfo(oldInfo);
119 <    oldSimSetup->parseFile(&inputFileName[0]);
120 <    oldSimSetup->createSim();
121 <
122 <    if (oldInfo->nComponents >= 2) {
111 >    if (oldInfo->getNMoleculeStamp()>= 2) {
112          std::cerr << "can not build the system with more than two components"
113              << std::endl;
114          exit(1);
115      }
116  
117      //get mass of molecule.
129    //Due to the design of OOPSE, given atom type, we have to query forcefiled to get the mass
130    mass = getMolMass(oldInfo->compStamps[0], oldSimSetup->getForceField());
118  
119 +    mass = getMolMass(oldInfo->getMoleculeStamp(0), oldInfo->getForceField());
120 +
121      //creat lattice
122      simpleLat = LatticeFactory::getInstance()->createLattice(latticeType);
123  
# Line 150 | Line 139 | int main(int argc, char *argv []) {
139      //calculate the total number of molecules
140      numMol = nx * ny * nz * numMolPerCell;
141  
142 <    if (oldInfo->n_mol != numMol) {
142 >    if (oldInfo->getNGlobalMolecules() != numMol) {
143          outPrefix = getPrefix(inputFileName.c_str()) + "_" + latticeType;
144          outMdFileName = outPrefix + ".md";
145  
# Line 169 | Line 158 | int main(int argc, char *argv []) {
158          outInitFileName = args_info.output_arg;
159      else
160          outInitFileName = getPrefix(inputFileName.c_str()) + ".in";
161 <
173 <    //allocat memory for storing pos, vel and etc
174 <    oldInfo->getConfiguration()->createArrays(oldInfo->n_atoms);
175 <
176 <    for(int i = 0; i < oldInfo->n_atoms; i++)
177 < oldInfo->atoms[i]->setCoords();
178 <
161 >    
162      //creat Molocator
163 <    locator = new MoLocator(oldInfo->compStamps[0],
181 <                            oldSimSetup->getForceField());
163 >    locator = new MoLocator(oldInfo->getMoleculeStamp(0), oldInfo->getForceField());
164  
165      //fill Hmat
166 <    Hmat[0][0] = nx * latticeConstant;
167 <    Hmat[0][1] = 0.0;
168 <    Hmat[0][2] = 0.0;
166 >    hmat(0, 0)= nx * latticeConstant;
167 >    hmat(0, 1) = 0.0;
168 >    hmat(0, 2) = 0.0;
169  
170 <    Hmat[1][0] = 0.0;
171 <    Hmat[1][1] = ny * latticeConstant;
172 <    Hmat[1][2] = 0.0;
170 >    hmat(1, 0) = 0.0;
171 >    hmat(1, 1) = ny * latticeConstant;
172 >    hmat(1, 2) = 0.0;
173  
174 <    Hmat[2][0] = 0.0;
175 <    Hmat[2][1] = 0.0;
176 <    Hmat[2][2] = nz * latticeConstant;
174 >    hmat(2, 0) = 0.0;
175 >    hmat(2, 1) = 0.0;
176 >    hmat(2, 2) = nz * latticeConstant;
177  
178      //set Hmat
179 <    oldInfo->setBoxM(Hmat);
179 >    oldInfo->getSnapshotManager()->getCurrentSnapshot()->setHmat(hmat);
180  
181      //place the molecules
182  
# Line 204 | Line 186 | oldInfo->atoms[i]->setCoords();
186      //for the same type of molecule in same lattice, it will not change
187      latticeOrt = simpleLat->getLatticePointsOrt();
188  
189 +    Molecule* mol;
190 +    SimInfo::MoleculeIterator mi;
191 +    mol = oldInfo->beginMolecule(mi);
192      for(int i = 0; i < nx; i++) {
193          for(int j = 0; j < ny; j++) {
194              for(int k = 0; k < nz; k++) {
# Line 211 | Line 196 | oldInfo->atoms[i]->setCoords();
196                  //get the position of the cell sites
197                  simpleLat->getLatticePointsPos(latticePos, i, j, k);
198  
199 <                for(int l = 0; l < numMolPerCell; l++)
200 <            locator->placeMol(latticePos[l], latticeOrt[l],
201 <                              &(oldInfo->molecules[curMolIndex++]));
199 >                for(int l = 0; l < numMolPerCell; l++) {
200 >                    if (mol != NULL) {
201 >                        locator->placeMol(latticePos[l], latticeOrt[l], mol);
202 >                    } else {
203 >                        std::cerr << std::endl;                    
204 >                    }
205 >                    mol = oldInfo->nextMolecule(mi);
206 >                }
207              }
208          }
209      }
210  
211      //create dumpwriter and write out the coordinates
212 <    oldInfo->finalName = outInitFileName;
213 <    writer = new DumpWriter(oldInfo);
212 >    oldInfo->setFinalConfigFileName(outInitFileName);
213 >    writer = new DumpWriter(oldInfo, oldInfo->getDumpFileName());
214  
215      if (writer == NULL) {
216          std::cerr << "error in creating DumpWriter" << std::endl;
217          exit(1);
218      }
219  
220 <    writer->writeFinal(0);
221 <    cout << "new initial configuration file: " << outInitFileName
220 >    writer->writeDump();
221 >    std::cout << "new initial configuration file: " << outInitFileName
222          << " is generated." << std::endl;
223  
224      //delete objects
# Line 237 | Line 227 | oldInfo->atoms[i]->setCoords();
227      if (oldInfo != NULL)
228          delete oldInfo;
229  
240    if (oldSimSetup != NULL)
241        delete oldSimSetup;
242
230      if (writer != NULL)
231          delete writer;
232  
# Line 275 | Line 262 | double getMolMass(MoleculeStamp *molStamp, ForceFields
262      newMdFile.close();
263   }
264  
278 double getMolMass(MoleculeStamp *molStamp, ForceFields *myFF) {
279    int nAtoms;
280    AtomStamp *currAtomStamp;
281    double totMass;
282
283    totMass = 0;
284    nAtoms = molStamp->getNAtoms();
285
286    for(size_t i = 0; i < nAtoms; i++) {
287        currAtomStamp = molStamp->getAtom(i);
288        totMass += myFF->getAtomTypeMass(currAtomStamp->getType());
289    }
290
291    return totMass;
292 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines