Exemple #1
0
def runThermoEstimator(inputFile):
    """
    Estimate thermo for a list of species using RMG and the settings chosen inside a thermo input file.
    """
    
    rmg = RMG()
    rmg.loadThermoInput(inputFile)
    
    # initialize and load the database as well as any QM settings
    rmg.loadDatabase()
    if rmg.quantumMechanics:
        rmg.quantumMechanics.initialize()
    
    # Generate the thermo for all the species and write them to chemkin format as well as
    # ThermoLibrary format with values for H, S, and Cp's.
    output = open(os.path.join(rmg.outputDirectory, 'output.txt'),'wb')
    library = ThermoLibrary(name='Thermo Estimation Library')
    for species in rmg.initialSpecies:
        species.generateThermoData(rmg.database, quantumMechanics=rmg.reactionModel.quantumMechanics)

        library.loadEntry(
            index = len(library.entries) + 1,
            label = species.label,
            molecule = species.molecule[0].toAdjacencyList(),
            thermo = species.thermo.toThermoData(),
            shortDesc = species.thermo.comment,
        )
        output.write(writeThermoEntry(species))
        output.write('\n')
    
    output.close()
    library.save(os.path.join(rmg.outputDirectory,'ThermoLibrary.py'))
Exemple #2
0
def runThermoEstimator(inputFile):
    """
    Estimate thermo for a list of species using RMG and the settings chosen inside a thermo input file.
    """

    rmg = RMG()
    rmg.loadThermoInput(inputFile)

    # initialize and load the database as well as any QM settings
    rmg.loadDatabase()
    if rmg.quantumMechanics:
        rmg.quantumMechanics.initialize()

    # Generate the thermo for all the species and write them to chemkin format as well as
    # ThermoLibrary format with values for H, S, and Cp's.
    output = open(os.path.join(rmg.outputDirectory, 'output.txt'), 'wb')
    library = ThermoLibrary(name='Thermo Estimation Library')
    for species in rmg.initialSpecies:
        species.generateThermoData(
            rmg.database, quantumMechanics=rmg.reactionModel.quantumMechanics)

        library.loadEntry(
            index=len(library.entries) + 1,
            label=species.label,
            molecule=species.molecule[0].toAdjacencyList(),
            thermo=species.thermo.toThermoData(),
            shortDesc=species.thermo.comment,
        )
        output.write(writeThermoEntry(species))
        output.write('\n')

    output.close()
    library.save(os.path.join(rmg.outputDirectory, 'ThermoLibrary.py'))
Exemple #3
0
    def save(self, outputFile):
        """
        Save the results of the thermodynamics job to the file located
        at `path` on disk.
        """
        species = self.species
        logging.info('Saving thermo for {0}...'.format(species.label))
        
        f = open(outputFile, 'a')
    
        f.write('# Thermodynamics for {0}:\n'.format(species.label))
        H298 = species.getThermoData().getEnthalpy(298) / 4184.
        S298 = species.getThermoData().getEntropy(298) / 4.184
        f.write('#   Enthalpy of formation (298 K)   = {0:9.3f} kcal/mol\n'.format(H298))
        f.write('#   Entropy of formation (298 K)    = {0:9.3f} cal/(mol*K)\n'.format(S298))
        f.write('#    =========== =========== =========== =========== ===========\n')
        f.write('#    Temperature Heat cap.   Enthalpy    Entropy     Free energy\n')
        f.write('#    (K)         (cal/mol*K) (kcal/mol)  (cal/mol*K) (kcal/mol)\n')
        f.write('#    =========== =========== =========== =========== ===========\n')
        for T in [300,400,500,600,800,1000,1500,2000,2400]:
            try:
                Cp = species.getThermoData().getHeatCapacity(T) / 4.184
                H = species.getThermoData().getEnthalpy(T) / 4184.
                S = species.getThermoData().getEntropy(T) / 4.184
                G = species.getThermoData().getFreeEnergy(T) / 4184.
                f.write('#    {0:11g} {1:11.3f} {2:11.3f} {3:11.3f} {4:11.3f}\n'.format(T, Cp, H, S, G))
            except ValueError:
                logging.debug("Valid thermo for {0} is outside range for temperature {1}".format(species,T))
        f.write('#    =========== =========== =========== =========== ===========\n')

        thermo_string = 'thermo(label={0!r}, thermo={1!r})'.format(species.label, species.getThermoData())
        f.write('{0}\n\n'.format(prettify(thermo_string)))
        
        f.close()
        # write chemkin file
        f = open(os.path.join(os.path.dirname(outputFile), 'chem.inp'), 'a')
        if isinstance(species, Species):
            if species.molecule and isinstance(species.molecule[0], Molecule):
                elementCounts = retrieveElementCount(species.molecule[0])
            else:
                try:
                    elementCounts = species.props['elementCounts']
                except KeyError:
                    elementCounts = {'C': 0, 'H': 0}
        else:
            elementCounts = {'C': 0, 'H': 0}
        chemkin_thermo_string = writeThermoEntry(species, elementCounts=elementCounts, verbose=True)
        f.write('{0}\n'.format(chemkin_thermo_string))
        f.close()

        # write species dictionary
        if isinstance(species, Species):
            if species.molecule and isinstance(species.molecule[0], Molecule):
                with open(os.path.join(os.path.dirname(outputFile), 'species_dictionary.txt'), 'a') as f:
                    f.write(species.molecule[0].toAdjacencyList(removeH=False, label=species.label))
                    f.write('\n')
        return chemkin_thermo_string
Exemple #4
0
    def save(self, outputFile):
        """
        Save the results of the thermodynamics job to the file located
        at `path` on disk.
        """
        species = self.species
        logging.info('Saving thermo for {0}...'.format(species.label))

        f = open(outputFile, 'a')

        f.write('# Thermodynamics for {0}:\n'.format(species.label))
        H298 = species.getThermoData().getEnthalpy(298) / 4184.
        S298 = species.getThermoData().getEntropy(298) / 4.184
        f.write(
            '#   Enthalpy of formation (298 K)   = {0:9.3f} kcal/mol\n'.format(
                H298))
        f.write('#   Entropy of formation (298 K)    = {0:9.3f} cal/(mol*K)\n'.
                format(S298))
        f.write(
            '#    =========== =========== =========== =========== ===========\n'
        )
        f.write(
            '#    Temperature Heat cap.   Enthalpy    Entropy     Free energy\n'
        )
        f.write(
            '#    (K)         (cal/mol*K) (kcal/mol)  (cal/mol*K) (kcal/mol)\n'
        )
        f.write(
            '#    =========== =========== =========== =========== ===========\n'
        )
        for T in [300, 400, 500, 600, 800, 1000, 1500, 2000, 2400]:
            Cp = species.getThermoData().getHeatCapacity(T) / 4.184
            H = species.getThermoData().getEnthalpy(T) / 4184.
            S = species.getThermoData().getEntropy(T) / 4.184
            G = species.getThermoData().getFreeEnergy(T) / 4184.
            f.write('#    {0:11g} {1:11.3f} {2:11.3f} {3:11.3f} {4:11.3f}\n'.
                    format(T, Cp, H, S, G))
        f.write(
            '#    =========== =========== =========== =========== ===========\n'
        )

        string = 'thermo(label={0!r}, thermo={1!r})'.format(
            species.label, species.getThermoData())
        f.write('{0}\n\n'.format(prettify(string)))

        f.close()

        f = open(os.path.join(os.path.dirname(outputFile), 'chem.inp'), 'a')
        string = writeThermoEntry(species,
                                  elementCounts=species.props['elementCounts'],
                                  verbose=False)
        f.write(string)
        f.close()
Exemple #5
0
def runThermoEstimator(inputFile):
    """
    Estimate thermo for a list of species using RMG and the settings chosen inside a thermo input file.
    """
    
    rmg = RMG()
    rmg.loadThermoInput(inputFile)
    
    rmg.database = RMGDatabase()
    path = os.path.join(settings['database.directory'])

    # forbidden structure loading
    rmg.database.loadThermo(os.path.join(path, 'thermo'), rmg.thermoLibraries, depository=False)
   
    if rmg.solvent:
        rmg.database.loadSolvation(os.path.join(path, 'solvation'))
        Species.solventData = rmg.database.solvation.getSolventData(rmg.solvent)
        Species.solventName = rmg.solvent
        
    # Generate the thermo for all the species and write them to chemkin format as well as
    # ThermoLibrary format with values for H, S, and Cp's.
    output = open(os.path.join(rmg.outputDirectory, 'output.txt'),'wb')
    library = ThermoLibrary(name='Thermo Estimation Library')
    for species in rmg.initialSpecies:
        species.getThermoData(rmg.database)

        library.loadEntry(
            index = len(library.entries) + 1,
            label = species.label,
            molecule = species.molecule[0].toAdjacencyList(),
            thermo = species.thermo.toThermoData(),
            shortDesc = species.thermo.comment,
        )
        output.write(writeThermoEntry(species))
        output.write('\n')
    
    output.close()
    library.save(os.path.join(rmg.outputDirectory,'ThermoLibrary.py'))
Exemple #6
0
    def write_chemkin(self, output_directory):
        """
        Appends the thermo block to `chem.inp` and species name to
        `species_dictionary.txt` within the `outut_directory` specified
        """
        species = self.species
        with open(os.path.join(output_directory, 'chem.inp'), 'a') as f:
            if isinstance(species, Species):
                if species.molecule and isinstance(species.molecule[0], Molecule):
                    element_counts = retrieveElementCount(species.molecule[0])
                else:
                    try:
                        element_counts = species.props['element_counts']
                    except KeyError:
                        element_counts = self.element_count_from_conformer()
            else:
                element_counts = {'C': 0, 'H': 0}
            chemkin_thermo_string = writeThermoEntry(species, elementCounts=element_counts, verbose=True)
            f.write('{0}\n'.format(chemkin_thermo_string))

        # write species dictionary
        if isinstance(species, Species):
            if species.molecule and isinstance(species.molecule[0], Molecule):
                spec_dict_path = os.path.join(output_directory, 'species_dictionary.txt')
                is_species_in_dict = False
                if os.path.isfile(spec_dict_path):
                    with open(spec_dict_path, 'r') as f:
                        # check whether the species dictionary contains this species, in which case do not re-append
                        for line in f.readlines():
                            if species.label == line.strip():
                                is_species_in_dict = True
                                break
                if not is_species_in_dict:
                    with open(spec_dict_path, 'a') as f:
                        f.write(species.molecule[0].toAdjacencyList(removeH=False, label=species.label))
                        f.write('\n')
        return chemkin_thermo_string
Exemple #7
0
 def save(self, outputFile):
     """
     Save the results of the thermodynamics job to the file located
     at `path` on disk.
     """
     species = self.species
     logging.info('Saving thermo for {0}...'.format(species.label))
     
     f = open(outputFile, 'a')
 
     f.write('# Thermodynamics for {0}:\n'.format(species.label))
     H298 = species.getThermoData().getEnthalpy(298) / 4184.
     S298 = species.getThermoData().getEntropy(298) / 4.184
     f.write('#   Enthalpy of formation (298 K)   = {0:9.3f} kcal/mol\n'.format(H298))
     f.write('#   Entropy of formation (298 K)    = {0:9.3f} cal/(mol*K)\n'.format(S298))
     f.write('#    =========== =========== =========== =========== ===========\n')
     f.write('#    Temperature Heat cap.   Enthalpy    Entropy     Free energy\n')
     f.write('#    (K)         (cal/mol*K) (kcal/mol)  (cal/mol*K) (kcal/mol)\n')
     f.write('#    =========== =========== =========== =========== ===========\n')
     for T in [300,400,500,600,800,1000,1500,2000,2400]:
         Cp = species.getThermoData().getHeatCapacity(T) / 4.184
         H = species.getThermoData().getEnthalpy(T) / 4184.
         S = species.getThermoData().getEntropy(T) / 4.184
         G = species.getThermoData().getFreeEnergy(T) / 4184.
         f.write('#    {0:11g} {1:11.3f} {2:11.3f} {3:11.3f} {4:11.3f}\n'.format(T, Cp, H, S, G))
     f.write('#    =========== =========== =========== =========== ===========\n')
     
     string = 'thermo(label={0!r}, thermo={1!r})'.format(species.label, species.getThermoData())
     f.write('{0}\n\n'.format(prettify(string)))
     
     f.close()
     
     f = open(os.path.join(os.path.dirname(outputFile), 'chem.inp'), 'a')
     string = writeThermoEntry(species, elementCounts=species.props['elementCounts'], verbose=False)
     f.write(string)
     f.close()