How can I extract muscle activations after static optimization?

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Riza Bayoglu
Posts: 19
Joined: Wed Aug 02, 2023 8:54 am

How can I extract muscle activations after static optimization?

Post by Riza Bayoglu » Mon Mar 04, 2024 10:29 am

Hi,

I am running a static optimization simulation using Python scripting with OpenSim 4.4. I am interested to store muscle activations after a static optimization run. With this code below, I can access muscle names in my model and print activations, but the values seem un-correct (prints 0.05 for all the muscles). I understand that I need to access the model state corresponding the static optimization but failed to do this so far.

----

model = osim.Model(modelpath)

stat_opt = osim.AnalyzeTool('staticOpt_Setup.xml')
stat_opt.setModel(model)
stat_opt.setStartTime(0)
stat_opt.setFinalTime(0)
stat_opt.setCoordinatesFileName(posturepath)
stat_opt.run();

state = model.initSystem();
muscle_set = model.getMuscles()

for i in range(0, muscle_set.getSize()):

print(muscle_set.get(i).getName())
print(muscle_set.get(i).getActivation(state))

----

Another question I have is that I am more interested in storing the mathematical sum of all the muscles in the model than individual muscle activations. Is there a feature/default parameter in OpenSim that stores this value? Thanks for any help on this post.

Tags:

User avatar
Nicos Haralabidis
Posts: 188
Joined: Tue Aug 16, 2016 1:46 am

Re: How can I extract muscle activations after static optimization?

Post by Nicos Haralabidis » Mon Mar 04, 2024 11:20 am

Hey Riza,

After you run each StaticOptimization you should get an output file (*.sto) which contains the muscle activations for each muscle. You can load in that file and then perform your preferred analysis.

Hope that helps!

Best wishes,

Nicos

User avatar
Riza Bayoglu
Posts: 19
Joined: Wed Aug 02, 2023 8:54 am

Re: How can I extract muscle activations after static optimization?

Post by Riza Bayoglu » Mon Mar 04, 2024 11:44 am

Thanks Nicos! Yes, I should be able to extract the muscle activations using the .sto file. However, I will need to run static optimization several times within a loop, and ideally I like to access the values without exporting and reading the .sto file. Is that possible?

User avatar
Nicos Haralabidis
Posts: 188
Joined: Tue Aug 16, 2016 1:46 am

Re: How can I extract muscle activations after static optimization?

Post by Nicos Haralabidis » Mon Mar 04, 2024 4:22 pm

I see I see. You could write your own implementation of static optimization based on the tutorial here to avoid having to load the file as you say: https://simtk-confluence.stanford.edu:8 ... +in+MATLAB

Best wishes,

Nicos

POST REPLY