コード例 #1
0
ファイル: test_pmutt_reaction.py プロジェクト: wittregr/pMuTT
    def test_get_A(self):
        # Testing partition function method
        exp_sm_q = self.H2O_TS_sm.get_q(T=c.T0('K'), include_ZPE=False) \
            / self.H2_sm.get_q(T=c.T0('K'), include_ZPE=False) \
            / self.O2_sm.get_q(T=c.T0('K'), include_ZPE=False)**0.5
        exp_sm_A = c.kb('J/K') * c.T0('K') / c.h('J s') * exp_sm_q
        exp_sm_q_rev = self.H2O_TS_sm.get_q(T=c.T0('K'), include_ZPE=False) \
            / self.H2O_sm.get_q(T=c.T0('K'), include_ZPE=False)
        exp_sm_A_rev = c.kb('J/K') * c.T0('K') / c.h('J s') * exp_sm_q_rev
        np.testing.assert_almost_equal(self.rxn_sm.get_A(T=c.T0('K')),
                                       exp_sm_A,
                                       decimal=0)
        np.testing.assert_almost_equal(self.rxn_sm.get_A(T=c.T0('K'),
                                                         rev=True),
                                       exp_sm_A_rev,
                                       decimal=0)

        # Testing entropy method
        exp_sm_SoR = self.H2O_TS_sm.get_SoR(T=c.T0('K')) \
            - self.H2_sm.get_SoR(T=c.T0('K')) \
            - self.O2_sm.get_SoR(T=c.T0('K'))*0.5
        exp_sm_A = c.kb('J/K') * c.T0('K') / c.h('J s') * np.exp(exp_sm_SoR)
        exp_sm_SoR_rev = self.H2O_TS_sm.get_SoR(T=c.T0('K')) \
            - self.H2O_sm.get_SoR(T=c.T0('K'))
        exp_sm_A_rev = c.kb('J/K')*c.T0('K')/c.h('J s') \
            * np.exp(exp_sm_SoR_rev)
        np.testing.assert_almost_equal(self.rxn_sm.get_A(T=c.T0('K'),
                                                         use_q=False),
                                       exp_sm_A,
                                       decimal=0)
        np.testing.assert_almost_equal(self.rxn_sm.get_A(T=c.T0('K'),
                                                         rev=True,
                                                         use_q=False),
                                       exp_sm_A_rev,
                                       decimal=0)
コード例 #2
0
ファイル: zacros.py プロジェクト: paulmeza/pMuTT
 def __init__(self,
              A_st=None,
              atoms=None,
              symmetrynumber=None,
              inertia=None,
              geometry=None,
              vib_wavenumbers=None,
              potentialenergy=None,
              **kwargs):
     super().__init__(atoms=atoms,
                      symmetrynumber=symmetrynumber,
                      geometry=geometry,
                      vib_wavenumbers=vib_wavenumbers,
                      potentialenergy=potentialenergy,
                      **kwargs)
     self.A_st = A_st
     self.atoms = atoms
     self.geometry = geometry
     self.symmetrynumber = symmetrynumber
     self.inertia = inertia
     self.etotal = potentialenergy
     self.vib_energies = c.wavenumber_to_energy(np.array(vib_wavenumbers))
     self.theta = np.array(self.vib_energies) / c.kb('eV/K')
     self.zpe = sum(np.array(self.vib_energies)/2.) *\
         c.convert_unit(initial='eV', final='kcal')*c.Na
     if np.sum(self.vib_energies) != 0:
         self.q_vib = np.product(
             np.divide(1, (1 - np.exp(-self.theta / c.T0('K')))))
     if self.phase == 'G':
         if self.inertia is not None:
             self.I3 = self.inertia
         else:
             self.I3 = atoms.get_moments_of_inertia() *\
                     c.convert_unit(initial='A2', final='m2') *\
                     c.convert_unit(initial='amu', final='kg')
         self.T_I = c.h('J s')**2 / (8 * np.pi**2 * c.kb('J/K'))
     if self.phase == 'G':
         Irot = np.max(self.I3)
         if self.geometry == 'nonlinear':
             self.q_rot = np.sqrt(np.pi*Irot)/self.symmetrynumber *\
                                 (c.T0('K')/self.T_I)**(3./2.)
         else:
             self.q_rot = (c.T0('K') * Irot /
                           self.symmetrynumber) / self.T_I
     else:
         self.q_rot = 0.
     if self.A_st is not None:
         self.MW = mw(self.elements) * c.convert_unit(initial='g',
                                                      final='kg') / c.Na
         self.q_trans2D = self.A_st * (2 * np.pi * self.MW * c.kb('J/K') *
                                       c.T0('K')) / c.h('J s')**2
コード例 #3
0
ファイル: trans.py プロジェクト: wittregr/pMuTT
    def get_SoR(self, T, P=c.P0('bar')):
        """Calculates the dimensionless entropy

        :math:`\\frac{S^{trans}}{R}=1+\\frac{n_{degrees}}{2}+\\log\\bigg(\\big(
        \\frac{2\\pi mk_bT}{h^2})^\\frac{n_{degrees}}{2}\\frac{RT}{PN_a}\\bigg)`

        Parameters
        ----------
            T : float
                Temperature in K
            P : float, optional
                Pressure (bar) or pressure-like quantity.
                Default is atmospheric pressure

        Returns
        -------
            SoR_trans : float
                Translational dimensionless entropy
        """
        V = self.get_V(T=T, P=P)
        unit_mass = self.molecular_weight *\
            c.convert_unit(initial='g', final='kg')/c.Na
        return 1. + float(self.n_degrees)/2. \
            + np.log((2.*np.pi*unit_mass*c.kb('J/K')*T/c.h('J s')**2)
                     ** (float(self.n_degrees)/2.)*V/c.Na)
コード例 #4
0
    def get_A(self,
              sden_operation='min',
              include_entropy=True,
              T=c.T0('K'),
              units='molec/cm2',
              **kwargs):
        """Calculates the preexponential factor in the Cantera format

        Parameters
        ----------
        sden_operation : str, optional
            Site density operation to use. Default is 'min'
        include_entropy : bool, optional
            If True, includes the entropy of activation. Default is True
        T : float, optional
            Temperature in K. Default is 298.15 K
        units : str or :class:`~pmutt.omkm.units.Units`, optional
            Units for A. If `Units` class specified, determines the units for A.
            Default is 'molec/cm2'
        kwargs : keyword arguments
            Parameters required to calculate pre-exponential factor
        """

        if self.transition_state is None or not include_entropy:
            A = c.kb('J/K') / c.h('J s')
        else:
            A = super().get_A(T=T, **kwargs) / T

        # Uses site with highest site density
        site_dens = []
        for reactant, stoich in zip(self.reactants, self.reactants_stoich):
            # Skip species without a catalyst site
            try:
                site_den = reactant.phase.site_density
            except AttributeError:
                continue
            site_dens.extend([site_den] * int(stoich))

        # Apply the operation to the site densities
        if len(site_dens) == 0:
            err_msg = ('At least one species requires a catalytic site with '
                       'site density to calculate A.')
            raise ValueError(err_msg)
        eff_site_den = _apply_numpy_operation(quantity=site_dens,
                                              operation=sden_operation,
                                              verbose=False)
        # Convert site density to appropriate unit
        if isinstance(units, Units):
            quantity_unit = units.quantity
            area_unit = '{}2'.format(units.length)
        else:
            quantity_unit, area_unit = units.split('/')
        eff_site_den = eff_site_den\
                       *c.convert_unit(initial='mol', final=quantity_unit)\
                       /c.convert_unit(initial='cm2', final=area_unit)

        n_surf = self._get_n_surf()
        A = A / eff_site_den**(n_surf - 1)
        return A
コード例 #5
0
    def _get_SoR_RRHO(self, T, vib_inertia):
        """Calculates the dimensionless RRHO contribution to entropy

        Parameters
        ----------
            T : float
                Temperature in K
            vib_inertia : float
                Vibrational inertia in kg m2
        Returns
        -------
            SoR_RHHO : float
                Dimensionless entropy of Rigid Rotor Harmonic Oscillator
        """
        return 0.5 + np.log(
            (8. * np.pi**3 * vib_inertia * c.kb('J/K') * T / c.h('J s')**2)**
            0.5)
コード例 #6
0
ファイル: trans.py プロジェクト: wittregr/pMuTT
    def get_q(self, T, P=c.P0('bar')):
        """Calculates the partition function

        :math:`q_{trans} = \\bigg(\\frac{2\\pi \\sum_{i}^{atoms}m_ikT}{h^2}
        \\bigg)^\\frac {n_{degrees}} {2}V`

        Parameters
        ----------
            T : float
                Temperature in K
            P : float, optional
                Pressure (bar) or pressure-like quantity.
                Default is atmospheric pressure
        Returns
        -------
            q_trans : float
                Translational partition function
        """
        V = self.get_V(T=T, P=P)
        unit_mass = self.molecular_weight *\
            c.convert_unit(initial='g', final='kg')/c.Na
        return V*(2*np.pi*c.kb('J/K')*T*unit_mass/c.h('J s')**2) \
            ** (float(self.n_degrees)/2.)
コード例 #7
0
 def test_h(self):
     # Test h for all units (bar=False)
     self.assertAlmostEqual(c.h('J s', bar=False), self.ans.at['test_h', 0])
     self.assertAlmostEqual(c.h('kJ s', bar=False), self.ans.at['test_h',
                                                                1])
     self.assertAlmostEqual(c.h('eV s', bar=False), self.ans.at['test_h',
                                                                2])
     self.assertAlmostEqual(c.h('Eh s', bar=False), self.ans.at['test_h',
                                                                3])
     self.assertAlmostEqual(c.h('Ha s', bar=False), self.ans.at['test_h',
                                                                4])
     # Test h for all units (bar=True)
     self.assertAlmostEqual(c.h('J s', bar=True), self.ans.at['test_h', 5])
     self.assertAlmostEqual(c.h('kJ s', bar=True), self.ans.at['test_h', 6])
     self.assertAlmostEqual(c.h('eV s', bar=True), self.ans.at['test_h', 7])
     self.assertAlmostEqual(c.h('Eh s', bar=True), self.ans.at['test_h', 8])
     self.assertAlmostEqual(c.h('Ha s', bar=True), self.ans.at['test_h', 9])
     # Test h raises an error when an supported unit is passed
     with self.assertRaises(KeyError):
         c.h('arbitrary unit')
コード例 #8
0
ファイル: NAM_2019_Workshop.py プロジェクト: wittregr/pMuTT
# <a id='section_3'></a>

# # 3. Constants
#
# The [constants module](https://vlachosgroup.github.io/pMuTT/constants.html) has a wide variety of functions for constants and unit conversion.

# <a id='section_3_1'></a>

# ## 3.1. Access common constants in appropriate units
# Below, we access Planck's constant in J s.

# In[1]:

from pmutt import constants as c

h1 = c.h('eV s', bar=True)
print('h = {} eV s'.format(h1))

# <a id='section_3_2'></a>

# ## 3.2. Convert between units
# Below, we convert 12 atm of pressure to psi.

# In[2]:

from pmutt import constants as c

P_atm = 12.  # atm
P_psi = c.convert_unit(num=P_atm, initial='atm', final='psi')

print('{} atm = {} psi'.format(P_atm, P_psi))
コード例 #9
0
 def test_h(self):
     self.assertEqual(c.h('J s', bar=False), 6.626070040e-34)
     self.assertEqual(c.h('J s', bar=True), 6.626070040e-34 / (2. * np.pi))
     with self.assertRaises(KeyError):
         c.h('arbitrary unit')