Page 1 of 1
how to get states from .mot file using API commands?
Posted: Tue Oct 23, 2018 2:23 pm
by dhruv
Hello all,
This might be trivial for a lot of you, but I am new to using API/Doxygen commands in MATLAB. I am trying to find muscle moment arms using the command
Muscle.computeMomentArm(state, coordinate);
How can I find the "state" from a .mot file?
Thanks!
Dhruv
Re: how to get states from .mot file using API commands?
Posted: Tue Oct 23, 2018 2:33 pm
by chrisdembia
If you are using 4.0, you can use the StatesTrajectory class. See the following example in Python (the code should look very similar in MATLAB).
https://github.com/opensim-org/opensim- ... example.py
Re: how to get states from .mot file using API commands?
Posted: Tue Oct 23, 2018 3:17 pm
by dhruv
Thanks for the response, Christopher. Based on the link, it seems like I need to use StatesTrajectory.createFromStatesStorage().
So is it anything like this?
import org.opensim.modeling.*
modelFile = 'ULB.osim';
osimModel = Model(modelFile);
motFile='mymotion_ik.mot';
coordinateSto = Storage(motFile);
state = StatesTrajectory.createFromStatesStorage(coordinateSto)
shoulderElvCoord = osimModel.updCoordinateSet().get('shoulder_elv');
muscles = osimModel.getMuscles();
nMuscles = muscles.getSize();
DELT1 = osimModel.getMuscles().get('DELT1');
momentarm = DELT1.computeMomentArm(state, shoulderElvCoord);
Does the computeMomentArm function calculate the muscle moment arm for the entire states trajectory or just one time point?
Again, I am sorry I am new to using API through MATLAB. So far I have only been using command line execution through MATLAB as a link to OpenSim.
Thanks for your time!
Dhruv
Re: how to get states from .mot file using API commands?
Posted: Tue Oct 23, 2018 3:42 pm
by chrisdembia
Dhruv that's pretty close. The return value of createFromStateStorage() is a StatesTrajectory, not a single state. So you need to loop through each state. There is likely a method like get() on the StatesTrajectory.
computeMomentArm() operates on a single state, not the entire trajectory.
Re: how to get states from .mot file using API commands?
Posted: Tue Oct 23, 2018 5:44 pm
by dhruv
Thanks Christopher. I looked up in the API documentation and is said that the use in python is something like this:
import opensim
model = opensim.Model("subject01.osim")
sto = opensim.Storage("subject01_states.sto")
states = opensim.StatesTrajectory.createFromStatesStorage(model, sto)
so for MATLAB I wrote this:
import org.opensim.modeling.*
modelFile = 'ULB_Simple_v33_Thorax_markers_hand_MoBLmuscles_knee.osim';
osimModel = Model(modelFile);
coordinateSto = Storage('M_S9_R_MB_f6_ik.mot');
states = StatesTrajectory.createFromStatesStorage(osimModel, coordinateSto)
But it gives me an error that
Undefined variable "StatesTrajectory" or class "StatesTrajectory.createFromStatesStorage".
I think I missed your earlier comment. I am using OpenSim 3.3. Is there a way to load the additional library or something so I can use the functions of StatesTrajectory?
Thank You
Dhruv
Re: how to get states from .mot file using API commands?
Posted: Tue Oct 23, 2018 5:52 pm
by chrisdembia
StatesTrajectory is only available in 4.0. For 3.3, you can try reimplementing the following Python program in Matlab:
https://github.com/chrisdembia/perimysi ... ng.py#L619
Re: how to get states from .mot file using API commands?
Posted: Tue Oct 23, 2018 7:03 pm
by dhruv
Thank You, Christopher. It seems to work, but I have a question though. I calculated the moment arm using three different ways
1. In the plotter in GUI using the _ik.mot file
2. In MATLAB using the _ik.mot file
3. In MATLAB using the _states.sto file (exported by performing RRA on the same motion).
For case 2 I used line 5 and for case 3 I used line 6 of the attached code.
The results for 1 and 3 match, but 2 does not. It make me wonder is the states calculations based on a _ik.mot in MATLAB correct?
- momentcalc.jpg (258.31 KiB) Viewed 738 times