@@ -53,7 +53,12 @@ def custom_error(self, msg):
5353 "Use --help for help." ,
5454 ]
5555 ),
56- epilog = "Please report bugs to diffpy-dev@googlegroups.com." ,
56+ epilog = "\n " .join (
57+ [
58+ "Please report bugs to diffpy-users@googlegroups.com." ,
59+ "For more information, see the PDFmorph website at https://www.diffpy.org/diffpy.pdfmorph." ,
60+ ]
61+ ),
5762 )
5863
5964 parser .add_option ("-V" , "--version" , action = "version" , help = "Show program version and exit." )
@@ -90,65 +95,6 @@ def custom_error(self, msg):
9095 minimizing the residual.""" ,
9196 )
9297
93- group = optparse .OptionGroup (
94- parser ,
95- "Multiple Morphs" ,
96- """This program can morph a PDF against multiple targets in one command.
97- See -s and Plot Options for how saving and plotting functionality changes when performing multiple morphs.""" ,
98- )
99- parser .add_option_group (group )
100- group .add_option (
101- "--multiple" ,
102- dest = "multiple" ,
103- action = "store_true" ,
104- help = f"""Changes usage to \' { prog_short } [options] FILE DIRECTORY\' . FILE
105- will be morphed with each file in DIRECTORY as target.
106- Files in DIRECTORY are sorted by alphabetical order unless a field is
107- specified by --sort-by.""" ,
108- )
109- group .add_option (
110- "--sort-by" ,
111- metavar = "FIELD" ,
112- dest = "field" ,
113- help = """Used with --multiple to sort files in DIRECTORY by FIELD from lowest to highest.
114- FIELD must be included in the header of all the PDF files.""" ,
115- )
116- group .add_option (
117- "--reverse" ,
118- dest = "reverse" ,
119- action = "store_true" ,
120- help = """Sort from highest to lowest instead.""" ,
121- )
122- group .add_option (
123- "--serial-file" ,
124- metavar = "SERIALFILE" ,
125- dest = "serfile" ,
126- help = """Look for FIELD in a serial file instead.
127- Must specify name of serial file SERIALFILE.""" ,
128- )
129- group .add_option (
130- "--save-names-file" ,
131- metavar = "NAMESFILE" ,
132- dest = "snamesfile" ,
133- help = f"""Used when both -s and --multiple are enabled.
134- Specify names for each manipulated PDF when saving (see -s) using a serial file
135- NAMESFILE. The format of NAMESFILE should be as follows: each target PDF
136- is an entry in NAMESFILE. For each entry, there should be a key { __save_morph_as__ }
137- whose value specifies the name to save the manipulated PDF as.
138- (See sample names files in the PDFmorph tutorial).""" ,
139- )
140- group .add_option (
141- "--plot-parameter" ,
142- metavar = "PLOTPARAM" ,
143- dest = "plotparam" ,
144- help = """Used when both plotting and --multiple are enabled.
145- Choose a PLOTPARAM to plot for each morph (i.e. adding --pp=Pearson means the program
146- will display a plot of the Pearson correlation coefficient for each morph-target pair).
147- PLOTPARAM is not case sensitive, so both Pearson and pearson indicate the same parameter.
148- When PLOTPARAM is not specified, Rw values for each morph-target pair will be plotted.
149- PLOTPARAM will be displayed as the vertical axis label for the plot.""" ,
150- )
151-
15298 # Manipulations
15399 group = optparse .OptionGroup (
154100 parser ,
@@ -199,7 +145,7 @@ def custom_error(self, msg):
199145 "--qdamp" ,
200146 type = "float" ,
201147 metavar = "QDAMP" ,
202- help = "Dampen PDF by a factor QDAMP. (See PDFGui manual.) " ,
148+ help = "Dampen PDF by a factor QDAMP." ,
203149 )
204150 group .add_option (
205151 "--radius" ,
@@ -255,20 +201,82 @@ def custom_error(self, msg):
255201 "--mlabel" ,
256202 metavar = "MLABEL" ,
257203 dest = "mlabel" ,
258- help = "Set label for morphed data to MLABEL on plot. Ignored if using file names as labels ." ,
204+ help = "Set label for morphed data to MLABEL on plot. Default label is FILE1 ." ,
259205 )
260206 group .add_option (
261207 "--tlabel" ,
262208 metavar = "TLABEL" ,
263209 dest = "tlabel" ,
264- help = "Set label for target data to TLABEL on plot. Ignored if using file names as labels ." ,
210+ help = "Set label for target data to TLABEL on plot. Default label is FILE2 ." ,
265211 )
266212 group .add_option ("--pmin" , type = "float" , help = "Minimum r-value to plot. Defaults to RMIN." )
267213 group .add_option ("--pmax" , type = "float" , help = "Maximum r-value to plot. Defaults to RMAX." )
268- group .add_option ("--maglim" , type = "float" , help = "Magnify plot curves beyond MAGLIM by MAG." )
269- group .add_option ("--mag" , type = "float" , help = "Magnify plot curves beyond MAGLIM by MAG." )
214+ group .add_option ("--maglim" , type = "float" , help = "Magnify plot curves beyond r= MAGLIM by MAG." )
215+ group .add_option ("--mag" , type = "float" , help = "Magnify plot curves beyond r= MAGLIM by MAG." )
270216 group .add_option ("--lwidth" , type = "float" , help = "Line thickness of plotted curves." )
271217
218+ # Multiple morph options
219+ group = optparse .OptionGroup (
220+ parser ,
221+ "Multiple Morphs" ,
222+ """This program can morph a PDF against multiple targets in one command.
223+ See -s and Plot Options for how saving and plotting functionality changes when performing multiple morphs.""" ,
224+ )
225+ parser .add_option_group (group )
226+ group .add_option (
227+ "--multiple" ,
228+ dest = "multiple" ,
229+ action = "store_true" ,
230+ help = f"""Changes usage to \' { prog_short } [options] FILE DIRECTORY\' . FILE
231+ will be morphed with each file in DIRECTORY as target.
232+ Files in DIRECTORY are sorted by alphabetical order unless a field is
233+ specified by --sort-by.""" ,
234+ )
235+ group .add_option (
236+ "--sort-by" ,
237+ metavar = "FIELD" ,
238+ dest = "field" ,
239+ help = """Used with --multiple to sort files in DIRECTORY by FIELD.
240+ If the FIELD being used has a numerical value, sort from lowest to highest.
241+ Otherwise, sort in ASCII sort order.
242+ FIELD must be included in the header of all the PDF files.""" ,
243+ )
244+ group .add_option (
245+ "--reverse" ,
246+ dest = "reverse" ,
247+ action = "store_true" ,
248+ help = """Sort from highest to lowest instead.""" ,
249+ )
250+ group .add_option (
251+ "--serial-file" ,
252+ metavar = "SERIALFILE" ,
253+ dest = "serfile" ,
254+ help = """Look for FIELD in a serial file instead.
255+ Must specify name of serial file SERIALFILE.""" ,
256+ )
257+ group .add_option (
258+ "--save-names-file" ,
259+ metavar = "NAMESFILE" ,
260+ dest = "snamesfile" ,
261+ help = f"""Used when both -s and --multiple are enabled.
262+ Specify names for each manipulated PDF when saving (see -s) using a serial file
263+ NAMESFILE. The format of NAMESFILE should be as follows: each target PDF
264+ is an entry in NAMESFILE. For each entry, there should be a key { __save_morph_as__ }
265+ whose value specifies the name to save the manipulated PDF as. An example .json
266+ serial file is shown in the PDFmorph manual.""" ,
267+ )
268+ group .add_option (
269+ "--plot-parameter" ,
270+ metavar = "PLOTPARAM" ,
271+ dest = "plotparam" ,
272+ help = """Used when both plotting and --multiple are enabled.
273+ Choose a PLOTPARAM to plot for each morph (i.e. adding --plot-parameter=Pearson means the
274+ program will display a plot of the Pearson correlation coefficient for each morph-target
275+ pair). PLOTPARAM is not case sensitive, so both Pearson and pearson indicate the same
276+ parameter. When PLOTPARAM is not specified, Rw values for each morph-target pair will be
277+ plotted. PLOTPARAM will be displayed as the vertical axis label for the plot.""" ,
278+ )
279+
272280 # Defaults
273281 parser .set_defaults (multiple = False )
274282 parser .set_defaults (reverse = False )
@@ -330,10 +338,11 @@ def single_morph(parser, opts, pargs, stdout_flag=True):
330338 chain .append (helpers .TransformXtalRDFtoPDF ())
331339 refpars .append ("smear" )
332340 config ["smear" ] = opts .smear
341+ # Set baselineslope if not given
333342 config ["baselineslope" ] = opts .baselineslope
334343 if opts .baselineslope is None :
335- refpars .append ("baselineslope" )
336344 config ["baselineslope" ] = - 0.5
345+ refpars .append ("baselineslope" )
337346 # Size
338347 radii = [opts .radius , opts .pradius ]
339348 nrad = 2 - radii .count (None )
@@ -370,8 +379,7 @@ def single_morph(parser, opts, pargs, stdout_flag=True):
370379
371380 # Now remove non-refinable parameters
372381 if opts .exclude is not None :
373- refpars = set (refpars ) - set (opts .exclude )
374- refpars = list (refpars )
382+ refpars = list (set (refpars ) - set (opts .exclude ))
375383
376384 # Refine or execute the morph
377385 refiner = refine .Refiner (chain , x_morph , y_morph , x_target , y_target )
@@ -387,12 +395,15 @@ def single_morph(parser, opts, pargs, stdout_flag=True):
387395 if "scale" in refpars :
388396 rptemp .append ("scale" )
389397 refiner .refine (* rptemp )
398+ # Adjust all parameters
390399 refiner .refine (* refpars )
391400 except ValueError as e :
392401 parser .custom_error (str (e ))
393- elif "smear" in refpars and opts .baselineslope is None :
402+ # Smear is not being refined, but baselineslope needs to refined to apply smear
403+ # Note that baselineslope is only added to the refine list if smear is applied
404+ elif "baselineslope" in refpars :
394405 try :
395- refiner .refine ("baselineslope" , baselineslope = - 0.5 )
406+ refiner .refine ("baselineslope" , baselineslope = config [ "baselineslope" ] )
396407 except ValueError as e :
397408 parser .custom_error (str (e ))
398409 else :
@@ -475,8 +486,13 @@ def multiple_morphs(parser, opts, pargs, stdout_flag=True):
475486 if not target_directory .is_dir ():
476487 parser .custom_error (f"{ target_directory } is not a directory. Go to --help for usage." )
477488
478- # Do not morph morph_file against itself if it is in the same directory
489+ # Get list of files from target directory
479490 target_list = list (target_directory .iterdir ())
491+ for target in target_list :
492+ if target .is_dir ():
493+ target_list .remove (target )
494+
495+ # Do not morph morph_file against itself if it is in the same directory
480496 if morph_file in target_list :
481497 target_list .remove (morph_file )
482498
0 commit comments