
<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.jmol.org/index.php?action=history&amp;feed=atom&amp;title=Recycling_Corner%2FCenter_Of_Mass</id>
	<title>Recycling Corner/Center Of Mass - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.jmol.org/index.php?action=history&amp;feed=atom&amp;title=Recycling_Corner%2FCenter_Of_Mass"/>
	<link rel="alternate" type="text/html" href="https://wiki.jmol.org/index.php?title=Recycling_Corner/Center_Of_Mass&amp;action=history"/>
	<updated>2026-05-16T12:27:17Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.32.0</generator>
	<entry>
		<id>https://wiki.jmol.org/index.php?title=Recycling_Corner/Center_Of_Mass&amp;diff=8144&amp;oldid=prev</id>
		<title>AngelHerraez: moving long sections to subpages</title>
		<link rel="alternate" type="text/html" href="https://wiki.jmol.org/index.php?title=Recycling_Corner/Center_Of_Mass&amp;diff=8144&amp;oldid=prev"/>
		<updated>2013-10-23T14:18:11Z</updated>

		<summary type="html">&lt;p&gt;moving long sections to subpages&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Center of mass ==&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
1. Run or define or load from a script file this content in JmolScript:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function CoM(atomSet) {&lt;br /&gt;
  if (atomSet==&amp;quot;&amp;quot;) {&lt;br /&gt;
    print &amp;quot;Warning: there are no atoms in the provided set. Using all atoms in the model.&amp;quot;; &lt;br /&gt;
    atomSet = {*}; &lt;br /&gt;
  }&lt;br /&gt;
  var n = atomSet.size;&lt;br /&gt;
  var mx = 0; var my = 0; var mz = 0;&lt;br /&gt;
  for (i=0; i&amp;lt;n; i+=1) {&lt;br /&gt;
    mx = mx + atomSet[i].x * atomSet[i].mass;&lt;br /&gt;
    my = my + atomSet[i].y * atomSet[i].mass;&lt;br /&gt;
    mz = mz + atomSet[i].z * atomSet[i].mass;&lt;br /&gt;
  }&lt;br /&gt;
  var m = atomSet.mass.sum;&lt;br /&gt;
  mx = mx / m;&lt;br /&gt;
  my = my / m;&lt;br /&gt;
  mz = mz / m;&lt;br /&gt;
  return {@mx @my @mz};&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function drawCoM(atomSet) {&lt;br /&gt;
  draw ctr diameter 0.9 color translucent yellowTint @{CoM(atomSet)};&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function axesCoM(atomSet) {&lt;br /&gt;
  axes center @{CoM(atomSet)};&lt;br /&gt;
  axes on;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. after that has been executed, you can&lt;br /&gt;
* retrieve the coordinates of the center:&lt;br /&gt;
&amp;lt;pre&amp;gt;c = CoM(); // using all atoms&lt;br /&gt;
print @c;&lt;br /&gt;
c = CoM( {_C},{_O} ); // just the carbon and oxygen atoms&lt;br /&gt;
print @c;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* draw a sphere in the center of mass:&lt;br /&gt;
&amp;lt;pre&amp;gt;drawCoM();&lt;br /&gt;
drawCoM( {_C},{_O} );&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* place axes in the center of mass:&lt;br /&gt;
&amp;lt;pre&amp;gt;axesCoM();&lt;br /&gt;
axesCoM( {_C},{_O} );&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>AngelHerraez</name></author>
		
	</entry>
</feed>