Hey Moderators,
I'm scripting CMCs from Matlab. Prior to scake/IK/RRA, I saved a generic model with metabolic probes (UMB2010). However, when I get to CMC, the probes are disabled for some reason. I have found ways to addProbes and I can load the UMB Probeset, but I'm wondering if there's a way to simply enable the probes already present and update the model.
I noticed there are "isEnabled" and "set_enabled" functions & properties for the Probe in the API, but I can't seem to call the function correctly when referencing the model. I'm wondering if there is a difference between "Probe" and "ProbeSet"
https://simtk.org/api_docs/opensim/api_ ... Probe.html
I have an override by opening the model in OpenSim and manually enabling the probe, but it would be amazing to automate it.
Thank you!
Enable Metabolic Probe in Model?
- Ricky Pimentel
- Posts: 7
- Joined: Wed Aug 22, 2012 10:08 am
Enable Metabolic Probe in Model?
- Attachments
-
- Enabled Probes.JPG (30.52 KiB) Viewed 1170 times
-
- Disabled Probes.JPG (29.24 KiB) Viewed 1170 times
Tags:
- Thomas Uchida
- Posts: 1793
- Joined: Wed May 16, 2012 11:40 am
Re: Enable Metabolic Probe in Model?
It would be helpful to see what you're doing now. I think you should be using the setEnabled() method (https://simtk.org/api_docs/opensim/api_ ... 962f28529f).I noticed there are "isEnabled" and "set_enabled" functions & properties for the Probe in the API, but I can't seem to call the function correctly when referencing the model.
Yes, a Probe is an object that calculates something as a function of the State (https://simtk.org/api_docs/opensim/api_ ... Probe.html). A ProbeSet is a Set (collection) of such objects (https://simtk.org/api_docs/opensim/api_ ... beSet.html).I'm wondering if there is a difference between "Probe" and "ProbeSet"
- Ricky Pimentel
- Posts: 7
- Joined: Wed Aug 22, 2012 10:08 am
Re: Enable Metabolic Probe in Model?
Thanks Thomas,
My failed attempts to update or enable the current probe in the model are below. When I do this, CMC will run, but it will not export any muscle metabolic costs (attached picture).
As I already have the UMB2010 probe set up in the model, I'm trying to enable it. I could alternatively add the probe all over again, but I was wondering if simply enabling the current probe was possible before I attempt to re-create the "addMetabolicProbes.py" script in Matlab.
My failed attempts to update or enable the current probe in the model are below. When I do this, CMC will run, but it will not export any muscle metabolic costs (attached picture).
As I already have the UMB2010 probe set up in the model, I'm trying to enable it. I could alternatively add the probe all over again, but I was wondering if simply enabling the current probe was possible before I attempt to re-create the "addMetabolicProbes.py" script in Matlab.
Code: Select all
CMCmodel = Model(RRAUpdatedModel);
CMCmodel.initSystem();
% % cant make a call to the current probe, no function getProbe?
% Probe = CMCmodel.getProbe()
% % adding a probe adds as metabolics_0, but does not add probes to
% each muscle that the previous model already contains.
% activationMaintenanceRateOn = 'True';
% shorteningRateOn = 'True';
% basalRateOn = 'False';
% mechanicalWorkRateOn = 'True';
% reportTotalMetabolicsOnly = 'False';
wholeBodyProbe = Umberger2010MuscleMetabolicsProbe(); %activationMaintenanceRateOn, shorteningRateOn, basalRateOn, mechanicalWorkRateOn);
wholeBodyProbe.set_enabled(1)
wholeBodyProbe.isEnabled() % prints enable status in command window
wholeBodyProbe.setName("metabolics");
CMCmodel.addProbe(wholeBodyProbe)
% save model
CMCModel = strcat(CMCFolder, '\', Subjects(subj).name, '_', Subjects(subj).Trials(trial).name, '_CMC.osim');
CMCmodel.print(CMCModel);
- Attachments
-
- NoMetabolicResults.JPG (80.01 KiB) Viewed 1136 times
- Thomas Uchida
- Posts: 1793
- Joined: Wed May 16, 2012 11:40 am
Re: Enable Metabolic Probe in Model?
The "metabolics_0_TOTAL" column is the computed metabolic cost. The probe is enabled. My guess is that you wish to see a value for each muscle. To do that, you need to set "report_total_metabolics_only" to false (one of the lines you have commented out). Please see the documentation here: https://simtk.org/api_docs/opensim/api_ ... dd686dce8a.
- Ricky Pimentel
- Posts: 7
- Joined: Wed Aug 22, 2012 10:08 am
Re: Enable Metabolic Probe in Model?
Thanks, that is what I am trying to do. I have tried calling the function by:
activationMaintenanceRateOn = "True";
shorteningRateOn = "True";
basalRateOn = "False";
mechanicalWorkRateOn = "True";
reportTotalMetabolicsOnly = "False";
wholeBodyProbe = Umberger2010MuscleMetabolicsProbe(activationMaintenanceRateOn, shorteningRateOn, basalRateOn, mechanicalWorkRateOn);
as described in the documentation and example files (I also tried "modeling.Umberger2010... "), but I get the error:
or as an empty "wholeBodyProbe = Umberger2010MuscleMetabolicsProbe()" and then defining "wholeBodyProbe.set_report_total_metabolics_only(reportTotalMetabolicsOnly)" later on and the error reads.
That is why I am just trying to enable the current probe in the first place, rather than adding a new one. Any ideas on those errors or how to just enable the pre-loaded probe? Thanks for all the help
activationMaintenanceRateOn = "True";
shorteningRateOn = "True";
basalRateOn = "False";
mechanicalWorkRateOn = "True";
reportTotalMetabolicsOnly = "False";
wholeBodyProbe = Umberger2010MuscleMetabolicsProbe(activationMaintenanceRateOn, shorteningRateOn, basalRateOn, mechanicalWorkRateOn);
as described in the documentation and example files (I also tried "modeling.Umberger2010... "), but I get the error:
Code: Select all
No constructor 'org.opensim.modeling.Umberger2010MuscleMetabolicsProbe' with matching signature found.
Error in ABL_Batch_OpenSim (line 498)
wholeBodyProbe = Umberger2010MuscleMetabolicsProbe(activationMaintenanceRateOn, shorteningRateOn,
basalRateOn, mechanicalWorkRateOn);
Code: Select all
No method 'set_report_total_metabolics_only' with matching signature found for class
'org.opensim.modeling.Umberger2010MuscleMetabolicsProbe'.
Error in ABL_Batch_OpenSim (line 504)
wholeBodyProbe.set_report_total_metabolics_only(reportTotalMetabolicsOnly)
- Thomas Uchida
- Posts: 1793
- Joined: Wed May 16, 2012 11:40 am
Re: Enable Metabolic Probe in Model?
I think this should work:
Code: Select all
wholeBodyProbe.set_report_total_metabolics_only(false);
- Ricky Pimentel
- Posts: 7
- Joined: Wed Aug 22, 2012 10:08 am
Re: Enable Metabolic Probe in Model?
Gah, the capitalization and lack of ' ' got me. Hooray for working in multiple programming languages at once.
On that note, I translated the python addMetabolicProbes script into matlab.
Thank you for the help!
Hopefully this can be useful for someone:
On that note, I translated the python addMetabolicProbes script into matlab.
Thank you for the help!
Hopefully this can be useful for someone:
Code: Select all
clc;
import org.opensim.modeling.*
import java.io.*
% define model for CMC
CMCmodel = Model(RRAUpdatedModel);
CMCmodel.initSystem();
% get slow twitch data from text file
fn = 'C:\Users\richa\Documents\OpenSim 4.0\Metabolix\Scripts\metabolicsSlowTwitchRatios_Gait2392.txt';
fdata = importdata(fn);
muscleName = fdata.textdata;
twitchRatio = fdata.data;
% The following booleans are constructor arguments for the Umberger probe.
% These settings are used for all probes.
activationMaintenanceRateOn = true;
shorteningRateOn = true;
basalRateOn = false;
mechanicalWorkRateOn = true;
reportTotalMetabolicsOnly = false;
% The mass of each muscle will be calculated using data from the model:
% muscleMass = (maxIsometricForce / sigma) * rho * optimalFiberLength
% where sigma = 0.25e6 is the specific tension of mammalian muscle (in
% Pascals) and rho = 1059.7 is the density of mammalian muscle (in kg/m^3).
% The slow-twitch ratio used for muscles that either do not appear in the
% file, or appear but whose proportion of slow-twitch fibers is unknown.
defaultTwitchRatio = 0.5;
% Get the slow-twitch ratio as the default value.
slowTwitchRatio = ones(1,length(twitchRatio)) * defaultTwitchRatio;
% Define a whole-body probe that will report the total metabolic energy
% consumption over the simulation.
wholeBodyProbe = Umberger2010MuscleMetabolicsProbe(...
activationMaintenanceRateOn,...
shorteningRateOn,...
basalRateOn,...
mechanicalWorkRateOn);
wholeBodyProbe.setOperation("value");
wholeBodyProbe.set_report_total_metabolics_only(reportTotalMetabolicsOnly);
% Add the probe to the model and provide a name.
CMCmodel.addProbe(wholeBodyProbe);
wholeBodyProbe.setName("metabolics");
% Loop through all muscles, adding parameters for each into the whole-body probe.
for j = 1:CMCmodel.getMuscles().getSize()
% offset for python/C++ looping
iMuscle = j -1;
% save muscle name in text file via diary function
diary('temp.txt');
thisMuscle = CMCmodel.getMuscles().get(iMuscle)
diary off
% get muscle name and save
FID = fopen('temp.txt');
TXT = textscan(FID, '%s');
if strcmp(TXT{1}(end), 'off')
TXT{1}(end) = [];
end
if strcmp(TXT{1}(end), 'diary')
TXT{1}(end) = [];
end
txt = TXT{1}(end);
Muscle = txt{1}(1:end-2);
% Set the slow-twitch ratio to the physiological value, if it is known.
% for i = 1:length(twitchRatio) % in twitchRatios.items():
ind = find(contains({muscleName{:}}, Muscle));
if strcmp(Muscle, muscleName{ind}) && twitchRatio(ind) ~= -1
slowTwitchRatio(ind) = twitchRatio(ind);
end
% Add this muscle to the whole-body probe. The arguments are muscle
% name, slow-twitch ratio, and muscle mass. Note that the muscle mass
% is ignored unless we set useProvidedMass to True.
wholeBodyProbe.addMuscle(thisMuscle.getName(),...
slowTwitchRatio(ind));
end
% Save the new model to a file
CMCModelPath = strcat(CMCFolder, '\', Subjects(subj).name, '_', Subjects(subj).Trials(trial).name, '_CMC.osim');
CMCmodel.print(CMCModelPath);