# HG changeset patch
# User muon-spectroscopy-computational-project
# Date 1689686780 0
# Node ID e1e338f56656c14289a0174cabb17dbd5184ceee
# Parent  331d0776abb4ef0da9332569acf0f720c754d443
planemo upload for repository https://github.com/muon-spectroscopy-computational-project/muon-galaxy-tools/main/muspinsim_config commit 70a4d37ecdf5d586703cfc509922311e95d3205c
diff -r 331d0776abb4 -r e1e338f56656 build_file.py
--- 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:
diff -r 331d0776abb4 -r e1e338f56656 config_macros.xml
--- 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 @@
             
         
     
+    
+        
+            
+                
+                    
+                    
+                    
+                
+                
+                    
+                    
+                
+                
+                
+            
+        
+    
+    
+        
+            
+                
+                    
+                    
+                
+                
+                    
+                    
+                
+                
+            
+        
+    
+    
+        
+            
+                
+                    
+                    
+                    
+                    
+                    
+                
+                
+                    
+                    
+                
+                
+                    
+                    
+                    
+                        
+                            
+                            
+                        
+                    
+                
+                
+                    
+                    
+                    
+                
+                
+                    
+                    
+                        
+                            
+                            
+                        
+                    
+                
+                
+                    
+                    
+                
+            
+        
+    
+    
+        
+        
+        
+        
+        
+        
+            
+                ^[a-zA-Z]+$
+            
+        
+        
+    
 
diff -r 331d0776abb4 -r e1e338f56656 muon_macros.xml
--- /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 @@
+
+    
+        
+            
+            
+        
+    
+    
+        
+        
+    
+    
+        
+    
+    
+        
+            ^[\s\d,\[\]]+$
+        
+    
+    
+    
+    
+    2.2.1
+    10.5281/zenodo.7733979
+    10.5281/zenodo.6517626
+    0.3.0
+    10.5281/zenodo.8026711
+    10.5281/zenodo.7025643
+
\ No newline at end of file
diff -r 331d0776abb4 -r e1e338f56656 muspinsim_config.xml
--- 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 @@
-
+
     define simulation parameters
     
-        
-        2.0.2
         
         0
-        
-        
-        
-            @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}
-            }
-        
         config_macros.xml
+        muon_macros.xml
     
     
         
@@ -28,83 +13,60 @@
         
     
     
-        muspinsim
+        muspinsim
     
     
         
         
     
     
     
-        
+        
     
     
-        
-        
-            
-                
-                    
-                        
-                        
-                        
-                    
-                    
-                        
-                        
-                    
-                    
-                    
-                
-            
-        
-        
-            
-                
-                    
-                        
-                        
-                        
-                        
-                        
-                    
-                    
-                        
-                        
-                    
-                    
-                        
-                        
-                        
-                            
-                                
-                                
-                            
-                        
-                    
-                    
-                        
-                        
-                        
-                    
-                    
-                        
-                        
-                            
-                                
-                                
-                            
-                        
-                    
-                    
-                        
-                        
-                    
-                
-            
-        
+        
+        
+            
+                
+                
+            
+            
+                
+                
+                
+            
+            
+                
+                
+            
+        
         
             
                 
@@ -169,6 +131,7 @@
     
         
             
+            
             
             
             
@@ -184,6 +147,7 @@
         
         
             
+            
             
             
             
@@ -199,6 +163,7 @@
         
         
             
+            
             
             
             
@@ -218,6 +183,7 @@
         
         
             
+            
             
             
             
@@ -252,6 +218,7 @@
         
         
             
+            
             
             
             
@@ -270,6 +237,7 @@
         
         
             
+            
             
             
             
@@ -284,6 +252,7 @@
         
         
             
+            
             
             
             
@@ -298,6 +267,86 @@
             
             
         
+        
+
+        
+        
+            
+            
+            
+            
+            
+            
+        
+        
+        
+            
+            
+            
+            
+            
+            
+            
+            
+            
+            
+            
+        
+        
+        
+            
+            
+            
+            
+            
+            
+            
+            
+            
+            
+        
+        
+        
+            
+            
+            
+            
+            
+            
+            
+            
+            
+            
+            
+            
+            
+            
+            
+            
+        
+        
+        
+            
+            
+            
+            
+            
+            
+            
+            
+            
+            
+            
+            
+            
+            
+            
+            
+            
+            
+            
+            
+        
     
     
         10.1103/PhysRevLett.56.2720
-        
-            @TOOL_CITATION@
-        
+        @MUSPINSIM_CITATION@
     
 
diff -r 331d0776abb4 -r e1e338f56656 test-data/Basic.cell
--- /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
diff -r 331d0776abb4 -r e1e338f56656 test-data/Basic.magres
--- /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
diff -r 331d0776abb4 -r e1e338f56656 test-data/muspinsim_gen_template.in
--- /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
diff -r 331d0776abb4 -r e1e338f56656 test-data/test_10.in
--- /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
diff -r 331d0776abb4 -r e1e338f56656 test-data/test_11.in
--- /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
diff -r 331d0776abb4 -r e1e338f56656 test-data/test_12.in
--- /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
diff -r 331d0776abb4 -r e1e338f56656 test-data/test_8.in
--- /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
diff -r 331d0776abb4 -r e1e338f56656 test-data/test_9.in
--- /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