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

Comparing trunk/OOPSE-2.0/src/brains/SimCreator.cpp (file contents):
Revision 2187 by tim, Wed Apr 13 18:41:17 2005 UTC vs.
Revision 2469 by tim, Fri Dec 2 15:38:03 2005 UTC

# Line 47 | Line 47
47   * @version 1.0
48   */
49  
50 + #include <iostream>
51 + #include <sstream>
52 + #include <string>
53 +
54   #include "brains/MoleculeCreator.hpp"
55   #include "brains/SimCreator.hpp"
56   #include "brains/SimSnapshotManager.hpp"
57   #include "io/DumpReader.hpp"
54 #include "io/parse_me.h"
58   #include "UseTheForce/ForceFieldFactory.hpp"
59   #include "utils/simError.h"
60   #include "utils/StringUtils.hpp"
61   #include "math/SeqRandNumGen.hpp"
62 + #include "mdParser/MDLexer.hpp"
63 + #include "mdParser/MDParser.hpp"
64 + #include "mdParser/MDTreeParser.hpp"
65 + #include "mdParser/SimplePreprocessor.hpp"
66 +
67 +
68   #ifdef IS_MPI
60 #include "io/mpiBASS.h"
69   #include "math/ParallelRandNumGen.hpp"
70   #endif
71  
72   namespace oopse {
73    
74 <  void SimCreator::parseFile(const std::string mdFileName,  MakeStamps* stamps,
75 <                             Globals* simParams){
74 > Globals* SimCreator::parseFile(const std::string mdFileName){
75 >        Globals* simParams = NULL;
76 >        try {
77 >
78 >            // Create a preprocessor that preprocesses md file into an ostringstream
79 >            std::stringstream ppStream;
80 > #ifdef IS_MPI            
81 >            int streamSize;
82 >            const int masterNode = 0;
83 >            int commStatus;
84 >            if (worldRank == masterNode) {
85 > #endif
86 >                
87 >                SimplePreprocessor preprocessor;
88 >                preprocessor.preprocess(mdFileName, ppStream);
89 >                
90 > #ifdef IS_MPI            
91 >                //brocasting the stream size
92 >                streamSize = ppStream.str().size() +1;
93 >                commStatus = MPI_Bcast(&streamSize, 1, MPI_LONG, masterNode, MPI_COMM_WORLD);                  
94 >
95 >                commStatus = MPI_Bcast(ppStream.str().c_str(), streamSize, MPI_CHAR, masterNode, MPI_COMM_WORLD);
96 >            
97 >                
98 >            } else {
99 >                //get stream size
100 >                commStatus = MPI_Bcast(&streamSize, 1, MPI_LONG, masterNode, MPI_COMM_WORLD);  
101 >                
102 >                  char* buf = new char[streamSize];
103 >                  assert(buf);
104 >                
105 >                  //receive file content
106 >                  commStatus = MPI_Bcast(buf, streamSize, MPI_CHAR, masterNode, MPI_COMM_WORLD);
107 >                
108 >                  ppStream.str(buf);
109 >                  delete buf;
110 >
111 >            }
112 > #endif            
113 >            // Create a scanner that reads from the input stream
114 >            MDLexer lexer(ppStream);
115 >            lexer.setFilename(mdFileName);
116 >            lexer.initDeferredLineCount();
117      
118 < #ifdef IS_MPI
118 >            // Create a parser that reads from the scanner
119 >            MDParser parser(lexer);
120 >            parser.setFilename(mdFileName);
121 >
122 >            // Create an observer that synchorizes file name change
123 >            FilenameObserver observer;
124 >            observer.setLexer(&lexer);
125 >            observer.setParser(&parser);
126 >            lexer.setObserver(&observer);
127      
128 <    if (worldRank == 0) {
129 < #endif // is_mpi
130 <      
131 <      simParams->initalize();
132 <      set_interface_stamps(stamps, simParams);
133 <      
134 < #ifdef IS_MPI
135 <      
136 <      mpiEventInit();
137 <      
138 < #endif
139 <      
140 <      yacc_BASS(mdFileName.c_str());
141 <      
142 < #ifdef IS_MPI
143 <      
144 <      throwMPIEvent(NULL);
88 <    } else {
89 <      set_interface_stamps(stamps, simParams);
90 <      mpiEventInit();
91 <      MPIcheckPoint();
92 <      mpiEventLoop();
93 <    }
94 <    
95 < #endif
96 <    
128 >            antlr::ASTFactory factory;
129 >            parser.initializeASTFactory(factory);
130 >            parser.setASTFactory(&factory);
131 >            parser.mdfile();
132 >
133 >            // Create a tree parser that reads information into Globals
134 >            MDTreeParser treeParser;
135 >            treeParser.initializeASTFactory(factory);
136 >            treeParser.setASTFactory(&factory);
137 >             simParams = treeParser.walkTree(parser.getAST());
138 >
139 >        }
140 >        catch (exception& e) {
141 >            cerr << "parser exception: " << e.what() << endl;
142 >        }
143 >
144 >        return simParams;
145    }
146    
147 <  SimInfo*  SimCreator::createSim(const std::string & mdFileName, bool loadInitCoords) {
148 <    
149 <    MakeStamps * stamps = new MakeStamps();
102 <    
103 <    Globals * simParams = new Globals();
104 <    
147 >  SimInfo*  SimCreator::createSim(const std::string & mdFileName,
148 >                                  bool loadInitCoords) {
149 >
150      //parse meta-data file
151 <    parseFile(mdFileName, stamps, simParams);
151 >    Globals* simParams = parseFile(mdFileName);
152      
153      //create the force field
154 <    ForceField * ff = ForceFieldFactory::getInstance()->createForceField(
155 <                                                                         simParams->getForceField());
154 >    ForceField * ff = ForceFieldFactory::getInstance()
155 >      ->createForceField(simParams->getForceField());
156      
157      if (ff == NULL) {
158 <      sprintf(painCave.errMsg, "ForceField Factory can not create %s force field\n",
159 <              simParams->getForceField());
158 >      sprintf(painCave.errMsg,
159 >              "ForceField Factory can not create %s force field\n",
160 >              simParams->getForceField().c_str());
161        painCave.isFatal = 1;
162        simError();
163      }
# Line 140 | Line 186 | namespace oopse {
186      }
187      
188      ff->parse(forcefieldFileName);
189 <    
144 <    //extract the molecule stamps
145 <    std::vector < std::pair<MoleculeStamp *, int> > moleculeStampPairs;
146 <    compList(stamps, simParams, moleculeStampPairs);
147 <    
189 >        
190      //create SimInfo
191 <    SimInfo * info = new SimInfo(stamps, moleculeStampPairs, ff, simParams);
191 >    SimInfo * info = new SimInfo(ff, simParams);
192      
193      //gather parameters (SimCreator only retrieves part of the parameters)
194      gatherParameters(info, mdFileName);
# Line 186 | Line 228 | namespace oopse {
228    
229    void SimCreator::gatherParameters(SimInfo *info, const std::string& mdfile) {
230      
231 <    //figure out the ouput file names
231 >    //figure out the output file names
232      std::string prefix;
233      
234   #ifdef IS_MPI
# Line 392 | Line 434 | namespace oopse {
434        
435      } //end for(int i=0)  
436    }
395  
396  void SimCreator::compList(MakeStamps *stamps, Globals* simParams,
397                            std::vector < std::pair<MoleculeStamp *, int> > &moleculeStampPairs) {
398    int i;
399    char * id;
400    MoleculeStamp * currentStamp;
401    Component** the_components = simParams->getComponents();
402    int n_components = simParams->getNComponents();
437      
404    if (!simParams->haveNMol()) {
405      // we don't have the total number of molecules, so we assume it is
406      // given in each component
407      
408      for(i = 0; i < n_components; i++) {
409        if (!the_components[i]->haveNMol()) {
410          // we have a problem
411          sprintf(painCave.errMsg,
412                  "SimCreator Error. No global NMol or component NMol given.\n"
413                  "\tCannot calculate the number of atoms.\n");
414          
415          painCave.isFatal = 1;
416          simError();
417        }
418        
419        id = the_components[i]->getType();
420
421        currentStamp = stamps->getMolStamp(id);
422        if (currentStamp == NULL) {
423          sprintf(painCave.errMsg,
424                  "SimCreator error: Component \"%s\" was not found in the "
425                  "list of declared molecules\n", id);
426          
427          painCave.isFatal = 1;
428          simError();
429        }
430        
431        moleculeStampPairs.push_back(
432                                     std::make_pair(currentStamp, the_components[i]->getNMol()));
433      } //end for (i = 0; i < n_components; i++)
434    } else {
435      sprintf(painCave.errMsg, "SimSetup error.\n"
436              "\tSorry, the ability to specify total"
437              " nMols and then give molfractions in the components\n"
438              "\tis not currently supported."
439              " Please give nMol in the components.\n");
440      
441      painCave.isFatal = 1;
442      simError();
443    }
444    
445 #ifdef IS_MPI
446    
447    strcpy(checkPointMsg, "Component stamps successfully extracted\n");
448    MPIcheckPoint();
449    
450 #endif // is_mpi
451    
452  }
453  
438    void SimCreator::setGlobalIndex(SimInfo *info) {
439      SimInfo::MoleculeIterator mi;
440      Molecule::AtomIterator ai;
# Line 602 | Line 586 | namespace oopse {
586        //invalid initial coordinate file
587        sprintf(painCave.errMsg,
588                "Initial configuration file %s should at least contain one frame\n",
589 <              simParams->getInitialConfig());
589 >              simParams->getInitialConfig().c_str());
590        painCave.isFatal = 1;
591        simError();
592      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines