Remove unnecessary includes of arrayref.h
[alexxy/gromacs.git] / src / gromacs / fileio / mrcdensitymap.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2019,2020, 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.
8  *
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.
13  *
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.
18  *
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.
23  *
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.
31  *
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.
34  */
35 /*! \libinternal \file
36  * \brief
37  * Declars mrc/ccp4-file format handling.
38  *
39  * \author Christian Blau <blau@kth.se>
40  *
41  * \inlibraryapi
42  * \ingroup module_fileio
43  */
44 #include <string>
45 #include <vector>
46
47 #include "gromacs/math/multidimarray.h"
48 #include "gromacs/mdspan/extensions.h"
49 #include "gromacs/utility/classhelpers.h"
50
51 namespace gmx
52 {
53 template<typename>
54 class ArrayRef;
55 struct MrcDensityMapHeader;
56 class ISerializer;
57 class TranslateAndScale;
58
59 /*! \libinternal \brief Read an mrc/ccp4 file that contains float values.
60  */
61 class MrcDensityMapOfFloatReader
62 {
63 public:
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
69      */
70     explicit MrcDensityMapOfFloatReader(ISerializer* serializer);
71
72     ~MrcDensityMapOfFloatReader();
73
74     //! Return a view on the data of the density grid
75     ArrayRef<const float> constView() const;
76     //! Return the header
77     const MrcDensityMapHeader& header() const;
78
79 private:
80     class Impl;
81     PrivateImplPointer<Impl> impl_;
82 };
83
84 /*! \libinternal \brief Read an mrc density map from a given file.
85  *
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.
89  *
90  * Attempts reading with swapped endianess if header is not sane.
91  *
92  * Performs basic sanity checks on header information and data size.
93  *
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.
97  */
98 class MrcDensityMapOfFloatFromFileReader
99 {
100 public:
101     MrcDensityMapOfFloatFromFileReader();
102
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
107      *                     data size
108      */
109     explicit MrcDensityMapOfFloatFromFileReader(const std::string& filename);
110
111     ~MrcDensityMapOfFloatFromFileReader();
112
113     //! Return the coordinate transformation into the density
114     TranslateAndScale transformationToDensityLattice() const;
115
116     //! Return a copy of the density data
117     MultiDimArray<std::vector<float>, dynamicExtents3D> densityDataCopy() const;
118
119 private:
120     class Impl;
121     PrivateImplPointer<Impl> impl_;
122 };
123
124 /*! \libinternal \brief Write an mrc/ccp4 file that contains float values.
125  */
126 class MrcDensityMapOfFloatWriter
127 {
128 public:
129     /*! \brief Construct by setting the data and the header.
130      *
131      * \throws if the header data description does not match the provided data
132      *
133      * \param[in] header mrc density map header
134      * \param[in] data the density map data
135      */
136     MrcDensityMapOfFloatWriter(const MrcDensityMapHeader& header, ArrayRef<const float> data);
137
138     ~MrcDensityMapOfFloatWriter();
139
140     //! Serialize the mrc density data.
141     void write(ISerializer* serializer) const;
142
143 private:
144     class Impl;
145     PrivateImplPointer<Impl> impl_;
146 };
147
148 } // namespace gmx