# | 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 | < | set_interface_stamps(stamps, simParams); |
132 | < | |
133 | < | #ifdef IS_MPI |
134 | < | |
135 | < | mpiEventInit(); |
136 | < | |
137 | < | #endif |
138 | < | |
139 | < | yacc_BASS(mdFileName.c_str()); |
140 | < | |
141 | < | #ifdef IS_MPI |
142 | < | |
143 | < | throwMPIEvent(NULL); |
144 | < | } else { |
88 | < | set_interface_stamps(stamps, simParams); |
89 | < | mpiEventInit(); |
90 | < | MPIcheckPoint(); |
91 | < | mpiEventLoop(); |
92 | < | } |
93 | < | |
94 | < | #endif |
95 | < | |
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 | < | |
101 | < | MakeStamps * stamps = new MakeStamps(); |
102 | < | |
103 | < | Globals * simParams = new Globals(); |
104 | < | |
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 141 | Line 186 | namespace oopse { | |
186 | } | |
187 | ||
188 | ff->parse(forcefieldFileName); | |
189 | < | |
145 | < | //extract the molecule stamps |
146 | < | std::vector < std::pair<MoleculeStamp *, int> > moleculeStampPairs; |
147 | < | compList(stamps, simParams, moleculeStampPairs); |
148 | < | |
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 187 | 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 393 | Line 434 | namespace oopse { | |
434 | ||
435 | } //end for(int i=0) | |
436 | } | |
396 | – | |
397 | – | void SimCreator::compList(MakeStamps *stamps, Globals* simParams, |
398 | – | std::vector < std::pair<MoleculeStamp *, int> > &moleculeStampPairs) { |
399 | – | int i; |
400 | – | char * id; |
401 | – | MoleculeStamp * currentStamp; |
402 | – | Component** the_components = simParams->getComponents(); |
403 | – | int n_components = simParams->getNComponents(); |
404 | – | |
405 | – | if (!simParams->haveNMol()) { |
406 | – | // we don't have the total number of molecules, so we assume it is |
407 | – | // given in each component |
408 | – | |
409 | – | for(i = 0; i < n_components; i++) { |
410 | – | if (!the_components[i]->haveNMol()) { |
411 | – | // we have a problem |
412 | – | sprintf(painCave.errMsg, |
413 | – | "SimCreator Error. No global NMol or component NMol given.\n" |
414 | – | "\tCannot calculate the number of atoms.\n"); |
415 | – | |
416 | – | painCave.isFatal = 1; |
417 | – | simError(); |
418 | – | } |
419 | – | |
420 | – | id = the_components[i]->getType(); |
421 | – | |
422 | – | currentStamp = stamps->getMolStamp(id); |
423 | – | if (currentStamp == NULL) { |
424 | – | sprintf(painCave.errMsg, |
425 | – | "SimCreator error: Component \"%s\" was not found in the " |
426 | – | "list of declared molecules\n", id); |
427 | – | |
428 | – | painCave.isFatal = 1; |
429 | – | simError(); |
430 | – | } |
431 | – | |
432 | – | moleculeStampPairs.push_back( |
433 | – | std::make_pair(currentStamp, the_components[i]->getNMol())); |
434 | – | } //end for (i = 0; i < n_components; i++) |
435 | – | } else { |
436 | – | sprintf(painCave.errMsg, "SimSetup error.\n" |
437 | – | "\tSorry, the ability to specify total" |
438 | – | " nMols and then give molfractions in the components\n" |
439 | – | "\tis not currently supported." |
440 | – | " Please give nMol in the components.\n"); |
441 | – | |
442 | – | painCave.isFatal = 1; |
443 | – | simError(); |
444 | – | } |
437 | ||
446 | – | #ifdef IS_MPI |
447 | – | |
448 | – | strcpy(checkPointMsg, "Component stamps successfully extracted\n"); |
449 | – | MPIcheckPoint(); |
450 | – | |
451 | – | #endif // is_mpi |
452 | – | |
453 | – | } |
454 | – | |
438 | void SimCreator::setGlobalIndex(SimInfo *info) { | |
439 | SimInfo::MoleculeIterator mi; | |
440 | Molecule::AtomIterator ai; |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |