class GeometryTools {

    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);
    }

}