# calculate mass content of a group of particles through something like label

Hi,
I'd like to calculate the mass content of a group of spheres, as far as I know, we can obtain a mass of one sphere by:
O.bodies[id].state.mass
I'd like to ask that if we can obtain the mass of a group of spheres like: appending some spheres with a same label, like:
then we can obtain the total mass of spheres with label1, and label2 respectively?
I have tried in Yade, it seems that we can not give each sphere a label, is there any way that we can classify the spheres to different groups so that we can just loop in one group of spheres to calculate the mass?

## Question information

Language:
English Edit question
Status:
Solved
For:
Assignee:
No assignee Edit question
Solved by:
gaoxuesong
Solved:
2019-08-15
Last query:
2019-08-15
2019-08-15
 gaoxuesong (260582472-9) said on 2019-08-15: #1

Hi,

The possible way i think is that using different lists to save the sphere's id of different groups and do loop in each list.
## group 1 ##
list1 = []
...
## group 2 ##
list2 = []
...
## calculate the mass of different groups ##
masstotal1 = 0
for each in list1:
masstotal1 + = O.bodies[each].state.mass
masstotal2 = 0
for each in list2:
masstotal2 + = O.bodies[each].state.mass

## ends ##

Cheers,
Xuesong

 Leonard (z2521899293) said on 2019-08-15: #2

Hi xuesong,
Your approach works very well, while one point should be noted that:
--->>The possible way i think is that using different lists to save the sphere's id of different groups and do loop in each list.
--->>## group 1 ##
--->>list1 = []
In this way, the list1 stores not the id of sphere, but the sphere body, so for the next code:
--->>## calculate the mass of different groups ##
--->>masstotal1 = 0
--->>for each in list1:
--->>masstotal1 + = O.bodies[each].state.mass
May should be:
masstotal1 = 0
for each in list1:
masstotal1 + = each.state.mass

Thanks again for your help, I just mention it more clearly for other beginners.

 Leonard (z2521899293) said on 2019-08-15: #3

Thanks gaoxuesong, that solved my question.

 Leonard (z2521899293) said on 2019-08-15: #4

Hi xuesong,
I am sorry that I make a wrong answer in #2.
You are right.
In this way, the list1 stores the id of the sphere.
The reason why I make the mistake is I did like this:
-->>list1=[]
-->>list1.append(s1)
then in this way, the list1 stores the body of sphere.
Thank you again.
Cheers,
Leonard

 gaoxuesong (260582472-9) said on 2019-08-15: #5

You are welcome. However, in the way as you said,
###
-->>list1=[]
-->>list1.append(s1)
###
list1 also stores the id of a body. In this way, it stores the body.