Access model properties through python API; names of muscles and joints

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Neil Dhir
Posts: 17
Joined: Wed May 27, 2015 6:51 am

Access model properties through python API; names of muscles and joints

Post by Neil Dhir » Wed Aug 17, 2016 6:45 am

Hi, I am using the Gait2354_simbody.osim model for some work I am trying out.

Through the .osim file I know what the model components are called e.g. the given name of the muscles, through string assignments or bodies:

Code: Select all

				<Body name="femur_r">
					<mass>9.3014</mass>
					<mass_center> 0 -0.17 0</mass_center>
					<inertia_xx>0.1339</inertia_xx>
					<inertia_yy>0.0351</inertia_yy>
					<inertia_zz>0.1412</inertia_zz>
					<inertia_xy>0</inertia_xy>
					<inertia_xz>0</inertia_xz>
					<inertia_yz>0</inertia_yz>
Now I would like to access these strings through the python API. But I am not sure how to do this. Take the below:

Code: Select all

# Load model
model = osim.Model("gait2354_simbody.osim")

muscles = model.getMuscles()
muSize = muscles.getSize()
for i in range(muSize):
    print muscles.get(i)
It gets me all the 54 muscles, looping through them one by one, but just returns an object no specific identifier such as "glut_max3_r". How do I get access to these specifically?

User avatar
Christopher Dembia
Posts: 506
Joined: Fri Oct 12, 2012 4:09 pm

Re: Access model properties through python API; names of muscles and joints

Post by Christopher Dembia » Wed Aug 17, 2016 7:02 am

Try this:

model.getMuscles().get("soleus_r")

User avatar
Neil Dhir
Posts: 17
Joined: Wed May 27, 2015 6:51 am

Re: Access model properties through python API; names of muscles and joints

Post by Neil Dhir » Wed Aug 17, 2016 7:08 am

No sure, I know you can do that; what I want is a list of all the muscles names as strings. I know I can access them one by one, by looking up the string name in the .osim file. I don't want to do this, I would just like to call a function that returns each muscle name to me. Something like:

Code: Select all

model.getMuscles().get(3).name()
>>>"glut_max3_r"

User avatar
Christopher Dembia
Posts: 506
Joined: Fri Oct 12, 2012 4:09 pm

Re: Access model properties through python API; names of muscles and joints

Post by Christopher Dembia » Wed Aug 17, 2016 10:07 am

Each Object (including Muscle) has a method getName():

Code: Select all

model.getMuscles().get(3).getName()

POST REPLY