Introduce SimulatorBuilder
[gromacs.git] / src / gromacs / coordinateio / outputadapters / outputselector.h
blob0f1a854f3c84943402dae3da522a8e1ddfde975e
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 /*! \file
36 * \brief
37 * Declares gmx::OutputSelector.
39 * \author Paul Bauer <paul.bauer.q@gmail.com>
40 * \inpublicapi
41 * \ingroup module_coordinateio
43 #ifndef GMX_COORDINATEIO_OUTPUTSELECTOR_H
44 #define GMX_COORDINATEIO_OUTPUTSELECTOR_H
46 #include <algorithm>
48 #include "gromacs/coordinateio/ioutputadapter.h"
49 #include "gromacs/selection/selectionoption.h"
50 #include "gromacs/topology/atoms.h"
52 namespace gmx
55 /*!\brief
56 * OutputSelector class controls setting which coordinates are actually written.
58 * This adapter selects a subset of the particles and their data for output.
59 * The subset is specified via a selection object (see \ref module_selection).
60 * The corresponding particle data (coordinates, velocities, forces) and
61 * topology information is copied from as available from the input data.
63 * \inpublicapi
64 * \ingroup module_coordinateio
67 class OutputSelector : public IOutputAdapter
69 public:
70 /*! \brief
71 * Construct OutputSelector object with initial selection.
73 * Can be used to initialize OutputSelector from outside of trajectoryanalysis
74 * framework.
76 explicit OutputSelector(const Selection &sel) :
77 sel_(sel), selectionAtoms_(nullptr)
79 GMX_RELEASE_ASSERT(sel.isValid() && sel.hasOnlyAtoms(),
80 "Need a valid selection out of simple atom indices");
82 /*! \brief
83 * Move assignment constructor for OutputSelector.
85 OutputSelector(OutputSelector &&old) noexcept = default;
87 ~OutputSelector() override {}
89 /*! \brief
90 * Change coordinate frame information for output.
92 * Takes the previously internally stored coordinates and saves them again.
93 * Applies correct number of atoms in this case.
95 * \param[in] input Coordinate frame to be modified later.
97 void processFrame(int /*framenumber*/, t_trxframe *input) override;
99 void checkAbilityDependencies(unsigned long /* abilities */) const override {}
101 private:
103 /*! \brief
104 * Selection of atoms that will be written to disk.
106 * Internal selection of atoms chosen by the user that will be written
107 * to disk during processing.
109 const Selection &sel_;
110 /*! \brief
111 * Local storage of modified atoms.
113 * When selection input information, we might will have to adjust the
114 * atoms content to match the new output. To perform this, we keep track
115 * of modified atoms information in this object that is not used by default.
117 AtomsDataPtr selectionAtoms_;
118 //! Local storage for coordinates
119 std::vector<RVec> localX_;
120 //! Local storage for velocities
121 std::vector<RVec> localV_;
122 //! Local storage for forces
123 std::vector<RVec> localF_;
124 //! Local storage for atom indices
125 std::vector<int> localIndex_;
128 //! Smart pointer to manage the object.
129 using OutputSelectorPointer = std::unique_ptr<OutputSelector>;
131 } // namespace gmx
133 #endif