Add replacements for pbc enumerations
[gromacs.git] / src / gromacs / math / coordinatetransformation.cpp
blob6d057d4c6790c978fe8834de968ecc02c74f6021
1 /*
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 /*! \internal \file
36 * \brief Implements coordinate transformation routines.
38 * \author Christian Blau <blau@kth.se>
40 #include "gmxpre.h"
42 #include "coordinatetransformation.h"
44 #include <vector>
46 #include "gromacs/math/vec.h"
48 namespace gmx
50 /********************************************************************
51 * ScaleCoordinates::Impl
54 class ScaleCoordinates::Impl
56 public:
57 Impl(const RVec &scale);
58 void inverseIgnoringZeroScale(ArrayRef<RVec> coordinates) const;
59 void scale(ArrayRef<RVec> coordinates) const;
60 private:
61 RVec scale_;
63 ScaleCoordinates::Impl::Impl(const RVec &scale) : scale_ { scale }
67 void ScaleCoordinates::Impl::scale(ArrayRef<RVec> coordinates) const
69 for (auto &coordinate : coordinates)
71 coordinate[XX] *= scale_[XX];
72 coordinate[YY] *= scale_[YY];
73 coordinate[ZZ] *= scale_[ZZ];
77 void ScaleCoordinates::Impl::inverseIgnoringZeroScale(ArrayRef<RVec> coordinates) const
79 RVec inverseScale;
80 for (int dimension = XX; dimension <= ZZ; ++dimension)
82 inverseScale[dimension] = scale_[dimension] != 0 ? 1. / scale_[dimension] : 1.;
85 for (auto &coordinate : coordinates)
87 coordinate[XX] *= inverseScale[XX];
88 coordinate[YY] *= inverseScale[YY];
89 coordinate[ZZ] *= inverseScale[ZZ];
93 /********************************************************************
94 * ScaleCoordinates
97 ScaleCoordinates::ScaleCoordinates(const RVec &scale) : impl_ {new Impl(scale)}
102 void ScaleCoordinates::operator()(ArrayRef<RVec> coordinates) const
104 impl_->scale(coordinates);
107 void ScaleCoordinates::inverseIgnoringZeroScale(ArrayRef<RVec> coordinates) const
109 impl_->inverseIgnoringZeroScale(coordinates);
112 ScaleCoordinates::~ScaleCoordinates() = default;
114 ScaleCoordinates::ScaleCoordinates(const ScaleCoordinates &other)
115 : impl_(new Impl(*other.impl_))
119 ScaleCoordinates &ScaleCoordinates::operator=(const ScaleCoordinates &other)
121 *impl_ = *other.impl_;
122 return *this;
125 ScaleCoordinates::ScaleCoordinates(ScaleCoordinates &&) noexcept = default;
127 ScaleCoordinates &ScaleCoordinates::operator=(ScaleCoordinates &&) noexcept = default;
129 /********************************************************************
130 * TranslateAndScale::Impl
133 class TranslateAndScale::Impl
135 public:
136 Impl(const RVec &scale, const RVec &translation);
137 void transform(ArrayRef<RVec> coordinates) const;
138 RVec scale_;
139 RVec translation_;
142 TranslateAndScale::Impl::Impl(const RVec &scale, const RVec &translation) :
143 scale_ {scale}, translation_ {
144 translation
149 void TranslateAndScale::Impl::transform(ArrayRef<RVec> coordinates) const
151 for (auto &coordinate : coordinates)
153 coordinate += translation_;
154 coordinate[XX] *= scale_[XX];
155 coordinate[YY] *= scale_[YY];
156 coordinate[ZZ] *= scale_[ZZ];
161 /********************************************************************
162 * TranslateAndScale
165 TranslateAndScale::TranslateAndScale(const RVec &scale, const RVec &translation) :
166 impl_(new Impl(scale, translation))
170 void TranslateAndScale::operator()(ArrayRef<RVec> coordinates) const
172 impl_->transform(coordinates);
175 ScaleCoordinates TranslateAndScale::scaleOperationOnly() const
177 return ScaleCoordinates {
178 impl_->scale_
182 TranslateAndScale::~TranslateAndScale() = default;
184 TranslateAndScale::TranslateAndScale(const TranslateAndScale &other)
185 : impl_(new Impl(*other.impl_))
189 TranslateAndScale &TranslateAndScale::operator=(const TranslateAndScale &other)
191 *impl_ = *other.impl_;
192 return *this;
195 TranslateAndScale::TranslateAndScale(TranslateAndScale &&) noexcept = default;
197 TranslateAndScale &TranslateAndScale::operator=(TranslateAndScale &&) noexcept = default;
200 } // namespace gmx