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

Comparing branches/new_design/OOPSE-2.0/src/brains/SimCreator.cpp (file contents):
Revision 1806 by tim, Wed Nov 24 17:42:37 2004 UTC vs.
Revision 1807 by tim, Tue Nov 30 22:43:51 2004 UTC

# Line 31 | Line 31
31   * @version 1.0
32   */
33  
34 + #include <sprng.h>
35 +
36 + #include "brains/MoleculeCreator.hpp"
37   #include "brains/SimCreator.hpp"
38 + #include "brains/SimSnapshotManager.hpp"
39 + #include "io/DumpReader.hpp"
40 + #include "io/parse_me.h"
41 + #include "UseTheForce/ForceFieldFactory.hpp"
42 + #include "utils/simError.h"
43 + #include "utils/StringUtils.hpp"
44 + #ifdef IS_MPI
45 + #include "io/mpiBASS.h"
46 + #endif
47  
48   namespace oopse {
49  
50 < void SimCreator::parseFile(const std::string& mdFileName, MakeStamps *stamps, Globals *globals) {
50 > void SimCreator::parseFile(const std::string mdFileName,  MakeStamps* stamps, Globals* globals){
51  
52   #ifdef IS_MPI
53  
# Line 68 | Line 80 | SimInfo*  SimCreator::createSim(const std::string & md
80   }
81  
82   SimInfo*  SimCreator::createSim(const std::string & mdFileName) {
71
72    mdFileName_ = mdFileName;
83      
84      MakeStamps * stamps = new MakeStamps();
85  
86      Globals * globals = new Globals();
87  
88      //parse meta-data file
89 <    parseFile(mdFileName_, stamps, globals);
89 >    parseFile(mdFileName, stamps, globals);
90  
91      //create the force field
92 <    ForceFiled * ff = ForceFieldFactory::getInstance()->createObject(
92 >    ForceField * ff = ForceFieldFactory::getInstance()->createForceField(
93                            globals->getForceField());
94      
95      if (ff == NULL) {
96 <        sprintf(painCave.errMsg, "ForceFiled Factory can not create %s force field\n",
96 >        sprintf(painCave.errMsg, "ForceField Factory can not create %s force field\n",
97                  globals->getForceField());
98          painCave.isFatal = 1;
99          simError();
100      }
91    ff->parse();
101  
102 +    std::string forcefieldFileName;
103 +    forcefieldFileName = ff->getForceFieldFileName();
104 +
105 +    if (globals->haveForceFieldVariant()) {
106 +        //If the force field has variant, the variant force field name will be
107 +        //Base.variant.frc. For exampel EAM.u6.frc
108 +        
109 +        std::string variant = globals->getForceFieldVariant();
110 +
111 +        std::string::size_type pos = forcefieldFileName.rfind(".frc");
112 +        variant = "." + variant;
113 +        if (pos != std::string::npos) {
114 +            forcefieldFileName.insert(pos, variant);
115 +        } else {
116 +            //If the default force field file name does not containt .frc suffix, just append the .variant
117 +            forcefieldFileName.append(variant);
118 +        }
119 +    }
120 +    
121 +    ff->parse(forcefieldFileName);
122 +    
123      //extract the molecule stamps
124      std::vector < std::pair<MoleculeStamp *, int> > moleculeStampPairs;
125      compList(stamps, globals, moleculeStampPairs);
# Line 98 | Line 128 | SimInfo*  SimCreator::createSim(const std::string & md
128      SimInfo * info = new SimInfo(moleculeStampPairs, ff, globals);
129  
130      //gather parameters (SimCreator only retrieves part of the parameters)
131 <    gatherParameters(info);
131 >    gatherParameters(info, mdFileName);
132  
133      //divide the molecules and determine the global index of molecules
134 + #ifdef IS_MPI
135      divideMolecules(info);
136 + #endif
137  
138      //create the molecules
139      createMolecules(info);
140  
109    //set the global index of atoms, rigidbodies and cutoffgroups (only need to be set once, the
110    //global index will never change again). Local indices of atoms and rigidbodies are already set by
111    //MoleculeCreator class which actually delegates the responsibility to LocalIndexManager.
112    setGlobalIndices(info);
141  
142      //allocate memory for DataStorage(circular reference, need to break it)
143      info->setSnapshotManager(new SimSnapshotManager(info));
144 +    
145 +    //set the global index of atoms, rigidbodies and cutoffgroups (only need to be set once, the
146 +    //global index will never change again). Local indices of atoms and rigidbodies are already set by
147 +    //MoleculeCreator class which actually delegates the responsibility to LocalIndexManager.
148 +    setGlobalIndex(info);
149  
150 <    //initialize fortran -- setup the cutoff
118 <    initFortran(info);
150 >    
151  
152      //load initial coordinates, some extra information are pushed into SimInfo's property map ( such as
153      //eta, chi for NPT integrator)
# Line 123 | Line 155 | void SimCreator::gatherParameters(SimInfo *info) {
155      return info;
156   }
157  
158 < void SimCreator::gatherParameters(SimInfo *info) {
158 > void SimCreator::gatherParameters(SimInfo *info, const std::string& mdfile) {
159  
160      //setup seed for random number generator
161      int seedValue;
# Line 187 | Line 219 | void SimCreator::gatherParameters(SimInfo *info) {
219   #endif // is_mpi
220  
221          if (globals->haveFinalConfig()) {
222 <            prefix = StringUtils::getPrefix(globals->getFinalConfig());
222 >            prefix = getPrefix(globals->getFinalConfig());
223          } else {
224 <            prefix = StringUtils::getPrefix(mdfile_);
224 >            prefix = getPrefix(mdfile);
225          }
226  
227          info->setFinalConfigFileName(prefix + ".eor");
# Line 205 | Line 237 | void SimCreator::gatherParameters(SimInfo *info) {
237   }
238  
239   #ifdef IS_MPI
208
240   void SimCreator::divideMolecules(SimInfo *info) {
241      double numerator;
242      double denominator;
# Line 364 | Line 395 | void SimCreator::createMolecules(SimInfo *info) {
395   #endif
396  
397              stampId = info->getMoleculeStampId(i);
398 <            Molecule * mol = molCreator.createMolecule(info->getForceField(),
399 <                                                info->getMoleculeStamp(stampId), stampId, i);
398 >            Molecule * mol = molCreator.createMolecule(info->getForceField(), info->getMoleculeStamp(stampId),
399 >                                                                                    stampId, i, info->getLocalIndexManager());
400  
401              info->addMolecule(mol);
402  
# Line 383 | Line 414 | void SimCreator::compList(MakeStamps *stamps, Globals*
414      int i;
415      char * id;
416      MoleculeStamp * currentStamp;
417 <    Component * the_components = globals->getComponents();
417 >    Component** the_components = globals->getComponents();
418      int n_components = globals->getNComponents();
419  
420      if (!globals->haveNMol()) {
# Line 394 | Line 425 | void SimCreator::compList(MakeStamps *stamps, Globals*
425              if (!the_components[i]->haveNMol()) {
426                  // we have a problem
427                  sprintf(painCave.errMsg,
428 <                        "SimSetup Error. No global NMol or component NMol given.\n"
428 >                        "SimCreator Error. No global NMol or component NMol given.\n"
429                              "\tCannot calculate the number of atoms.\n");
430  
431                  painCave.isFatal = 1;
# Line 402 | Line 433 | void SimCreator::compList(MakeStamps *stamps, Globals*
433              }
434  
435              id = the_components[i]->getType();
436 <            currentStamp = stamps->extractMolStamp(id);
436 >            currentStamp = (stamps->extractMolStamp(id))->getStamp();
437  
438              if (currentStamp == NULL) {
439                  sprintf(painCave.errMsg,
440 <                        "SimSetup error: Component \"%s\" was not found in the "
440 >                        "SimCreator error: Component \"%s\" was not found in the "
441                              "list of declared molecules\n", id);
442  
443                  painCave.isFatal = 1;
# Line 414 | Line 445 | void SimCreator::compList(MakeStamps *stamps, Globals*
445              }
446  
447              moleculeStampPairs.push_back(
448 <                make_pair(currentStamp, the_components[i]->getNMol));
448 >                make_pair(currentStamp, the_components[i]->getNMol()));
449          } //end for (i = 0; i < n_components; i++)
450      } else {
451          sprintf(painCave.errMsg, "SimSetup error.\n"
# Line 437 | Line 468 | void SimCreator::setGlobalIndex(SimInfo *info) {
468   }
469  
470   void SimCreator::setGlobalIndex(SimInfo *info) {
471 <    typename SimInfo::MoleculeIterator mi;
472 <    typename Molecule::AtomIterator ai;
473 <    typename Molecule::RigidBodyIterator ri;
474 <    typename Molecule::CutoffGroupIterator ci;
471 >    SimInfo::MoleculeIterator mi;
472 >    Molecule::AtomIterator ai;
473 >    Molecule::RigidBodyIterator ri;
474 >    Molecule::CutoffGroupIterator ci;
475      Molecule * mol;
476      Atom * atom;
477      RigidBody * rb;
# Line 516 | Line 547 | void SimCreator::setGlobalIndex(SimInfo *info) {
547  
548      //fill globalGroupMembership
549      std::vector<int> globalGroupMembership(info->getNGlobalAtoms(), 0);
550 <    for(mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) {        
550 >    for(mol = info->beginMolecule(mi); mol != NULL; mol = info->nextMolecule(mi)) {        
551          for (cg = mol->beginCutoffGroup(ci); cg != NULL; cg = mol->nextCutoffGroup(ci)) {
552  
553              for(atom = cg->beginAtom(ai); atom != NULL; atom = cg->nextAtom(ai)) {
# Line 561 | Line 592 | void SimCreator::setGlobalIndex(SimInfo *info) {
592          info->getGlobalMolMembershipPointer());
593   #endif
594  
595 +    }
596   }
597  
598   void SimCreator::loadCoordinates(SimInfo* info) {
# Line 574 | Line 606 | void SimCreator::loadCoordinates(SimInfo* info) {
606          simError();
607      }
608          
609 <    DumpReader reader(globals->getInitialConfig());
610 <    int nframes = reader->getNframes();
609 >    DumpReader reader(info, globals->getInitialConfig());
610 >    int nframes = reader.getNFrames();
611  
612      if (nframes > 0) {
613 <        reader.readFrame(info, nframes - 1);
613 >        reader.readFrame(nframes - 1);
614      } else {
615          //invalid initial coordinate file
616          sprintf(painCave.errMsg, "Initial configuration file %s should at least contain one frame\n",

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines