code: public static Point2d get2DCentreOfMass(IAtomContainer ac) {
          double xsum = 0.0;
          double ysum = 0.0;
  
          double totalmass = 0.0;
  
          Iterator<IAtom> atoms = ac.atoms().iterator();
          while (atoms.hasNext()) {
              IAtom a = (IAtom) atoms.next();
              Double mass = a.getExactMass();
              if (mass == null) return null;
              totalmass += mass;
              xsum += mass * a.getPoint2d().x;
              ysum += mass * a.getPoint2d().y;
          }
  
          return new Point2d(xsum / totalmass, ysum / totalmass);
      }
docs: Calculates the center of mass for the <code>Atom</code>s in the
  AtomContainer for the 2D coordinates.
  See comment for center(IAtomContainer atomCon, Dimension areaDim, HashMap renderingCoordinates) for details on coordinate sets
  
  @param  ac      AtomContainer for which the center of mass is calculated
  @return         Null, if any of the atomcontainer {@link IAtom}'s masses are null
  @cdk.keyword    center of mass