Page 1 of 1

How can I extract muscle activations after static optimization?

Posted: Mon Mar 04, 2024 10:29 am
by rizab34
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.

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

Posted: Mon Mar 04, 2024 11:20 am
by nicos1993
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

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

Posted: Mon Mar 04, 2024 11:44 am
by rizab34
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?

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

Posted: Mon Mar 04, 2024 4:22 pm
by nicos1993
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