diff --git a/Gui/CMakeLists.txt b/Gui/CMakeLists.txt index f00e156ad..795455fb8 100644 --- a/Gui/CMakeLists.txt +++ b/Gui/CMakeLists.txt @@ -13,8 +13,8 @@ endif() # etc INSTALL(DIRECTORY opensim/dist/opensim/opensim/etc/ DESTINATION etc) # Scripts -INSTALL(DIRECTORY opensim/Scripts/ DESTINATION Scripts/GUI_Scripting PATTERN ".svn" EXCLUDE - PATTERN "opensim/Scripts/Metabolics_example_scripts" EXCLUDE) +INSTALL(DIRECTORY opensim/Scripts/ DESTINATION Scripts/GUI_Scripting PATTERN ".svn" EXCLUDE) + # remaining folders INSTALL(DIRECTORY opensim/dist/opensim/opensim/ide/ DESTINATION ide) INSTALL(DIRECTORY opensim/dist/opensim/opensim/platform/ DESTINATION platform) @@ -35,4 +35,3 @@ INSTALL_FILES(/doc/ FILES ${TUTORIAL_FILES}) INCLUDE(${CMAKE_ROOT}/Modules/FindJava.cmake) SET(JRE_TO_PACKAGE "" CACHE PATH "jdk folder to include with distro") INSTALL(DIRECTORY ${JRE_TO_PACKAGE} DESTINATION jdk) - diff --git a/Gui/opensim/Scripts/Metabolics_example_scripts/CMC_EvaluateResults.py b/Gui/opensim/Scripts/Metabolics_example_scripts/CMC_EvaluateResults.py deleted file mode 100644 index 7240f9020..000000000 --- a/Gui/opensim/Scripts/Metabolics_example_scripts/CMC_EvaluateResults.py +++ /dev/null @@ -1,115 +0,0 @@ -# --------------------------------------------------------------------------- # -# OpenSim: CMC_EvaluateResults.py # -# --------------------------------------------------------------------------- # -# OpenSim is a toolkit for musculoskeletal modeling and simulation, # -# developed as an open source project by a worldwide community. Development # -# and support is coordinated from Stanford University, with funding from the # -# U.S. NIH and DARPA. See http://opensim.stanford.edu and the README file # -# for more information including specific grant numbers. # -# # -# Copyright (c) 2005-2017 Stanford University and the Authors # -# Author(s): Ayman Habib # -# # -# Licensed under the Apache License, Version 2.0 (the "License"); you may # -# not use this file except in compliance with the License. You may obtain a # -# copy of the License at http://www.apache.org/licenses/LICENSE-2.0 # -# # -# Unless required by applicable law or agreed to in writing, software # -# distributed under the License is distributed on an "AS IS" BASIS, # -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # -# See the License for the specific language governing permissions and # -# limitations under the License. # -# --------------------------------------------------------------------------- # -# Import needed packages - -# Utils contains tools to browse for files and folders -import org.opensim.utils as utils - -# Obtain Directory containing CMC results -#resultsFolderCMC = getInstallDir() + "/Models/gait10dof18musc/CMC/ResultsCMC" -resultsFolderCMC = utils.FileUtils.getInstance().browseForFolder("Select the folder with CMC Results",1); - -#################################### -# Plot kinematics errors -# Create Plotter panel -pErrPlot = createPlotterPanel("Kinematics Tracking Errors for CMC") - -# Load and plot kinematics data from CMC -src = addDataSource(pErrPlot, resultsFolderCMC+"/walk_subject_pErr.sto") -addCurve(pErrPlot, src, "time", "pelvis_tilt") -addCurve(pErrPlot, src, "time", "hip_flexion_r") -addCurve(pErrPlot, src, "time", "knee_angle_r") -addCurve(pErrPlot, src, "time", "ankle_angle_r") - -thresholdErrorGood = modeling.Constant(0.0349) -thresholdErrorGood.setName('GOOD') -addFunctionCurve(pErrPlot, thresholdErrorGood) -setCurveColor(pErrPlot, 4, 0.0, 1.0, 0.0) - -thresholdErrorGoodNeg = modeling.Constant(-0.0349) -thresholdErrorGoodNeg.setName('GOOD') -addFunctionCurve(pErrPlot, thresholdErrorGoodNeg) -setCurveColor(pErrPlot, 5, 0.0, 1.0, 0.0) - -thresholdErrorOK = modeling.Constant(0.0873) -thresholdErrorOK.setName('OK') -addFunctionCurve(pErrPlot, thresholdErrorOK) -setCurveColor(pErrPlot, 6, 1.0, 0.6, 0.4) - -thresholdErrorOKNeg = modeling.Constant(-0.0873) -thresholdErrorOKNeg.setName('OK') -addFunctionCurve(pErrPlot, thresholdErrorOKNeg) -setCurveColor(pErrPlot, 7, 1.0, 0.6, 0.4) - -############################## -# Plot the residual forces and moments -residualForcePlot = createPlotterPanel("Residual Forces and Moments") -src = addDataSource(residualForcePlot, resultsFolderCMC+"/walk_subject_Actuation_force.sto") - -# Add data to plots, label plots in legend -addCurve(residualForcePlot, src, "time", "FX") -addCurve(residualForcePlot, src, "time", "FY") -addCurve(residualForcePlot, src, "time", "MZ") - -# Plot threshold values -thresholdResidualForceGood = modeling.Constant(10) -thresholdResidualForceGood.setName('GOOD') -addFunctionCurve(residualForcePlot, thresholdResidualForceGood) -setCurveColor(residualForcePlot, 3, 0.0, 1.0, 0.0) - -thresholdResidualForceGoodNeg = modeling.Constant(-10) -thresholdResidualForceGoodNeg.setName('GOOD') -addFunctionCurve(residualForcePlot, thresholdResidualForceGoodNeg) -setCurveColor(residualForcePlot, 4, 0.0, 1.0, 0.0) - -thresholdResidualForceOK = modeling.Constant(25) -thresholdResidualForceOK.setName('OK') -addFunctionCurve(residualForcePlot, thresholdResidualForceOK) -setCurveColor(residualForcePlot, 5, 1.0, 0.6, 0.4) - -thresholdResidualForceOKNeg = modeling.Constant(-25) -thresholdResidualForceOKNeg.setName('OK') -addFunctionCurve(residualForcePlot, thresholdResidualForceOKNeg) -setCurveColor(residualForcePlot, 6, 1.0, 0.6, 0.4) - -############################## -# Plot the reserve actuator forces -reserveForcePlot = createPlotterPanel("Reserve Actuators") -src = addDataSource(reserveForcePlot, resultsFolderCMC+"/walk_subject_Actuation_force.sto") - -# Add data to plots, label plots in legend -addCurve(reserveForcePlot, src, "time", "hip_flexion_r_reserve") -addCurve(reserveForcePlot, src, "time", "knee_angle_r_reserve") -addCurve(reserveForcePlot, src, "time", "ankle_angle_r_reserve") -addCurve(reserveForcePlot, src, "time", "lumbar_extension_reserve") - -# Plot threshold values -thresholdReserveForceGood = modeling.Constant(25) -thresholdReserveForceGood.setName('GOOD') -addFunctionCurve(reserveForcePlot, thresholdReserveForceGood) -setCurveColor(reserveForcePlot, 4, 0.0, 1.0, 0.0) - -thresholdReserveForceGoodNeg = modeling.Constant(-25) -thresholdReserveForceGoodNeg.setName('GOOD') -addFunctionCurve(reserveForcePlot, thresholdReserveForceGoodNeg) -setCurveColor(reserveForcePlot, 5, 0.0, 1.0, 0.0) diff --git a/Gui/opensim/Scripts/Metabolics_example_scripts/addAnkleSpring.py b/Gui/opensim/Scripts/Metabolics_example_scripts/addAnkleSpring.py deleted file mode 100644 index 2e5f1a5cf..000000000 --- a/Gui/opensim/Scripts/Metabolics_example_scripts/addAnkleSpring.py +++ /dev/null @@ -1,52 +0,0 @@ -# --------------------------------------------------------------------------- # -# OpenSim: addAnkleSpring.py # -# --------------------------------------------------------------------------- # -# OpenSim is a toolkit for musculoskeletal modeling and simulation, # -# developed as an open source project by a worldwide community. Development # -# and support is coordinated from Stanford University, with funding from the # -# U.S. NIH and DARPA. See http://opensim.stanford.edu and the README file # -# for more information including specific grant numbers. # -# # -# Copyright (c) 2005-2017 Stanford University and the Authors # -# Author(s): Ayman Habib # -# # -# Licensed under the Apache License, Version 2.0 (the "License"); you may # -# not use this file except in compliance with the License. You may obtain a # -# copy of the License at http://www.apache.org/licenses/LICENSE-2.0 # -# # -# Unless required by applicable law or agreed to in writing, software # -# distributed under the License is distributed on an "AS IS" BASIS, # -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # -# See the License for the specific language governing permissions and # -# limitations under the License. # -# --------------------------------------------------------------------------- # -# Get a handle to the current model and create a new copy -baseModel = getCurrentModel() -ankleSpringModel = baseModel.clone() -ankleSpringModel.setName(baseModel.getName()+'_ankle_spring') - -# Create the spring we'll add to the model (a CoordinateLimitForce in OpenSim) -ankleSpring = modeling.CoordinateLimitForce() - -# Set the coordinate for the spring -ankleSpring.set_coordinate('ankle_angle_r') -ankleSpring.setName('AnkleLimitSpringDamper') - -# Add the spring to the model -ankleSpringModel.addForce(ankleSpring) - -# Load the model in the GUI -loadModel(ankleSpringModel) - -# Set the spring's properties -ankleSpring.setUpperStiffness(10.0) -ankleSpring.setUpperLimit(5.0) -ankleSpring.setLowerStiffness(1.0) -ankleSpring.setLowerLimit(-90.0) -ankleSpring.setDamping(0.01) -ankleSpring.setTransition(2.0) - -# Save the model to file -fullPathName = baseModel.getInputFileName() -newName = fullPathName.replace('.osim', '_spring.osim') -ankleSpringModel.print(newName) \ No newline at end of file diff --git a/Gui/opensim/Scripts/Metabolics_example_scripts/addMetabolicProbes.py b/Gui/opensim/Scripts/Metabolics_example_scripts/addMetabolicProbes.py deleted file mode 100644 index 2e6da6099..000000000 --- a/Gui/opensim/Scripts/Metabolics_example_scripts/addMetabolicProbes.py +++ /dev/null @@ -1,137 +0,0 @@ -# --------------------------------------------------------------------------- # -# OpenSim: addMetabolicProbes.py # -# --------------------------------------------------------------------------- # -# OpenSim is a toolkit for musculoskeletal modeling and simulation, # -# developed as an open source project by a worldwide community. Development # -# and support is coordinated from Stanford University, with funding from the # -# U.S. NIH and DARPA. See http://opensim.stanford.edu and the README file # -# for more information including specific grant numbers. # -# # -# Copyright (c) 2005-2017 Stanford University and the Authors # -# Author(s): Ayman Habib, Thomas Uchida, Christopher Dembia # -# # -# Licensed under the Apache License, Version 2.0 (the "License"); you may # -# not use this file except in compliance with the License. You may obtain a # -# copy of the License at http://www.apache.org/licenses/LICENSE-2.0 # -# # -# Unless required by applicable law or agreed to in writing, software # -# distributed under the License is distributed on an "AS IS" BASIS, # -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # -# See the License for the specific language governing permissions and # -# limitations under the License. # -# --------------------------------------------------------------------------- # - -# -# Authors: Christopher Dembia, Thomas Uchida -# Stanford University -# -# This script adds metabolic probes (MuscleMetabolicPowerProbeUmberger2010) -# to the current model loaded in the GUI. The new model is loaded into the -# GUI and saved to a file. The ratio of slow- to fast-twitch fibers in each -# muscle are obtained from a text file; all other probe parameters are -# defined below. - - -# Get a handle to the current model loaded in the GUI. -oldModel = getCurrentModel() - -# Create a fresh copy. Initialize and name the copy. -myModel = modeling.Model(oldModel) -myState = myModel.initSystem() -myModel.setName(oldModel.getName()+"_probed") - -# Open the data file containing slow-twitch ratios for common muscles. The -# file must be formatted as follows: -# - space-delimited -# - first column is the muscle name (excluding suffixes that distinguish -# between muscles on the left and right sides of the model) -# - second column is either the slow-twitch ratio (in the range [0,1]) or -# "-1" if the slow-twitch ratio is unknown for that muscle -import org.opensim.utils as utils -fn = utils.FileUtils.getInstance().browseForFilename(".txt", - "Please select the file containing the slow-twitch fiber ratios", True) -f = open(fn, "r") - -twitchRatios = dict() -for line in f: - # The file is space-delimited. - row = line.split(" ") - - # Ensure there are exactly two columns in each row. - if len(row) != 2: - raise Exception("There must be 2 columns in each row of the file.") - - muscleName = row[0] - twitchRatio = float(row[1]) - - # Place this row into the "twitchRatios" map. - twitchRatios[muscleName] = twitchRatio - - -# 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 - - -# Define a whole-body probe that will report the total metabolic energy -# consumption over the simulation. -wholeBodyProbe = modeling.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. -myModel.addProbe(wholeBodyProbe) -wholeBodyProbe.setName("metabolics") - -# Loop through all muscles, adding parameters for each into the whole-body -# probe. -for iMuscle in range(myModel.getMuscles().getSize()): - thisMuscle = myModel.getMuscles().get(iMuscle) - - # Get the slow-twitch ratio from the data we read earlier. Start with - # the default value. - slowTwitchRatio = defaultTwitchRatio - - # Set the slow-twitch ratio to the physiological value, if it is known. - for key, val in twitchRatios.items(): - if thisMuscle.getName().startswith(key) and val != -1: - slowTwitchRatio = val - - # 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) - -# Save the new model to a file with the suffix "_probed". -oldPathName = oldModel.getInputFileName() -newPathName = oldPathName.replace('.osim', '_probed.osim') -myModel.print(newPathName) - -# Add the new model to the GUI. -loadModel(newPathName) - -# Display the file name of the new model. -win = swing.JFrame("Complete") -dLabel = swing.JLabel("The probed model has been written to "+newPathName) -win.getContentPane().add(dLabel) -win.pack() -win.show() -win.setSize(1000,100) diff --git a/Gui/opensim/Scripts/Metabolics_example_scripts/addPathSpring.py b/Gui/opensim/Scripts/Metabolics_example_scripts/addPathSpring.py deleted file mode 100644 index 8b467d9b9..000000000 --- a/Gui/opensim/Scripts/Metabolics_example_scripts/addPathSpring.py +++ /dev/null @@ -1,48 +0,0 @@ -# --------------------------------------------------------------------------- # -# OpenSim: addPathSpring.py # -# --------------------------------------------------------------------------- # -# OpenSim is a toolkit for musculoskeletal modeling and simulation, # -# developed as an open source project by a worldwide community. Development # -# and support is coordinated from Stanford University, with funding from the # -# U.S. NIH and DARPA. See http://opensim.stanford.edu and the README file # -# for more information including specific grant numbers. # -# # -# Copyright (c) 2005-2017 Stanford University and the Authors # -# Author(s): Ayman Habib # -# # -# Licensed under the Apache License, Version 2.0 (the "License"); you may # -# not use this file except in compliance with the License. You may obtain a # -# copy of the License at http://www.apache.org/licenses/LICENSE-2.0 # -# # -# Unless required by applicable law or agreed to in writing, software # -# distributed under the License is distributed on an "AS IS" BASIS, # -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # -# See the License for the specific language governing permissions and # -# limitations under the License. # -# --------------------------------------------------------------------------- # -# Get a handle to the current model and create a new copy -baseModel = getCurrentModel() -pathSpringModel = baseModel.clone() -pathSpringModel.setName(baseModel.getName()+'_path_spring') - -# Create the spring we'll add to the model (a PathSpring in OpenSim) -name = 'BiarticularSpringDamper' -restLength = 0.4 -stiffness = 10000.0 -dissipation = 0.01 -pathSpring = modeling.PathSpring(name,restLength,stiffness,dissipation) - -# Set geometry path for the path spring to match the gastrocnemius muscle -gastroc = pathSpringModel.getMuscles().get('gastroc_r') -pathSpring.set_GeometryPath(gastroc.getGeometryPath()) - -# Add the spring to the model -pathSpringModel.addForce(pathSpring) - -# Load the model in the GUI -loadModel(pathSpringModel) - -# Save the model to file -fullPathName = baseModel.getInputFileName() -newName = fullPathName.replace('.osim', '_path_spring.osim') -pathSpringModel.print(newName) \ No newline at end of file diff --git a/Gui/opensim/Scripts/Metabolics_example_scripts/addPlotDeviceResults.py b/Gui/opensim/Scripts/Metabolics_example_scripts/addPlotDeviceResults.py deleted file mode 100644 index e76b557c6..000000000 --- a/Gui/opensim/Scripts/Metabolics_example_scripts/addPlotDeviceResults.py +++ /dev/null @@ -1,62 +0,0 @@ -# --------------------------------------------------------------------------- # -# OpenSim: addPlotDeviceResults.py # -# --------------------------------------------------------------------------- # -# OpenSim is a toolkit for musculoskeletal modeling and simulation, # -# developed as an open source project by a worldwide community. Development # -# and support is coordinated from Stanford University, with funding from the # -# U.S. NIH and DARPA. See http://opensim.stanford.edu and the README file # -# for more information including specific grant numbers. # -# # -# Copyright (c) 2005-2017 Stanford University and the Authors # -# Author(s): Ayman Habib # -# # -# Licensed under the Apache License, Version 2.0 (the "License"); you may # -# not use this file except in compliance with the License. You may obtain a # -# copy of the License at http://www.apache.org/licenses/LICENSE-2.0 # -# # -# Unless required by applicable law or agreed to in writing, software # -# distributed under the License is distributed on an "AS IS" BASIS, # -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # -# See the License for the specific language governing permissions and # -# limitations under the License. # -# --------------------------------------------------------------------------- # -# Plot the device results for comparison (muscle Rates and metabolic cost) -# Note: plotBaselineResults must be run first. -# Script assumes the prefix walk_subject for the CMC results - -# Utils contains tools to browse for files and folders -import org.opensim.utils as utils -import os - -# Obtain Directory containing device results -#resultsFolderCMC = getInstallDir() + "/Models/gait10dof18musc/CMC/ResultsCMC" -resultsFolderCMC = utils.FileUtils.getInstance().browseForFolder("Select the folder with device CMC Results",1); - -# Obtain the legend name -#legendName = "Device" -legendName = os.path.split(resultsFolderCMC)[1] - -# Plot the total metabolic energy -src = addDataSource(totalEnergyPlot, resultsFolderCMC+"/walk_subject_MetabolicsReporter_probes.sto") -crv = addCurve(totalEnergyPlot, src, "time", "metabolics_TOTAL") -crv.setLegend(legendName) - -# Plot the gastrocnemius muscle Rates -src = addDataSource(GastrocRatePlot, resultsFolderCMC+"/walk_subject_MetabolicsReporter_probes.sto") -crv = addCurve(GastrocRatePlot, src, "time", "metabolics_gastroc_r") -crv.setLegend(legendName) - -# Plot the soleus muscle Rates -src = addDataSource(SoleusRatePlot, resultsFolderCMC+"/walk_subject_MetabolicsReporter_probes.sto") -crv = addCurve(SoleusRatePlot, src, "time", "metabolics_soleus_r") -crv.setLegend(legendName) - -# Plot the tibialis anterior muscle Rates -src = addDataSource(TibAntRatePlot, resultsFolderCMC+"/walk_subject_MetabolicsReporter_probes.sto") -crv = addCurve(TibAntRatePlot, src, "time", "metabolics_tib_ant_r") -crv.setLegend(legendName) - -# Plot the iliopsoas metabolic rate -src = addDataSource(psoasRatePlot, resultsFolderCMC+"/walk_subject_MetabolicsReporter_probes.sto") -crv = addCurve(psoasRatePlot, src, "time", "metabolics_iliopsoas_r") -crv.setLegend(legendName) diff --git a/Gui/opensim/Scripts/Metabolics_example_scripts/computeMomentArm.py b/Gui/opensim/Scripts/Metabolics_example_scripts/computeMomentArm.py deleted file mode 100644 index 7234e58f2..000000000 --- a/Gui/opensim/Scripts/Metabolics_example_scripts/computeMomentArm.py +++ /dev/null @@ -1,198 +0,0 @@ -# --------------------------------------------------------------------------- # -# OpenSim: computeMomentArm.py # -# --------------------------------------------------------------------------- # -# OpenSim is a toolkit for musculoskeletal modeling and simulation, # -# developed as an open source project by a worldwide community. Development # -# and support is coordinated from Stanford University, with funding from the # -# U.S. NIH and DARPA. See http://opensim.stanford.edu and the README file # -# for more information including specific grant numbers. # -# # -# Copyright (c) 2005-2017 Stanford University and the Authors # -# Author(s): Ayman Habib, Thomas Uchida, Ajay Seth # -# # -# Licensed under the Apache License, Version 2.0 (the "License"); you may # -# not use this file except in compliance with the License. You may obtain a # -# copy of the License at http://www.apache.org/licenses/LICENSE-2.0 # -# # -# Unless required by applicable law or agreed to in writing, software # -# distributed under the License is distributed on an "AS IS" BASIS, # -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # -# See the License for the specific language governing permissions and # -# limitations under the License. # -# --------------------------------------------------------------------------- # - -# -# Author(s): Ajay Seth, Thomas Uchida, Ayman Habib -# Stanford University -# -# This script computes and plots moment arms for PathSprings, PathActuators, and -# other non-muscle forces that contain GeometryPaths. The user is first prompted -# to load the associated motion (kinematics) file, and must then select one of -# the model coordinates to use in the computation of the moment arms. - - -# Import required packages. -import org.opensim.utils as utils -from javax.swing import JButton,JComboBox,JFrame,JLabel -from java.awt import BorderLayout - - -# ------------------------------------------------------------------------------ -# Compute and plot moment arms for the coordinate selected by the user. -# ------------------------------------------------------------------------------ -def ComputeAndPlotMomentArms(coordIndex): - coordName = coordList[coordIndex] - - col_labels = motionStorage.getColumnLabels() - ncols = col_labels.getSize()-1 - ncoords = currentModel.getCoordinateSet().getSize() - nt = motionStorage.getSize() - inDegrees = motionStorage.isInDegrees() - if (inDegrees): - currentModel.getSimbodyEngine().convertDegreesToRadians(motionStorage) - - coord_inds = modeling.ArrayInt(ncoords, -1) - for i in range(0, ncoords): - coord_inds.set(i, motionStorage.getStateIndex(currentModel. - getCoordinateSet().get(i).getName())) - - # Create a zero-sized array, but pre-allocate the capacity to hold all the - # results. - momentArms = modeling.ArrayDouble(0.0, 0, nt) - times = modeling.ArrayDouble(0.0, 0, nt) - motionStorage.getTimeColumn(times) - - momentArmFunctions = modeling.FunctionSet() - - for i in range(0, pathForceNames.getSize()): - momentArmFunctions.adoptAndAppend(modeling.PiecewiseLinearFunction()) - momentArmFunctions.get(i).setName(pathForceNames.getitem(i) + '.' + - coordName) - - # For each instant in the motion file, update the coordinate values inside - # the state and compute the moment arms for the path force about the - # coordinate of interest. - for i in range(0, nt): - # Get the "state" data from the storage at this instant. - stateVec = motionStorage.getStateVector(i) - time = stateVec.getTime() - data = stateVec.getData() - - # Set the time on the state. - state.setTime(time) - - # Set the coordinate values on the state from the storage data. - for j in range(0, ncoords): - coord = currentModel.getCoordinateSet().get(j) - coord.setValue(state, data.getitem(coord_inds.getitem(j))) - - for k in range(0, pathForceNames.getSize()): - force = modeling.PathSpring.safeDownCast(forces.get(pathForceNames.getitem(k))) - if (force == None): - force = modeling.PathActuator.safeDownCast(forces.get(pathForceNames.getitem(k))) - ma_coord = currentModel.getCoordinateSet().get(coordIndex) - ma_coord.getName() - ma = force.computeMomentArm(state, ma_coord) - modeling.PiecewiseLinearFunction.safeDownCast(momentArmFunctions. - get(k)).addPoint(time, ma) - - # Plot moment arm curves - momentArmPlot = createPlotterPanel("Moment Arms") - momentArmPlot.setMinX(times.getitem(0)) - momentArmPlot.setMaxX(times.getitem(nt-1)) - momentArmPlot.setXAxisLabel(coordName + ' (rad)') - momentArmPlot.setYAxisLabel('Moment Arm (m)') - - for k in range(0, pathForceNames.getSize()): - hasNonZero = False - idx = 0 - while (not hasNonZero and modeling.PiecewiseLinearFunction.safeDownCast( - momentArmFunctions.get(k)).getNumberOfPoints() > idx): - if (modeling.PiecewiseLinearFunction.safeDownCast( - momentArmFunctions.get(k)).getY(idx) != 0): - hasNonZero = True - idx = idx + 1 - - if (hasNonZero): - addFunctionCurve(momentArmPlot, momentArmFunctions.get(k)) - - -# ------------------------------------------------------------------------------ -# Prompt the user to select the desired coordinate from the specified motion -# (kinematics) file. -# ------------------------------------------------------------------------------ -class CoordinateChooser: - def buttonPressed(self, event): - # The OK button was pressed; proceed to compute and plot moment arms - # relative to the selected coordinate. - coordIndex = self.cb.selectedIndex - coordName = self.data[coordIndex] - self.frame.setVisible(False) - ComputeAndPlotMomentArms(coordIndex) - - def __init__(self): - # Populate and display window for selecting a coordinate from the - # specified motion (kinematics) file. - self.frame = JFrame("Coordinate chooser") - self.frame.setSize(350,100) - self.frame.setLayout(BorderLayout()) - self.frame.setLocationRelativeTo(None) - - self.data = coordList - self.cb = JComboBox(self.data, preferredSize=(200,25)) - self.frame.add(self.cb, BorderLayout.WEST) - - btn = JButton('OK', preferredSize=(75,25), - actionPerformed=self.buttonPressed) - self.frame.add(btn, BorderLayout.EAST) - - self.label = JLabel('Please select the coordinate to use in the \ - moment arm calculations', preferredSize=(325,50)) - self.frame.add(self.label, BorderLayout.NORTH) - - self.frame.setVisible(True) - - -# ------------------------------------------------------------------------------ -# [main] Find all non-muscle forces acting along a path in the current model. -# Prompt the user to select a motion (kinematics) file, then display the -# Coordinate Chooser window. Execution then proceeds in the buttonPressed event -# handler. -# ------------------------------------------------------------------------------ -currentModel = getCurrentModel() - -# Get a working state so we can update the coordinate values. -state = currentModel.initSystem() - -# Get the path forces from the current model's force set. -forces = currentModel.getForceSet() - -# List of non-muscle forces acting along a path (i.e., compute the moment arms -# corresponding to these elements). -pathForceNames = modeling.ArrayStr() - -for i in range(0, forces.getSize()): - force = forces.get(i) - muscle = modeling.Muscle.safeDownCast(force) - if (muscle == None): - # The force is not a muscle. - if (force.hasGeometryPath()): - pathForceNames.append(force.getName()) - print 'Adding ' + force.getName() + \ - ' to list of forces to compute moment arm.' - -# Obtain a file containing the motion to use for computing moment arms. -motionFile = utils.FileUtils.getInstance().browseForFilename(".sto", - "Please select the storage/motion file with kinematics to compute moment \ - arms.", 1); -print motionFile - -if (motionFile != None): - motionStorage = modeling.Storage(motionFile) - - # Generate list of coordinates. - coordList = [] - for i in range(0, currentModel.getCoordinateSet().getSize()): - coordList.append(currentModel.getCoordinateSet().get(i).getName()) - - CoordinateChooser() diff --git a/Gui/opensim/Scripts/Metabolics_example_scripts/metabolicsSlowTwitchRatios_Gait2392.txt b/Gui/opensim/Scripts/Metabolics_example_scripts/metabolicsSlowTwitchRatios_Gait2392.txt deleted file mode 100644 index 75b9d8b19..000000000 --- a/Gui/opensim/Scripts/Metabolics_example_scripts/metabolicsSlowTwitchRatios_Gait2392.txt +++ /dev/null @@ -1,46 +0,0 @@ -glut_med1 0.55 -glut_med2 0.55 -glut_med3 0.55 -glut_min1 0.55 -glut_min2 0.55 -glut_min3 0.55 -semimem 0.4925 -semiten 0.425 -bifemlh 0.5425 -bifemsh 0.529 -add_mag1 0.552 -add_mag2 0.552 -add_mag3 0.552 -glut_max1 0.55 -glut_max2 0.55 -glut_max3 0.55 -iliacus 0.5 -psoas 0.5 -rect_fem 0.3865 -vas_med 0.503 -vas_int 0.543 -vas_lat 0.455 -med_gas 0.566 -lat_gas 0.507 -soleus 0.803 -tib_post 0.6 -flex_dig 0.6 -flex_hal 0.6 -tib_ant 0.7 -per_brev 0.6 -per_long 0.6 -per_tert 0.75 -ext_dig 0.75 -ext_hal 0.75 -ercspn 0.6 -intobl 0.56 -extobl 0.58 -sar -1 -add_long -1 -add_brev -1 -tfl -1 -pect -1 -grac -1 -quad_fem -1 -gem -1 -peri -1 \ No newline at end of file diff --git a/Gui/opensim/Scripts/Metabolics_example_scripts/metabolicsSlowTwitchRatios_gait10dof18musc.txt b/Gui/opensim/Scripts/Metabolics_example_scripts/metabolicsSlowTwitchRatios_gait10dof18musc.txt deleted file mode 100644 index 9400234d4..000000000 --- a/Gui/opensim/Scripts/Metabolics_example_scripts/metabolicsSlowTwitchRatios_gait10dof18musc.txt +++ /dev/null @@ -1,9 +0,0 @@ -hamstrings 0.49 -bifemsh 0.53 -glut_max 0.55 -iliopsoas 0.50 -rect_fem 0.39 -vasti 0.50 -gastroc 0.54 -soleus 0.80 -tib_ant 0.70 \ No newline at end of file diff --git a/Gui/opensim/Scripts/Metabolics_example_scripts/plotBaselineResults.py b/Gui/opensim/Scripts/Metabolics_example_scripts/plotBaselineResults.py deleted file mode 100644 index 867554a5c..000000000 --- a/Gui/opensim/Scripts/Metabolics_example_scripts/plotBaselineResults.py +++ /dev/null @@ -1,65 +0,0 @@ -# --------------------------------------------------------------------------- # -# OpenSim: plotBaselineResults.py # -# --------------------------------------------------------------------------- # -# OpenSim is a toolkit for musculoskeletal modeling and simulation, # -# developed as an open source project by a worldwide community. Development # -# and support is coordinated from Stanford University, with funding from the # -# U.S. NIH and DARPA. See http://opensim.stanford.edu and the README file # -# for more information including specific grant numbers. # -# # -# Copyright (c) 2005-2017 Stanford University and the Authors # -# Author(s): Ayman Habib # -# # -# Licensed under the Apache License, Version 2.0 (the "License"); you may # -# not use this file except in compliance with the License. You may obtain a # -# copy of the License at http://www.apache.org/licenses/LICENSE-2.0 # -# # -# Unless required by applicable law or agreed to in writing, software # -# distributed under the License is distributed on an "AS IS" BASIS, # -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # -# See the License for the specific language governing permissions and # -# limitations under the License. # -# --------------------------------------------------------------------------- # -# Plot the baseline results (muscle Rates and metabolic cost) - -# Utils contains tools to browse for files and folders -import org.opensim.utils as utils -import os - -# Obtain Directory containing baseline results -#resultsFolderCMC = getInstallDir() + "/Models/gait10dof18musc/CMC/ResultsCMC" -resultsFolderCMC = utils.FileUtils.getInstance().browseForFolder("Select the folder with baseline CMC Results",1); - -# Obtain the legend name -#legendName = "Baseline" -legendName = os.path.split(resultsFolderCMC)[1] - -# Plot the total metabolic energy -totalEnergyPlot = createPlotterPanel("Total Metabolic Energy") -src = addDataSource(totalEnergyPlot, resultsFolderCMC+"/walk_subject_MetabolicsReporter_probes.sto") -crv = addCurve(totalEnergyPlot, src, "time", "metabolics_TOTAL") -crv.setLegend(legendName) - -# Plot the gastrocnemius muscle Rates -GastrocRatePlot = createPlotterPanel("Gastrocnemius Muscle Metabolic Rate (Right)") -src = addDataSource(GastrocRatePlot, resultsFolderCMC+"/walk_subject_MetabolicsReporter_probes.sto") -crv = addCurve(GastrocRatePlot, src, "time", "metabolics_gastroc_r") -crv.setLegend(legendName) - -# Plot the soleus muscle Rates -SoleusRatePlot = createPlotterPanel("Soleus Muscle Metabolic Rate (Right)") -src = addDataSource(SoleusRatePlot, resultsFolderCMC+"/walk_subject_MetabolicsReporter_probes.sto") -crv = addCurve(SoleusRatePlot, src, "time", "metabolics_soleus_r") -crv.setLegend(legendName) - -# Plot the tibialis anterior muscle Rates -TibAntRatePlot = createPlotterPanel("Tibialis Anterior Muscle Metabolic Rate (Right)") -src = addDataSource(TibAntRatePlot, resultsFolderCMC+"/walk_subject_MetabolicsReporter_probes.sto") -crv = addCurve(TibAntRatePlot, src, "time", "metabolics_tib_ant_r") -crv.setLegend(legendName) - -# Plot the iliopsoas metabolic rate -psoasRatePlot = createPlotterPanel("Iliopsoas Muscle Metabolic Rate (Right)") -src = addDataSource(psoasRatePlot, resultsFolderCMC+"/walk_subject_MetabolicsReporter_probes.sto") -crv = addCurve(psoasRatePlot, src, "time", "metabolics_iliopsoas_r") -crv.setLegend(legendName)