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 |
|
} |
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(moleculeStampPairs, ff, simParams); |
192 |
< |
|
191 |
> |
SimInfo * info = new SimInfo(ff, simParams); |
192 |
> |
|
193 |
|
//gather parameters (SimCreator only retrieves part of the parameters) |
194 |
|
gatherParameters(info, mdFileName); |
195 |
|
|
220 |
|
info->addExcludePairs(mol); |
221 |
|
} |
222 |
|
|
181 |
– |
|
182 |
– |
//load initial coordinates, some extra information are pushed into SimInfo's property map ( such as |
183 |
– |
//eta, chi for NPT integrator) |
223 |
|
if (loadInitCoords) |
224 |
|
loadCoordinates(info); |
225 |
|
|
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 |
434 |
|
|
435 |
|
} //end for(int i=0) |
436 |
|
} |
398 |
– |
|
399 |
– |
void SimCreator::compList(MakeStamps *stamps, Globals* simParams, |
400 |
– |
std::vector < std::pair<MoleculeStamp *, int> > &moleculeStampPairs) { |
401 |
– |
int i; |
402 |
– |
char * id; |
403 |
– |
LinkedMolStamp* extractedStamp = NULL; |
404 |
– |
MoleculeStamp * currentStamp; |
405 |
– |
Component** the_components = simParams->getComponents(); |
406 |
– |
int n_components = simParams->getNComponents(); |
407 |
– |
|
408 |
– |
if (!simParams->haveNMol()) { |
409 |
– |
// we don't have the total number of molecules, so we assume it is |
410 |
– |
// given in each component |
411 |
– |
|
412 |
– |
for(i = 0; i < n_components; i++) { |
413 |
– |
if (!the_components[i]->haveNMol()) { |
414 |
– |
// we have a problem |
415 |
– |
sprintf(painCave.errMsg, |
416 |
– |
"SimCreator Error. No global NMol or component NMol given.\n" |
417 |
– |
"\tCannot calculate the number of atoms.\n"); |
418 |
– |
|
419 |
– |
painCave.isFatal = 1; |
420 |
– |
simError(); |
421 |
– |
} |
422 |
– |
|
423 |
– |
id = the_components[i]->getType(); |
424 |
– |
|
425 |
– |
extractedStamp = stamps->extractMolStamp(id); |
426 |
– |
if (extractedStamp == NULL) { |
427 |
– |
sprintf(painCave.errMsg, |
428 |
– |
"SimCreator error: Component \"%s\" was not found in the " |
429 |
– |
"list of declared molecules\n", id); |
430 |
– |
|
431 |
– |
painCave.isFatal = 1; |
432 |
– |
simError(); |
433 |
– |
} |
434 |
– |
|
435 |
– |
currentStamp = extractedStamp->getStamp(); |
436 |
– |
|
437 |
– |
|
438 |
– |
moleculeStampPairs.push_back( |
439 |
– |
std::make_pair(currentStamp, the_components[i]->getNMol())); |
440 |
– |
} //end for (i = 0; i < n_components; i++) |
441 |
– |
} else { |
442 |
– |
sprintf(painCave.errMsg, "SimSetup error.\n" |
443 |
– |
"\tSorry, the ability to specify total" |
444 |
– |
" nMols and then give molfractions in the components\n" |
445 |
– |
"\tis not currently supported." |
446 |
– |
" Please give nMol in the components.\n"); |
447 |
– |
|
448 |
– |
painCave.isFatal = 1; |
449 |
– |
simError(); |
450 |
– |
} |
437 |
|
|
452 |
– |
#ifdef IS_MPI |
453 |
– |
|
454 |
– |
strcpy(checkPointMsg, "Component stamps successfully extracted\n"); |
455 |
– |
MPIcheckPoint(); |
456 |
– |
|
457 |
– |
#endif // is_mpi |
458 |
– |
|
459 |
– |
} |
460 |
– |
|
438 |
|
void SimCreator::setGlobalIndex(SimInfo *info) { |
439 |
|
SimInfo::MoleculeIterator mi; |
440 |
|
Molecule::AtomIterator ai; |
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 |
|
} |