2 * This file is part of the GROMACS molecular simulation package.
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.
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.
38 * Implements helper function to populate requirements from user input.
40 * \author Paul Bauer <paul.bauer.q@gmail.com>
41 * \ingroup module_coordinateio
46 #include "requirements.h"
50 #include "gromacs/options/basicoptions.h"
51 #include "gromacs/options/filenameoption.h"
52 #include "gromacs/options/ioptionscontainer.h"
53 #include "gromacs/utility/enumerationhelpers.h"
54 #include "gromacs/utility/exceptions.h"
59 //! Mapping for enums from \ref ChangeSettingType.
60 static const EnumerationArray
<ChangeSettingType
, const char*> c_changeSettingTypeNames
= {
61 { "preserved-if-present", "always", "never" }
63 //! Mapping for enums from \ref ChangeAtomsType.
64 static const EnumerationArray
<ChangeAtomsType
, const char*> c_changeAtomsTypeNames
= {
65 { "preserved-if-present", "always-from-structure", "never", "always" }
68 //! Mapping for enums from \ref ChangeFrameInfoType.
69 static const EnumerationArray<ChangeFrameInfoType, const char*> c_changeFrameInfoTypeNames = { {
70 "preserved-if-present", "always" } };
71 //! Mapping for values from \ref ChangeFrameTimeType.
72 static const EnumerationArray<ChangeFrameTimeType, const char*> c_changeFrameTimeTypeNames = { {
73 "preserved-if-present", "starttime", "timestep", "both" } };
76 void OutputRequirementOptionDirector::initOptions(IOptionsContainer
* options
)
78 options
->addOption(EnumOption
<ChangeSettingType
>("vel")
79 .enumValue(c_changeSettingTypeNames
)
81 .description("Save velocities from frame if possible"));
82 options
->addOption(EnumOption
<ChangeSettingType
>("force")
83 .enumValue(c_changeSettingTypeNames
)
85 .description("Save forces from frame if possible"));
87 EnumOption
<ChangeAtomsType
>("atoms").enumValue(c_changeAtomsTypeNames
).store(&atoms_
).description("Decide on providing new atom information from topology or using current frame atom information"));
88 options
->addOption(IntegerOption("precision")
91 .storeIsSet(&setNewPrecision_
)
92 .description("Set output precision to custom value"));
93 options
->addOption(RealOption("starttime")
94 .store(&startTimeValue_
)
95 .defaultValue(startTimeValue_
)
97 .storeIsSet(&setNewStartTime_
)
98 .description("Change start time for first frame"));
99 options
->addOption(RealOption("timestep")
100 .store(&timeStepValue_
)
101 .defaultValue(timeStepValue_
)
103 .storeIsSet(&setNewTimeStep_
)
104 .description("Change time between different frames"));
105 options
->addOption(RealOption("box")
107 .storeVector(&newBoxVector_
)
109 .storeIsSet(&setNewBox_
)
110 .description("New diagonal box vector for output frame"));
113 OutputRequirements
OutputRequirementOptionDirector::process() const
115 OutputRequirements requirements
;
116 /* If the user has just set the values directly without setting the flags,
117 * we set the flags to state that user requested changes are there.*/
120 requirements
.box
= ChangeFrameInfoType::Always
;
121 clear_mat(requirements
.newBox
);
122 for (int i
= 0; i
< DIM
; ++i
)
124 requirements
.newBox
[i
][i
] = newBoxVector_
[i
];
127 if (setNewPrecision_
)
129 requirements
.precision
= ChangeFrameInfoType::Always
;
130 requirements
.prec
= prec_
;
132 if ((setNewTimeStep_
|| setNewStartTime_
))
134 requirements
.startTimeValue
= startTimeValue_
;
135 requirements
.timeStepValue
= timeStepValue_
;
136 if (setNewTimeStep_
&& setNewStartTime_
)
138 requirements
.frameTime
= ChangeFrameTimeType::Both
;
140 else if (setNewTimeStep_
)
142 requirements
.frameTime
= ChangeFrameTimeType::TimeStep
;
146 requirements
.frameTime
= ChangeFrameTimeType::StartTime
;
149 requirements
.atoms
= atoms_
;
150 requirements
.velocity
= velocity_
;
151 requirements
.force
= force_
;