2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2019, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
35 /*! \libinternal \file
37 * Declars mrc/ccp4-file format handling.
39 * \author Christian Blau <blau@kth.se>
42 * \ingroup module_fileio
47 #include "gromacs/math/multidimarray.h"
48 #include "gromacs/mdspan/extensions.h"
49 #include "gromacs/utility/arrayref.h"
50 #include "gromacs/utility/classhelpers.h"
55 struct MrcDensityMapHeader;
57 class TranslateAndScale;
59 /*! \libinternal \brief Read an mrc/ccp4 file that contains float values.
61 class MrcDensityMapOfFloatReader
64 /*! \brief Construct from directly de-serializing data into the object.
65 * \throws InternalError if serializer is not reading
66 * \throws InternalError if header is inconsistent
67 * \throws if serializer throws error upon failed reading
68 * \param[in] serializer Serializer to read the object data from
70 explicit MrcDensityMapOfFloatReader(ISerializer* serializer);
72 ~MrcDensityMapOfFloatReader();
74 //! Return a view on the data of the density grid
75 ArrayRef<const float> constView() const;
77 const MrcDensityMapHeader& header() const;
81 PrivateImplPointer<Impl> impl_;
84 /*! \libinternal \brief Read an mrc density map from a given file.
86 * Higher level class than MrcDensityMapOfFloatReader that takes a file name
87 * upon construction and returns coordinate transformation into the density
88 * lattice as well as the density data.
90 * Attempts reading with swapped endianess if header is not sane.
92 * Performs basic sanity checks on header information and data size.
94 * \note File reading is completed during construction. When the constructor
95 * completes succesfully, transformation to density lattice and density
96 * data are valid, irrespective of the state of the read file.
98 class MrcDensityMapOfFloatFromFileReader
101 MrcDensityMapOfFloatFromFileReader();
103 /*! \brief Read from filename.
104 * \throws FileIOError if file does not exist
105 * \throws FileIOError if read in buffer size does not match file size
106 * \throws FileIOError if header information does not match density
109 explicit MrcDensityMapOfFloatFromFileReader(const std::string& filename);
111 ~MrcDensityMapOfFloatFromFileReader();
113 //! Return the coordinate transformation into the density
114 TranslateAndScale transformationToDensityLattice() const;
116 //! Return a copy of the density data
117 MultiDimArray<std::vector<float>, dynamicExtents3D> densityDataCopy() const;
121 PrivateImplPointer<Impl> impl_;
124 /*! \libinternal \brief Write an mrc/ccp4 file that contains float values.
126 class MrcDensityMapOfFloatWriter
129 /*! \brief Construct by setting the data and the header.
131 * \throws if the header data description does not match the provided data
133 * \param[in] header mrc density map header
134 * \param[in] data the density map data
136 MrcDensityMapOfFloatWriter(const MrcDensityMapHeader& header, ArrayRef<const float> data);
138 ~MrcDensityMapOfFloatWriter();
140 //! Serialize the mrc density data.
141 void write(ISerializer* serializer) const;
145 PrivateImplPointer<Impl> impl_;