Enable parallel tests.
[hoomd-blue.git] / libhoomd / analyzers / DCDDumpWriter.h
blob351ffbcea00e644bcb5b955dfaf32fa032901710
1 /*
2 Highly Optimized Object-oriented Many-particle Dynamics -- Blue Edition
3 (HOOMD-blue) Open Source Software License Copyright 2009-2014 The Regents of
4 the University of Michigan All rights reserved.
6 HOOMD-blue may contain modifications ("Contributions") provided, and to which
7 copyright is held, by various Contributors who have granted The Regents of the
8 University of Michigan the right to modify and/or distribute such Contributions.
10 You may redistribute, use, and create derivate works of HOOMD-blue, in source
11 and binary forms, provided you abide by the following conditions:
13 * Redistributions of source code must retain the above copyright notice, this
14 list of conditions, and the following disclaimer both in the code and
15 prominently in any materials provided with the distribution.
17 * Redistributions in binary form must reproduce the above copyright notice, this
18 list of conditions, and the following disclaimer in the documentation and/or
19 other materials provided with the distribution.
21 * All publications and presentations based on HOOMD-blue, including any reports
22 or published results obtained, in whole or in part, with HOOMD-blue, will
23 acknowledge its use according to the terms posted at the time of submission on:
24 http://codeblue.umich.edu/hoomd-blue/citations.html
26 * Any electronic documents citing HOOMD-Blue will link to the HOOMD-Blue website:
27 http://codeblue.umich.edu/hoomd-blue/
29 * Apart from the above required attributions, neither the name of the copyright
30 holder nor the names of HOOMD-blue's contributors may be used to endorse or
31 promote products derived from this software without specific prior written
32 permission.
34 Disclaimer
36 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS'' AND
37 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
38 WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND/OR ANY
39 WARRANTIES THAT THIS SOFTWARE IS FREE OF INFRINGEMENT ARE DISCLAIMED.
41 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
42 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
43 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
44 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
45 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
46 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
47 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
50 // Maintainer: joaander
52 #ifndef __DCDDUMPWRITER_H__
53 #define __DCDDUMPWRITER_H__
55 #include <string>
56 #include <boost/shared_ptr.hpp>
57 #include <fstream>
58 #include "Analyzer.h"
59 #include "ParticleGroup.h"
61 /*! \file DCDDumpWriter.h
62 \brief Declares the DCDDumpWriter class
65 #ifdef NVCC
66 #error This header cannot be compiled by nvcc
67 #endif
69 // The DCD Dump writer is based on code from the molfile plugin to VMD
70 // and is use under the following license
72 // University of Illinois Open Source License
73 // Copyright 2003 Theoretical and Computational Biophysics Group,
74 // All rights reserved.
76 // Developed by: Theoretical and Computational Biophysics Group
77 // University of Illinois at Urbana-Champaign
78 // http://www.ks.uiuc.edu/
80 //! Analyzer for writing out DCD dump files
81 /*! DCDDumpWriter writes out the current position of all particles to a DCD file
82 every time analyze() is called. Use it to create a DCD trajectory for loading
83 into VMD.
85 On the first call to analyze() \a fname is created with a dcd header. If the file already exists,
86 it is overwritten.
88 Due to a limitation in the DCD format, the time step period between calls to
89 analyze() \b must be specified up front. If analyze() detects that this period is
90 not being maintained, it will print a warning but continue.
91 \ingroup analyzers
93 class DCDDumpWriter : public Analyzer
95 public:
96 //! Construct the writer
97 DCDDumpWriter(boost::shared_ptr<SystemDefinition> sysdef,
98 const std::string &fname,
99 unsigned int period,
100 boost::shared_ptr<ParticleGroup> group,
101 bool overwrite=false);
103 //! Destructor
104 ~DCDDumpWriter();
106 //! Write out the data for the current timestep
107 void analyze(unsigned int timestep);
109 //! Set whether coordinates should be written out wrapped or unwrapped.
110 void setUnwrapFull(bool enable)
112 m_unwrap_full = enable;
115 //! Set whether rigid body coordinates should be written out wrapped or unwrapped.
116 void setUnwrapRigid(bool enable)
118 m_unwrap_rigid = enable;
121 //! Set whether the z-component should be overwritten by the orientation angle
122 void setAngleZ(bool enable)
124 m_angle = enable;
127 private:
128 std::string m_fname; //!< The file name we are writing to
129 unsigned int m_start_timestep; //!< First time step written to the file
130 unsigned int m_period; //!< Time step period bewteen writes
131 boost::shared_ptr<ParticleGroup> m_group; //!< Group of particles to write to the DCD file
132 boost::shared_ptr<RigidData> m_rigid_data; //!< For accessing rigid body data
133 unsigned int m_num_frames_written; //!< Count the number of frames written to the file
134 unsigned int m_last_written_step; //!< Last timestep written in a a file we are appending to
135 bool m_appending; //!< True if this instance is appending to an existing DCD file
136 bool m_unwrap_full; //!< True if coordinates should be written out fully unwrapped in the box
137 bool m_unwrap_rigid; //!< True if rigid bodies should be written out unwrapped
138 bool m_angle; //!< True if the z-component should be set to the orientation angle
140 bool m_overwrite; //!< True if file should be overwritten
141 bool m_is_initialized; //!< True if file IO has been initialized
143 float *m_staging_buffer; //!< Buffer for staging particle positions in tag order
145 // helper functions
147 //! Initalizes the file header
148 void write_file_header(std::fstream &file);
149 //! Writes the frame header
150 void write_frame_header(std::fstream &file);
151 //! Writes the particle positions for a frame
152 void write_frame_data(std::fstream &file, const SnapshotParticleData& snapshot);
153 //! Updates the file header
154 void write_updated_header(std::fstream &file, unsigned int timestep);
155 //! Initializes the output file for writing
156 void initFileIO();
160 //! Exports the DCDDumpWriter class to python
161 void export_DCDDumpWriter();
163 #endif