changeset 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
files build_file.py config_macros.xml muon_macros.xml muspinsim_config.xml test-data/Basic.cell test-data/Basic.magres test-data/muspinsim_gen_template.in test-data/test_10.in test-data/test_11.in test-data/test_12.in test-data/test_8.in test-data/test_9.in
diffstat 12 files changed, 653 insertions(+), 91 deletions(-) [+]
line wrap: on
line diff
--- a/build_file.py	Fri Feb 03 15:39:07 2023 +0000
+++ b/build_file.py	Tue Jul 18 13:26:20 2023 +0000
@@ -1,6 +1,7 @@
 import json
 import re
 import sys
+from typing import List
 
 from muspinsim import MuSpinInput
 
@@ -395,21 +396,63 @@
     return err_found
 
 
+def append_template_file(
+    template_path: str,
+    mu_params: dict,
+    file_contents: List[str]
+):
+    """
+    Loads an input file generated using muspinsim-gen and appends its contents
+    to what has already been created from config. Also ensures that the spins
+    are appended correctly.
+    """
+    # Check if we have already defined spins in the file
+    spins_line = None
+    spins_line_index = None
+    if ("spins" in mu_params):
+        # Find the current line definition in the file
+        # In the format 'spins\n e\n'
+        for i, line in enumerate(file_contents):
+            if line.startswith("spins"):
+                spins_line = line.split("\n")[1].strip()
+                spins_line_index = i
+        if spins_line_index is not None:
+            del file_contents[spins_line_index]
+
+    # Append the template file's contents
+    with open(template_path, encoding="utf-8") as template_file:
+        for line in template_file:
+            # Append the spins if needed
+            if line.startswith("spins") and spins_line is not None:
+                next_line = template_file.readline().strip()
+                file_contents += f"spins\n    {next_line} {spins_line}\n"
+            else:
+                file_contents += line
+
+
 def main():
     """
     Entry point
     """
     input_json_path = sys.argv[1]
-    mu_params = json.load(open(input_json_path, "r", encoding="utf-8"))
+    mu_input_params = json.load(open(input_json_path, "r", encoding="utf-8"))
+
+    out_file_name = mu_input_params["out_file_prefix"].strip().replace(
+        " ", "_")
 
-    out_file_name = mu_params["out_file_prefix"].strip().replace(" ", "_")
+    # Check if using a template
+    template_path = None
+    if (mu_input_params["use_structure_file_conditional"]
+            ["use_structure_file"]) == "true":
+        template_path = "muspinsim_gen_out.in"
 
     # combine all sections
     mu_params = {
-        **mu_params["spins"],
-        **mu_params["interaction_params"],
-        **mu_params["experiment_params"],
-        **mu_params["fitting_params"]["fitting_options"],
+        **mu_input_params["use_structure_file_conditional"]["spins"],
+        ** (mu_input_params["use_structure_file_conditional"]
+            ["interaction_params"]),
+        **mu_input_params["experiment_params"],
+        **mu_input_params["fitting_params"]["fitting_options"],
     }
 
     # get experiment parameters
@@ -430,6 +473,10 @@
     if parse_dict(parse_func_dict, mu_params, file_contents):
         sys.exit(1)
 
+    # Load and append the template if specified
+    if template_path is not None:
+        append_template_file(template_path, mu_params, file_contents)
+
     write_file("outfile.in", file_contents)
 
     try:
--- a/config_macros.xml	Fri Feb 03 15:39:07 2023 +0000
+++ b/config_macros.xml	Tue Jul 18 13:26:20 2023 +0000
@@ -142,4 +142,94 @@
             </when>
         </conditional>
     </xml>
+    <xml name="spin_options">
+        <repeat name="spins" title="Spins to simulate" min="1" help="Specify the spins to be used in the system. This should include a muon (mu) and one or more electrons (e)">
+            <conditional name="spin_options">
+                <param name="spin_preset" type="select" value="mu" label="Species" help="Select 'custom' to define own">
+                    <option selected="true" value="mu">mu</option>
+                    <option value="e">e</option>
+                    <option value="custom">custom</option>
+                </param>
+                <when value="custom">
+                    <param name="spin" optional="false" type="text" label="Species name"/>
+                    <param name="atomic_mass" optional="true" type="integer" min="0" value="" label="Atomic mass" help="Leave blank to use default mass - whole numbers only"/>
+                </when>
+                <when value="mu"/>
+                <when value="e"/>
+            </conditional>
+        </repeat>
+    </xml>
+    <xml name="additional_spin_options">
+        <repeat name="spins" title="Additional spins to simulate" min="0" help="Specify any additional spins to be used in the system other than those generated from the structure file.">
+            <conditional name="spin_options">
+                <param name="spin_preset" type="select" value="e" label="Species" help="Select 'custom' to define own">
+                    <option value="e">e</option>
+                    <option value="custom">custom</option>
+                </param>
+                <when value="custom">
+                    <param name="spin" optional="false" type="text" label="Species name"/>
+                    <param name="atomic_mass" optional="true" type="integer" min="0" value="" label="Atomic mass" help="Leave blank to use default mass - whole numbers only"/>
+                </when>
+                <when value="e"/>
+            </conditional>
+        </repeat>
+    </xml>
+    <xml name="interaction_options">
+        <repeat name="interactions" title="Interactions to simulate" help="Add couplings between spins, and/or dissipation terms. Interaction terms available: Zeeman, hyperfine, dipolar, quadrupolar or dissipation. See MuSpinSim docs for more info">
+            <conditional name="interaction_options">
+                <param name="interaction" type="select" label="Choose interaction type">
+                    <option value="zeeman">Zeeman</option>
+                    <option value="hyperfine">hyperfine</option>
+                    <option value="dipolar">dipolar</option>
+                    <option value="quadrupolar">quadrupolar</option>
+                    <option value="dissipation">dissipation</option>
+                </param>
+                <when value="zeeman">
+                    <param name="zeeman_index" type="integer" value="" label="Index of coupled spin" min="1" help="Index refers to the order of the spins listed in 'spins' section.  The first spin in the list has index 1, the second has index 2, and so on."/>
+                    <param name="zeeman_vector" type="text" value="" label="Zeeman coupling vector" help="Define 1X3 vector for local magnetic field coupling (T). Allows default expressions, constants and functions (see help)"/>
+                </when>
+                <when value="hyperfine">
+                    <param name="hfine_index" type="integer" value="" label="Index of nuclear coupled spin" min="1" help="Non-electronic spin - muon or otherwise. Index refers to the order of the spins listed in 'spins' section.  The first spin in the list has index 1, the second has index 2, and so on."/>
+                    <param name="hfine_e_index" type="integer" value="" optional="true" min="1" label="Index of electronic coupled spin" help="Optional, will use first defined electronic spin if unspecified"/>
+                    <param name="hfine_matrix" area="true" type="text" value="" label="Hyperfine coupling tensor" help="Define 3X3 tensor for coupling between electron and non-electron spins (in MHz). Allows default expressions, constants and functions (see help)">
+                        <sanitizer>
+                            <valid initial="string.printable">
+                            </valid>
+                        </sanitizer>
+                    </param>
+                </when>
+                <when value="dipolar">
+                    <param name="di_index" type="integer" value="" min="1" label="Index of 1st coupled spin" help="Index refers to the order of the spins listed in 'spins' section.  The first spin in the list has index 1, the second has index 2, and so on."/>
+                    <param name="di_index_2" type="integer" value="" label="Index of 2nd coupled spin" help="Index refers to the order of the spins listed in 'spins' section.  The first spin in the list has index 1, the second has index 2, and so on."/>
+                    <param name="di_vector" type="text" value="" label="Dipole coupling vector" help="Define 1X3 vector for coupling between two spins (Angstrom). Allows default expressions, constants and functions (see help)"/>
+                </when>
+                <when value="quadrupolar">
+                    <param name="quad_index" type="integer" value="" label="Index of coupled spin" help="Index refers to the order of the spins listed in 'spins' section.  The first spin in the list has index 1, the second has index 2, and so on."/>
+                    <param name="quad_matrix" area="true" type="text" value="" label="Electric Field Gradient tensor" help="Define 3X3 tensor (in atomic units) for quadrupolar coupling. Allows default expressions, constants and functions (see help). Warning: spins with zero quadrupole moment will have zero coupling regardless of the input">
+                        <sanitizer>
+                            <valid initial="string.printable">
+                            </valid>
+                        </sanitizer>
+                    </param>
+                </when>
+                <when value="dissipation">
+                    <param name="dis_index" type="integer" value="" label="Index of spin with dissipation" help="Index refers to the order of the spins listed in 'spins' section.  The first spin in the list has index 1, the second has index 2, and so on."/>
+                    <param name="dis_val" type="text" value="" label="Dissipation" help="Define dissipation term (MHz). Allows default expressions, constants and functions (see help)"/>
+                </when>
+            </conditional>
+        </repeat>
+    </xml>
+    <xml name="generator_options">
+        <param name="structure_file" type="data" format="cif,cell,magres,extxyz" label="File containing the structure (.cif, .cell, .magres or .extxyz)"/>
+        <param name="number_closest" type="integer" value="4" label="Number of closest nuclei" help="Number of closest nuclei to the muon which should included in the generated file"/>
+        <param name="dipolar" type="boolean" checked="true" truevalue="--dipolar" falsevalue="" label="Include dipole interactions?"/>
+        <param name="quadrupolar" type="boolean" checked="false" truevalue="--quadrupolar" falsevalue="" label="Include quadrupole interactions?" help="Requires a Magres input file with EFG tensors calculated via CASTEP."/>
+        <param name="include_interatomic" type="boolean" checked="false" truevalue="--include_interatomic" falsevalue="" label="Include interatomic interactions?" help="Whether to include interactions between selected nuclei which don't involve the muon."/>
+        <repeat name="ignored_symbols" title="Ignored symbols" min="0" help="Specify symbols that should be ignored e.g. if they have zero spin">
+            <param type="text" name="ignored_symbol" label="Ignored symbol">
+                <validator type="regex" message="Input should only contain letters">^[a-zA-Z]+$</validator>
+            </param>
+        </repeat>
+        <param name="muon_symbol" type="text" value="H" label="Muon Symbol" help="Symbol representing the muon in the given structure file."/>
+    </xml>
 </macros>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/muon_macros.xml	Tue Jul 18 13:26:20 2023 +0000
@@ -0,0 +1,29 @@
+<macros>
+    <xml name="dftb_set">
+        <param type="select" name="dftb_set" value="3ob-3-1" display="radio" label="DFTB parameter set" help="The parameter set to use for DFTB+. Currently supported are: 3ob-3-1 and pbc-0-3. See help section at the bottom of the page for details.">
+            <option value="3ob-3-1">3ob-3-1</option>
+            <option value="pbc-0-3">pbc-0-3</option>
+        </param>
+    </xml>
+    <xml name="dftb+">
+        <expand macro="dftb_set"/>
+        <param type="boolean" name="dftb_pbc" label="Use periodic boundary conditions" help="Whether to turn on periodic boundary conditions in DFTB+." checked="true"/>
+    </xml>
+    <xml name="dftb_optionals">
+        <param type="text" argument="dftb_optionals" value="[]" optional="true" label="DFTB optional files" help="Additional optional json files to activate for DFTBArgs (for example, dftd3.json will use DFTD3 dispersion forces for 3ob-3-1 if DFTB+ has been compiled to support them)."/>
+    </xml>
+    <xml name="k_points_grid">
+        <param type="text" argument="k_points_grid" value="[1,1,1]" label="K-points grid" help="List of three integer k-points. Default is [1,1,1].">
+            <validator type="regex" message="Input should only contain whitespace, '[', ']', ',' and digits.">^[\s\d,\[\]]+$</validator>
+        </param>
+    </xml>
+    <!-- version of underlying tool (PEP 440) -->
+    <!-- citation should be updated with every underlying tool version -->
+    <!-- concept is not updated, and should only be used for referencing the idea of the software -->
+    <token name="@MUSPINSIM_VERSION@">2.2.1</token>
+    <token name="@MUSPINSIM_CITATION@">10.5281/zenodo.7733979</token>
+    <token name="@MUSPINSIM_CONCEPT@">10.5281/zenodo.6517626</token>
+    <token name="@PYMUONSUITE_VERSION@">0.3.0</token>
+    <token name="@PYMUONSUITE_CITATION@">10.5281/zenodo.8026711</token>
+    <token name="@PYMUONSUITE_CONCEPT@">10.5281/zenodo.7025643</token>
+</macros>
\ No newline at end of file
--- a/muspinsim_config.xml	Fri Feb 03 15:39:07 2023 +0000
+++ b/muspinsim_config.xml	Tue Jul 18 13:26:20 2023 +0000
@@ -1,25 +1,10 @@
-<tool id="muspinsim_config" name="MuSpinSim Configure" version="@TOOL_VERSION@+galaxy@WRAPPER_VERSION@" python_template_version="3.5" profile="22.05" license="MIT">
+<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 underlying tool (PEP 440) -->
-        <token name="@TOOL_VERSION@">2.0.2</token>
         <!-- version of this tool wrapper (integer) -->
         <token name="@WRAPPER_VERSION@">0</token>
-        <!-- citation should be updated with every underlying tool version -->
-        <!-- typical fields to update are version, month, year, and doi -->
-        <token name="@TOOL_CITATION@">
-            @software{muspinsim,
-                author = {Sturniolo, Simone and Liborio, Leandro and Owen, Josh and Mudaraddi, Anish and Davies, Joel and Wilkinson, John and {Muon Spectroscopy Computational Project}},
-                license = {MIT},
-                title = {{muspinsim}},
-                url = {https://github.com/muon-spectroscopy-computational-project/muspinsim},
-                version = {v2.0.2},
-                month = {1},
-                year = {2023}
-                doi = {10.5281/zenodo.7568830}
-            }
-        </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"/>
@@ -28,83 +13,60 @@
         <organization url="https://muon-spectroscopy-computational-project.github.io/index.html" name="The Muon Spectroscopy Computational Project"/>
     </creator>
     <requirements>
-        <requirement type="package" version="@TOOL_VERSION@">muspinsim</requirement>
+        <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" filename="inputs.json"/>
+        <inputs name="inputs" data_style="paths" filename="inputs.json"/>
     </configfiles>
     <inputs>
-        <param type="text" name="out_file_prefix" label="Name" help="A name with which to label this configuration" optional="true" value="muspinsim"/>
-        <section name="spins" expanded="true" title="Spins">
-            <repeat name="spins" title="Spins to simulate" min="1" help="Specify the spins to be used in the system. This should include a muon (mu) and one or more electrons (e)">
-                <conditional name="spin_options">
-                    <param name="spin_preset" type="select" value="mu" label="Species" help="Select 'custom' to define own">
-                        <option selected="true" value="mu">mu</option>
-                        <option value="e">e</option>
-                        <option value="custom">custom</option>
-                    </param>
-                    <when value="custom">
-                        <param name="spin" optional="false" type="text" label="Species name"/>
-                        <param name="atomic_mass" optional="true" type="integer" min="0" value="" label="Atomic mass" help="Leave blank to use default mass - whole numbers only"/>
-                    </when>
-                    <when value="mu"/>
-                    <when value="e"/>
-                </conditional>
-            </repeat>
-        </section>
-        <section name="interaction_params" expanded="true" title="Spin Interactions" help="">
-            <repeat name="interactions" title="Interactions to simulate" help="Add couplings between spins, and/or dissipation terms. Interaction terms available: Zeeman, hyperfine, dipolar, quadrupolar or dissipation. See MuSpinSim docs for more info">
-                <conditional name="interaction_options">
-                    <param name="interaction" type="select" label="Choose interaction type">
-                        <option value="zeeman">Zeeman</option>
-                        <option value="hyperfine">hyperfine</option>
-                        <option value="dipolar">dipolar</option>
-                        <option value="quadrupolar">quadrupolar</option>
-                        <option value="dissipation">dissipation</option>
-                    </param>
-                    <when value="zeeman">
-                        <param name="zeeman_index" type="integer" value="" label="Index of coupled spin" min="1" help="Index refers to the order of the spins listed in 'spins' section.  The first spin in the list has index 1, the second has index 2, and so on."/>
-                        <param name="zeeman_vector" type="text" value="" label="Zeeman coupling vector" help="Define 1X3 vector for local magnetic field coupling (T). Allows default expressions, constants and functions (see help)"/>
-                    </when>
-                    <when value="hyperfine">
-                        <param name="hfine_index" type="integer" value="" label="Index of nuclear coupled spin" min="1" help="Non-electronic spin - muon or otherwise. Index refers to the order of the spins listed in 'spins' section.  The first spin in the list has index 1, the second has index 2, and so on."/>
-                        <param name="hfine_e_index" type="integer" value="" optional="true" min="1" label="Index of electronic coupled spin" help="Optional, will use first defined electronic spin if unspecified"/>
-                        <param name="hfine_matrix" area="true" type="text" value="" label="Hyperfine coupling tensor" help="Define 3X3 tensor for coupling between electron and non-electron spins (in MHz). Allows default expressions, constants and functions (see help)">
-                            <sanitizer>
-                                <valid initial="string.printable">
-                                </valid>
-                            </sanitizer>
-                        </param>
-                    </when>
-                    <when value="dipolar">
-                        <param name="di_index" type="integer" value="" min="1" label="Index of 1st coupled spin" help="Index refers to the order of the spins listed in 'spins' section.  The first spin in the list has index 1, the second has index 2, and so on."/>
-                        <param name="di_index_2" type="integer" value="" label="Index of 2nd coupled spin" help="Index refers to the order of the spins listed in 'spins' section.  The first spin in the list has index 1, the second has index 2, and so on."/>
-                        <param name="di_vector" type="text" value="" label="Dipole coupling vector" help="Define 1X3 vector for coupling between two spins (Angstrom). Allows default expressions, constants and functions (see help)"/>
-                    </when>
-                    <when value="quadrupolar">
-                        <param name="quad_index" type="integer" value="" label="Index of coupled spin" help="Index refers to the order of the spins listed in 'spins' section.  The first spin in the list has index 1, the second has index 2, and so on."/>
-                        <param name="quad_matrix" area="true" type="text" value="" label="Electric Field Gradient tensor" help="Define 3X3 tensor (in atomic units) for quadrupolar coupling. Allows default expressions, constants and functions (see help). Warning: spins with zero quadrupole moment will have zero coupling regardless of the input">
-                            <sanitizer>
-                                <valid initial="string.printable">
-                                </valid>
-                            </sanitizer>
-                        </param>
-                    </when>
-                    <when value="dissipation">
-                        <param name="dis_index" type="integer" value="" label="Index of spin with dissipation" help="Index refers to the order of the spins listed in 'spins' section.  The first spin in the list has index 1, the second has index 2, and so on."/>
-                        <param name="dis_val" type="text" value="" label="Dissipation" help="Define dissipation term (MHz). Allows default expressions, constants and functions (see help)"/>
-                    </when>
-                </conditional>
-            </repeat>
-        </section>
+        <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">
@@ -169,6 +131,7 @@
     <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"/>
@@ -184,6 +147,7 @@
         </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"/>
@@ -199,6 +163,7 @@
         </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"/>
@@ -218,6 +183,7 @@
         </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"/>
@@ -252,6 +218,7 @@
         </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"/>
@@ -270,6 +237,7 @@
         </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"/>
@@ -284,6 +252,7 @@
         </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"/>
@@ -298,6 +267,86 @@
             <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.
@@ -377,8 +426,6 @@
             }
         </citation>
         <citation type="doi">10.1103/PhysRevLett.56.2720</citation>
-        <citation type="bibtex">
-            @TOOL_CITATION@
-        </citation>
+        <citation type="doi">@MUSPINSIM_CITATION@</citation>
     </citations>
 </tool>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/Basic.cell	Tue Jul 18 13:26:20 2023 +0000
@@ -0,0 +1,12 @@
+%BLOCK LATTICE_CART
+   14.18160000000000   0.000000000000000   0.000000000000000
+   0.000000000000000   14.18160000000000   0.000000000000000
+   0.000000000000000   0.000000000000000   14.18160000000000
+%ENDBLOCK LATTICE_CART
+
+%BLOCK POSITIONS_FRAC
+V             0.0791557133        0.0000005853        0.1708904764
+V             0.9161667724        0.0000005823        0.8325662729
+Si            0.4996287249        0.8331358706        0.8331663251
+H             0.1666672745        0.0000018274        0.0833332099
+%ENDBLOCK POSITIONS_FRAC
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/Basic.magres	Tue Jul 18 13:26:20 2023 +0000
@@ -0,0 +1,17 @@
+#$magres-abinitio-v1.0
+[atoms]
+units lattice Angstrom
+lattice          14.18160000000000   0.000000000000000   0.000000000000000                 0.000000000000000   14.18160000000000   0.000000000000000                 0.000000000000000   0.000000000000000   14.18160000000000
+units atom Angstrom
+atom V       V   1     1.1225546637        0.0000083005        2.4235003801
+atom V       V   2     12.992710700        0.0000082580        11.807121856
+atom Si      Si  3     7.0855347250        11.815199663        11.815631556
+atom H:mu    H:mu   1     2.3636086201        0.0000259155        1.1817982368
+[/atoms]
+[magres]
+units efg au
+efg V  1         -0.008877        0.000022       -0.011811                  0.000022       -0.030585        0.000005                 -0.011811        0.000005        0.039462
+efg V  2          0.221597       -0.000002       -0.009013                 -0.000002       -0.109627       -0.000009                 -0.009013       -0.000009       -0.111970
+efg Si 3         -0.002604       -0.000000       -0.000001                 -0.000000       -0.002551       -0.000009                 -0.000001       -0.000009        0.005154
+efg H:mu  1      -0.034266        0.000000        0.000000                  0.000000       -0.034268        0.000000                  0.000000        0.000000        0.068534
+[/magres]
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/muspinsim_gen_template.in	Tue Jul 18 13:26:20 2023 +0000
@@ -0,0 +1,106 @@
+spins
+    mu V V V V V V V V
+quadrupolar 2
+    -0.008877 2.2e-05 -0.011811
+    2.2e-05 -0.030585 5e-06
+    -0.011811 5e-06 0.039462
+dipolar 1 2
+    1.2410539563139198 1.7614965359999998e-05 -1.2417021305964
+dipolar 2 3
+    2.3114439642674407 4.25447999999999e-08 4.7979785243555995
+dipolar 2 4
+    2.3114439642674407 4.25447999999999e-08 -9.3836214756444
+dipolar 2 5
+    -11.87015603573256 4.25447999999999e-08 4.7979785243555995
+dipolar 2 6
+    0.0 0.0 14.1816
+dipolar 2 7
+    -14.1816 0.0 0.0
+dipolar 2 8
+    0.0 -14.1816 0.0
+dipolar 2 9
+    0.0 14.1816 0.0
+quadrupolar 3
+    0.221597 -2e-06 -0.009013
+    -2e-06 -0.109627 -9e-06
+    -0.009013 -9e-06 -0.11197
+dipolar 1 3
+    3.5524979205813603 1.7657510159999996e-05 3.5562763937592
+dipolar 3 4
+    0.0 0.0 -14.1816
+dipolar 3 5
+    -14.1816 0.0 0.0
+dipolar 3 6
+    -2.3114439642674407 -4.25447999999999e-08 9.3836214756444
+dipolar 3 7
+    -16.49304396426744 -4.25447999999999e-08 -4.7979785243555995
+dipolar 3 8
+    -2.3114439642674407 -14.1816000425448 -4.7979785243555995
+dipolar 3 9
+    -2.3114439642674407 14.1815999574552 -4.7979785243555995
+quadrupolar 4
+    0.221597 -2e-06 -0.009013
+    -2e-06 -0.109627 -9e-06
+    -0.009013 -9e-06 -0.11197
+dipolar 1 4
+    3.5524979205813603 1.7657510159999996e-05 -10.6253236062408
+dipolar 4 5
+    -14.1816 0.0 14.1816
+dipolar 4 6
+    -2.3114439642674407 -4.25447999999999e-08 23.5652214756444
+dipolar 4 7
+    -16.49304396426744 -4.25447999999999e-08 9.3836214756444
+dipolar 4 8
+    -2.3114439642674407 -14.1816000425448 9.3836214756444
+dipolar 4 9
+    -2.3114439642674407 14.1815999574552 9.3836214756444
+quadrupolar 5
+    0.221597 -2e-06 -0.009013
+    -2e-06 -0.109627 -9e-06
+    -0.009013 -9e-06 -0.11197
+dipolar 1 5
+    -10.62910207941864 1.7657510159999996e-05 3.5562763937592
+dipolar 5 6
+    11.87015603573256 -4.25447999999999e-08 9.3836214756444
+dipolar 5 7
+    -2.31144396426744 -4.25447999999999e-08 -4.7979785243555995
+dipolar 5 8
+    11.87015603573256 -14.1816000425448 -4.7979785243555995
+dipolar 5 9
+    11.87015603573256 14.1815999574552 -4.7979785243555995
+quadrupolar 6
+    -0.008877 2.2e-05 -0.011811
+    2.2e-05 -0.030585 5e-06
+    -0.011811 5e-06 0.039462
+dipolar 1 6
+    1.2410539563139198 1.7614965359999998e-05 12.9398978694036
+dipolar 6 7
+    -14.1816 0.0 -14.1816
+dipolar 6 8
+    0.0 -14.1816 -14.1816
+dipolar 6 9
+    0.0 14.1816 -14.1816
+quadrupolar 7
+    -0.008877 2.2e-05 -0.011811
+    2.2e-05 -0.030585 5e-06
+    -0.011811 5e-06 0.039462
+dipolar 1 7
+    -12.94054604368608 1.7614965359999998e-05 -1.2417021305964
+dipolar 7 8
+    14.1816 -14.1816 0.0
+dipolar 7 9
+    14.1816 14.1816 0.0
+quadrupolar 8
+    -0.008877 2.2e-05 -0.011811
+    2.2e-05 -0.030585 5e-06
+    -0.011811 5e-06 0.039462
+dipolar 1 8
+    1.2410539563139198 -14.18158238503464 -1.2417021305964
+dipolar 8 9
+    0.0 28.3632 0.0
+quadrupolar 9
+    -0.008877 2.2e-05 -0.011811
+    2.2e-05 -0.030585 5e-06
+    -0.011811 5e-06 0.039462
+dipolar 1 9
+    1.2410539563139198 14.18161761496536 -1.2417021305964
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/test_10.in	Tue Jul 18 13:26:20 2023 +0000
@@ -0,0 +1,54 @@
+
+#######################################################
+# Muspinsim Input File
+# Generated using Muon Galaxy Tool Muspinsim_Input
+#######################################################
+
+name
+    test_10
+average_axes
+    orientation
+x_axis
+    time
+y_axis
+    asymmetry
+time
+    range(0,8.0,1000)
+spins
+    mu V V V V
+quadrupolar 2
+    -0.008877 2.2e-05 -0.011811
+    2.2e-05 -0.030585 5e-06
+    -0.011811 5e-06 0.039462
+dipolar 1 2
+    1.2410539564 1.7615e-05 -1.2417021433000002
+dipolar 2 3
+    2.3114439636999995 4.2500000000000017e-08 4.7979785240999995
+dipolar 2 4
+    2.3114439636999995 4.2500000000000017e-08 -9.3836214759
+dipolar 2 5
+    -11.8701560363 4.2500000000000017e-08 4.7979785240999995
+quadrupolar 3
+    0.221597 -2e-06 -0.009013
+    -2e-06 -0.109627 -9e-06
+    -0.009013 -9e-06 -0.11197
+dipolar 1 3
+    3.5524979200999995 1.7657499999999998e-05 3.556276380799999
+dipolar 3 4
+    0.0 0.0 -14.1816
+dipolar 3 5
+    -14.1816 0.0 0.0
+quadrupolar 4
+    0.221597 -2e-06 -0.009013
+    -2e-06 -0.109627 -9e-06
+    -0.009013 -9e-06 -0.11197
+dipolar 1 4
+    3.5524979200999995 1.7657499999999998e-05 -10.6253236192
+dipolar 4 5
+    -14.1816 0.0 14.1816
+quadrupolar 5
+    0.221597 -2e-06 -0.009013
+    -2e-06 -0.109627 -9e-06
+    -0.009013 -9e-06 -0.11197
+dipolar 1 5
+    -10.6291020799 1.7657499999999998e-05 3.556276380799999
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/test_11.in	Tue Jul 18 13:26:20 2023 +0000
@@ -0,0 +1,50 @@
+
+#######################################################
+# Muspinsim Input File
+# Generated using Muon Galaxy Tool Muspinsim_Input
+#######################################################
+
+name
+    test_11
+hyperfine 3
+    (300/2) 3 4*10
+    3 15*10 6-3+2
+    4 5 15
+hyperfine 2
+    580 5 10
+    5 580 9
+    10 9 580
+average_axes
+    orientation
+x_axis
+    time
+y_axis
+    asymmetry
+time
+    range(0,8.0,1000)
+spins
+    mu V V V V
+quadrupolar 2
+    -0.008877 2.2e-05 -0.011811
+    2.2e-05 -0.030585 5e-06
+    -0.011811 5e-06 0.039462
+dipolar 1 2
+    1.2410539564 1.7615e-05 -1.2417021433000002
+quadrupolar 3
+    0.221597 -2e-06 -0.009013
+    -2e-06 -0.109627 -9e-06
+    -0.009013 -9e-06 -0.11197
+dipolar 1 3
+    3.5524979200999995 1.7657499999999998e-05 3.556276380799999
+quadrupolar 4
+    0.221597 -2e-06 -0.009013
+    -2e-06 -0.109627 -9e-06
+    -0.009013 -9e-06 -0.11197
+dipolar 1 4
+    3.5524979200999995 1.7657499999999998e-05 -10.6253236192
+quadrupolar 5
+    0.221597 -2e-06 -0.009013
+    -2e-06 -0.109627 -9e-06
+    -0.009013 -9e-06 -0.11197
+dipolar 1 5
+    -10.6291020799 1.7657499999999998e-05 3.556276380799999
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/test_12.in	Tue Jul 18 13:26:20 2023 +0000
@@ -0,0 +1,50 @@
+
+#######################################################
+# Muspinsim Input File
+# Generated using Muon Galaxy Tool Muspinsim_Input
+#######################################################
+
+name
+    test_12
+hyperfine 3
+    (300/2) 3 4*10
+    3 15*10 6-3+2
+    4 5 15
+hyperfine 2
+    580 5 10
+    5 580 9
+    10 9 580
+average_axes
+    orientation
+x_axis
+    time
+y_axis
+    asymmetry
+time
+    range(0,8.0,1000)
+spins
+    mu V V V V 19F e
+quadrupolar 2
+    -0.008877 2.2e-05 -0.011811
+    2.2e-05 -0.030585 5e-06
+    -0.011811 5e-06 0.039462
+dipolar 1 2
+    1.2410539564 1.7615e-05 -1.2417021433000002
+quadrupolar 3
+    0.221597 -2e-06 -0.009013
+    -2e-06 -0.109627 -9e-06
+    -0.009013 -9e-06 -0.11197
+dipolar 1 3
+    3.5524979200999995 1.7657499999999998e-05 3.556276380799999
+quadrupolar 4
+    0.221597 -2e-06 -0.009013
+    -2e-06 -0.109627 -9e-06
+    -0.009013 -9e-06 -0.11197
+dipolar 1 4
+    3.5524979200999995 1.7657499999999998e-05 -10.6253236192
+quadrupolar 5
+    0.221597 -2e-06 -0.009013
+    -2e-06 -0.109627 -9e-06
+    -0.009013 -9e-06 -0.11197
+dipolar 1 5
+    -10.6291020799 1.7657499999999998e-05 3.556276380799999
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/test_8.in	Tue Jul 18 13:26:20 2023 +0000
@@ -0,0 +1,26 @@
+
+#######################################################
+# Muspinsim Input File
+# Generated using Muon Galaxy Tool Muspinsim_Input
+#######################################################
+
+name
+    test_8
+average_axes
+    orientation
+x_axis
+    time
+y_axis
+    asymmetry
+time
+    range(0,8.0,1000)
+spins
+    mu V V Si Si
+dipolar 1 2
+    1.2410539563139198 1.7614965359999998e-05 -1.2417021305964
+dipolar 1 3
+    3.5524979205813603 1.7657510159999996e-05 3.5562763937592
+dipolar 1 4
+    -4.72192610499264 2.366426252954879 3.54776669347968
+dipolar 1 5
+    9.45967389500736 2.366426252954879 3.54776669347968
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/test_9.in	Tue Jul 18 13:26:20 2023 +0000
@@ -0,0 +1,34 @@
+
+#######################################################
+# Muspinsim Input File
+# Generated using Muon Galaxy Tool Muspinsim_Input
+#######################################################
+
+name
+    test_9
+average_axes
+    orientation
+x_axis
+    time
+y_axis
+    asymmetry
+time
+    range(0,8.0,1000)
+spins
+    mu V V V V V V V V
+dipolar 1 2
+    1.2410539564 1.7615e-05 -1.2417021433000002
+dipolar 1 3
+    3.5524979200999995 1.7657499999999998e-05 3.556276380799999
+dipolar 1 4
+    3.5524979200999995 1.7657499999999998e-05 -10.6253236192
+dipolar 1 5
+    -10.6291020799 1.7657499999999998e-05 3.556276380799999
+dipolar 1 6
+    1.2410539564 1.7615e-05 12.9398978567
+dipolar 1 7
+    -12.940546043600001 1.7615e-05 -1.2417021433000002
+dipolar 1 8
+    1.2410539564 -14.181582384999999 -1.2417021433000002
+dipolar 1 9
+    1.2410539564 14.181617615 -1.2417021433000002