Beispiel #1
0
 def __init__(self,
              stoichiometry,
              A=c.kb('J/K') / c.h('J s'),
              EoRT=None,
              BEP=None,
              beta=0.,
              T_ref=1.,
              use_sticking_coefficient=False,
              s=0.5):
     self.stoichiometry = stoichiometry
     self.A = A
     self.EoRT = EoRT
     self.BEP = BEP
     self.beta = beta
     self.T_ref = T_ref
     self.use_sticking_coefficient = use_sticking_coefficient
     self.s = s
Beispiel #2
0
 def _get_single_CpoR(self, T):
     """
     Returns the constant pressure heat capacity.
     """
     if self.is_gas:
         if self.IdealGasThermo.geometry == 'monatomic':
             return 2.5
         elif self.IdealGasThermo.geometry == 'linear':
             CpoR = 2.5
         elif self.IdealGasThermo.geometry == 'nonlinear':
             CpoR = 3.
         else:
             warnings.warn(
                 "Gas phase species with invalid geometry. Returning 0.")
             return 0.
         #Correction between Cv and Cp
         CpoR += 1.
     else:
         CpoR = 0.
     for vib_f in self.vib_freq:
         vib_T = vib_f * c.c('cm/s') * c.h('J s') / c.kb('J/K')
         CpoR += (vib_T / (2. * T))**2 * 1. / (np.sinh(vib_T / (2. * T)))**2
     return CpoR
Beispiel #3
0
def dft_to_thermdat(input_path,
                    ref_path='thermdat_ref.csv',
                    T_low=300.,
                    T_high=800.,
                    write_files=True,
                    out_path='thermdat',
                    verbose=False,
                    warn=False,
                    freq_cut_off=0.,
                    pressure=1.,
                    add_gas_species=True,
                    gas_path='thermdat_gas'):
    """
    Convert DFT energies and frequencies to NASA polynomials that can be written as a thermdat file
    Attributes
    ----------
        input_path - string
            Path to .csv file that contains the DFT information of all species to be written in thermdat
        ref_path - string
            Path to .csv file that contains the gas-phase reference information
        T_low - float
            Lower temperature bound for the NASA polynomials
        T_high - float
            Higher temperature bound for the NASA polynomials
        write_files - boolean
            Whether or not the thermdat file should be written
        out_path - string
            Path where the thermdat file will be written
        verbose - boolean
            Whether or not more detailed output should be given
        warn - boolean
            Whether or not warnings should be given
        freq_cut_off - float
            Cut off frequency. If vibrational frequencies (in 1/cm) are below this value, they are ignored
            since they are assumed to be frustrated rotational or translational modes
        pressure - float
            Pressure (in atmospheres) to generate the NASA polynomials. Usually this value is left at 1 atm
        add_gas_species - boolean
            Whether or not gas-phase species from gas_path should be written to the thermdat file
        gas_path - string
            Path to thermdat file that contains the gas-phase species to add
    Returns
    -------
        thermdat - Thermdat object
            The successfully converted thermdat object
    """
    T_range = np.linspace(T_low, T_high, T_high - T_low)
    n_T = len(T_range)

    print("Opening reference file: %s" % ref_path)
    (fund_energies, fund_CHON, rm_list) = read_ref(ref_path,
                                                   verbose=verbose,
                                                   warn=warn)
    print('Fundamental energies:')
    print(fund_energies)
    print('Fund CHON')
    print(fund_CHON)

    #Read the species to be processed
    print("Opening input file: %s" % input_path)
    thermdats_dft = read_freq(input_path,
                              verbose=verbose,
                              freq_cut_off=freq_cut_off,
                              warn=warn)

    for i, thermdat_dft in enumerate(thermdats_dft):
        print("-" * 10)
        print("Processing %s..." % thermdat_dft.symbol)
        thermdat_dft.nasa = Nasa(symbol=thermdat_dft.symbol,
                                 T_low=min(T_range),
                                 T_high=max(T_range))

        print("Calculating heat capacities.")
        CpoR = thermdat_dft.get_CpoR(T_range)

        print("Calculating DFT enthalpy of formation")
        if thermdat_dft.is_gas:
            H0 = thermdat_dft.IdealGasThermo.get_enthalpy(
                temperature=c.T0('K'), verbose=verbose)
            thermo_parameters = thermdat_dft.IdealGasThermo.__dict__
        else:
            thermo_parameters = thermdat_dft.HarmonicThermo.__dict__
            if np.sum(thermdat_dft.HarmonicThermo.vib_energies) == 0:
                H0 = thermdat_dft.HarmonicThermo.potentialenergy
            else:
                H0 = thermdat_dft.HarmonicThermo.get_internal_energy(
                    temperature=c.T0('K'), verbose=verbose)
        print("Adjusting enthalpy to reference")
        CHON = np.delete(thermdat_dft.CHON, rm_list)
        TransformCHON = np.dot(CHON, np.linalg.inv(fund_CHON))
        HoRT0 = (H0 - np.dot(TransformCHON, fund_energies)) / (c.T0('K') *
                                                               c.kb('eV/K'))

        print("Calculating DFT enthalpy of formation")
        if thermdat_dft.is_gas:
            S0 = thermdat_dft.IdealGasThermo.get_entropy(
                temperature=c.T0('K'),
                pressure=pressure * c.convert_unit(from_='atm', to='Pa'),
                verbose=verbose)
        else:
            if np.sum(thermdat_dft.HarmonicThermo.vib_energies) == 0:
                S0 = 0.
            else:
                S0 = thermdat_dft.HarmonicThermo.get_entropy(
                    temperature=c.T0('K'), verbose=verbose)
        SoR0 = S0 / c.kb('eV/K')
        print('Species: {}'.format(thermdat_dft.symbol))
        print('thermo parameters: {}'.format(thermo_parameters))
        print('HoRT0 = {}'.format(HoRT0))
        print('S/R0 = {}'.format(SoR0))
        print('#')
        print("Calculating NASA polynomials")
        thermdat_dft.nasa.fit_NASA(T_range, CpoR, HoRT0, SoR0)

    #Add gas-phase species
    if add_gas_species:
        print("Opening gas phase file: {}".format(gas_path))
        thermdats_gas = Thermdats.from_thermdat(thermdat_path=gas_path,
                                                verbose=verbose,
                                                warn=warn)
        print("Attaching gas species")
        thermdats_dft.extend(thermdats_gas)

    if write_files:
        print("Writing to thermdat")
        thermdats_dft.write_thermdat(out_path, verbose=False)

    return thermdats_dft
Beispiel #4
0
 def test_kb(self):
     self.assertEqual(c.kb('J/K'), 1.38064852e-23)
Beispiel #5
0
def get_chemical_potential(atoms,
                           freq,
                           geometry,
                           potentialenergy,
                           symmetrynumber,
                           spin,
                           T,
                           nasa_liq=None,
                           H_gas=None,
                           S_gas=None,
                           x=None,
                           gas_phase=False,
                           verbose=False):
    """
    Calculates the chemical potential of the toluene-phase species
    atoms - ASE Atoms object
    freq - Numpy array of floats
        Frequencies of the species in 1/cm
    geometry - string
        Geometry of the species (monatomic, linear, nonlinear)
    potentialenergy - float
        DFT Energy of the species in eV
    symmetrynumber - float
        Symmetry number of the species
    spin - int
        Number of unpaired electrons in the species
    nasa_liq - NASA object
        NASA polynomial of the species in the liquid phase
    H_gas - float
        Enthalpy of the gas in kJ/mol/K
    S_gas - float
        Entropy of the gas in J/mol/K
    T - float
        Temperature to perform analysis
    x - float
        Mole fraction of species in liquid
    """

    #DFT Delta G
    DFT_thermo = IdealGasThermo(vib_energies=freq * c.h('eV s') * c.c('cm/s'),
                                geometry=geometry,
                                potentialenergy=potentialenergy,
                                natoms=len(atoms),
                                atoms=atoms,
                                symmetrynumber=symmetrynumber,
                                spin=spin)
    G_DFT = DFT_thermo.get_gibbs_energy(temperature=298.,
                                        pressure=1.e5,
                                        verbose=verbose)

    if gas_phase:
        return np.array([
            DFT_thermo.get_gibbs_energy(temperature=T_i,
                                        pressure=1.e5,
                                        verbose=verbose) for T_i in T
        ])
    else:
        #ASPEN Liquid Data
        G_liq = nasa_liq.get_GoRT(T=T, verbose=False) * c.kb('eV/K') * T

        #NIST Gas Phase Data
        G_gas = H_gas * c.convert_unit(
            from_='kJ/mol', to='eV/molecule') - T * S_gas * c.convert_unit(
                from_='J/mol', to='eV/molecule')

        return G_DFT + G_liq - G_gas + c.kb('eV/K') * T * np.log(x)