Molmodel

PeriodicPdbWriter.h

Go to the documentation of this file.
00001 /* -------------------------------------------------------------------------- *
00002  *                      SimTK Core: SimTK Molmodel                            *
00003  * -------------------------------------------------------------------------- *
00004  * This is part of the SimTK Core biosimulation toolkit originating from      *
00005  * Simbios, the NIH National Center for Physics-Based Simulation of           *
00006  * Biological Structures at Stanford, funded under the NIH Roadmap for        *
00007  * Medical Research, grant U54 GM072970. See https://simtk.org.               *
00008  *                                                                            *
00009  * Portions copyright (c) 2008 Stanford University and the Authors.           *
00010  * Authors: Christopher Bruns                                                 *
00011  * Contributors:                                                              *
00012  *                                                                            *
00013  * Permission is hereby granted, free of charge, to any person obtaining a    *
00014  * copy of this software and associated documentation files (the "Software"), *
00015  * to deal in the Software without restriction, including without limitation  *
00016  * the rights to use, copy, modify, merge, publish, distribute, sublicense,   *
00017  * and/or sell copies of the Software, and to permit persons to whom the      *
00018  * Software is furnished to do so, subject to the following conditions:       *
00019  *                                                                            *
00020  * The above copyright notice and this permission notice shall be included in *
00021  * all copies or substantial portions of the Software.                        *
00022  *                                                                            *
00023  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
00024  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,   *
00025  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL    *
00026  * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,    *
00027  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR      *
00028  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE  *
00029  * USE OR OTHER DEALINGS IN THE SOFTWARE.                                     *
00030  * -------------------------------------------------------------------------- */
00031 
00032 #ifndef SimTK_MOLMODEL_PERIODICPDBWRITER_H_
00033 #define SimTK_MOLMODEL_PERIODICPDBWRITER_H_
00034 
00035 #include "SimTKsimbody.h"
00036 #include "molmodel/internal/Compound.h"
00037 #include <iostream>
00038 #include <iomanip>
00039 #include <vector>
00040 
00041 namespace SimTK {
00042 
00045 class PeriodicPdbWriter : public PeriodicEventReporter {
00046 public:
00047     PeriodicPdbWriter(
00048         const CompoundSystem& system, 
00049         std::ostream& outputStream,
00050         Real interval) 
00051         : PeriodicEventReporter(interval), 
00052           system(system), 
00053           outputStream(outputStream) 
00054     {}
00055 
00056     void handleEvent(const State& state) const {
00057         static int modelNumber = 1; // increments by one at each reporting step
00058         int nextAtomSerialNumber = 1; // atom serial number for each compound picks up where previous compound left off
00059 
00060         system.realize(state, Stage::Position);
00061 
00062         outputStream << "MODEL     " << std::setw(4) << modelNumber << std::endl;
00063 
00064         for (SimTK::CompoundSystem::CompoundIndex c(0); c < system.getNumCompounds(); ++c)
00065             system.getCompound(c).writePdb(state, outputStream, nextAtomSerialNumber);
00066 
00067         outputStream << "ENDMDL" << std::endl;
00068     
00069         //scf added time reporting 
00070                 time_t rawtime;
00071                 struct tm * timeinfo;
00072                 time ( &rawtime );
00073                 timeinfo = localtime ( &rawtime );
00074                 outputStream <<"REMARK Current time is: "<<asctime (timeinfo) <<"REMARK elapsed time: "<<(clock()/CLOCKS_PER_SEC)<<std::endl;
00075                 //outputStream <<"REMARK Energy :"<<system.calcEnergy(state)<<std::endl;
00076         //
00077     
00078         ++modelNumber;
00079     }
00080 
00081 private:
00082     const CompoundSystem& system;
00083     std::ostream& outputStream;
00084 };
00085 
00086 } // namespace SimTK
00087 
00088 #endif // SimTK_MOLMODEL_PERIODICPDBWRITER_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines