--- trunk/src/io/RestWriter.cpp 2005/03/10 15:10:24 417 +++ trunk/src/io/RestWriter.cpp 2009/10/07 20:49:50 1364 @@ -1,5 +1,5 @@ - /* - * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. +/* + * Copyright (c) 2009 The University of Notre Dame. All Rights Reserved. * * The University of Notre Dame grants you ("Licensee") a * non-exclusive, royalty free, license to use, modify and @@ -38,150 +38,94 @@ * University of Notre Dame has been advised of the possibility of * such damages. */ - -#include + + #include -#include -#include "primitives/Molecule.hpp" #include "io/RestWriter.hpp" #include "utils/simError.h" +#include "brains/SnapshotManager.hpp" +#ifdef IS_MPI +#include +#endif - namespace oopse { - RestWriter::RestWriter(SimInfo* info) : - info_(info) { - - //we use master - slave mode, only master node writes to disk - outName = info_->getRestFileName(); - } - - RestWriter::~RestWriter() {} - - void RestWriter::writeZangle(){ - const int BUFFERSIZE = 2000; - char tempBuffer[BUFFERSIZE]; - char writeLine[BUFFERSIZE]; - - std::ofstream finalOut; - - Molecule* mol; - StuntDouble* integrableObject; - SimInfo::MoleculeIterator mi; - Molecule::IntegrableObjectIterator ii; - + RestWriter::RestWriter(SimInfo* info, const std::string& filename, + std::vector restraints ) : + info_(info){ + + //use master - slave mode, only master node writes to disk #ifdef IS_MPI - if(worldRank == 0 ){ -#endif - finalOut.open( outName.c_str(), std::ios::out | std::ios::trunc ); - if( !finalOut ){ + if(worldRank == 0){ +#endif + + output_.open(filename.c_str()); + + if(!output_){ sprintf( painCave.errMsg, - "Could not open \"%s\" for zAngle output.\n", - outName ); + "Could not open %s for restraint output.\n", + filename.c_str()); painCave.isFatal = 1; simError(); } -#ifdef IS_MPI - } -#endif // is_mpi - -#ifndef IS_MPI - // first we do output for the single processor version - finalOut - << info_->getSnapshotManager()->getCurrentSnapshot()->getTime() - << " : omega values at this time\n"; - - for (mol = info_->beginMolecule(mi); mol != NULL; - mol = info_->nextMolecule(mi)) { + + output_ << "#time\t"; - for (integrableObject = mol->beginIntegrableObject(ii); - integrableObject != NULL; - integrableObject = mol->nextIntegrableObject(ii)) { - - sprintf( tempBuffer, - "%14.10lf\n", - integrableObject->getZangle()); - strcpy( writeLine, tempBuffer ); - - finalOut << writeLine; - } - - } - -#else - int nproc; - MPI_Comm_size(MPI_COMM_WORLD, &nproc); - const int masterNode = 0; - int myNode = worldRank; - std::vector tmpNIntObjects(nproc, 0); - std::vector nIntObjectsInProc(nproc, 0); - tmpNIntObjects[myNode] = info_->getNGlobalIntegrableObjects(); - - //do MPI_ALLREDUCE to exchange the total number of atoms, rigidbodies and cutoff groups - MPI_Allreduce(&tmpNIntObjects[0], &nIntObjectsInProc[0], nproc, MPI_INT, - MPI_SUM, MPI_COMM_WORLD); - - MPI_Status ierr; - int intObIndex; - double zAngle; - - if (masterNode == 0) { - std::map zAngData; - for(int i = 0 ; i < nproc; ++i) { - if (i == masterNode) { - for (mol = info_->beginMolecule(mi); mol != NULL; - mol = info_->nextMolecule(mi)) { - - for (integrableObject = mol->beginIntegrableObject(ii); - integrableObject != NULL; - integrableObject = mol->nextIntegrableObject(ii)) { - - intObIndex = integrableObject->getGlobalIndex() ; - zAngle = integrableObject->getZangle(); - zAngData.insert(pair(intObIndex, zAngle)); - } - } + // TODO: get Restraint info from slave nodes: + std::vector::const_iterator resti; + for(resti=restraints.begin(); resti != restraints.end(); ++resti){ + + if ((*resti)->getPrintRestraint()) { + std::string myName = (*resti)->getRestraintName(); + int myType = (*resti)->getRestraintType(); - } else { - for(int k = 0; k < nIntObjectsInProc[i]; ++k) { - MPI_Recv(&intObIndex, 1, MPI_INT, i, 0, MPI_COMM_WORLD,&ierr); - MPI_Recv(&zAngle, 1, MPI_DOUBLE, i, 0, MPI_COMM_WORLD,&ierr); - zAngData.insert(pair(intObIndex, zAngle)); - } + output_ << myName << ":"; + + if (myType & Restraint::rtDisplacement) + output_ << "\tPosition(angstroms)\tEnergy(kcal/mol)"; + + if (myType & Restraint::rtTwist) + output_ << "\tTwistAngle(radians)\tEnergy(kcal/mol)"; + + if (myType & Restraint::rtSwingX) + output_ << "\tSwingXAngle(radians)\tEnergy(kcal/mol)"; + + if (myType & Restraint::rtSwingY) + output_ << "\tSwingYAngle(radians)\tEnergy(kcal/mol)"; + } - } - - finalOut - << info_->getSnapshotManager()->getCurrentSnapshot()->getTime() - << " : omega values at this time\n"; - - std::map::iterator l; - for (l = zAngData.begin(); l != zAngData.end(); ++l) { - finalOut << l->second << "\n"; - } - - } else { - - for (mol = info_->beginMolecule(mi); mol != NULL; - mol = info_->nextMolecule(mi)) { - - for (integrableObject = mol->beginIntegrableObject(ii); - integrableObject != NULL; - integrableObject = mol->nextIntegrableObject(ii)) { - intObIndex = integrableObject->getGlobalIndex(); - zAngle = integrableObject->getZangle(); - MPI_Send(&intObIndex, 1, MPI_INT, masterNode, 0, MPI_COMM_WORLD); - MPI_Send(&zAngle, 1, MPI_DOUBLE, masterNode, 0, MPI_COMM_WORLD); - } - } + output_ << "\n"; +#ifdef IS_MPI } -#endif - +#endif + } + + RestWriter::~RestWriter() { #ifdef IS_MPI - finalOut.close(); + if(worldRank == 0 ){ +#endif + output_.close(); +#ifdef IS_MPI + } #endif + } + + void RestWriter::writeRest(std::vector > restInfo){ + + output_ << info_->getSnapshotManager()->getCurrentSnapshot()->getTime(); + + // output some information about the molecules + std::vector >::const_iterator i; + std::map::const_iterator j; + for( i = restInfo.begin(); i != restInfo.end(); ++i){ + for(j = (*i).begin(); j != (*i).end(); ++j){ + output_ << "\t" << (j->second).first << "\t" << (j->second).second; + } + output_ << std::endl; + } } -} +}// end oopse +