Skip to main content

MuscleTendonPersonalizationTool.m


% This function is part of the NMSM Pipeline, see file for full license.
%
% This function takes a properly formatted XML file and runs the
% MuscleTendonPersonalization module and saves the results correctly for
% use in the OpenSim GUI.
%
% (string) -> (None)
% Run MuscleTendonPersonalization from settings file


function MuscleTendonPersonalizationTool(settingsFileName)
settingsTree = xml2struct(settingsFileName);
verifyVersion(settingsTree, "MuscleTendonPersonalizationTool");
[inputs, params, resultsDirectory] = ...
parseMuscleTendonPersonalizationSettingsTree(settingsTree);
precalInputs = parseMuscleTendonLengthInitializationSettingsTree(settingsTree);
if isstruct(precalInputs)
optimizedInitialGuess = MuscleTendonLengthInitialization(precalInputs);
inputs = updateMtpInitialGuess(inputs, precalInputs, ...
optimizedInitialGuess);
else
precalInputs = struct('optimizeIsometricMaxForce', false);
end

optimizedParams = MuscleTendonPersonalization(inputs, params);
if params.performMuscleTendonLengthInitialization
reportMuscleTendonPersonalizationResults(optimizedParams, ...
inputs, precalInputs);
else
reportMuscleTendonPersonalizationResults(optimizedParams, inputs);
end
finalValues = makeMtpValuesAsStruct([], optimizedParams, zeros(1, 7));
if precalInputs.optimizeIsometricMaxForce
finalValues.maxIsometricForce = inputs.maxIsometricForce;
end
results = calcMtpSynXModeledValues(finalValues, inputs, params);

results.time = inputs.emgTime(:, inputs.numPaddingFrames + 1 : ...
end - inputs.numPaddingFrames);
saveMuscleTendonPersonalizationResults(inputs.model, ...
inputs.osimxFileName, inputs.prefixes, inputs.coordinateNames, ...
finalValues, results, resultsDirectory, inputs.muscleTendonColumnNames);
end