def verify_topology(cgmodel):
    """
        Given a coarse grained model that contains a Topology() (cgmodel.topology), this function verifies the validity of the topology.

        :param cgmodel: CGModel() class object.
        :type cgmodel: class

        :Example:

        >>> from foldamers.cg_model.cgmodel import CGModel
        >>> cgmodel = CGModel()
        >>> verify_topology(cgmodel)

        .. warning:: The function will force an error exit if the topology is invalid, and will proceed as normal if the topology is valid. 

        """
    if cgmodel.num_beads != cgmodel.topology.getNumAtoms():
        print('ERROR: The number of particles in the coarse grained model\n')
        print(
            'does not match the number of particles in the OpenMM topology.\n')
        print('There are ' + str(cgmodel.num_beads) +
            ' particles in the coarse grained model\n')
        print('and ' + str(cgmodel.topology.getNumAtoms()) +
            ' particles in the OpenMM topology.')
        exit()
    if cgmodel.polymer_length != cgmodel.topology.getNumResidues():
        print('ERROR: The number of monomers in the coarse grained model\n')
        print('does not match the number of residues in the OpenMM topology.\n'
            )
        print('There are ' + str(cgmodel.polymer_length) +
            """ monomers in the coarse grained model
""")
        print('and ' + str(cgmodel.topology.getNumResidues()) +
            ' monomers in the OpenMM topology.')
        exit()
    return
