Introduce SimulatorBuilder
[gromacs.git] / src / gromacs / coordinateio / requirements.cpp
blob6bf2a4303e05221b8969a91cdfd36a468efc6912
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
36 * \file
37 * \brief
38 * Implements helper function to populate requirements from user input.
40 * \author Paul Bauer <paul.bauer.q@gmail.com>
41 * \ingroup module_coordinateio
44 #include "gmxpre.h"
46 #include "requirements.h"
48 #include <algorithm>
50 #include "gromacs/options/basicoptions.h"
51 #include "gromacs/options/filenameoption.h"
52 #include "gromacs/options/ioptionscontainer.h"
53 #include "gromacs/utility/exceptions.h"
55 namespace gmx
58 void
59 OutputRequirementOptionDirector::initOptions(IOptionsContainer *options)
61 options->addOption(EnumOption<ChangeSettingType>("vel")
62 .enumValue(cChangeSettingTypeEnum)
63 .store(&velocity_)
64 .description("Save velocities from frame if possible"));
65 options->addOption(EnumOption<ChangeSettingType>("force")
66 .enumValue(cChangeSettingTypeEnum)
67 .store(&force_)
68 .description("Save forces from frame if possible"));
69 options->addOption(EnumOption<ChangeAtomsType>("atoms")
70 .enumValue(cChangeAtomsTypeEnum)
71 .store(&atoms_)
72 .description("Decide on providing new atom information from topology or using current frame atom information"));
73 options->addOption(IntegerOption("precision")
74 .store(&prec_)
75 .defaultValue(prec_)
76 .storeIsSet(&setNewPrecision_)
77 .description("Set output precision to custom value"));
78 options->addOption(RealOption("starttime")
79 .store(&startTimeValue_)
80 .defaultValue(startTimeValue_)
81 .timeValue()
82 .storeIsSet(&setNewStartTime_)
83 .description("Change start time for first frame"));
84 options->addOption(RealOption("timestep")
85 .store(&timeStepValue_)
86 .defaultValue(timeStepValue_)
87 .timeValue()
88 .storeIsSet(&setNewTimeStep_)
89 .description("Change time between different frames"));
90 options->addOption(RealOption("box")
91 .vector()
92 .storeVector(&newBoxVector_)
93 .valueCount(3)
94 .storeIsSet(&setNewBox_)
95 .description("New diagonal box vector for output frame"));
98 OutputRequirements
99 OutputRequirementOptionDirector::process() const
101 OutputRequirements requirements;
102 /* If the user has just set the values directly without setting the flags,
103 * we set the flags to state that user requested changes are there.*/
104 if (setNewBox_)
106 requirements.box = ChangeFrameInfoType::Always;
107 clear_mat(requirements.newBox);
108 for (int i = 0; i < DIM; ++i)
110 requirements.newBox[i][i] = newBoxVector_[i];
113 if (setNewPrecision_)
115 requirements.precision = ChangeFrameInfoType::Always;
116 requirements.prec = prec_;
118 if ((setNewTimeStep_ || setNewStartTime_))
120 requirements.startTimeValue = startTimeValue_;
121 requirements.timeStepValue = timeStepValue_;
122 if (setNewTimeStep_ && setNewStartTime_)
124 requirements.frameTime = ChangeFrameTimeType::Both;
126 else if (setNewTimeStep_)
128 requirements.frameTime = ChangeFrameTimeType::TimeStep;
130 else
132 requirements.frameTime = ChangeFrameTimeType::StartTime;
135 requirements.atoms = atoms_;
136 requirements.velocity = velocity_;
137 requirements.force = force_;
138 return requirements;
141 } // namespace gmx