Ejemplo n.º 1
0
def test_ZPE(verbose=True, *args, **kwargs):
    """Test that Zero-Point-Energy stored in the default RADIS database
    corresponds to the Energy calculated for vi=0, J=0 for all molecules and isotopes
    and electronic states in the RADIS :py:data:`~radis.db.molecules.Molecules`
    list.
    """
    for M, isotopes in Molecules.items():
        if M != "CO2":
            continue
        for iso, elecstates in isotopes.items():
            for state, ElecState in elecstates.items():
                jsonfile = get_default_jsonfile(M)
                coeffs = _get_rovib_coefficients(
                    M,
                    iso,
                    ElecState.get_statename_utf(),
                    jsonfile=jsonfile,
                    remove_trailing_cm1=True,
                )
                if "ZPE" in coeffs:
                    # Calculate ZPE by setting all parameters to 0. Note that
                    # the number of parameters in ElecState.Erovib depends on
                    # the molecule. @dev: we use inspect to get the number of
                    # parameters
                    from radis.misc.utils import getarglist

                    params = [
                        k for k in getarglist(ElecState._Erovib)
                        if k not in ["remove_ZPE", "coeff_dict"]
                    ]
                    # Calculate ZPE:
                    params = [0] * len(params)
                    assert ElecState.Erovib(*params,
                                            remove_ZPE=False) == coeffs["ZPE"]
                    if verbose:
                        print(
                            "ZPE calculated for {0} matches value in database ({1:.2f} cm-1)"
                            .format(ElecState.get_fullname(), coeffs["ZPE"]))
                else:
                    if verbose:
                        print("No ZPE defined for ".format(
                            ElecState.get_fullname()))
Ejemplo n.º 2
0
    def _parse_rovib_constants(self, spectroscopic_constants,
                               spectroscopic_constants_type):
        r"""Parse spectroscopic constants

        Stores :py:attr:`~radis.db.classes.ElectronicState.Te` and
        :py:attr:`~radis.db.classes.ElectronicState.re` as electronic state
        attributes, and the rest under :py:attr:`~radis.db.classes.ElectronicState.rovib_constants`

        Parameters
        ----------

        spectroscopic_constants: str, or ``'default'``
            filename of spectroscopic constants under Herzberg or Dunham format.

            Expected in the file:

                Yij: cm-1
                    rovibrational coefficients in Dunham convention

            or

                wexe, Be, etc. : cm-1
                    rovibrational coefficients in Herzberg convention

            or

                Te: cm-1
                    electronic energy. Default ``None`` if not given

            If ``default``, the constants defined in
            :ref:`spectroscopic constants <label_db_spectroscopic_constants>` are used.


        spectroscopic_constants_type: ``'herzberg'``, ``'dunham'``
            convention for spectroscopic constants. Default ``'herzberg'``

        Returns
        -------

        None:
            but constants are stored under :py:attr:`~radis.db.classes.ElectronicState.rovib_constants`,
            and store json file in :py:attr:`~radis.db.classes.ElectronicState.jsonfile`

        """

        # Get file name
        if spectroscopic_constants == "default":
            jsonfile = get_default_jsonfile(self.name)
        elif exists(spectroscopic_constants):  # absolute path
            jsonfile = spectroscopic_constants
        else:  # assume a json file stored in the default folder
            jsonfile = join(dirname(get_default_jsonfile(self.name)),
                            spectroscopic_constants)

        # Parse file
        if spectroscopic_constants_type == "dunham":
            rovib_constants = get_dunham_coefficients(self.name,
                                                      self.iso,
                                                      self.get_statename_utf(),
                                                      jsonfile=jsonfile)
        elif spectroscopic_constants_type == "herzberg":
            rovib_constants = get_herzberg_coefficients(
                self.name,
                self.iso,
                self.get_statename_utf(),
                jsonfile=jsonfile)
        else:
            raise ValueError(
                "Unexpected spectroscopic constant type: {0}".format(
                    spectroscopic_constants_type))

        # Clean keys
        # In particular, remove trailing '_cm-1' if given in dict or database
        import re

        rovib_constants = {
            re.sub("_cm-1$", "", k): v
            for (k, v) in rovib_constants.items()
        }

        # Get specific keys
        self.Te = rovib_constants.pop("Te", None)  # default None
        self.re = rovib_constants.pop("re", None)

        # Store
        self.rovib_constants = rovib_constants
        self.jsonfile = jsonfile