view muspinsim_config.xml @ 4:e1e338f56656 draft default tip

planemo upload for repository https://github.com/muon-spectroscopy-computational-project/muon-galaxy-tools/main/muspinsim_config commit 70a4d37ecdf5d586703cfc509922311e95d3205c
author muon-spectroscopy-computational-project
date Tue, 18 Jul 2023 13:26:20 +0000
parents 331d0776abb4
children
line wrap: on
line source

<tool id="muspinsim_config" name="MuSpinSim Configure" version="@MUSPINSIM_VERSION@+galaxy@WRAPPER_VERSION@" python_template_version="3.5" profile="22.05" license="MIT">
    <description>define simulation parameters</description>
    <macros>
        <!-- version of this tool wrapper (integer) -->
        <token name="@WRAPPER_VERSION@">0</token>
        <import>config_macros.xml</import>
        <import>muon_macros.xml</import>
    </macros>
    <creator>
        <person givenName="Anish" familyName="Mudaraddi" identifier="https://orcid.org/0000-0002-2135-2705"/>
        <person givenName="Eli" familyName="Chadwick" url="https://github.com/elichad" identifier="https://orcid.org/0000-0002-0035-6475"/>
        <person givenName="Joel" familyName="Davies" url="https://github.com/joelvdavies" identifier="https://orcid.org/0000-0002-4153-6819"/>
        <organization url="https://muon-spectroscopy-computational-project.github.io/index.html" name="The Muon Spectroscopy Computational Project"/>
    </creator>
    <requirements>
        <requirement type="package" version="@MUSPINSIM_VERSION@">muspinsim</requirement>
    </requirements>
    <required_files>
        <include type="literal" path="sample_fitting_data.dat"/>
        <include type="literal" path="build_file.py"/>
    </required_files>
    <command detect_errors="exit_code"><![CDATA[
        #if $use_structure_file_conditional.use_structure_file == "true":
            #set generator_params = $use_structure_file_conditional.generator
            structure_name_internal=\$(sed 's/ /\_/g' <<< '$generator_params.structure_file.name') &&
            ln -s '$generator_params.structure_file' \$structure_name_internal &&
            muspinsim-gen \$structure_name_internal $generator_params.number_closest --out muspinsim_gen_out.in
            $generator_params.dipolar
            $generator_params.quadrupolar
            $generator_params.include_interatomic
            --muon_symbol $generator_params.muon_symbol
            #for $ignored_symbol in $generator_params.ignored_symbols:
            --ignore_symbol $ignored_symbol.ignored_symbol
            #end for
            &&
        #end if
        cp '${__tool_directory__}/sample_fitting_data.dat' ./fitting_data.dat &&
        python '${__tool_directory__}/build_file.py' inputs.json
    ]]></command>
    <configfiles>
        <inputs name="inputs" data_style="paths" filename="inputs.json"/>
    </configfiles>
    <inputs>
        <param name="out_file_prefix" type="text" label="Name" help="A name with which to label this configuration" optional="true" value="muspinsim"/>
        <conditional name="use_structure_file_conditional">
            <param name="use_structure_file" type="select" display="radio" value="false" label="Generate interactions from a file?" help="Use a file containing a structure to obtain the spins and generate interactions.">
                <option value="true">Yes</option>
                <option value="false" selected="true">No</option>
            </param>
            <when value="true">
                <section name="generator" expanded="true" title="Generator">
                    <expand macro="generator_options"/>
                </section>
                <section name="spins" expanded="true" title="Additional Spins">
                    <expand macro="additional_spin_options"/>
                </section>
                <section name="interaction_params" expanded="true" title="Additional Spin Interactions" help="Use this section to include any interactions that are not automatically generated from the structure file. The muon index will always be 1, then the rest of the requested number of spins, N, will be in order of distance to the muon (excluding any ignored symbols). So any spins added above will have indices starting at N + 2.">
                    <expand macro="interaction_options"/>
                </section>
            </when>
            <when value="false">
                <section name="spins" expanded="true" title="Spins">
                    <expand macro="spin_options"/>
                </section>
                <section name="interaction_params" expanded="true" title="Spin Interactions" help="">
                    <expand macro="interaction_options"/>
                </section>
            </when>
        </conditional>
        <section name="experiment_params" expanded="true" title="Experiment Parameters">
            <conditional name="experiment">
                <param name="experiment_preset" type="select" value="custom" display="radio" label="Experiment type" help="Experiment preset to use. Avoided Level Crossing (ALC): sets polarization to longitudinal, x-axis to field and y-axis to integral. Zero field: sets polarization to transverse, field to 0, x-axis to time and y-axis to asymmetry. Choose custom for no preset">
                    <option value="alc">Avoided Level Crossing (ALC)</option>
                    <option value="zero_field">Zero Field</option>
                    <option selected="true" value="custom">Custom</option>
                </param>
                <when value="alc">
                    <expand macro="restricted_axes_options"/>
                    <expand macro="fields"/>
                    <expand macro="temperatures"/>
                    <expand macro="orientations"/>
                    <expand macro="euler_convention"/>
                </when>
                <when value="zero_field">
                    <expand macro="restricted_axes_options"/>
                    <expand macro="times"/>
                    <expand macro="temperatures"/>
                    <expand macro="orientations"/>
                    <expand macro="euler_convention"/>
                    <expand macro="celio_options"/>
                </when>
                <when value="custom">
                    <expand macro="axes_options"/>
                    <expand macro="times"/>
                    <expand macro="fields"/>
                    <expand macro="intrinsic_fields"/>
                    <expand macro="temperatures"/>
                    <expand macro="polarizations"/>
                    <expand macro="orientations"/>
                    <expand macro="euler_convention"/>
                    <expand macro="celio_options"/>
                </when>
            </conditional>
        </section>
        <section name="fitting_params" expanded="true" title="Fitting Parameters">
            <conditional name="fitting_options">
                <param name="fitting" type="select" display="radio" optional="false" value="" label="Fit experimental data with simulations" help="Fitting requires a file with data to fit. File must be given in MuSpinSim tool, or by manually setting filepath for keyword 'fitting_data' if running MuSpinSim externally">
                    <option value="true">Yes</option>
                    <option selected="true" value="">No</option>
                </param>
                <when value="true">
                    <param name="fitting_method" type="select" display="radio" optional="false" value="nelder-mead" label="Method to use to fit the data" help="See the help section for a description of each method">
                        <option selected="true" value="nelder-mead">Nelder-Mead</option>
                        <option value="lbfgs">L-BFGS</option>
                    </param>
                    <repeat name="fitting_variables" title="Variable to fit to the experimental data">
                        <param name="var_name" type="text" optional="false" label="Name of the variable"/>
                        <param name="start_val" type="text" value="0" label="Starting value" help="Allows default expressions, constants and functions, plus MHz, muon_gyr constants. Cannot contain names of other variables"/>
                        <param name="min_bound" type="text" value="-inf" label="minimum bound" help="Allows default expressions, constants and functions, plus MHz, muon_gyr constants"/>
                        <param name="max_bound" type="text" value="inf" label="maximum bound" help="Allows default expressions, constants and functions, plus MHz, muon_gyr constants"/>
                    </repeat>
                    <param name="fitting_tolerance" type="float" optional="true" value="" label="Fitting Tolerance" help="Used as the tol parameter in Scipy's scipy.optimize.minimize method. Will use scipy defaults if left blank. Does not accept expressions/functions/constants"/>
                </when>
                <when value=""/>
            </conditional>
        </section>
    </inputs>
    <outputs>
        <data format="txt" label="muspinsim input file $out_file_prefix" name="out_file" from_work_dir="outfile.in"/>
    </outputs>
    <tests>
        <test expect_num_outputs="1">
            <param name="out_file_prefix" value="test_1"/>
            <param name="use_structure_file" value="false"/>
            <param name="spin_preset" value="custom"/>
            <param name="spin" value="H"/>
            <param name="spin_preset" value="mu"/>
            <param name="interaction" value="zeeman"/>
            <param name="zeeman_index" value="1"/>
            <param name="zeeman_vector" value="1 0 0"/>
            <param name="zeeman_index" value="2"/>
            <param name="zeeman_vector" value="2 0 0"/>
            <param name="y_axis" value="asymmetry"/>
            <param name="x_axis" value="time"/>
            <param name="average_axes" value="orientation"/>
            <output name="out_file" file="test_1.in" ftype="txt" compare="diff"/>
        </test>
        <test expect_num_outputs="1">
            <param name="out_file_prefix" value="test_2"/>
            <param name="use_structure_file" value="false"/>
            <param name="experiment_preset" value="custom"/>
            <param name="spin_preset" value="e"/>
            <param name="spin_preset" value="mu"/>
            <param name="interaction" value="hyperfine"/>
            <param name="hfine_index" value="1"/>
            <param name="hfine_matrix" value="[1 0 0 sin(10) (5*2) 0 10*pi 5 cos(20)]"/>
            <param name="time" value="range(0, 0.1)"/>
            <param name="y_axis" value="asymmetry"/>
            <param name="x_axis" value="time"/>
            <param name="field" value="1.0"/>
            <param name="temperature" value="1.0"/>
            <output name="out_file" file="test_2.in" ftype="txt" compare="diff"/>
        </test>
        <test expect_num_outputs="1">
            <param name="out_file_prefix" value="test_3"/>
            <param name="use_structure_file" value="false"/>
            <param name="spin_preset" value="custom"/>
            <param name="spin" value="H"/>
            <param name="spin_preset" value="mu"/>
            <param name="spin_preset" value="e"/>
            <param name="interaction" value="hyperfine"/>
            <param name="hfine_index" value="2"/>
            <param name="hfine_matrix" value="[580 5  10 5   580 9 10  9   580]"/>
            <param name="interaction" value="hyperfine"/>
            <param name="hfine_index" value="3"/>
            <param name="hfine_matrix" value="[(300/2)  3   4*10 ], [3  15*10 6-3+2]  ,[4  5   15 ]"/>
            <param name="average_axes" value="orientation,temperature"/>
            <param name="experiment_preset" value="alc"/>
            <param name="field" value="range(1.8, 2.6, 100)"/>
            <param name="orientation_preset" value="zcw"/>
            <param name="zcw_n" value="20"/>
            <output name="out_file" file="test_3.in" ftype="txt" compare="diff"/>
        </test>
        <test expect_num_outputs="1">
            <param name="out_file_prefix" value="test_4"/>
            <param name="use_structure_file" value="false"/>
            <param name="spin_preset" value="custom"/>
            <param name="spin" value="F"/>
            <param name="spin_preset" value="custom"/>
            <param name="spin" value="F"/>
            <param name="spin_preset" value="mu"/>
            <param name="interaction" value="dipolar"/>
            <param name="di_index" value="1"/>
            <param name="di_index_2" value="2"/>
            <param name="di_vector" value="0.9 0.9 0"/>
            <param name="interaction" value="dipolar"/>
            <param name="di_index" value="1"/>
            <param name="di_index_2" value="3"/>
            <param name="di_vector" value="-0.9 -0.9 0"/>
            <param name="interaction" value="dissipation"/>
            <param name="dis_index" value="1"/>
            <param name="dis_val" value="0.5"/>
            <param name="average_axes" value=""/>
            <param name="experiment_preset" value="custom"/>
            <param name="field" value="1.5e-2 1.0e-2 1.0e-2"/>
            <param name="field" value="0.01"/>
            <param name="intrinsic_field" value="1.6e-2 1.1e-2 1.1e-2"/>
            <param name="intrinsic_field" value="0.02"/>
            <param name="polarization_preset" value="custom"/>
            <param name="polarization" value="1 0 0"/>
            <param name="time" value="range(0,8.0,1000)"/>
            <param name="time" value="range(0,1.0)"/>
            <param name="orientation_preset" value="eulrange"/>
            <param name="eul_n" value="10"/>
            <param name="celio_enabled" value="true"/>
            <param name="celio_k" value="10"/>
            <output name="out_file" file="test_4.in" ftype="txt" compare="diff"/>
        </test>
        <test expect_num_outputs="1">
            <param name="out_file_prefix" value="test_5"/>
            <param name="use_structure_file" value="false"/>
            <param name="spin_preset" value="mu"/>
            <param name="interaction" value="dissipation"/>
            <param name="dis_index" value="1"/>
            <param name="dis_val" value="g"/>
            <param name="experiment_preset" value="custom"/>
            <param name="field" value="1.0/muon_gyr"/>
            <param name="intrinsic_field" value="2.0/muon_gyr"/>
            <param name="fitting" value="true"/>
            <param name="var_name" value="g"/>
            <param name="min_bound" value="0.0"/>
            <param name="fitting_tolerance" value="1.0"/>
            <param name="celio_enabled" value="true"/>
            <param name="celio_k" value="10"/>
            <param name="celio_averages" value="4"/>
            <output name="out_file" file="test_5.in" ftype="txt" compare="diff"/>
        </test>
        <test expect_num_outputs="1">
            <param name="out_file_prefix" value="test_6"/>
            <param name="use_structure_file" value="false"/>
            <param name="experiment_preset" value="zero_field"/>
            <param name="spin_preset" value="custom"/>
            <param name="spin" value="H"/>
            <param name="spin_preset" value="mu"/>
            <param name="interaction" value="zeeman"/>
            <param name="zeeman_index" value="1"/>
            <param name="zeeman_vector" value="1 0 0"/>
            <param name="zeeman_index" value="2"/>
            <param name="zeeman_vector" value="2 0 0"/>
            <param name="average_axes" value="orientation,temperature"/>
            <output name="out_file" file="test_6.in" ftype="txt" compare="diff"/>
        </test>
        <test expect_num_outputs="1">
            <param name="out_file_prefix" value="test_7"/>
            <param name="use_structure_file" value="false"/>
            <param name="experiment_preset" value="custom"/>
            <param name="spin_preset" value="custom"/>
            <param name="spin" value="H"/>
            <param name="spin_preset" value="mu"/>
            <param name="interaction" value="zeeman"/>
            <param name="zeeman_index" value="1"/>
            <param name="zeeman_vector" value="1 0 0"/>
            <param name="zeeman_index" value="2"/>
            <param name="zeeman_vector" value="2 0 0"/>
            <param name="y_axis" value="integral"/>
            <param name="x_axis" value="field"/>
            <param name="average_axes" value="orientation,temperature"/>
            <output name="out_file" file="test_7.in" ftype="txt" compare="diff"/>
        </test>
        <!-- The tests below use a structure file to generate interactions -->

        <!-- Default generator values with cell file -->
        <test expect_num_outputs="1">
            <param name="out_file_prefix" value="test_8"/>
            <param name="use_structure_file" value="true"/>
            <param name="structure_file" value="Basic.cell" ftype="cell"/>
            <param name="experiment_preset" value="custom"/>
            <param name="time" value="range(0,8.0,1000)"/>
            <output name="out_file" file="test_8.in" ftype="txt" compare="diff"/>
        </test>
        <!-- Magres file -->
        <test expect_num_outputs="1">
            <param name="out_file_prefix" value="test_9"/>
            <param name="use_structure_file" value="true"/>
            <param name="structure_file" value="Basic.magres" ftype="cell"/>
            <param name="number_closest" value="8"/>
            <param name="dipolar" value="true"/>
            <param name="quadrupolar" value="false"/>
            <param name="ignored_symbol" value="Si"/>
            <param name="include_interatomic" value="false"/>
            <param name="experiment_preset" value="custom"/>
            <param name="time" value="range(0,8.0,1000)"/>
            <output name="out_file" file="test_9.in" ftype="txt" compare="diff"/>
        </test>
        <!-- Magres file with quadrupolar and interatomic -->
        <test expect_num_outputs="1">
            <param name="out_file_prefix" value="test_10"/>
            <param name="use_structure_file" value="true"/>
            <param name="structure_file" value="Basic.magres" ftype="cell"/>
            <param name="dipolar" value="true"/>
            <param name="quadrupolar" value="true"/>
            <param name="ignored_symbol" value="Si"/>
            <param name="include_interatomic" value="true"/>
            <param name="experiment_preset" value="custom"/>
            <param name="time" value="range(0,8.0,1000)"/>
            <output name="out_file" file="test_10.in" ftype="txt" compare="diff"/>
        </test>
        <!-- Magres file with quadrupolar, and extra interactions as well -->
        <test expect_num_outputs="1">
            <param name="out_file_prefix" value="test_11"/>
            <param name="use_structure_file" value="true"/>
            <param name="structure_file" value="Basic.magres" ftype="cell"/>
            <param name="dipolar" value="true"/>
            <param name="quadrupolar" value="true"/>
            <param name="ignored_symbol" value="Si"/>
            <param name="include_interatomic" value="false"/>
            <param name="interaction" value="hyperfine"/>
            <param name="hfine_index" value="2"/>
            <param name="hfine_matrix" value="[580 5  10 5   580 9 10  9   580]"/>
            <param name="interaction" value="hyperfine"/>
            <param name="hfine_index" value="3"/>
            <param name="hfine_matrix" value="[(300/2)  3   4*10 ], [3  15*10 6-3+2]  ,[4  5   15 ]"/>
            <param name="experiment_preset" value="custom"/>
            <param name="time" value="range(0,8.0,1000)"/>
            <output name="out_file" file="test_11.in" ftype="txt" compare="diff"/>
        </test>
        <!-- Test adding extra spins -->
        <test expect_num_outputs="1">
            <param name="out_file_prefix" value="test_12"/>
            <param name="use_structure_file" value="true"/>
            <param name="structure_file" value="Basic.magres" ftype="cell"/>
            <param name="dipolar" value="true"/>
            <param name="quadrupolar" value="true"/>
            <param name="ignored_symbol" value="Si"/>
            <param name="include_interatomic" value="false"/>
            <param name="spin_preset" value="e"/>
            <param name="spin_preset" value="custom"/>
            <param name="spin" value="F"/>
            <param name="atomic_mass" value="19"/>
            <param name="interaction" value="hyperfine"/>
            <param name="hfine_index" value="2"/>
            <param name="hfine_matrix" value="[580 5  10 5   580 9 10  9   580]"/>
            <param name="interaction" value="hyperfine"/>
            <param name="hfine_index" value="3"/>
            <param name="hfine_matrix" value="[(300/2)  3   4*10 ], [3  15*10 6-3+2]  ,[4  5   15 ]"/>
            <param name="experiment_preset" value="custom"/>
            <param name="time" value="range(0,8.0,1000)"/>
            <output name="out_file" file="test_12.in" ftype="txt" compare="diff"/>
        </test>
    </tests>
    <help><![CDATA[
    Tool to create input parameter file for MuSpinSim.


    This tool creates a structured text file with keywords and values which describe the system to model for MuSpinSim.
    See MuSpinSim docs for more information https://muon-spectroscopy-computational-project.github.io/muspinsim/input/.


    MuSpinSim allows expressions and special functions to be used when defining certain keywords. This tool also allows this.
    Check the hint at the bottom of each input to see what, if any, special function or expressions can be used.


    Default expressions include the use of the operators :code:`+ - * /` and :code:`^` for exponentiation. Expressions
    should not contain whitespace. For example, use :code:`1+2` not :code:`1 + 2`.


    Default constants include:
        - :code:`pi`: ratio of a circle and its diameter
        - :code:`e`: base of the natural logarithm
        - :code:`deg`: conversion factor between radians and degrees, equivalent to 180/pi
        - :code:`inf`: infinity

    Special constants include:
        - :code:`muon_gyr`: gyromagnetic ratio of muon (135.5388 MHz/T)
        - :code:`MHz`: :code:`1/(2*muon_gyr)`


    Default functions include:
        - :code:`sin(x)`: sine
        - :code:`cos(x)`: cosine
        - :code:`tan(x)`: tangent
        - :code:`arcsin(x)`: inverse of the sine
        - :code:`arccos(x)`: inverse of the cosine
        - :code:`arctan(x)`: inverse of the tangent
        - :code:`arctan2(y, x)`: inverse of the tangent taking two arguments as (sine, cosine) to resolve the quadrant
        - :code:`exp(x)`: exponential with base e
        - :code:`log(x)`: natural logarithm
        - :code:`sqrt(x)`: square root

    Special functions include:
        - :code:`range(x, y, z)`: get z equally spaced values between x and y
        - :code:`zcw(n)`: Zaremba-Conroy-Wolfsberg helper function
        - :code:`eulrange(n)`: helper function to create regular grid of n × n × n Euler angles with appropriate weights.


    To enter vectors or matrices the following formats are accepted:
        - :code:`[[1, 2, 3], [4, 5, 6], [7, 8, 9]]`
        - :code:`1 2 3 4 5 6 7 8 9`
        - :code:`[1 2 3] [4 5 6] [7 8 9]`


    The fitting (function minimization) algorithms available are:


    Nelder-Mead
        - A direct search method.
        - Starting with a 'simplex' of candidates, the algorithm will iteratively move the position of the worst candidate towards the optimum until all candidates converge (have values within a predefined tolerance level).
        - Scipy default tolerance is :code:`1e-4`


    L-BFGS
        - Limited Memory Broyden–Fletcher–Goldfarb–Shanno algorithm.
        - A second-order Quasi-Newton optimization algorithm
        - Makes use of second-order derivative (Hessian Matrix) to converge on optimum.
        - Scipy default tolerance is :code:`1e-5`
    ]]></help>
    <citations>
        <citation type="doi">10.1093/comjnl/7.4.308</citation>
        <citation type="bibtex">
            @book{nocedal_wright_2006,
                place={New York (NY)},
                title={Numerical Optimization},
                publisher={Springer},
                author={Nocedal, Jorge and Wright, Stephen J},
                year={2006}
            }
        </citation>
        <citation type="doi">10.1103/PhysRevLett.56.2720</citation>
        <citation type="doi">@MUSPINSIM_CITATION@</citation>
    </citations>
</tool>