2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014,2017,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.
37 * Implements classes in dataframe.h.
39 * \author Teemu Murtola <teemu.murtola@gmail.com>
40 * \ingroup module_analysisdata
44 #include "dataframe.h"
46 #include "gromacs/utility/gmxassert.h"
51 /********************************************************************
52 * AnalysisDataFrameHeader
55 AnalysisDataFrameHeader::AnalysisDataFrameHeader() : index_(-1), x_(0.0), dx_(0.0) {}
58 AnalysisDataFrameHeader::AnalysisDataFrameHeader(int index
, real x
, real dx
) :
63 GMX_ASSERT(index
>= 0, "Invalid frame index");
67 /********************************************************************
68 * AnalysisDataPointSetRef
71 AnalysisDataPointSetRef::AnalysisDataPointSetRef(const AnalysisDataFrameHeader
& header
,
72 const AnalysisDataPointSetInfo
& pointSetInfo
,
73 const AnalysisDataValuesRef
& values
) :
75 dataSetIndex_(pointSetInfo
.dataSetIndex()),
76 firstColumn_(pointSetInfo
.firstColumn()),
77 values_(constArrayRefFromArray(&*values
.begin() + pointSetInfo
.valueOffset(), pointSetInfo
.valueCount()))
79 GMX_ASSERT(header_
.isValid(), "Invalid point set reference should not be constructed");
83 AnalysisDataPointSetRef::AnalysisDataPointSetRef(const AnalysisDataFrameHeader
& header
,
84 const std::vector
<AnalysisDataValue
>& values
) :
90 GMX_ASSERT(header_
.isValid(), "Invalid point set reference should not be constructed");
94 AnalysisDataPointSetRef::AnalysisDataPointSetRef(const AnalysisDataPointSetRef
& points
,
97 header_(points
.header()),
98 dataSetIndex_(points
.dataSetIndex()),
101 GMX_ASSERT(firstColumn
>= 0, "Invalid first column");
102 GMX_ASSERT(columnCount
>= 0, "Invalid column count");
103 if (points
.lastColumn() < firstColumn
|| points
.firstColumn() >= firstColumn
+ columnCount
108 AnalysisDataValuesRef::const_iterator begin
= points
.values().begin();
109 int pointsOffset
= firstColumn
- points
.firstColumn();
110 if (pointsOffset
> 0)
112 // Offset pointer if the first column is not the first in points.
113 begin
+= pointsOffset
;
117 // Take into account if first column is before the first in points.
118 firstColumn_
= -pointsOffset
;
119 columnCount
-= -pointsOffset
;
121 // Decrease column count if there are not enough columns in points.
122 AnalysisDataValuesRef::const_iterator end
= begin
+ columnCount
;
123 if (pointsOffset
+ columnCount
> points
.columnCount())
125 end
= points
.values().end();
127 values_
= AnalysisDataValuesRef(begin
, end
);
131 bool AnalysisDataPointSetRef::allPresent() const
133 AnalysisDataValuesRef::const_iterator i
;
134 for (i
= values_
.begin(); i
!= values_
.end(); ++i
)
145 /********************************************************************
146 * AnalysisDataFrameRef
149 AnalysisDataFrameRef::AnalysisDataFrameRef() {}
152 AnalysisDataFrameRef::AnalysisDataFrameRef(const AnalysisDataFrameHeader
& header
,
153 const AnalysisDataValuesRef
& values
,
154 const AnalysisDataPointSetInfosRef
& pointSets
) :
157 pointSets_(pointSets
)
159 GMX_ASSERT(!pointSets_
.empty(), "There must always be a point set");
163 AnalysisDataFrameRef::AnalysisDataFrameRef(const AnalysisDataFrameHeader
& header
,
164 const std::vector
<AnalysisDataValue
>& values
,
165 const std::vector
<AnalysisDataPointSetInfo
>& pointSets
) :
168 pointSets_(pointSets
)
170 GMX_ASSERT(!pointSets_
.empty(), "There must always be a point set");
174 AnalysisDataFrameRef::AnalysisDataFrameRef(const AnalysisDataFrameRef
& frame
, int firstColumn
, int columnCount
) :
175 header_(frame
.header()),
176 values_(constArrayRefFromArray(&frame
.values_
[firstColumn
], columnCount
)),
177 pointSets_(frame
.pointSets_
)
179 // FIXME: This doesn't produce a valid internal state, although it does
180 // work in some cases. The point sets cannot be correctly managed here, but
181 // need to be handles by the data proxy class.
182 GMX_ASSERT(firstColumn
>= 0, "Invalid first column");
183 GMX_ASSERT(columnCount
>= 0, "Invalid column count");
184 GMX_ASSERT(pointSets_
.size() == 1U, "Subsets of frames only supported with simple data");
185 GMX_ASSERT(firstColumn
+ columnCount
<= ssize(values_
), "Invalid last column");
189 bool AnalysisDataFrameRef::allPresent() const
191 GMX_ASSERT(isValid(), "Invalid data frame accessed");
192 AnalysisDataValuesRef::const_iterator i
;
193 for (i
= values_
.begin(); i
!= values_
.end(); ++i
)