code: def ctr_mass(geom, masses):
      
  
      # Imports
      import numpy as np
      from .base import safe_cast as scast
  
      # Shape check
      if len(geom.shape) != 1:
          raise ValueError("Geometry is not a vector")
      ## end if
      if len(masses.shape) != 1:
          raise ValueError("Masses cannot be parsed as a vector")
      ## end if
      if not geom.shape[0] % 3 == 0:
          raise ValueError("Geometry is not length-3N")
      ## end if
      if geom.shape[0] != 3*masses.shape[0] and geom.shape[0] != masses.shape[0]:
          raise ValueError("Inconsistent geometry and masses vector lengths")
      ## end if
  
      # If N masses are provided, expand to 3N; if 3N, retain.
      if geom.shape[0] == 3*masses.shape[0]:
          masses = masses.repeat(3)
      ## end if
  
      # Calculate the mass-weighted coordinates, reshape to group by coordinate
      #  column-wise, sum each column, then divide by the sum of masses, which
      #  must further be divided by three because there are three replicates
      #  (possibly perturbed) of the mass of each atom.
      ctr = np.multiply(geom, masses).reshape((geom.shape[0]//3, 3)) \
                                  .sum(axis=0).squeeze() / (masses.sum() / 3)
  
      # Return the vector
      return ctr
docs: Calculate the center of mass of the indicated geometry.
  
      Take a geometry and atom masses and compute the location of
      the center of mass.
  
      Parameters
      ----------
      geom
          length-3N |npfloat_| --
          Coordinates of the atoms
  
      masses
          length-N OR length-3N |npfloat_| --
          Atomic masses of the atoms. Length-3N option is to allow calculation of
          a per-coordinate perturbed value.
  
      Returns
      -------
      ctr
          length-3 |npfloat_| --
          Vector location of center of mass
  
      Raises
      ------
      ~exceptions.ValueError
          If `geom` & `masses` shapes are inconsistent