6 |
|
* redistribute this software in source and binary code form, provided |
7 |
|
* that the following conditions are met: |
8 |
|
* |
9 |
< |
* 1. Acknowledgement of the program authors must be made in any |
10 |
< |
* publication of scientific results based in part on use of the |
11 |
< |
* program. An acceptable form of acknowledgement is citation of |
12 |
< |
* the article in which the program was described (Matthew |
13 |
< |
* A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher |
14 |
< |
* J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented |
15 |
< |
* Parallel Simulation Engine for Molecular Dynamics," |
16 |
< |
* J. Comput. Chem. 26, pp. 252-271 (2005)) |
17 |
< |
* |
18 |
< |
* 2. Redistributions of source code must retain the above copyright |
9 |
> |
* 1. Redistributions of source code must retain the above copyright |
10 |
|
* notice, this list of conditions and the following disclaimer. |
11 |
|
* |
12 |
< |
* 3. Redistributions in binary form must reproduce the above copyright |
12 |
> |
* 2. Redistributions in binary form must reproduce the above copyright |
13 |
|
* notice, this list of conditions and the following disclaimer in the |
14 |
|
* documentation and/or other materials provided with the |
15 |
|
* distribution. |
28 |
|
* arising out of the use of or inability to use software, even if the |
29 |
|
* University of Notre Dame has been advised of the possibility of |
30 |
|
* such damages. |
31 |
+ |
* |
32 |
+ |
* SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your |
33 |
+ |
* research, please cite the appropriate papers when you publish your |
34 |
+ |
* work. Good starting points are: |
35 |
+ |
* |
36 |
+ |
* [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). |
37 |
+ |
* [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). |
38 |
+ |
* [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008). |
39 |
+ |
* [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). |
40 |
+ |
* [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). |
41 |
|
*/ |
42 |
|
|
43 |
|
/** |
77 |
|
#include "antlr/NoViableAltException.hpp" |
78 |
|
|
79 |
|
#ifdef IS_MPI |
80 |
+ |
#include "mpi.h" |
81 |
|
#include "math/ParallelRandNumGen.hpp" |
82 |
|
#endif |
83 |
|
|
84 |
< |
namespace oopse { |
84 |
> |
namespace OpenMD { |
85 |
|
|
86 |
< |
Globals* SimCreator::parseFile(std::istream& rawMetaDataStream, const std::string& filename, int startOfMetaDataBlock ){ |
86 |
> |
Globals* SimCreator::parseFile(std::istream& rawMetaDataStream, const std::string& filename, int mdFileVersion, int startOfMetaDataBlock ){ |
87 |
|
Globals* simParams = NULL; |
88 |
|
try { |
89 |
|
|
94 |
|
const int masterNode = 0; |
95 |
|
int commStatus; |
96 |
|
if (worldRank == masterNode) { |
97 |
< |
#endif |
98 |
< |
|
97 |
> |
commStatus = MPI_Bcast(&mdFileVersion, 1, MPI_INT, masterNode, MPI_COMM_WORLD); |
98 |
> |
#endif |
99 |
|
SimplePreprocessor preprocessor; |
100 |
|
preprocessor.preprocess(rawMetaDataStream, filename, startOfMetaDataBlock, ppStream); |
101 |
|
|
108 |
|
|
109 |
|
|
110 |
|
} else { |
111 |
+ |
|
112 |
+ |
commStatus = MPI_Bcast(&mdFileVersion, 1, MPI_INT, masterNode, MPI_COMM_WORLD); |
113 |
+ |
|
114 |
|
//get stream size |
115 |
|
commStatus = MPI_Bcast(&streamSize, 1, MPI_LONG, masterNode, MPI_COMM_WORLD); |
116 |
|
|
219 |
|
painCave.isFatal = 1; |
220 |
|
simError(); |
221 |
|
} |
222 |
< |
catch (OOPSEException& e) { |
222 |
> |
catch (OpenMDException& e) { |
223 |
|
sprintf(painCave.errMsg, |
224 |
|
"%s\n", |
225 |
|
e.getMessage().c_str()); |
234 |
|
simError(); |
235 |
|
} |
236 |
|
|
237 |
+ |
simParams->setMDfileVersion(mdFileVersion); |
238 |
|
return simParams; |
239 |
|
} |
240 |
|
|
241 |
|
SimInfo* SimCreator::createSim(const std::string & mdFileName, |
242 |
|
bool loadInitCoords) { |
243 |
< |
|
243 |
> |
|
244 |
|
const int bufferSize = 65535; |
245 |
|
char buffer[bufferSize]; |
246 |
|
int lineNo = 0; |
249 |
|
int metaDataBlockEnd = -1; |
250 |
|
int i; |
251 |
|
int mdOffset; |
252 |
+ |
int mdFileVersion; |
253 |
|
|
254 |
|
#ifdef IS_MPI |
255 |
|
const int masterNode = 0; |
269 |
|
mdFile_.getline(buffer, bufferSize); |
270 |
|
++lineNo; |
271 |
|
std::string line = trimLeftCopy(buffer); |
272 |
< |
i = CaseInsensitiveFind(line, "<OOPSE"); |
272 |
> |
i = CaseInsensitiveFind(line, "<OpenMD"); |
273 |
|
if (static_cast<size_t>(i) == string::npos) { |
274 |
+ |
// try the older file strings to see if that works: |
275 |
+ |
i = CaseInsensitiveFind(line, "<OOPSE"); |
276 |
+ |
} |
277 |
+ |
|
278 |
+ |
if (static_cast<size_t>(i) == string::npos) { |
279 |
+ |
// still no luck! |
280 |
|
sprintf(painCave.errMsg, |
281 |
< |
"SimCreator: File: %s is not an OOPSE file!\n", |
281 |
> |
"SimCreator: File: %s is not a valid OpenMD file!\n", |
282 |
|
mdFileName.c_str()); |
283 |
|
painCave.isFatal = 1; |
284 |
|
simError(); |
285 |
|
} |
286 |
+ |
|
287 |
+ |
// found the correct opening string, now try to get the file |
288 |
+ |
// format version number. |
289 |
|
|
290 |
+ |
StringTokenizer tokenizer(line, "=<> \t\n\r"); |
291 |
+ |
std::string fileType = tokenizer.nextToken(); |
292 |
+ |
toUpper(fileType); |
293 |
+ |
|
294 |
+ |
mdFileVersion = 0; |
295 |
+ |
|
296 |
+ |
if (fileType == "OPENMD") { |
297 |
+ |
while (tokenizer.hasMoreTokens()) { |
298 |
+ |
std::string token(tokenizer.nextToken()); |
299 |
+ |
toUpper(token); |
300 |
+ |
if (token == "VERSION") { |
301 |
+ |
mdFileVersion = tokenizer.nextTokenAsInt(); |
302 |
+ |
break; |
303 |
+ |
} |
304 |
+ |
} |
305 |
+ |
} |
306 |
+ |
|
307 |
|
//scan through the input stream and find MetaData tag |
308 |
|
while(mdFile_.getline(buffer, bufferSize)) { |
309 |
|
++lineNo; |
359 |
|
std::stringstream rawMetaDataStream(mdRawData); |
360 |
|
|
361 |
|
//parse meta-data file |
362 |
< |
Globals* simParams = parseFile(rawMetaDataStream, mdFileName, metaDataBlockStart+1); |
362 |
> |
Globals* simParams = parseFile(rawMetaDataStream, mdFileName, mdFileVersion, |
363 |
> |
metaDataBlockStart + 1); |
364 |
|
|
365 |
|
//create the force field |
366 |
|
ForceField * ff = ForceFieldFactory::getInstance()->createForceField(simParams->getForceField()); |
397 |
|
} |
398 |
|
|
399 |
|
ff->parse(forcefieldFileName); |
366 |
– |
ff->setFortranForceOptions(); |
400 |
|
//create SimInfo |
401 |
|
SimInfo * info = new SimInfo(ff, simParams); |
402 |
|
|
414 |
|
//create the molecules |
415 |
|
createMolecules(info); |
416 |
|
|
384 |
– |
|
417 |
|
//allocate memory for DataStorage(circular reference, need to |
418 |
|
//break it) |
419 |
|
info->setSnapshotManager(new SimSnapshotManager(info)); |
439 |
|
|
440 |
|
if (loadInitCoords) |
441 |
|
loadCoordinates(info, mdFileName); |
410 |
– |
|
442 |
|
return info; |
443 |
|
} |
444 |
|
|
502 |
|
"\tthe number of molecules. This will not result in a \n" |
503 |
|
"\tusable division of atoms for force decomposition.\n" |
504 |
|
"\tEither try a smaller number of processors, or run the\n" |
505 |
< |
"\tsingle-processor version of OOPSE.\n", nProcessors, nGlobalMols); |
505 |
> |
"\tsingle-processor version of OpenMD.\n", nProcessors, nGlobalMols); |
506 |
|
|
507 |
|
painCave.isFatal = 1; |
508 |
|
simError(); |
637 |
|
#endif |
638 |
|
|
639 |
|
stampId = info->getMoleculeStampId(i); |
640 |
< |
Molecule * mol = molCreator.createMolecule(info->getForceField(), info->getMoleculeStamp(stampId), |
641 |
< |
stampId, i, info->getLocalIndexManager()); |
640 |
> |
Molecule * mol = molCreator.createMolecule(info->getForceField(), |
641 |
> |
info->getMoleculeStamp(stampId), |
642 |
> |
stampId, i, |
643 |
> |
info->getLocalIndexManager()); |
644 |
|
|
645 |
|
info->addMolecule(mol); |
646 |
|
|
667 |
|
int beginRigidBodyIndex; |
668 |
|
int beginCutoffGroupIndex; |
669 |
|
int nGlobalAtoms = info->getNGlobalAtoms(); |
637 |
– |
|
638 |
– |
/**@todo fixme */ |
639 |
– |
#ifndef IS_MPI |
640 |
– |
|
641 |
– |
beginAtomIndex = 0; |
642 |
– |
beginRigidBodyIndex = 0; |
643 |
– |
beginCutoffGroupIndex = 0; |
644 |
– |
|
645 |
– |
#else |
646 |
– |
|
647 |
– |
int nproc; |
648 |
– |
int myNode; |
649 |
– |
|
650 |
– |
myNode = worldRank; |
651 |
– |
MPI_Comm_size(MPI_COMM_WORLD, &nproc); |
652 |
– |
|
653 |
– |
std::vector < int > tmpAtomsInProc(nproc, 0); |
654 |
– |
std::vector < int > tmpRigidBodiesInProc(nproc, 0); |
655 |
– |
std::vector < int > tmpCutoffGroupsInProc(nproc, 0); |
656 |
– |
std::vector < int > NumAtomsInProc(nproc, 0); |
657 |
– |
std::vector < int > NumRigidBodiesInProc(nproc, 0); |
658 |
– |
std::vector < int > NumCutoffGroupsInProc(nproc, 0); |
670 |
|
|
660 |
– |
tmpAtomsInProc[myNode] = info->getNAtoms(); |
661 |
– |
tmpRigidBodiesInProc[myNode] = info->getNRigidBodies(); |
662 |
– |
tmpCutoffGroupsInProc[myNode] = info->getNCutoffGroups(); |
663 |
– |
|
664 |
– |
//do MPI_ALLREDUCE to exchange the total number of atoms, rigidbodies and cutoff groups |
665 |
– |
MPI_Allreduce(&tmpAtomsInProc[0], &NumAtomsInProc[0], nproc, MPI_INT, |
666 |
– |
MPI_SUM, MPI_COMM_WORLD); |
667 |
– |
MPI_Allreduce(&tmpRigidBodiesInProc[0], &NumRigidBodiesInProc[0], nproc, |
668 |
– |
MPI_INT, MPI_SUM, MPI_COMM_WORLD); |
669 |
– |
MPI_Allreduce(&tmpCutoffGroupsInProc[0], &NumCutoffGroupsInProc[0], nproc, |
670 |
– |
MPI_INT, MPI_SUM, MPI_COMM_WORLD); |
671 |
– |
|
671 |
|
beginAtomIndex = 0; |
672 |
|
beginRigidBodyIndex = 0; |
673 |
|
beginCutoffGroupIndex = 0; |
674 |
< |
|
675 |
< |
for(int i = 0; i < myNode; i++) { |
677 |
< |
beginAtomIndex += NumAtomsInProc[i]; |
678 |
< |
beginRigidBodyIndex += NumRigidBodiesInProc[i]; |
679 |
< |
beginCutoffGroupIndex += NumCutoffGroupsInProc[i]; |
680 |
< |
} |
681 |
< |
|
682 |
< |
#endif |
683 |
< |
|
684 |
< |
//rigidbody's index begins right after atom's |
685 |
< |
beginRigidBodyIndex += info->getNGlobalAtoms(); |
686 |
< |
|
687 |
< |
for(mol = info->beginMolecule(mi); mol != NULL; |
688 |
< |
mol = info->nextMolecule(mi)) { |
674 |
> |
|
675 |
> |
for(int i = 0; i < info->getNGlobalMolecules(); i++) { |
676 |
|
|
677 |
< |
//local index(index in DataStorge) of atom is important |
678 |
< |
for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { |
679 |
< |
atom->setGlobalIndex(beginAtomIndex++); |
677 |
> |
#ifdef IS_MPI |
678 |
> |
if (info->getMolToProc(i) == worldRank) { |
679 |
> |
#endif |
680 |
> |
// stuff to do if I own this molecule |
681 |
> |
mol = info->getMoleculeByGlobalIndex(i); |
682 |
> |
|
683 |
> |
//local index(index in DataStorge) of atom is important |
684 |
> |
for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { |
685 |
> |
atom->setGlobalIndex(beginAtomIndex++); |
686 |
> |
} |
687 |
> |
|
688 |
> |
for(rb = mol->beginRigidBody(ri); rb != NULL; |
689 |
> |
rb = mol->nextRigidBody(ri)) { |
690 |
> |
rb->setGlobalIndex(beginRigidBodyIndex++); |
691 |
> |
} |
692 |
> |
|
693 |
> |
//local index of cutoff group is trivial, it only depends on |
694 |
> |
//the order of travesing |
695 |
> |
for(cg = mol->beginCutoffGroup(ci); cg != NULL; |
696 |
> |
cg = mol->nextCutoffGroup(ci)) { |
697 |
> |
cg->setGlobalIndex(beginCutoffGroupIndex++); |
698 |
> |
} |
699 |
> |
|
700 |
> |
#ifdef IS_MPI |
701 |
> |
} else { |
702 |
> |
|
703 |
> |
// stuff to do if I don't own this molecule |
704 |
> |
|
705 |
> |
int stampId = info->getMoleculeStampId(i); |
706 |
> |
MoleculeStamp* stamp = info->getMoleculeStamp(stampId); |
707 |
> |
|
708 |
> |
beginAtomIndex += stamp->getNAtoms(); |
709 |
> |
beginRigidBodyIndex += stamp->getNRigidBodies(); |
710 |
> |
beginCutoffGroupIndex += stamp->getNCutoffGroups() + stamp->getNFreeAtoms(); |
711 |
|
} |
712 |
< |
|
713 |
< |
for(rb = mol->beginRigidBody(ri); rb != NULL; |
714 |
< |
rb = mol->nextRigidBody(ri)) { |
715 |
< |
rb->setGlobalIndex(beginRigidBodyIndex++); |
698 |
< |
} |
699 |
< |
|
700 |
< |
//local index of cutoff group is trivial, it only depends on the order of travesing |
701 |
< |
for(cg = mol->beginCutoffGroup(ci); cg != NULL; |
702 |
< |
cg = mol->nextCutoffGroup(ci)) { |
703 |
< |
cg->setGlobalIndex(beginCutoffGroupIndex++); |
704 |
< |
} |
705 |
< |
} |
706 |
< |
|
712 |
> |
#endif |
713 |
> |
|
714 |
> |
} //end for(int i=0) |
715 |
> |
|
716 |
|
//fill globalGroupMembership |
717 |
|
std::vector<int> globalGroupMembership(info->getNGlobalAtoms(), 0); |
718 |
|
for(mol = info->beginMolecule(mi); mol != NULL; mol = info->nextMolecule(mi)) { |
724 |
|
|
725 |
|
} |
726 |
|
} |
727 |
< |
|
727 |
> |
|
728 |
|
#ifdef IS_MPI |
729 |
|
// Since the globalGroupMembership has been zero filled and we've only |
730 |
|
// poked values into the atoms we know, we can do an Allreduce |
794 |
|
globalIO++; |
795 |
|
} |
796 |
|
} |
797 |
< |
|
797 |
> |
|
798 |
|
info->setIOIndexToIntegrableObject(IOIndexToIntegrableObject); |
799 |
|
|
800 |
|
} |
801 |
|
|
802 |
|
void SimCreator::loadCoordinates(SimInfo* info, const std::string& mdFileName) { |
803 |
|
Globals* simParams; |
804 |
+ |
|
805 |
|
simParams = info->getSimParams(); |
806 |
|
|
797 |
– |
|
807 |
|
DumpReader reader(info, mdFileName); |
808 |
|
int nframes = reader.getNFrames(); |
809 |
< |
|
809 |
> |
|
810 |
|
if (nframes > 0) { |
811 |
|
reader.readFrame(nframes - 1); |
812 |
|
} else { |
817 |
|
painCave.isFatal = 1; |
818 |
|
simError(); |
819 |
|
} |
811 |
– |
|
820 |
|
//copy the current snapshot to previous snapshot |
821 |
|
info->getSnapshotManager()->advance(); |
822 |
|
} |
823 |
|
|
824 |
< |
} //end namespace oopse |
824 |
> |
} //end namespace OpenMD |
825 |
|
|
826 |
|
|