Skip to content

Commit

Permalink
a few fixes and tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
blairlyons committed Dec 21, 2023
1 parent fabad3f commit bdc7957
Showing 1 changed file with 30 additions and 37 deletions.
67 changes: 30 additions & 37 deletions simularium_readdy_models/visualization/actin_visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def get_bond_stretch_plot(
# stddev_long = np.std(stretch_long, axis=1)
return ScatterPlotData(
title="Bond stretch",
xaxis_title="Time (μs)",
xaxis_title="T (ms)",
yaxis_title="Bond stretch (nm)",
xtrace=times[::stride],
ytraces={
Expand Down Expand Up @@ -318,7 +318,7 @@ def get_angle_stretch_plot(
mean_long_long = np.mean(stretch_long_long, axis=1)
return ScatterPlotData(
title="Angle stretch",
xaxis_title="Time (μs)",
xaxis_title="T (ms)",
yaxis_title="Angle stretch (degrees)",
xtrace=times[::stride],
ytraces={
Expand Down Expand Up @@ -353,7 +353,7 @@ def get_dihedral_stretch_plot(
mean_long_long_long = np.mean(stretch_long_long_long, axis=1)
return ScatterPlotData(
title="Dihedral stretch",
xaxis_title="Time (μs)",
xaxis_title="T (ms)",
yaxis_title="Angle stretch (degrees)",
xtrace=times[::stride],
ytraces={
Expand All @@ -366,7 +366,7 @@ def get_dihedral_stretch_plot(
)

@staticmethod
def generate_filament_structure_plots(
def generate_actin_structure_plots(
trajectory: List[FrameData],
box_size: np.ndarray,
periodic_boundary: bool = True,
Expand Down Expand Up @@ -417,28 +417,28 @@ def generate_actin_compression_plots(
peak_asym = []
contour_length = []
total_steps = len(axis_positions)
control_pts = ReaddyPostProcessor.linear_fiber_control_points(axis_positions, 10.)
for time_ix in range(total_steps):
first_polymer_trace = axis_positions[time_ix][0]
perp_dist.append(CompressionAnalyzer.get_average_distance_from_end_to_end_axis(
polymer_trace=first_polymer_trace,
polymer_trace=control_pts[time_ix][0],
))
bending_energy.append(1000. * CompressionAnalyzer.get_bending_energy_from_trace(
polymer_trace=first_polymer_trace,
polymer_trace=control_pts[time_ix][0],
))
non_coplanarity.append(CompressionAnalyzer.get_third_component_variance(
polymer_trace=first_polymer_trace,
polymer_trace=control_pts[time_ix][0],
))
peak_asym.append(CompressionAnalyzer.get_asymmetry_of_peak(
polymer_trace=first_polymer_trace,
polymer_trace=control_pts[time_ix][0],
))
contour_length.append(CompressionAnalyzer.get_contour_length_from_trace(
polymer_trace=first_polymer_trace,
polymer_trace=control_pts[time_ix][0],
))
times = timestep * np.arange(total_steps)
plots["scatter"] += [
ScatterPlotData(
title="Average Perpendicular Distance",
xaxis_title="Time (μs)",
xaxis_title="T (ms)",
yaxis_title="distance (nm)",
xtrace=times,
ytraces={
Expand All @@ -450,7 +450,7 @@ def generate_actin_compression_plots(
),
ScatterPlotData(
title="Bending Energy",
xaxis_title="Time (μs)",
xaxis_title="T (ms)",
yaxis_title="energy",
xtrace=times,
ytraces={
Expand All @@ -462,7 +462,7 @@ def generate_actin_compression_plots(
),
ScatterPlotData(
title="Non-coplanarity",
xaxis_title="Time (μs)",
xaxis_title="T (ms)",
yaxis_title="3rd component variance from PCA",
xtrace=times,
ytraces={
Expand All @@ -474,7 +474,7 @@ def generate_actin_compression_plots(
),
ScatterPlotData(
title="Peak Asymmetry",
xaxis_title="Time (μs)",
xaxis_title="T (ms)",
yaxis_title="normalized peak distance",
xtrace=times,
ytraces={
Expand All @@ -486,7 +486,7 @@ def generate_actin_compression_plots(
),
ScatterPlotData(
title="Contour Length",
xaxis_title="Time (μs)",
xaxis_title="T (ms)",
yaxis_title="filament contour length (nm)",
xtrace=times,
ytraces={
Expand Down Expand Up @@ -585,14 +585,14 @@ def simularium_trajectory(
path_to_readdy_h5: str,
box_size: np.ndarray,
total_steps: int,
time_multiplier: float,
saved_frames: float,
longitudinal_bonds: bool = True,
) -> TrajectoryData:
"""
Get a TrajectoryData to visualize an actin trajectory in Simularium.
"""
data = ReaddyData(
timestep=(ActinVisualization.TIMESTEP * total_steps * time_multiplier),
timestep=1e-6 * (ActinVisualization.TIMESTEP * total_steps / saved_frames),
path_to_readdy_h5=path_to_readdy_h5,
meta_data=MetaData(
box_size=box_size,
Expand All @@ -605,19 +605,10 @@ def simularium_trajectory(
scale_factor=1.0,
),
display_data=ActinVisualization.ACTIN_DISPLAY_DATA(longitudinal_bonds),
time_units=UnitData("µs"),
time_units=UnitData("ms"),
spatial_units=UnitData("nm"),
)
converter = ReaddyConverter(data)
traj_data = converter.filter_data(
[
MultiplyTimeFilter(
multiplier=time_multiplier,
apply_to_plots=False,
)
]
)
return traj_data
return ReaddyConverter(data)._data

@staticmethod
def analyze_and_visualize_trajectory(
Expand All @@ -642,7 +633,7 @@ def analyze_and_visualize_trajectory(
path_to_readdy_h5=output_name + ".h5",
box_size=parameters["box_size"],
total_steps=total_steps,
time_multiplier=1e-3, # ns to us
saved_frames=1e3,
longitudinal_bonds=bool(parameters.get("longitudinal_bonds", True)),
)

Expand All @@ -651,6 +642,7 @@ def analyze_and_visualize_trajectory(
fiber_chain_ids = None
axis_positions = None
new_chain_ids = None
time_step = max(1, total_steps * 1E-3) * parameters.get("internal_timestep", 0.1) * 1E-6 # ms
if visualize_normals or visualize_control_pts or visualize_edges or plot_actin_structure or plot_actin_compression:
periodic_boundary = parameters.get("periodic_boundary", False)
post_processor = ReaddyPostProcessor(
Expand All @@ -659,7 +651,7 @@ def analyze_and_visualize_trajectory(
min_time_ix=0,
max_time_ix=-1,
time_inc=1,
timestep=parameters.get("internal_timestep", 0.1) * 1E-3, # us
timestep=time_step,
save_pickle_file=save_pickle,
).trajectory(),
box_size=parameters["box_size"],
Expand Down Expand Up @@ -692,18 +684,19 @@ def analyze_and_visualize_trajectory(

# create plots
plots = None
if plot_actin_compression:
print("plot actin compression metrics")
plots = ActinVisualization.generate_actin_compression_plots(
axis_positions,
time_step,
plots=plots,
)
if plot_actin_structure:
print("plot actin structure metrics")
plots = ActinVisualization.generate_filament_structure_plots(
plots = ActinVisualization.generate_actin_structure_plots(
post_processor.trajectory,
parameters["box_size"],
periodic_boundary=True,
)
if plot_actin_compression:
print("plot actin compression metrics")
plots = ActinVisualization.generate_actin_compression_plots(
axis_positions,
parameters.get("internal_timestep", 0.1) * 1E-3, # us
plots=plots,
)
traj_data = ActinVisualization.add_plots_to_trajectory(traj_data, plots)
Expand Down

0 comments on commit bdc7957

Please sign in to comment.