Skip to content

Commit

Permalink
Pushing up mods
Browse files Browse the repository at this point in the history
  • Loading branch information
kenatcampbellmusclelab committed Mar 11, 2024
1 parent 5229484 commit aaf0665
Show file tree
Hide file tree
Showing 61 changed files with 32,410 additions and 57 deletions.
Binary file modified bin/FiberCpp.exe
Binary file not shown.
Binary file modified bin/FiberCpp.pdb
Binary file not shown.
4 changes: 2 additions & 2 deletions code/FiberCpp/global_definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

#define MAX_NO_OF_HALF_SARCOMERES 500

#define MAX_NO_OF_THICK_FILAMENTS 200
#define MAX_NO_OF_THICK_FILAMENTS 10000

#define MAX_NO_OF_THIN_FILAMENTS 400
#define MAX_NO_OF_THIN_FILAMENTS 20000

#define MAX_NO_OF_KINETIC_STATES 10

Expand Down
2 changes: 1 addition & 1 deletion code/FiberPy/FiberPy/package/modules/batch/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def run_batch(json_batch_file_string=[],
while threads or my_list:
if (len(threads) < num_processes) and my_list:
t = threading.Thread(target=worker, args=[my_list.pop()])
t.setDaemon(True)
t.daemon = True
t.start()
threads.append(t)
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,8 @@ def generate_model_files(json_analysis_file_string):
orig_options_file = os.path.join(temp_dir,
model_struct['options_file'])
new_options_file = os.path.join(generated_dir, model_struct['options_file'])
elif (model_struct['relative_to'] == 'false'):
elif (model_struct['relative_to'] == 'False'):
orig_options_file = model_struct['options_file']

temp, file_name = os.path.split(orig_options_file)
new_options_file = os.path.join(generated_dir, file_name)
else:
Expand Down Expand Up @@ -1965,4 +1964,12 @@ def characterize_fv_with_pCa_and_isometric_force(json_analysis_file_string,

# Now run the isotonic batch
batch.run_batch(isotonic_batch_file, figures_only=figures_only)


def return_base_dir(struct, file_string):
base_dir = ''
if ('relative_to' in struct):
if (struct['relative_to'] == 'this_file'):
base_dir = str(Path(file_string).parent.absolute().resolve())
elif not (struct['relative_to'] == 'False'):
base_dir = struct['relative_to']
return base_dir
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ def run_render_batch():
last argument is render_job_file """

# Unpack the arguments
render_job_file = sys.argv[-1]
for (i,a) in enumerate(sys.argv):
print('%i %s' % (i,sys.argv[i]))

render_job_file = sys.argv[5]

# Open the render file and pull off the job
with open(render_job_file, 'r') as f:
Expand Down Expand Up @@ -72,7 +75,7 @@ def run_render_job(frame_data, template_data, options_data):
hs_blend = hs_b.hs_blender(h, frame_data, template_data, options_data,
output_image_file)

bpy.ops.wm.quit_blender()
# bpy.ops.wm.quit_blender()

return

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def __init__(self, json_file_string):
hs_data = json_data['hs_data']
self.t_attach_a_node = json_data['titin']['t_attach_a_node']
self.t_attach_m_node = json_data['titin']['t_attach_m_node']
self.t_slack_length = json_data['titin']['t_slack_length']
self.t_k_stiff = json_data['titin']['t_k_stiff']
self.cb_extensions = hs_data['cb_extensions']
self.hs_id = hs_data['hs_id']
Expand Down
83 changes: 72 additions & 11 deletions code/FiberPy/FiberPy/package/modules/visualization/hs_blender.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,26 @@ def __init__(self, hs, frame, template, options, output_image_file):

# Create thick filaments
for i, thick_fil in enumerate(self.hs.thick_fil):
self.create_thick_filament(i)
if (thick_fil.m_y < 3):
self.create_thick_filament(i)

# Create thin filaments
for i, thin_fil in enumerate(self.hs.thin_fil):
self.create_thin_filament(i)
if (thin_fil.a_y < 2):
self.create_thin_filament(i)

# Set nearest thin filaments
# by adding an array into the hs.thick_fil structure
self.set_nearest_thin_filaments()
# # Set nearest thin filaments
# # by adding an array into the hs.thick_fil structure
# self.set_nearest_thin_filaments()

# # # Draws titin filaments
self.create_titin_filaments()
# # # # Draws titin filaments
# self.create_titin_filaments()

# Create cross-bridges
self.create_cross_bridges()
# # Create cross-bridges
# self.create_cross_bridges()

# Create mybpc
self.create_mybpcs()
# # Create mybpc
# self.create_mybpcs()

# Hide the primitives
for p in self.hs_b['primitives']:
Expand Down Expand Up @@ -142,6 +144,11 @@ def create_camera(self):
location=loc,
rotation=rot)
bpy.context.object.data.lens = 20

if ('orthographic' in self.frame['camera']):
bpy.context.object.data.type = 'ORTHO'
bpy.context.object.data.ortho_scale = self.frame['camera']['orthographic']['ortho_scale']
bpy.context.object.data.clip_end = self.options['max_render_distance']

bpy.context.scene.camera = bpy.context.object

Expand All @@ -153,6 +160,12 @@ def render_screenshot(self):
"""Renders a screen capture of the current geometry."""

bpy.context.scene.render.filepath = self.output_image_file

print(self.options)

bpy.context.scene.render.resolution_x = self.options['image_pixels'][0]
bpy.context.scene.render.resolution_y = self.options['image_pixels'][1]

bpy.context.scene.frame_set(1)
bpy.ops.render.render(write_still=True)
return
Expand Down Expand Up @@ -257,6 +270,38 @@ def create_thin_filament(self, thin_id):
cam_loc = np.asarray([self.frame['camera']['location']['x'],
self.frame['camera']['location']['y'],
self.frame['camera']['location']['z']])

# Branch on mode
if (self.frame['style'] == 'x_ray'):

thin_f = self.hs.thin_fil[thin_id]
bs_indices = np.arange(0, thin_f.a_no_of_bs)

for bs_i in bs_indices:

bs_angle = thin_f.bs_angle[bs_i]

sph = self.hs_b['primitives']['bs_sphere'].copy()
sph.name = ('a_bs_sp_%i_%i' % (thin_id, bs_i))

bot_x = thin_f.bs_x[bs_i]
bot_y = self.yz_scaling * thin_f.a_y + \
self.template['thin_filament']['node']['radius'] * \
np.sin(np.pi * bs_angle / 180.0)
bot_z = self.yz_scaling * thin_f.a_z + \
self.template['thin_filament']['node']['radius'] * \
np.cos(np.pi * bs_angle / 180.0)

# Check distance
h = np.linalg.norm(cam_loc - np.asarray([bot_x, bot_y, bot_z]))
if (h > self.options['max_render_distance']):
continue

sph.location=(bot_x, bot_y, bot_z)

bpy.context.collection.objects.link(sph)

return

# Set the thin file
thin_f = self.hs.thin_fil[thin_id]
Expand Down Expand Up @@ -1372,6 +1417,22 @@ def create_bs_primitives(self):
mesh.materials.append(mat)

self.hs_b['primitives'][m_name] = m

# Create bs_sphere
bpy.ops.mesh.primitive_ico_sphere_add(
radius = self.template['thin_filament']['sphere']['radius'],
enter_editmode=False,
subdivisions=4,
location=(0,0,0))

m = bpy.context.object
mesh = m.data
m_name = 'bs_sphere'
mat = bpy.data.materials.new(name=m_name)
mat.diffuse_color = self.template['thin_filament']['sphere']['color']
mesh.materials.append(mat)

self.hs_b['primitives']['bs_sphere'] = m

def return_all_filament_y_coords(self):
"""Returns a list of all filament y coordinates"""
Expand Down
18 changes: 11 additions & 7 deletions code/FiberPy/FiberPy/package/modules/visualization/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def generate_images(render_batch_file):
threads.append(t)
else:
for thread in threads:
if not thread.isAlive():
if not thread.is_alive():
threads.remove(thread)

return
Expand All @@ -126,7 +126,7 @@ def worker(render_file):
blender_exe_path = options_data['blender_exe_path']

# Generate the command string
command_string = ('cd "%s"\n ' % blender_exe_path)
command_string = ('c: & cd "%s" & ' % blender_exe_path)

# Deduce the path to this folder
parent_path = Path(__file__).parent
Expand All @@ -142,10 +142,14 @@ def worker(render_file):

# Complete the commmand line
command_string = command_string + \
('blender -noaudio %s --python "%s" -- -j "%s"' %
(background_string,
generate_path,
os.path.abspath(render_file)))
('blender --python "%s" -- -j "%s" -noaudio %s ' %
(generate_path,
os.path.abspath(render_file),
background_string))

print('\nCommand string:')
print(command_string)
print('')

# Write command to temp.bat
bat_file_string = 'run_job_%i.bat' % render_job['job_number']
Expand All @@ -158,7 +162,7 @@ def worker(render_file):
subprocess.call(bat_file_string)
time.sleep(1)
try:
os.remove(bat_file_string)
# os.remove(bat_file_string)
print('deleted %s' % bat_file_string)
except:
print('No file to delete')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,15 @@ def summary_figure():
no_of_conditions = no_of_conditions - 1

# Now we can make a figure with one column per condition
no_of_rows = 4
no_of_rows = 7
no_of_cols = no_of_conditions

pCa_row = 1
hs_force_row = 2
hs_titin_row = 3
hs_length_row = 4
m_pop_row = 5
delta_hs_length_row = 6

fig = plt.figure(constrained_layout = False)
spec = gridspec.GridSpec(nrows = no_of_rows,
Expand Down Expand Up @@ -135,14 +137,48 @@ def summary_figure():
# hs_length
plot_index = ((hs_length_row-1) * no_of_cols) + i
for j in range(no_of_hs):
col_string = 'hs_%i_length' % (j+1);
col_string = 'hs_%i_length' % (j+1)
ax[plot_index].plot(d['time'], d[col_string], '-',
color=cmap(cmap_values[j]))
if (d[col_string].max() > max_hsl):
max_hsl = d[col_string].max()
if (d[col_string].max() < min_hsl):
min_hsl = d[col_string].min()


# m_pops
plot_index = ((m_pop_row-1) * no_of_cols) + i
for j in range(no_of_hs):
col_string = 'hs_%i_m_pop_1' % (j+1);
ax[plot_index].plot(d['time'], d[col_string], '-',
color=cmap(cmap_values[j]),
label = 'hs_%i' % (j+1))

# delta_hs_length_row
plot_index = ((delta_hs_length_row-1) * no_of_cols) + i
bp = []
for j in range(no_of_hs):
col_string = 'hs_%i_length' % (j+1)
d_hsl_dt = d[col_string].diff()
vi = d_hsl_dt.idxmax()
ax[plot_index].plot(d['time'], d[col_string].diff(), '-',
color=cmap(cmap_values[j]),
label = 'hs_%i' % (j+1))
ax[plot_index].plot(d['time'].loc[vi], d_hsl_dt.loc[vi], 'o',
color=cmap(cmap_values[j]),
markerfacecolor='none')
bp.append(vi)

# Plot break_points
print(bp)
bp = np.asarray(bp)

plot_index = plot_index + no_of_cols
for j in range(no_of_hs):
print(j)
ax[plot_index].plot(j, bp[j],'o',
color=cmap(cmap_values[j]),
markerfacecolor='none')

# Apply limits
for i in range(no_of_conditions):

Expand All @@ -161,6 +197,20 @@ def summary_figure():
# HSL
plot_index = ((hs_length_row - 1) * no_of_cols) + i
ax[plot_index].set_ylim([min_hsl - 50, max_hsl + 50])

for i in range(no_of_cols):
for j in range(no_of_rows-1):
plot_index = j*no_of_cols + i
ax[plot_index].set_xlim([0.9, 1.5])


# # Add legend
# for i in range(no_of_conditions):

# # pCa
# plot_index = ((m_pop_row - 1) * no_of_cols) + i
# ax[plot_index].legend(loc='upper left',
# bbox_to_anchor=(1.05, 1))


ofs = os.path.join(top_data_folder, 'summary.png')
Expand Down Expand Up @@ -233,5 +283,5 @@ def superpose_traces():
if __name__ == "__main__":
summary_figure()

superpose_traces()
#superpose_traces()

Loading

0 comments on commit aaf0665

Please sign in to comment.