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 2211 by chrisfen, Thu Apr 21 14:12:19 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,
148                                    bool loadInitCoords) {
149 <    
102 <    MakeStamps * stamps = new MakeStamps();
103 <    
104 <    Globals * simParams = new Globals();
105 <    
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()
# Line 113 | Line 157 | namespace oopse {
157      if (ff == NULL) {
158        sprintf(painCave.errMsg,
159                "ForceField Factory can not create %s force field\n",
160 <              simParams->getForceField());
160 >              simParams->getForceField().c_str());
161        painCave.isFatal = 1;
162        simError();
163      }
# Line 140 | Line 184 | namespace oopse {
184          forcefieldFileName.append(variant);
185        }
186      }
143    
144    ff->parse(forcefieldFileName);
145    
146    //extract the molecule stamps
147    std::vector < std::pair<MoleculeStamp *, int> > moleculeStampPairs;
148    compList(stamps, simParams, moleculeStampPairs);
187      
188 +    ff->parse(forcefieldFileName);
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 188 | 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 394 | Line 434 | namespace oopse {
434        
435      } //end for(int i=0)  
436    }
397  
398  void SimCreator::compList(MakeStamps *stamps, Globals* simParams,
399                            std::vector < std::pair<MoleculeStamp *, int> > &moleculeStampPairs) {
400    int i;
401    char * id;
402    MoleculeStamp * currentStamp;
403    Component** the_components = simParams->getComponents();
404    int n_components = simParams->getNComponents();
405    
406    if (!simParams->haveNMol()) {
407      // we don't have the total number of molecules, so we assume it is
408      // given in each component
409      
410      for(i = 0; i < n_components; i++) {
411        if (!the_components[i]->haveNMol()) {
412          // we have a problem
413          sprintf(painCave.errMsg,
414                  "SimCreator Error. No global NMol or component NMol given.\n"
415                  "\tCannot calculate the number of atoms.\n");
416          
417          painCave.isFatal = 1;
418          simError();
419        }
420        
421        id = the_components[i]->getType();
422
423        currentStamp = stamps->getMolStamp(id);
424        if (currentStamp == NULL) {
425          sprintf(painCave.errMsg,
426                  "SimCreator error: Component \"%s\" was not found in the "
427                  "list of declared molecules\n", id);
428          
429          painCave.isFatal = 1;
430          simError();
431        }
432        
433        moleculeStampPairs.push_back(
434                                     std::make_pair(currentStamp, the_components[i]->getNMol()));
435      } //end for (i = 0; i < n_components; i++)
436    } else {
437      sprintf(painCave.errMsg, "SimSetup error.\n"
438              "\tSorry, the ability to specify total"
439              " nMols and then give molfractions in the components\n"
440              "\tis not currently supported."
441              " Please give nMol in the components.\n");
442      
443      painCave.isFatal = 1;
444      simError();
445    }
437      
447 #ifdef IS_MPI
448    
449    strcpy(checkPointMsg, "Component stamps successfully extracted\n");
450    MPIcheckPoint();
451    
452 #endif // is_mpi
453    
454  }
455  
438    void SimCreator::setGlobalIndex(SimInfo *info) {
439      SimInfo::MoleculeIterator mi;
440      Molecule::AtomIterator ai;
# Line 604 | 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