[gmx-developers] IMdpOptionProvider: How to read enum-style options from the .mdp ?
Kutzner, Carsten
ckutzne at gwdg.de
Fri Sep 22 09:15:12 CEST 2017
Thanks to both of you, I got it working!
Carsten
> On 21. Sep 2017, at 16:17, Teemu Murtola <teemu.murtola at gmail.com> wrote:
>
> You don't need to transform the value at all. EnumOption should be able to parse directly a string value. You may want to add something to the transform class to make expressing such a "move-only" transform less verbosely.
>
> Teemu
>
>
> On Thu, Sep 21, 2017, 16:53 Mark Abraham <mark.j.abraham at gmail.com> wrote:
> Hi,
>
> I had a go at that as part of https://gerrit.gromacs.org/c/6485/2/src/gromacs/mdtypes/legacymdp.cpp. Teemu had some initial feedback for me (thanks), but I haven't followed up yet. (We've refactored some of the related stuff since then.)
>
> Basically, I used some adapter functions stringToEnum() and vice-versa. You're using an enum class it seems, but the same kind of approach should still work.
>
> Mark
>
> On Thu, Sep 21, 2017 at 2:50 PM Kutzner, Carsten <ckutzne at gwdg.de> wrote:
> Dear developers,
>
> I want to read in an additional option from the .mdp file that is entered as a string and
> is one of several choices. How should/can such enum-style options be implemented within
> the IMdpOptionProvider framework? An example would be a temperature coupling
> option with possible values
>
> mytcoupl = no ; or andersen, or v-rescale, ...
>
> I have defined
> enum TempCouplType { tc_none, tc_andersen, tc_vrescale };
> const char *const TempCouplDesc[] = { "no", "andersen", "v-rescale" }
>
> The following three methods need to be implemented:
> 1) buildMdpOutput()
> 2) initMdpOptions()
> 3) initMdpTransform()
>
> in (1) I use
> TempCouplType myTcoupl = 1; // e.g.
> builder->addValue<string>("tcoupl", TempCouplDesc[myTcoupl] ); // outputs "tcoupl = andersen" in mdout.mdp
>
> in (2)
> section.addOption(EnumOption<TempCouplType>("mytcoupl").enumValue(TempCouplDesc).store(&myTcoupl));
>
> for (3) at the moment I use the following, which allows me to put _integers_ in the .mdp,
> but not _strings_ as I would like to:
>
> IKeyValueTreeTransformRules *rules;
> rules->addRule().from<string>("mytcoupl").to<int>("/special-section/tcoupl").transformWith(&fromStdString<int>);
>
> Thanks for any hint!
> Carsten
>
>
>
> --
> Gromacs Developers mailing list
>
> * Please search the archive at http://www.gromacs.org/Support/Mailing_Lists/GMX-developers_List before posting!
>
> * Can't post? Read http://www.gromacs.org/Support/Mailing_Lists
>
> * For (un)subscribe requests visit
> https://maillist.sys.kth.se/mailman/listinfo/gromacs.org_gmx-developers or send a mail to gmx-developers-request at gromacs.org.
> --
> Gromacs Developers mailing list
>
> * Please search the archive at http://www.gromacs.org/Support/Mailing_Lists/GMX-developers_List before posting!
>
> * Can't post? Read http://www.gromacs.org/Support/Mailing_Lists
>
> * For (un)subscribe requests visit
> https://maillist.sys.kth.se/mailman/listinfo/gromacs.org_gmx-developers or send a mail to gmx-developers-request at gromacs.org.
> --
> Gromacs Developers mailing list
>
> * Please search the archive at http://www.gromacs.org/Support/Mailing_Lists/GMX-developers_List before posting!
>
> * Can't post? Read http://www.gromacs.org/Support/Mailing_Lists
>
> * For (un)subscribe requests visit
> https://maillist.sys.kth.se/mailman/listinfo/gromacs.org_gmx-developers or send a mail to gmx-developers-request at gromacs.org.
More information about the gromacs.org_gmx-developers
mailing list