code: private double getMolecularWeight(IAtomContainer atomContainer) throws CDKException {
          double mw = 0.0;
          try {
              final IsotopeFactory isotopeFactory = Isotopes.getInstance();
  
              for (IAtom atom : atomContainer.atoms()) {
                  if (!atom.getSymbol().equals("H")) {
                      final IIsotope majorIsotope = isotopeFactory.getMajorIsotope(atom.getSymbol());
  
                      if (majorIsotope != null && majorIsotope.getExactMass() != null) {
                          mw += majorIsotope.getExactMass().doubleValue();
                      }
                  }
              }
          } catch (IOException e) {
              throw new CDKException(e.getMessage(), e);
          }
          return mw;
      }
docs: Returns the molecular weight (exact mass) of the major isotopes
  of all heavy atoms of the given IAtomContainer.
  @param atomContainer an IAtomContainer to calculate the mocular weight for
  @throws org.openscience.cdk.exception.CDKException if an error occurs with the IsotopeFactory
  @return the molecularweight (exact mass) of the major isotopes
  of all heavy atoms of the given IAtomContainer