Skip to content

Commit

Permalink
plotting code fix
Browse files Browse the repository at this point in the history
  • Loading branch information
brittyscience committed Oct 8, 2024
1 parent b36f645 commit b4b9b66
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions mdagent/tools/base_tools/analysis_tools/hydrogen_bonding_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def plot_and_save_hb_plot(
plot_type: str,
method: str,
path_registry: PathRegistry,
annotations: list | None = None,
ylabel: str = "Value", # Added ylabel parameter with default value
) -> str:
"""
Expand All @@ -84,8 +85,14 @@ def plot_and_save_hb_plot(

plt.figure(figsize=(10, 6))
if plot_type == "histogram":
plt.hist(data, bins=10, edgecolor="black")
plt.xlabel("Value")
plt.hist(data, bins=10, edgecolor="black", alpha=0.7)
plt.xlabel(
"Hydrogen Bond Persistence (%)"
if method == "bakker_hubbard"
else "Bond Length (nm)"
if method == "wernet_nilsson"
else "Bond Energy (kcal/mol)"
)
plt.ylabel("Frequency")
elif plot_type == "time_series":
plt.plot(data, label="Hydrogen Bonds")
Expand Down Expand Up @@ -146,14 +153,14 @@ def _run(
if self.path_registry is None:
raise ValueError("Path registry is not set.")
try:
print("Loading trajectory...")
traj = load_single_traj(self.path_registry, top_file, traj_file)
if not traj:
return """Failed. Trajectory could not be loaded; unable to retrieve
data needed to find hydrogen bonds. This may be due to missing files,
corrupted files, or incorrect formatted file. Please check and try
again."""

# Call the appropriate helper function based on the method
if method == "wernet_nilsson":
result = compute_wernet_nilsson(traj)
else:
Expand Down

0 comments on commit b4b9b66

Please sign in to comment.