Esempio n. 1
0
    def get_Morse_inc(self):
        r"""Get Morse potential energy increment correction for given molecule

        Examples
        --------

        ::

            inc = ElecState.get_Morse_inc()
            Delta_E(vi, vi+1) = Delta_E0 - (vi+1-vi0)*inc

        for the energy gap between vibrational level vi and vi+1,
        where vi0 is the last vibrational level calculated with Dunham
        expansion, and  and Delta_E0 = DeltaE(vi0-1, vi0)

        See Also
        --------

        :py:func:`~radis.phys.morse.morse_increment`

        """

        from radis.phys.morse import morse_increment

        c = self.rovib_constants

        if get_convention(c) == "dunham":

            # convert to get wexe, weae etc in Herzberg convention
            from radis.db.conventions import herzberg2dunham

            def convert(coef, default=0):
                if coef in c:
                    sign, Yij = herzberg2dunham[coef]
                    return sign * Yij
                else:
                    return default  # default

            we = convert("we")  # required
            wexe = convert("wexe", 0)  # optional: 0 is default value
            weye = convert("weye", 0)
            weze = convert("weze", 0)
            weae = convert("weae", 0)
            webe = convert("webe", 0)
            wece = convert("wece", 0)

            if we is None:
                raise KeyError(
                    "Mandatory spectroscopic constant `we` " +
                    "not defined for electronic state {0}".format(
                        self.get_fullname()) +
                    ". Check your ElectronicState definition. Given " +
                    "constants: {0}".format(list(c.keys())))

        else:
            try:
                we = c["we"]  # required
                wexe = c.get("wexe", 0)  # optional: 0 is default value
                weye = c.get("weye", 0)
                weze = c.get("weze", 0)
                weae = c.get("weae", 0)
                webe = c.get("webe", 0)
                wece = c.get("wece", 0)

            except KeyError as err:
                raise KeyError(
                    "Mandatory spectroscopic constant `{0}` ".format(
                        err.args[0]) +
                    "not defined for electronic state {0}".format(
                        self.get_fullname()) +
                    ". Check your ElectronicState definition. Given " +
                    "constants: {0}".format(list(c.keys())))

        return morse_increment(
            self.Ediss,
            we,
            wexe=wexe,
            weye=weye,
            weze=weze,
            weae=weae,
            webe=webe,
            wece=wece,
        )
Esempio n. 2
0
    def _assign_E(self, Erovib, Ehaj):
        r"""Finds appropriate Electrorovibrational energy function for this molecule ,
        based on which convention is used for spectroscopic coefficients
        (Dunham, or Herzberg)

        Replaces the :py:meth:`~radis.db.classes.ElectronicState.Erovib` template
        with the appropriate function for this molecule / isotope / electronic state.

        Default methods only work for diatomic molecules. For polyatomic molecules,
        you should give the energy function directly (see how CO2 is defined in
        radis.db.molecules.py)

        Returns
        -------

        None:
            but assigns the ``self.Erovib`` function to the molecule

        """
        # Check input
        if Erovib is None and Ehaj is not None:
            raise ValueError(
                "If giving Ehaj (harmonic and anharmonic component calculation) "
                + "you must also supply Erovib (total rovibrational energy)")

        if Erovib is not None:
            # overwrite energy calculation
            self.Erovib = Erovib
            self.Ehaj = Ehaj
            if self.verbose >= 2:
                print("{0}: overwritting Energy calculation with {1}".format(
                    self.get_fullname(), Erovib))
        else:
            # Autofind which energy model to use for the given molecule
            c = self.rovib_constants
            if len(c) == 0:
                pass  # keep the default function, that will raise an error on first call.
                if self.verbose >= 2:
                    print("{0}: No rovibconstants found".format(
                        self.get_fullname()))
            else:
                convention = get_convention(c)  # Herzberg or Dunham

                if self.name in HITRAN_CLASS1:
                    if convention == "herzberg":
                        self.Erovib = self._E_Herzberg
                        self.Ehaj = None  # NotImplemented
                        if self.verbose >= 2:
                            print(
                                "{0}: using Herzberg coefficients for Energy calculation"
                                .format(self.get_fullname()))
                    else:
                        self.Erovib = self._E_Dunham
                        self.Ehaj = None  # NotImplemented
                        if self.verbose >= 2:
                            print(
                                "{0}: using Dunham coefficients for Energy calculation"
                                .format(self.get_fullname()))
                        # TODO: reformat these methods as external functions, but keep docstrings
                elif self.name in HITRAN_CLASS5:
                    if convention == "herzberg":
                        from radis.levels.energies_co2 import EvJ_co2, EvJah_co2

                        self._Erovib = EvJ_co2
                        self._Ehaj = EvJah_co2
                        self.Erovib = self._Erovib_default_coefs
                        #                        self.Erovib.__doc__ == EvJ_co2.__doc__
                        self.Ehaj = self._Ehaj_default_coefs
                    #                        self.Ehaj.__doc__ == EvJah_co2.__doc__
                    else:
                        raise NotImplementedError(
                            "Only Herzberg convention spectroscopic " +
                            "constants defined for {0}. ".format(self.name) +
                            "You still define your own Erovib function " +
                            "and overwrite the ElectronicState class one.")