Skip to content

Adding multiple morphs for single target #145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Print statement fix
  • Loading branch information
Sparks29032 committed Oct 29, 2024
commit bed9b82ec4b8f83ac1268d454bb6923337baba29
22 changes: 18 additions & 4 deletions src/diffpy/pdfmorph/pdfmorph_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ def multiple_morph_output(
target_directory=None,
verbose=False,
stdout_flag=False,
mm=False,
):
"""Helper function for printing details about a series of multiple morphs.
Handles both printing to terminal and printing to a file.
Expand Down Expand Up @@ -201,6 +202,9 @@ def multiple_morph_output(
Print additional summary details when True (default False).
stdout_flag: bool
Print to terminal when True (default False).
mm: bool
Multiple morphs done with a single target rather than multiple targets for a single morphed file.
Swaps morph and target in the code.
"""

# Input parameters used for every morph
Expand All @@ -212,7 +216,10 @@ def multiple_morph_output(
if verbose:
# Output for every morph (information repeated in a succinct table below)
for target in morph_results.keys():
output = f"\n# Target: {target}\n"
if not mm:
output = f"\n# Target: {target}\n"
else:
output = f"\n# Morph: {target}\n"
output += "# Optimized morphing parameters:\n"
output += "\n".join(
f"# {param} = {morph_results[target][param]:.6f}" for param in morph_results[target]
Expand All @@ -223,7 +230,10 @@ def multiple_morph_output(
tabulated_results = tabulate_results(morph_results)

# Table labels
labels = "\n# Labels: [Target]"
if not mm:
labels = "\n# Labels: [Target]"
else:
labels = "\n# Labels: [Morph]"
if field is not None:
labels += f" [{field}]"
for param in tabulated_results.keys():
Expand Down Expand Up @@ -252,8 +262,12 @@ def multiple_morph_output(
target_path_name = str(Path(target_directory).resolve())

header = "# Data generated by pdfmorph\n"
header += f"# from morphing {morph_path_name}\n"
header += f"# with target directory {target_path_name}"
if not mm:
header += f"# from morphing {morph_path_name}\n"
header += f"# with target directory {target_path_name}"
else:
header += f"# from morphing directory {target_path_name}\n"
header += f"# with target {morph_path_name}"
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)
Expand Down
5 changes: 3 additions & 2 deletions src/diffpy/pdfmorph/pdfmorphapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,12 +732,13 @@ def multiple_morphs(parser, opts, pargs, stdout_flag=True):
morph_results,
morph_file_names,
save_directory=save_directory,
morph_directory=morph_directory,
target_file=target_file,
morph_file=target_file,
target_directory=morph_directory,
field=field,
field_list=field_list,
verbose=opts.verbose,
stdout_flag=stdout_flag,
mm=True,
)
except (FileNotFoundError, RuntimeError):
save_fail_message = "Unable to save summary to directory."
Expand Down