From 8ebb960bf6343573a4ed05816d8873a1852bbf3b Mon Sep 17 00:00:00 2001 From: Sparks29032 Date: Wed, 12 Jun 2024 19:49:44 -0400 Subject: [PATCH 1/7] Rename csv to txt (not csv) --- src/diffpy/pdfmorph/pdfmorph_io.py | 2 +- .../{Morph_Reference_Table.csv => Morph_Reference_Table.txt} | 0 .../{Morph_Reference_Table.csv => Morph_Reference_Table.txt} | 0 3 files changed, 1 insertion(+), 1 deletion(-) rename src/diffpy/pdfmorph/tests/testdata/testsaving/succinct/{Morph_Reference_Table.csv => Morph_Reference_Table.txt} (100%) rename src/diffpy/pdfmorph/tests/testdata/testsaving/verbose/{Morph_Reference_Table.csv => Morph_Reference_Table.txt} (100%) diff --git a/src/diffpy/pdfmorph/pdfmorph_io.py b/src/diffpy/pdfmorph/pdfmorph_io.py index 3153605e..81a96ece 100644 --- a/src/diffpy/pdfmorph/pdfmorph_io.py +++ b/src/diffpy/pdfmorph/pdfmorph_io.py @@ -249,7 +249,7 @@ def multiple_morph_output( header = "# Data generated by pdfmorph\n" header += f"# from morphing {morph_path_name}\n" header += f"# with target directory {target_path_name}" - reference_table = Path(save_directory).joinpath("Morph_Reference_Table.csv") + reference_table = Path(save_directory).joinpath("Morph_Reference_Table.txt") with open(reference_table, "w") as reference: print(f"{header}\n{inputs}\n{verbose_outputs}{table}", file=reference) diff --git a/src/diffpy/pdfmorph/tests/testdata/testsaving/succinct/Morph_Reference_Table.csv b/src/diffpy/pdfmorph/tests/testdata/testsaving/succinct/Morph_Reference_Table.txt similarity index 100% rename from src/diffpy/pdfmorph/tests/testdata/testsaving/succinct/Morph_Reference_Table.csv rename to src/diffpy/pdfmorph/tests/testdata/testsaving/succinct/Morph_Reference_Table.txt diff --git a/src/diffpy/pdfmorph/tests/testdata/testsaving/verbose/Morph_Reference_Table.csv b/src/diffpy/pdfmorph/tests/testdata/testsaving/verbose/Morph_Reference_Table.txt similarity index 100% rename from src/diffpy/pdfmorph/tests/testdata/testsaving/verbose/Morph_Reference_Table.csv rename to src/diffpy/pdfmorph/tests/testdata/testsaving/verbose/Morph_Reference_Table.txt From 0f79b9f583288f95c6b433dd39668d94aa11d0a1 Mon Sep 17 00:00:00 2001 From: Sparks29032 Date: Wed, 12 Jun 2024 19:54:57 -0400 Subject: [PATCH 2/7] Ignore directories for multiple morphs --- src/diffpy/pdfmorph/pdfmorphapp.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/diffpy/pdfmorph/pdfmorphapp.py b/src/diffpy/pdfmorph/pdfmorphapp.py index d017f094..4efdec10 100755 --- a/src/diffpy/pdfmorph/pdfmorphapp.py +++ b/src/diffpy/pdfmorph/pdfmorphapp.py @@ -475,8 +475,13 @@ def multiple_morphs(parser, opts, pargs, stdout_flag=True): if not target_directory.is_dir(): parser.custom_error(f"{target_directory} is not a directory. Go to --help for usage.") - # Do not morph morph_file against itself if it is in the same directory + # Get list of files from target directory target_list = list(target_directory.iterdir()) + for target in target_list: + if target.is_dir(): + target_list.remove(target) + + # Do not morph morph_file against itself if it is in the same directory if morph_file in target_list: target_list.remove(morph_file) From 36ee24c5f42ad0b5b9ce5614982aae5fb63353ea Mon Sep 17 00:00:00 2001 From: Sparks29032 Date: Wed, 12 Jun 2024 20:02:15 -0400 Subject: [PATCH 3/7] Reorder options for --help --- src/diffpy/pdfmorph/pdfmorphapp.py | 119 +++++++++++++++-------------- 1 file changed, 60 insertions(+), 59 deletions(-) diff --git a/src/diffpy/pdfmorph/pdfmorphapp.py b/src/diffpy/pdfmorph/pdfmorphapp.py index 4efdec10..bad8f1c7 100755 --- a/src/diffpy/pdfmorph/pdfmorphapp.py +++ b/src/diffpy/pdfmorph/pdfmorphapp.py @@ -90,65 +90,6 @@ def custom_error(self, msg): minimizing the residual.""", ) - group = optparse.OptionGroup( - parser, - "Multiple Morphs", - """This program can morph a PDF against multiple targets in one command. - See -s and Plot Options for how saving and plotting functionality changes when performing multiple morphs.""", - ) - parser.add_option_group(group) - group.add_option( - "--multiple", - dest="multiple", - action="store_true", - help=f"""Changes usage to \'{prog_short} [options] FILE DIRECTORY\'. FILE - will be morphed with each file in DIRECTORY as target. - Files in DIRECTORY are sorted by alphabetical order unless a field is - specified by --sort-by.""", - ) - group.add_option( - "--sort-by", - metavar="FIELD", - dest="field", - help="""Used with --multiple to sort files in DIRECTORY by FIELD from lowest to highest. - FIELD must be included in the header of all the PDF files.""", - ) - group.add_option( - "--reverse", - dest="reverse", - action="store_true", - help="""Sort from highest to lowest instead.""", - ) - group.add_option( - "--serial-file", - metavar="SERIALFILE", - dest="serfile", - help="""Look for FIELD in a serial file instead. - Must specify name of serial file SERIALFILE.""", - ) - group.add_option( - "--save-names-file", - metavar="NAMESFILE", - dest="snamesfile", - help=f"""Used when both -s and --multiple are enabled. - Specify names for each manipulated PDF when saving (see -s) using a serial file - NAMESFILE. The format of NAMESFILE should be as follows: each target PDF - is an entry in NAMESFILE. For each entry, there should be a key {__save_morph_as__} - whose value specifies the name to save the manipulated PDF as. -(See sample names files in the PDFmorph tutorial).""", - ) - group.add_option( - "--plot-parameter", - metavar="PLOTPARAM", - dest="plotparam", - help="""Used when both plotting and --multiple are enabled. - Choose a PLOTPARAM to plot for each morph (i.e. adding --pp=Pearson means the program - will display a plot of the Pearson correlation coefficient for each morph-target pair). - PLOTPARAM is not case sensitive, so both Pearson and pearson indicate the same parameter. - When PLOTPARAM is not specified, Rw values for each morph-target pair will be plotted. - PLOTPARAM will be displayed as the vertical axis label for the plot.""", - ) - # Manipulations group = optparse.OptionGroup( parser, @@ -269,6 +210,66 @@ def custom_error(self, msg): group.add_option("--mag", type="float", help="Magnify plot curves beyond MAGLIM by MAG.") group.add_option("--lwidth", type="float", help="Line thickness of plotted curves.") + # Multiple morph options + group = optparse.OptionGroup( + parser, + "Multiple Morphs", + """This program can morph a PDF against multiple targets in one command. + See -s and Plot Options for how saving and plotting functionality changes when performing multiple morphs.""", + ) + parser.add_option_group(group) + group.add_option( + "--multiple", + dest="multiple", + action="store_true", + help=f"""Changes usage to \'{prog_short} [options] FILE DIRECTORY\'. FILE + will be morphed with each file in DIRECTORY as target. + Files in DIRECTORY are sorted by alphabetical order unless a field is + specified by --sort-by.""", + ) + group.add_option( + "--sort-by", + metavar="FIELD", + dest="field", + help="""Used with --multiple to sort files in DIRECTORY by FIELD from lowest to highest. + FIELD must be included in the header of all the PDF files.""", + ) + group.add_option( + "--reverse", + dest="reverse", + action="store_true", + help="""Sort from highest to lowest instead.""", + ) + group.add_option( + "--serial-file", + metavar="SERIALFILE", + dest="serfile", + help="""Look for FIELD in a serial file instead. + Must specify name of serial file SERIALFILE.""", + ) + group.add_option( + "--save-names-file", + metavar="NAMESFILE", + dest="snamesfile", + help=f"""Used when both -s and --multiple are enabled. + Specify names for each manipulated PDF when saving (see -s) using a serial file + NAMESFILE. The format of NAMESFILE should be as follows: each target PDF + is an entry in NAMESFILE. For each entry, there should be a key {__save_morph_as__} + whose value specifies the name to save the manipulated PDF as. +(See sample names files in the PDFmorph tutorial).""", + ) + group.add_option( + "--plot-parameter", + metavar="PLOTPARAM", + dest="plotparam", + help="""Used when both plotting and --multiple are enabled. + Choose a PLOTPARAM to plot for each morph (i.e. adding --pp=Pearson means the program + will display a plot of the Pearson correlation coefficient for each morph-target pair). + PLOTPARAM is not case sensitive, so both Pearson and pearson indicate the same parameter. + When PLOTPARAM is not specified, Rw values for each morph-target pair will be plotted. + PLOTPARAM will be displayed as the vertical axis label for the plot.""", + ) + # Defaults parser.set_defaults(multiple=False) parser.set_defaults(reverse=False) From 9534053a579d5d308853de80317f30cd7f233783 Mon Sep 17 00:00:00 2001 From: Sparks29032 Date: Thu, 13 Jun 2024 02:29:09 -0400 Subject: [PATCH 4/7] Make default to refine slope unless -x used --- src/diffpy/pdfmorph/pdfmorphapp.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/diffpy/pdfmorph/pdfmorphapp.py b/src/diffpy/pdfmorph/pdfmorphapp.py index bad8f1c7..0752b159 100755 --- a/src/diffpy/pdfmorph/pdfmorphapp.py +++ b/src/diffpy/pdfmorph/pdfmorphapp.py @@ -331,10 +331,11 @@ def single_morph(parser, opts, pargs, stdout_flag=True): chain.append(helpers.TransformXtalRDFtoPDF()) refpars.append("smear") config["smear"] = opts.smear + # Set baselineslope if not given config["baselineslope"] = opts.baselineslope if opts.baselineslope is None: - refpars.append("baselineslope") config["baselineslope"] = -0.5 + refpars.append("baselineslope") # Size radii = [opts.radius, opts.pradius] nrad = 2 - radii.count(None) @@ -371,8 +372,7 @@ def single_morph(parser, opts, pargs, stdout_flag=True): # Now remove non-refinable parameters if opts.exclude is not None: - refpars = set(refpars) - set(opts.exclude) - refpars = list(refpars) + refpars = list(set(refpars) - set(opts.exclude)) # Refine or execute the morph refiner = refine.Refiner(chain, x_morph, y_morph, x_target, y_target) @@ -388,12 +388,15 @@ def single_morph(parser, opts, pargs, stdout_flag=True): if "scale" in refpars: rptemp.append("scale") refiner.refine(*rptemp) + # Adjust all parameters refiner.refine(*refpars) except ValueError as e: parser.custom_error(str(e)) - elif "smear" in refpars and opts.baselineslope is None: + # Smear is not being refined, but baselineslope needs to refined to apply smear + # Note that baselineslope is only added to the refine list if smear is applied + elif "baselineslope" in refpars: try: - refiner.refine("baselineslope", baselineslope=-0.5) + refiner.refine("baselineslope", baselineslope=config["baselineslope"]) except ValueError as e: parser.custom_error(str(e)) else: From 476bd25f9e9009bfb52a50d0ba337b350e86ec56 Mon Sep 17 00:00:00 2001 From: Sparks29032 Date: Thu, 13 Jun 2024 03:41:56 -0400 Subject: [PATCH 5/7] Update help menu tips --- src/diffpy/pdfmorph/pdfmorphapp.py | 35 ++++++++++++++++++------------ 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/src/diffpy/pdfmorph/pdfmorphapp.py b/src/diffpy/pdfmorph/pdfmorphapp.py index 0752b159..6da48fff 100755 --- a/src/diffpy/pdfmorph/pdfmorphapp.py +++ b/src/diffpy/pdfmorph/pdfmorphapp.py @@ -53,7 +53,12 @@ def custom_error(self, msg): "Use --help for help.", ] ), - epilog="Please report bugs to diffpy-dev@googlegroups.com.", + epilog="\n".join( + [ + "For more information, see the PDFmorph manual." + "Please report bugs to diffpy-dev@googlegroups.com.", + ] + ), ) parser.add_option("-V", "--version", action="version", help="Show program version and exit.") @@ -140,7 +145,7 @@ def custom_error(self, msg): "--qdamp", type="float", metavar="QDAMP", - help="Dampen PDF by a factor QDAMP. (See PDFGui manual.)", + help="Dampen PDF by a factor QDAMP.", ) group.add_option( "--radius", @@ -196,18 +201,18 @@ def custom_error(self, msg): "--mlabel", metavar="MLABEL", dest="mlabel", - help="Set label for morphed data to MLABEL on plot. Ignored if using file names as labels.", + help="Set label for morphed data to MLABEL on plot. Default label is FILE1.", ) group.add_option( "--tlabel", metavar="TLABEL", dest="tlabel", - help="Set label for target data to TLABEL on plot. Ignored if using file names as labels.", + help="Set label for target data to TLABEL on plot. Default label is FILE2.", ) group.add_option("--pmin", type="float", help="Minimum r-value to plot. Defaults to RMIN.") group.add_option("--pmax", type="float", help="Maximum r-value to plot. Defaults to RMAX.") - group.add_option("--maglim", type="float", help="Magnify plot curves beyond MAGLIM by MAG.") - group.add_option("--mag", type="float", help="Magnify plot curves beyond MAGLIM by MAG.") + group.add_option("--maglim", type="float", help="Magnify plot curves beyond r=MAGLIM by MAG.") + group.add_option("--mag", type="float", help="Magnify plot curves beyond r=MAGLIM by MAG.") group.add_option("--lwidth", type="float", help="Line thickness of plotted curves.") # Multiple morph options @@ -231,7 +236,9 @@ def custom_error(self, msg): "--sort-by", metavar="FIELD", dest="field", - help="""Used with --multiple to sort files in DIRECTORY by FIELD from lowest to highest. + help="""Used with --multiple to sort files in DIRECTORY by FIELD. + If the FIELD being used has a numerical value, sort from lowest to highest. + Otherwise, sort in ASCII sort order. FIELD must be included in the header of all the PDF files.""", ) group.add_option( @@ -255,19 +262,19 @@ def custom_error(self, msg): Specify names for each manipulated PDF when saving (see -s) using a serial file NAMESFILE. The format of NAMESFILE should be as follows: each target PDF is an entry in NAMESFILE. For each entry, there should be a key {__save_morph_as__} - whose value specifies the name to save the manipulated PDF as. -(See sample names files in the PDFmorph tutorial).""", + whose value specifies the name to save the manipulated PDF as. An example .json + serial file is shown in the PDFmorph manual.""", ) group.add_option( "--plot-parameter", metavar="PLOTPARAM", dest="plotparam", help="""Used when both plotting and --multiple are enabled. - Choose a PLOTPARAM to plot for each morph (i.e. adding --pp=Pearson means the program - will display a plot of the Pearson correlation coefficient for each morph-target pair). - PLOTPARAM is not case sensitive, so both Pearson and pearson indicate the same parameter. - When PLOTPARAM is not specified, Rw values for each morph-target pair will be plotted. - PLOTPARAM will be displayed as the vertical axis label for the plot.""", + Choose a PLOTPARAM to plot for each morph (i.e. adding --plot-parameter=Pearson means the + program will display a plot of the Pearson correlation coefficient for each morph-target + pair). PLOTPARAM is not case sensitive, so both Pearson and pearson indicate the same + parameter. When PLOTPARAM is not specified, Rw values for each morph-target pair will be + plotted. PLOTPARAM will be displayed as the vertical axis label for the plot.""", ) # Defaults From c56c6ada1f8fa948a8e9c35b54ad7a6488e634d2 Mon Sep 17 00:00:00 2001 From: Sparks29032 Date: Fri, 14 Jun 2024 10:44:41 -0400 Subject: [PATCH 6/7] Change diffpy-dev->diffpy-users --- src/diffpy/pdfmorph/pdfmorphapp.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/diffpy/pdfmorph/pdfmorphapp.py b/src/diffpy/pdfmorph/pdfmorphapp.py index 6da48fff..7f26ac00 100755 --- a/src/diffpy/pdfmorph/pdfmorphapp.py +++ b/src/diffpy/pdfmorph/pdfmorphapp.py @@ -55,8 +55,8 @@ def custom_error(self, msg): ), epilog="\n".join( [ - "For more information, see the PDFmorph manual." - "Please report bugs to diffpy-dev@googlegroups.com.", + "Please report bugs to diffpy-users@googlegroups.com.", + "For more information, see the PDFmorph website at https://www.diffpy.org/diffpy.pdfmorph.", ] ), ) From de7b62941839de69c8621e410ce68fe029a33c4c Mon Sep 17 00:00:00 2001 From: Sparks29032 Date: Fri, 14 Jun 2024 11:38:45 -0400 Subject: [PATCH 7/7] dev->users --- doc/manual/source/quickstart.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/manual/source/quickstart.rst b/doc/manual/source/quickstart.rst index 06e76455..5720be38 100644 --- a/doc/manual/source/quickstart.rst +++ b/doc/manual/source/quickstart.rst @@ -294,4 +294,4 @@ Bug Reports =========== Please enjoy using our software! If you come accross any bugs in the -application, please report them to diffpy-dev@googlegroups.com. +application, please report them to diffpy-users@googlegroups.com.