ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-1.0/utils/sysbuilder/simpleBuilder.cpp
(Generate patch)

Comparing trunk/OOPSE-1.0/utils/sysbuilder/simpleBuilder.cpp (file contents):
Revision 1427 by tim, Wed Jul 28 18:42:59 2004 UTC vs.
Revision 1432 by tim, Thu Jul 29 03:31:50 2004 UTC

# Line 7 | Line 7
7   #include <map>
8   #include <fstream>
9  
10 #include "simError.h"
10   #include "Globals.hpp"
11   #include "SimInfo.hpp"
12   #include "SimSetup.hpp"
13 < #include "simpleBuilderCmd.hpp"
13 > #include "simpleBuilderCmd.h"
14   #include "StringUtils.hpp"
15   #include "LatticeFactory.hpp"
16   #include "Vector3d.hpp"
17 + #include "MoLocator.hpp"
18 + #include "Lattice.hpp"
19  
20   using namespace std;
21  
22 + void createMdFile(const string& oldMdFileName, const string& newMdFileName, int numMol);
23 + double getMolMass(MoleculeStamp* molStamp, ForceFields* myFF);
24  
25   int main( int argc, char* argv[]){
26  
# Line 34 | Line 37 | int main( int argc, char* argv[]){
37    BaseLattice* simpleLat;
38    int numMol;
39    double latticeConstant;
40 <  vector lc;
40 >  vector<double> lc;
41    double mass;
42 +  const double rhoConvertConst = 1.661;
43    double density;
44    int nx, ny, nz;
45    double Hmat[3][3];
# Line 45 | Line 49 | int main( int argc, char* argv[]){
49    int numMolPerCell;
50    int curMolIndex;
51    DumpWriter* writer;
52 <
52 >  
53    // parse command line arguments
50
54    if (cmdline_parser (argc, argv, &args_info) != 0)
55      exit(1) ;
56  
57 +  //process density
58    if(!args_info.density_given && !args_info.ndensity_given){
59 <    cerr << "density or number density must be given" << endl;
60 <    return false;
59 >    cerr << "SimpleBuilder Error: density or number density must be given" << endl;
60 >    cmdline_parser_print_help();
61 >    exit(1);
62    }
63 +  else if(args_info.density_given){
64 +    if( args_info.ndensity_given)
65 +      cerr << "SimpleBuilder Warning: both of density and number density are given, use density" << endl;
66 +    
67 +    density = args_info.density_arg;
68 +  }
69 +  else if(args_info.ndensity_given){
70 +    //convert number density to density
71 +  }
72  
73 +
74 +  //get lattice type
75    latticeType = UpperCase(args_info.latticetype_arg);
76    if(!LatticeFactory::getInstance()->hasLatticeCreator(latticeType)){
77      cerr << latticeType << " is an invalid lattice type" << endl;
78 <    cerr << LatticeFactory::getInstance()->oString << endl;
78 >    cerr << LatticeFactory::getInstance()->toString() << endl;
79      exit(1);
80    }
81 <        
82 <  nx = args_info.nx_args;
81 >
82 >  //get the number of unit cell
83 >  nx = args_info.nx_arg;
84    if(nx <= 0){
85      cerr << "The number of unit cell in h direction must be greater than 0" << endl;
86      exit(1);
87    }
88  
89 <  nx = args_info.nx_args;
90 <  if(nx <= 0){
89 >  ny = args_info.ny_arg;
90 >  if(ny <= 0){
91      cerr << "The number of unit cell in l direction must be greater than 0" << endl;
92      exit(1);
93    }
94  
95 <  nx = args_info.nx_args;
96 <  if(nx <= 0){
95 >  nz = args_info.nz_arg;
96 >  if(nz <= 0){
97      cerr << "The number of unit cell in k direction must be greater than 0" << endl;
98      exit(1);
99    }
100          
101    //get input file name
102 <  if (args_info.inputs_num) {
102 >  if (args_info.inputs_num)
103      inputFileName = args_info.inputs[0];
87    cerr << in_name << "\n";      }
104    else {                
105      cerr <<"You must specify a input file name.\n" << endl;
106      cmdline_parser_print_help();
# Line 109 | Line 125 | int main( int argc, char* argv[]){
125       exit(1);
126    }
127  
128 <  oldSimSetup = new SimSetup(oldInfo);  
128 >  oldSimSetup = new SimSetup();  
129    if(oldSimSetup == NULL){
130       cerr << "error in creating SimSetup" << endl;
131       exit(1);
# Line 117 | Line 133 | int main( int argc, char* argv[]){
133      
134    oldSimSetup->setSimInfo(oldInfo );
135    oldSimSetup->parseFile(&inputFileName[0] );
136 <  oldSimSetup->createSim();
137 <
122 <
123 <  if(oldInfo->nComponets >=2){
136 >  oldSimSetup->createSim();
137 >  if(oldInfo->nComponents >=2){
138        cerr << "can not build the system with more than two components" << endl;
139        exit(1);
140    }
141  
142 +  
143 +  //get mass of molecule.
144 +  //Due to the design of OOPSE, given atom type, we have to query forcefiled to get the mass
145 +  mass = getMolMass(oldInfo->compStamps[0], oldSimSetup->getForceField());
146 +  
147    //creat lattice
148          simpleLat = LatticeFactory::getInstance()->createLattice(latticeType);
149          if(simpleLat == NULL){
# Line 132 | Line 151 | int main( int argc, char* argv[]){
151                  exit(1);
152          }
153  
154 <
136 <  numMolPerCell = simpleLat->getNpoints();
137 <  //calculate lattice constant
138 <  latticeConstant = pow(numMolPerCell * mass /density, 1.0/3.0);
154 >  numMolPerCell = simpleLat->getNumSitesPerCell();
155    
156 +  //calculate lattice constant (in Angstrom)
157 +  latticeConstant = pow(rhoConvertConst * numMolPerCell * mass /density, 1.0/3.0);
158 +  
159    //set lattice constant
160    lc.push_back(latticeConstant);
161    simpleLat->setLatticeConstant(lc);
162    
163 <  //calculate the total
163 >  //calculate the total number of molecules
164    numMol = args_info.nx_arg * args_info.ny_arg * args_info.nz_arg * numMolPerCell;
146
147  //fill Hmat
148  Hmat[0][0] = nx * latticeConstant;
149  Hmat[0][1] = 0.0;
150  Hmat[0][2] = 0.0;
151
152  Hmat[1][0] = ny * latticeConstant;
153  Hmat[1][1] = 0.0;
154  Hmat[1][2] = 0.0;
155
156  Hmat[2][0] = nz * latticeConstant;
157  Hmat[2][1] = 0.0;
158  Hmat[2][2] = 0.0;
165    
166    //creat new .md file on fly
167    createMdFile(inputFileName, outMdFileName, numMol);
# Line 166 | Line 172 | int main( int argc, char* argv[]){
172       cerr << "error in creating SimInfo" << endl;
173       exit(1);
174    }
175 <
176 <  newSimSetup = new SimSetup(newInfo);  
175 >  
176 >  newSimSetup = new SimSetup();  
177    if(newSimSetup == NULL){
178       cerr << "error in creating SimSetup" << endl;
179       exit(1);
# Line 177 | Line 183 | int main( int argc, char* argv[]){
183    newSimSetup->parseFile(&outMdFileName[0] );
184    newSimSetup->createSim();
185  
180  //set Hmat
181  newInfo->setBoxM(Hmat);
182
186    //allocat memory for storing pos, vel and etc
187 <  newInfo.getConfiguration()->createArrays(newInfo.n_atoms);
188 <  for (int i = 0; i < newInfo.n_atoms; i++)
189 <    newInfo.atoms[i]->setCoords();  
187 >  newInfo->getConfiguration()->createArrays(newInfo->n_atoms);
188 >  for (int i = 0; i < newInfo->n_atoms; i++)
189 >    newInfo->atoms[i]->setCoords();  
190  
191    //creat Molocator
192 <  locator = new MoLocator(newInfo->compStamps[0], newSimSetup->the_ff);
192 >  locator = new MoLocator(newInfo->compStamps[0], newSimSetup->getForceField());
193  
194 +  //fill Hmat
195 +  Hmat[0][0] = nx * latticeConstant;
196 +  Hmat[0][1] = 0.0;
197 +  Hmat[0][2] = 0.0;
198 +
199 +  Hmat[1][0] = ny * latticeConstant;
200 +  Hmat[1][1] = 0.0;
201 +  Hmat[1][2] = 0.0;
202 +
203 +  Hmat[2][0] = nz * latticeConstant;
204 +  Hmat[2][1] = 0.0;
205 +  Hmat[2][2] = 0.0;
206 +
207 +  //set Hmat
208 +  newInfo->setBoxM(Hmat);
209 +  
210    //place the molecules
211  
212    curMolIndex = 0;
# Line 204 | Line 223 | int main( int argc, char* argv[]){
223            simpleLat->getLatticePointsPos(latticePos, i, j, k);
224  
225            for(int l = 0; l < numMolPerCell; l++)
226 <            locator->placeMol(latticePos[l], latticeOrt[l], newInfo->molecules[curMolIndex++]);
226 >            locator->placeMol(latticePos[l], latticeOrt[l], &(newInfo->molecules[curMolIndex++]));
227         }
228      }
229    }
# Line 215 | Line 234 | int main( int argc, char* argv[]){
234      cerr << "error in creating DumpWriter" << endl;
235      exit(1);    
236    }
237 <  writer->writeFinal();
219 <
237 >  writer->writeFinal(0);
238    
239    //delete objects
240    if(!oldInfo)
# Line 241 | Line 259 | void createMdFile(const string& oldMdFileName, const s
259    ofstream newMdFile;
260    const int MAXLEN = 65535;
261    char buffer[MAXLEN];
262 +  string line;
263  
245
264    //create new .md file based on old .md file
265 <  oldMdFile.open(oldMdFileName.c_str())
266 <  newMdFile.open(newMdFileName);
265 >  oldMdFile.open(oldMdFileName.c_str());
266 >  newMdFile.open(newMdFileName.c_str());
267  
268    oldMdFile.getline(buffer, MAXLEN);
269    while(!oldMdFile.eof()){
270  
271 <    if(line.find("nMol") < line.size())
272 <      sprintf(buffer, "nMol = %s;", numMol);
271 >    if(line.find("nMol") < line.size()){
272 >      
273 >      sprintf(buffer, "\t\tnMol = %d;", numMol);
274 >      newMdFile << buffer << endl;
275 >    }
276      else
277        newMdFile << buffer << endl;
278  
# Line 262 | Line 283 | void createMdFile(const string& oldMdFileName, const s
283    newMdFile.close();
284  
285   }
286 +
287 + double getMolMass(MoleculeStamp* molStamp, ForceFields* myFF){
288 +  int nAtoms;
289 +  AtomStamp* currAtomStamp;
290 +  double totMass;
291 +  
292 +  totMass = 0;
293 +  nAtoms = molStamp->getNAtoms();
294 +
295 +  for(size_t i=0; i<nAtoms; i++){
296 +    currAtomStamp = molStamp->getAtom(i);
297 +    totMass += myFF->getAtomTypeMass(currAtomStamp->getType());
298 +  }
299 +
300 +  return totMass;
301 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines