diff --git a/examples/Notebooks/u_fit_tutorial.ipynb b/examples/Notebooks/u_fit_tutorial.ipynb index cb9b63e..8b49676 100644 --- a/examples/Notebooks/u_fit_tutorial.ipynb +++ b/examples/Notebooks/u_fit_tutorial.ipynb @@ -76,16 +76,26 @@ "name": "stdout", "output_type": "stream", "text": [ + "total 544K\n", + "drwxr-xr-x 4 l280162 l280162 4.0K Jul 10 22:35 .\n", + "drwxr-xr-x 5 l280162 l280162 4.0K Jul 10 13:23 ..\n", + "drwxr-xr-x 4 l280162 l280162 4.0K Jul 10 22:35 .archive\n", + "drwxr-xr-x 2 l280162 l280162 4.0K Jul 10 21:58 images\n", + "-rw-r--r-- 1 l280162 l280162 199K Jul 10 13:23 natEu_fit_tutorial.ipynb\n", + "-rw-r--r-- 1 l280162 l280162 1.5K Jul 10 13:23 nat_europium.ini\n", + "-rw-r--r-- 1 l280162 l280162 319K Jul 10 21:58 u_fit_tutorial.ipynb\n", + "-rw-r--r-- 1 l280162 l280162 1.5K Jul 10 21:58 uranium.ini\n", "total 16K\n", - "drwxr-xr-x 4 l280162 l280162 4.0K Jul 10 20:43 .\n", - "drwxr-xr-x 4 l280162 l280162 4.0K Jul 10 20:43 ..\n", - "drwxr-xr-x 2 l280162 l280162 4.0K Jul 10 20:43 endf\n", - "drwxr-xr-x 2 l280162 l280162 4.0K Jul 10 20:43 u235-u238\n" + "drwxr-xr-x 4 l280162 l280162 4.0K Jul 10 22:35 .\n", + "drwxr-xr-x 4 l280162 l280162 4.0K Jul 10 22:35 ..\n", + "drwxr-xr-x 4 l280162 l280162 4.0K Jul 10 22:35 endf\n", + "drwxr-xr-x 2 l280162 l280162 4.0K Jul 10 22:36 u235-u238\n" ] } ], "source": [ - "!ls -lah .archive/" + "!ls -lah \n", + "!ls -lah .archive/\n" ] }, { @@ -133,16 +143,19 @@ "name": "stdout", "output_type": "stream", "text": [ - "total 16K\n", - "drwxr-xr-x 4 l280162 l280162 4.0K Jul 10 20:43 .\n", - "drwxr-xr-x 4 l280162 l280162 4.0K Jul 10 20:43 ..\n", - "drwxr-xr-x 3 l280162 l280162 4.0K Jul 10 20:43 U235\n", - "drwxr-xr-x 3 l280162 l280162 4.0K Jul 10 20:43 U238\n" + "total 28K\n", + "drwxr-xr-x 3 l280162 l280162 4.0K Jul 10 22:37 .\n", + "drwxr-xr-x 4 l280162 l280162 4.0K Jul 10 22:35 ..\n", + "-rw-r--r-- 1 l280162 l280162 455 Jul 10 22:37 U235.inp\n", + "-rw-r--r-- 1 l280162 l280162 1.8K Jul 10 22:37 U235.out\n", + "-rw-r--r-- 1 l280162 l280162 17 Jul 10 22:37 U235_ENDF-dummy.dat\n", + "lrwxrwxrwx 1 l280162 l280162 74 Jul 10 22:35 res_endf8.endf -> /home/l280162/Programs/PLEIADES/nucDataLibs/resonanceTables/res_endf8.endf\n", + "drwxr-xr-x 2 l280162 l280162 4.0K Jul 10 22:37 results\n" ] } ], "source": [ - "!ls -lah .archive/endf" + "!ls -lah .archive/endf/U235/" ] }, { @@ -150,7 +163,7 @@ "id": "c8eb5fc4-3d84-4085-a6d3-b780a288c68b", "metadata": {}, "source": [ - "#### Configure SAMMY for the fit of Natural Eu\n", + "#### Configure SAMMY for the fit of Uranium foil\n", "\n", "Now that we have the needed SAMNDF.PAR files for each isotope (stored in the .archive/endf/Eu15* folders) we can configure all the needed SAMMY files to fit a naterual Eu transmission spectrum. \n", "\n", @@ -171,7 +184,8 @@ "Writing output parFile: /home/l280162/Programs/PLEIADES/examples/Notebooks/.archive/u235-u238/params.par\n", "Creating SAMMY inpFile files for isotopes: ['U-235', 'U-238'] with abundances: [0.01, 0.01]\n", "No config file given. Using default parameters.\n", - "Created compound input file: /home/l280162/Programs/PLEIADES/examples/Notebooks/.archive/u235-u238/input.inp\n" + "Created compound input file: /home/l280162/Programs/PLEIADES/examples/Notebooks/.archive/u235-u238/input.inp\n", + "Symlinking data file: /home/l280162/Programs/PLEIADES/examples/data/u235-u238.twenty into /home/l280162/Programs/PLEIADES/examples/Notebooks/.archive/u235-u238\n" ] } ], @@ -190,12 +204,35 @@ "Here Pleiades has taken all the needed information from the two (Eu151, Eu153) `SAMNDF.PAR` files and combined them to form a `params.par` file. Additionally Pleiades has created the needed input.inp file to run the natEu SAMMY fit. " ] }, + { + "cell_type": "code", + "execution_count": 7, + "id": "86240af4", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "total 40K\n", + "drwxr-xr-x 2 l280162 l280162 4.0K Jul 10 22:37 .\n", + "drwxr-xr-x 4 l280162 l280162 4.0K Jul 10 22:35 ..\n", + "-rw-r--r-- 1 l280162 l280162 582 Jul 10 22:37 input.inp\n", + "-rw-r--r-- 1 l280162 l280162 23K Jul 10 22:37 params.par\n", + "lrwxrwxrwx 1 l280162 l280162 62 Jul 10 22:37 u235-u238.twenty -> /home/l280162/Programs/PLEIADES/examples/data/u235-u238.twenty\n" + ] + } + ], + "source": [ + "!ls -lah .archive/u235-u238/" + ] + }, { "cell_type": "markdown", "id": "e5dd59be-27c0-4262-87bd-57d22d2eff63", "metadata": {}, "source": [ - "#### running the SAMMY of Uranium foil\n", + "#### Running the SAMMY fit on the Uranium foil data\n", "\n", "Now that everything is set we are prepared to run the actual fit on the natural Eu data. \n", "Note: You can change the print verbose level to print out important variables and paths. " @@ -203,7 +240,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 8, "id": "ac472354-2fba-4c54-bf1d-9706dae063df", "metadata": {}, "outputs": [ @@ -245,7 +282,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 11, "id": "0535922c", "metadata": {}, "outputs": [ @@ -304,7 +341,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 12, "id": "118e9ae4-bfdc-4aac-8819-5e756a6b2cff", "metadata": {}, "outputs": [ @@ -329,16 +366,20 @@ "id": "f134363d", "metadata": {}, "source": [ + "#### Something is missing!\n", + "\n", "Looking at the plot it appears that we are not capturing all the isotopes! We should think about what isotopes we should add to get a better fit. \n", "\n", "* First list the isotopes and abundances, \n", "* Then we can update the abundances based on the lptresults\n", - "* Finally we can add another isotope, like Ta (hint: its Ta)" + "* Finally we can add another isotope, like Ta (hint: its Ta)\n", + "\n", + "Additionally, we can change the name of the `sammy_fit_dir` in case we want to compare new fit results to the original. " ] }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 13, "id": "537592f3", "metadata": {}, "outputs": [ @@ -350,7 +391,8 @@ "Initial Abundance: [0.01, 0.01]\n", "Initial Thickness: 1.0\n", "New Abundance: [0.01276, 0.0057509]\n", - "New Thickness: 0.11592\n" + "New Thickness: 0.11592\n", + "New fit directory: /home/l280162/Programs/PLEIADES/examples/Notebooks/.archive/u235-u238-ta181\n" ] } ], @@ -369,12 +411,18 @@ "\n", "# check your work!\n", "print(f\"New Abundance: {uranium.params['isotopes']['abundances']}\")\n", - "print(f\"New Thickness: {uranium.params['broadening']['thickness']}\")\n" + "print(f\"New Thickness: {uranium.params['broadening']['thickness']}\")\n", + "\n", + "# Update the `sammy_fit_dir` to a new directory name\n", + "uranium.params['directories']['sammy_fit_dir'] = uranium.params['directories']['sammy_fit_dir'] + \"-ta181\"\n", + "\n", + "# check your work!\n", + "print(f\"New fit directory: {uranium.params['directories']['sammy_fit_dir']}\")\n" ] }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 14, "id": "2ed528b0", "metadata": {}, "outputs": [ @@ -409,7 +457,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 15, "id": "c1531978", "metadata": {}, "outputs": [], @@ -428,7 +476,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 16, "id": "072df3f1", "metadata": {}, "outputs": [ @@ -437,16 +485,16 @@ "output_type": "stream", "text": [ "total 20K\n", - "drwxr-xr-x 5 l280162 l280162 4.0K Jul 10 20:43 .\n", - "drwxr-xr-x 4 l280162 l280162 4.0K Jul 10 20:43 ..\n", - "drwxr-xr-x 3 l280162 l280162 4.0K Jul 10 20:43 Ta181\n", - "drwxr-xr-x 3 l280162 l280162 4.0K Jul 10 20:43 U235\n", - "drwxr-xr-x 3 l280162 l280162 4.0K Jul 10 20:43 U238\n" + "drwxr-xr-x 5 l280162 l280162 4.0K Jul 10 22:38 .\n", + "drwxr-xr-x 4 l280162 l280162 4.0K Jul 10 22:35 ..\n", + "drwxr-xr-x 3 l280162 l280162 4.0K Jul 10 22:38 Ta181\n", + "drwxr-xr-x 3 l280162 l280162 4.0K Jul 10 22:38 U235\n", + "drwxr-xr-x 3 l280162 l280162 4.0K Jul 10 22:38 U238\n" ] } ], "source": [ - "!ls -lah .archive/endf" + "!ls -lah .archive/endf/" ] }, { @@ -461,7 +509,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 17, "id": "3c6bcc36", "metadata": {}, "outputs": [ @@ -470,10 +518,11 @@ "output_type": "stream", "text": [ "Creating SAMMY parFile files for isotopes: ['U-235', 'U-238', 'Ta-181'] with abundances: [0.01276, 0.0057509, 0.01]\n", - "Writing output parFile: /home/l280162/Programs/PLEIADES/examples/Notebooks/.archive/u235-u238/params.par\n", + "Writing output parFile: /home/l280162/Programs/PLEIADES/examples/Notebooks/.archive/u235-u238-ta181/params.par\n", "Creating SAMMY inpFile files for isotopes: ['U-235', 'U-238', 'Ta-181'] with abundances: [0.01276, 0.0057509, 0.01]\n", "No config file given. Using default parameters.\n", - "Created compound input file: /home/l280162/Programs/PLEIADES/examples/Notebooks/.archive/u235-u238/input.inp\n" + "Created compound input file: /home/l280162/Programs/PLEIADES/examples/Notebooks/.archive/u235-u238-ta181/input.inp\n", + "Symlinking data file: /home/l280162/Programs/PLEIADES/examples/data/u235-u238.twenty into /home/l280162/Programs/PLEIADES/examples/Notebooks/.archive/u235-u238-ta181\n" ] } ], @@ -482,6 +531,37 @@ "sammyUtils.configure_sammy_run(uranium,verbose_level=1)" ] }, + { + "cell_type": "markdown", + "id": "40847c94", + "metadata": {}, + "source": [ + "#### `ls` the directory to see if anything was updated. " + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "cec02279", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "total 20K\n", + "drwxr-xr-x 5 l280162 l280162 4.0K Jul 10 22:39 .\n", + "drwxr-xr-x 4 l280162 l280162 4.0K Jul 10 22:35 ..\n", + "drwxr-xr-x 5 l280162 l280162 4.0K Jul 10 22:38 endf\n", + "drwxr-xr-x 3 l280162 l280162 4.0K Jul 10 22:38 u235-u238\n", + "drwxr-xr-x 2 l280162 l280162 4.0K Jul 10 22:39 u235-u238-ta181\n" + ] + } + ], + "source": [ + "!ls -lah .archive/" + ] + }, { "cell_type": "markdown", "id": "4b20bb33", @@ -496,7 +576,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 19, "id": "882ae5d7", "metadata": {}, "outputs": [ @@ -504,9 +584,9 @@ "name": "stdout", "output_type": "stream", "text": [ - "Running SAMMY for /home/l280162/Programs/PLEIADES/examples/Notebooks/.archive/u235-u238\n", - "Output file: /home/l280162/Programs/PLEIADES/examples/Notebooks/.archive/u235-u238/output.out\n", - "Running SAMMY for u235-u238...\n", + "Running SAMMY for /home/l280162/Programs/PLEIADES/examples/Notebooks/.archive/u235-u238-ta181\n", + "Output file: /home/l280162/Programs/PLEIADES/examples/Notebooks/.archive/u235-u238-ta181/output.out\n", + "Running SAMMY for u235-u238-ta181...\n", "SAMMY executed successfully.\n" ] } @@ -526,7 +606,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 20, "id": "583f22bb", "metadata": {}, "outputs": [ @@ -580,6 +660,14 @@ "print(json.dumps(uranium_fit._results['Iteration Results'][-1],indent=4))" ] }, + { + "cell_type": "markdown", + "id": "e81eee65", + "metadata": {}, + "source": [ + "#### Bug: Pleiades is only printing two isotopes. " + ] + }, { "cell_type": "markdown", "id": "ddba4fd0", @@ -590,7 +678,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 21, "id": "697222b9", "metadata": {}, "outputs": [ diff --git a/pleiades/sammyRunner.py b/pleiades/sammyRunner.py index 614c7c1..660270d 100644 --- a/pleiades/sammyRunner.py +++ b/pleiades/sammyRunner.py @@ -19,15 +19,6 @@ def single_run(fit_dir: str= "", input_file: str = "", par_file: str = "", data_ raise ValueError("Parameter file is required") if not data_file: raise ValueError("Data file is required") - - # Create a symbolic link to the data file in the fit_dir - data_file_name = pathlib.Path(data_file).name - - # Check if the symbolic link already exists - if os.path.islink(pathlib.Path(fit_dir) / data_file_name): - os.unlink(pathlib.Path(fit_dir) / data_file_name) # unlink old symlink - - os.symlink(data_file, pathlib.Path(fit_dir) / data_file_name) # create new symlink # Check if files exist full_path_to_input_file = pathlib.Path(fit_dir) / input_file @@ -62,7 +53,7 @@ def single_run(fit_dir: str= "", input_file: str = "", par_file: str = "", data_ sammy < 0: print(f"Writing output parFile: {output_par_file}") outputParFile.write(output_par_file) @@ -423,13 +433,26 @@ def configure_sammy_run(config: SammyFitConfig, verbose_level: int = 0): if verbose_level > 1: print(inp.data) # Create a run name or handle for the compound inpFile - #TODO: Think about a better way to name files and dir. Should we use 'compound' or 'final'. We used compound because there is often more than one isotope to be fitted, but this is confusing if you only have one isotope. + #TODO: fix hard coding of inpFile name output_inp_file = Path(sammy_fit_dir) / Path('input').with_suffix(".inp") # Write the SAMMY input file to the specified location. inp.process().write(output_inp_file) if verbose_level > 0: print(f"Created compound input file: {output_inp_file}") + # Create a symbolic link inside the sammy_fit_dir that points to the data file + data_file = os.path.join(data_dir, config.params['filenames']['data_file_name']) + data_file_name = pathlib.Path(data_file).name + + if verbose_level > 0: print(f"Symlinking data file: {data_file} into {sammy_fit_dir}") + + # Check if the symbolic link already exists + symlink_path = pathlib.Path(sammy_fit_dir) / data_file_name + if os.path.islink(symlink_path): + os.unlink(symlink_path) # unlink old symlink + + os.symlink(data_file, pathlib.Path(sammy_fit_dir) / data_file_name) # create new symlink + def run_sammy(config: SammyFitConfig, verbose_level: int = 0): """ @@ -443,8 +466,8 @@ def run_sammy(config: SammyFitConfig, verbose_level: int = 0): sammy_fit_dir = config.params['directories']['sammy_fit_dir'] data_dir = config.params['directories']['data_dir'] - input_file = 'input.inp' - parameter_file = 'params.par' + input_file = config.params['filenames']['input_file_name'] + parameter_file = config.params['filenames']['params_file_name'] data_file = data_dir +"/"+ config.params['filenames']['data_file_name'] sammyRunner.single_run(sammy_fit_dir, input_file, parameter_file, data_file, verbose_level=verbose_level)