# Recycling Corner/Center Of Mass

## Center of mass

Jmol centers the model around its geometric center, i.e. the center of the boundbox. If you are interested in the mass center of the molecule:

1. Run or define or load from a script file this content in JmolScript:

```function CoM(atomSet) {
if (atomSet=="") {
print "Warning: there are no atoms in the provided set. Using all atoms in the model.";
atomSet = {*};
}
var n = atomSet.size;
var mx = 0; var my = 0; var mz = 0;
for (i=0; i<n; i+=1) {
mx = mx + atomSet[i].x * atomSet[i].mass;
my = my + atomSet[i].y * atomSet[i].mass;
mz = mz + atomSet[i].z * atomSet[i].mass;
}
var m = atomSet.mass.sum;
mx = mx / m;
my = my / m;
mz = mz / m;
return {@mx @my @mz};
}

function drawCoM(atomSet) {
draw ctr diameter 0.9 color translucent yellowTint @{CoM(atomSet)};
}

function axesCoM(atomSet) {
axes center @{CoM(atomSet)};
axes on;
}
```

2. after that has been executed, you can

• retrieve the coordinates of the center:
```c = CoM(); // using all atoms
print @c;
c = CoM( {_C},{_O} ); // just the carbon and oxygen atoms
print @c;
```
• draw a sphere in the center of mass:
```drawCoM();
drawCoM( {_C},{_O} );
```
• place axes in the center of mass:
```axesCoM();
axesCoM( {_C},{_O} );
```