本文整理汇总了Python中rmgpy.data.rmg.RMGDatabase.load方法的典型用法代码示例。如果您正苦于以下问题:Python RMGDatabase.load方法的具体用法?Python RMGDatabase.load怎么用?Python RMGDatabase.load使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rmgpy.data.rmg.RMGDatabase
的用法示例。
在下文中一共展示了RMGDatabase.load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUpModule
# 需要导入模块: from rmgpy.data.rmg import RMGDatabase [as 别名]
# 或者: from rmgpy.data.rmg.RMGDatabase import load [as 别名]
def setUpModule():
"""A function that is run ONCE before all unit tests in this module."""
global database
database = RMGDatabase()
database.load(
path=os.path.join(settings['test_data.directory'], 'testing_database'),
thermoLibraries=['primaryThermoLibrary'],
reactionLibraries=['GRI-Mech3.0'],
kineticsFamilies=[
'R_Recombination',
'Disproportionation',
'R_Addition_MultipleBond',
'H_Abstraction',
'intra_H_migration',
],
testing=True,
depository=False,
solvation=False,
)
#load empty forbidden structures to avoid any dependence on forbidden structures
#for these tests
for family in database.kinetics.families.values():
family.forbidden = ForbiddenStructures()
database.forbiddenStructures = ForbiddenStructures()
# Prepare the database by loading training reactions and averaging the rate rules
for family in database.kinetics.families.values():
family.addKineticsRulesFromTrainingSet(thermoDatabase=database.thermo)
family.fillKineticsRulesByAveragingUp(verbose=True)
示例2: export
# 需要导入模块: from rmgpy.data.rmg import RMGDatabase [as 别名]
# 或者: from rmgpy.data.rmg.RMGDatabase import load [as 别名]
def export(input, output, database=None):
print 'Loading the new RMG-Py database...'
if not database:
database = RMGDatabase()
database.load(input)
print 'Constructing additional rate rules from kinetics depository...'
for family in database.kinetics.families.values():
generateRules(family, database)
print 'Saving old RMG-Java database...'
database.saveOld(output)
示例3: export
# 需要导入模块: from rmgpy.data.rmg import RMGDatabase [as 别名]
# 或者: from rmgpy.data.rmg.RMGDatabase import load [as 别名]
def export(input, output, database=None):
print 'Loading the new RMG-Py database...'
if not database:
database = RMGDatabase()
database.load(input, kineticsFamilies='all', kineticsDepositories='all')
print 'Constructing additional rate rules from kinetics depository...'
for family in database.kinetics.families.values():
family.addKineticsRulesFromTrainingSet(thermoDatabase=database.thermo)
print "Deleting thermo library entries with atoms RMG-Java can't understand..."
database.thermo.pruneHeteroatoms(allowed=['C','H','O','S'])
print 'Saving old RMG-Java database...'
database.saveOld(output)
print "Done!"
示例4: setUpModule
# 需要导入模块: from rmgpy.data.rmg import RMGDatabase [as 别名]
# 或者: from rmgpy.data.rmg.RMGDatabase import load [as 别名]
def setUpModule():
"""A function that is run ONCE before all unit tests in this module."""
global database
database = RMGDatabase()
database.load(
path=os.path.join(settings['test_data.directory'], 'testing_database'),
kineticsFamilies=[
'H_Abstraction','intra_H_migration'
],
testing=True,
depository=False,
solvation=False,
)
database.loadForbiddenStructures()
# Prepare the database by loading training reactions and averaging the rate rules
for family in database.kinetics.families.values():
family.addKineticsRulesFromTrainingSet(thermoDatabase=database.thermo)
family.fillKineticsRulesByAveragingUp(verbose=True)
示例5: __init__
# 需要导入模块: from rmgpy.data.rmg import RMGDatabase [as 别名]
# 或者: from rmgpy.data.rmg.RMGDatabase import load [as 别名]
class Uncertainty:
"""
This class contains functions associated with running uncertainty analyses
for a single RMG-generated mechanism.
"""
def __init__(self, speciesList=None, reactionList=None, outputDirectory=''):
"""
`speciesList`: list of RMG species objects
`reactionList`: list of RMG reaction objects
`outputDirectoy`: directory path for saving output files from the analyses
"""
self.database = None
self.speciesList = speciesList
self.reactionList = reactionList
self.speciesSourcesDict = None
self.reactionSourcesDict = None
self.allThermoSources = None
self.allKineticSources = None
self.thermoInputUncertainties = None
self.kineticInputUncertainties = None
self.outputDirectory = outputDirectory if outputDirectory else os.getcwd()
# Make output directory if it does not yet exist:
if not os.path.exists(self.outputDirectory):
try:
os.makedirs(self.outputDirectory)
except:
raise Exception('Uncertainty output directory could not be created.')
def loadDatabase(self, kineticsFamilies='all',kineticsDepositories=None,thermoLibraries=None, reactionLibraries=None):
"""
This function loads a single copy of the RMGDatabase with full verbose averaging
of the rate rule to trace kinetics sources.
By default, this function loads all the kinetics families, only the training kinetics depository,
the primaryThermoLibrary, and no reaction libraries.
"""
from rmgpy.data.rmg import RMGDatabase
from rmgpy import settings
if not kineticsDepositories:
kineticsDepositories = ['training']
if not thermoLibraries:
thermoLibraries = ['primaryThermoLibrary']
if not reactionLibraries:
reactionLibraries = []
self.database = RMGDatabase()
self.database.load(settings['database.directory'],
kineticsFamilies=kineticsFamilies,
kineticsDepositories=kineticsDepositories,
thermoLibraries=thermoLibraries,
reactionLibraries=reactionLibraries,
)
# Prepare the database by loading training reactions but not averaging the rate rules
for familyLabel, family in self.database.kinetics.families.iteritems():
family.addKineticsRulesFromTrainingSet(thermoDatabase=self.database.thermo)
family.fillKineticsRulesByAveragingUp(verbose=True)
def loadModel(self, chemkinPath, dictionaryPath, transportPath=None):
"""
Load a RMG-generated model into the Uncertainty class
`chemkinPath`: path to the chem_annotated.inp CHEMKIN mechanism
`dictionaryPath`: path to the species_dictionary.txt file
`transportPath`: path to the tran.dat file (optional)
Then create dictionaries stored in self.thermoGroups and self.rateRules
containing information about the source of the thermodynamic and kinetic
parameters
"""
from rmgpy.chemkin import loadChemkinFile
self.speciesList, self.reactionList = loadChemkinFile(chemkinPath,
dictionaryPath=dictionaryPath,
transportPath=transportPath)
def retrieveSaturatedSpeciesFromList(self,species):
"""
Given a radical `species`, this function retrieves the saturated species objects from a list of species objects
and returns the saturated species object along with a boolean that indicates if the species is not part of the model
(True->not in the model, False->in the model)
"""
molecule = species.molecule[0]
assert molecule.isRadical(), "Method only valid for radicals."
saturatedStruct = molecule.copy(deep=True)
saturatedStruct.saturate_radicals()
for otherSpecies in self.speciesList:
if otherSpecies.isIsomorphic(saturatedStruct):
return otherSpecies, False
#couldn't find saturated species in the model, try libraries
newSpc = Species(molecule=[saturatedStruct])
thermo = self.database.thermo.getThermoDataFromLibraries(newSpc)
#.........这里部分代码省略.........
示例6: files
# 需要导入模块: from rmgpy.data.rmg import RMGDatabase [as 别名]
# 或者: from rmgpy.data.rmg.RMGDatabase import load [as 别名]
# copy of this software and associated documentation files (the 'Software'), #
# to deal in the Software without restriction, including without limitation #
# the rights to use, copy, modify, merge, publish, distribute, sublicense, #
# and/or sell copies of the Software, and to permit persons to whom the #
# Software is furnished to do so, subject to the following conditions: #
# #
# The above copyright notice and this permission notice shall be included in #
# all copies or substantial portions of the Software. #
# #
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE #
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING #
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER #
# DEALINGS IN THE SOFTWARE. #
# #
###############################################################################
"""
This script machine writes all the families and groups (no libraries) so that RMG-database looks cleaner
and does not have duplicate indexes
"""
from rmgpy import settings
from rmgpy.data.rmg import RMGDatabase
database = RMGDatabase()
database.load(settings['database.directory'], kineticsFamilies = 'all')
database.save(settings['database.directory'])
示例7: loadDatabase
# 需要导入模块: from rmgpy.data.rmg import RMGDatabase [as 别名]
# 或者: from rmgpy.data.rmg.RMGDatabase import load [as 别名]
def loadDatabase():
print 'Loading RMG database...'
from rmgpy.data.rmg import RMGDatabase
database = RMGDatabase()
database.load(settings['database.directory'], kineticsFamilies='all', kineticsDepositories='all')
return database
示例8: loadDatabase
# 需要导入模块: from rmgpy.data.rmg import RMGDatabase [as 别名]
# 或者: from rmgpy.data.rmg.RMGDatabase import load [as 别名]
def loadDatabase():
print 'Loading RMG database...'
from rmgpy.data.rmg import RMGDatabase
database = RMGDatabase()
database.load('input')
return database
示例9: Generator
# 需要导入模块: from rmgpy.data.rmg import RMGDatabase [as 别名]
# 或者: from rmgpy.data.rmg.RMGDatabase import load [as 别名]
class RMG:
"""
A representation of a Reaction Mechanism Generator (RMG) job. The
attributes are:
=========================== ================================================
Attribute Description
=========================== ================================================
`inputFile` The path to the input file
`logFile` The path to the log file
--------------------------- ------------------------------------------------
`databaseDirectory` The directory containing the RMG database
`thermoLibraries` The thermodynamics libraries to load
`reactionLibraries` The kinetics libraries to load
`statmechLibraries` The statistical mechanics libraries to load
`seedMechanisms` The seed mechanisms included in the model
`kineticsFamilies` The kinetics families to use for reaction generation
`kineticsDepositories` The kinetics depositories to use for looking up kinetics in each family
`kineticsEstimator` The method to use to estimate kinetics: 'group additivity' or 'rate rules'
--------------------------- ------------------------------------------------
`reactionModel` The core-edge reaction model generated by this job
`reactionSystems` A list of the reaction systems used in this job
`database` The RMG database used in this job
--------------------------- ------------------------------------------------
`absoluteTolerance` The absolute tolerance used in the ODE/DAE solver
`relativeTolerance` The relative tolerance used in the ODE/DAE solver
`fluxToleranceKeepInEdge` The relative species flux below which species are discarded from the edge
`fluxToleranceMoveToCore` The relative species flux above which species are moved from the edge to the core
`fluxToleranceInterrupt` The relative species flux above which the simulation will halt
`maximumEdgeSpecies` The maximum number of edge species allowed at any time
`termination` A list of termination targets (i.e :class:`TerminationTime` and :class:`TerminationConversion` objects)
--------------------------- ------------------------------------------------
`outputDirectory` The directory used to save output files
`scratchDirectory` The directory used to save temporary files
`verbosity` The level of logging verbosity for console output
`loadRestart` ``True`` if restarting a previous job, ``False`` otherwise
`saveRestartPeriod` The time period to periodically save a restart file (:class:`Quantity`), or ``None`` for never.
`units` The unit system to use to save output files (currently must be 'si')
`drawMolecules` ``True`` to draw pictures of the species in the core, ``False`` otherwise
`generatePlots` ``True`` to generate plots of the job execution statistics after each iteration, ``False`` otherwise
`pressureDependence` Whether to process unimolecular (pressure-dependent) reaction networks
`wallTime` The maximum amount of CPU time in seconds to expend on this job; used to stop gracefully so we can still get profiling information
--------------------------- ------------------------------------------------
`initializationTime` The time at which the job was initiated, in seconds since the epoch (i.e. from time.time())
`done` Whether the job has completed (there is nothing new to add)
=========================== ================================================
"""
def __init__(self, inputFile=None, logFile=None, outputDirectory=None, scratchDirectory=None):
self.inputFile = inputFile
self.logFile = logFile
self.outputDirectory = outputDirectory
self.scratchDirectory = scratchDirectory
self.clear()
def clear(self):
"""
Clear all loaded information about the job (except the file paths).
"""
self.databaseDirectory = None
self.thermoLibraries = None
self.reactionLibraries = None
self.statmechLibraries = None
self.seedMechanisms = None
self.kineticsFamilies = None
self.kineticsDepositories = None
self.kineticsEstimator = 'group additivity'
self.reactionModel = None
self.reactionSystems = None
self.database = None
self.fluxToleranceKeepInEdge = 0.0
self.fluxToleranceMoveToCore = 1.0
self.fluxToleranceInterrupt = 1.0
self.absoluteTolerance = 1.0e-8
self.relativeTolerance = 1.0e-4
self.maximumEdgeSpecies = 1000000
self.termination = []
self.done = False
self.verbosity = logging.INFO
self.loadRestart = None
self.saveRestartPeriod = None
self.units = 'si'
self.drawMolecules = None
self.generatePlots = None
self.saveConcentrationProfiles = None
self.pressureDependence = None
self.wallTime = 0
self.initializationTime = 0
def loadInput(self, path=None):
"""
Load an RMG job from the input file located at `inputFile`, or
from the `inputFile` attribute if not given as a parameter.
"""
from input import readInputFile
if path is None: path = self.inputFile
#.........这里部分代码省略.........
示例10: RMGDatabase
# 需要导入模块: from rmgpy.data.rmg import RMGDatabase [as 别名]
# 或者: from rmgpy.data.rmg.RMGDatabase import load [as 别名]
data = kinetics,
reference = entry0.reference,
rank = entry0.rank,
shortDesc = entry0.shortDesc,
longDesc = entry0.longDesc,
history = entry0.history,
)
# Add the new rate rule to the depository of rate rules
rules.entries[entry.index] = entry
index += 1
################################################################################
if __name__ == '__main__':
oldPath = 'output/RMG_database'
newPath = 'input'
print 'Loading the new RMG-Py database...'
database = RMGDatabase()
database.load(newPath)
print 'Constructing additional rate rules from kinetics depository...'
for family in database.kinetics.groups:
generateAdditionalRateRules(family, database)
print 'Saving old RMG-Java database...'
database.saveOld(oldPath)
示例11: enumerate
# 需要导入模块: from rmgpy.data.rmg import RMGDatabase [as 别名]
# 或者: from rmgpy.data.rmg.RMGDatabase import load [as 别名]
for rxnFamily in rxnFamiles:
for k, line in enumerate(mechLines):
if line.startswith('! {0} estimate:'.format(rxnFamily)) or line.startswith('! {0} exact:'.format(rxnFamily)):
reaction = mechLines[k+1].split()[0]
if reaction not in gotit:
gotit.append(reaction)
rxnList.append((rxnFamily, mechLines[k+1]))
elif '{0} estimate:'.format(rxnFamily) in line or '{0} exact:'.format(rxnFamily) in line:
reaction = mechLines[k+1].split()[0]
if reaction not in gotit:
gotit.append(reaction)
rxnList.append((rxnFamily, mechLines[k+1]))
print 'Loading RMG Database ...'
rmgDatabase = RMGDatabase()
rmgDatabase.load(os.path.abspath(os.path.join(os.getenv('RMGpy'), '..', 'RMG-database', 'input')), kineticsFamilies='default')
print 'Finished loading RMG Database ...'
reactionTuple = rxnList[i-1]
rxnFamily, reactionLine = reactionTuple
rxnFormula, A, n, Ea = reactionLine.split()
reactants, products = rxnFormula.split('=')
if rxnFamily in ['H_Abstraction', 'Disproportionation']:
reactant1, reactant2 = [moleculeDict[j] for j in reactants.split('+')]
product1, product2 = [moleculeDict[j] for j in products.split('+')]
rSpecies1 = Species(molecule=[reactant1])
rSpecies2 = Species(molecule=[reactant2])
pSpecies1 = Species(molecule=[product1])
pSpecies2 = Species(molecule=[product2])
rSpecies1.generateResonanceIsomers()
rSpecies2.generateResonanceIsomers()
示例12: __init__
# 需要导入模块: from rmgpy.data.rmg import RMGDatabase [as 别名]
# 或者: from rmgpy.data.rmg.RMGDatabase import load [as 别名]
class Uncertainty:
"""
This class contains functions associated with running uncertainty analyses
for a single RMG-generated mechanism.
"""
def __init__(self, speciesList=None, reactionList=None, outputDirectory=''):
"""
`speciesList`: list of RMG species objects
`reactionList`: list of RMG reaction objects
`outputDirectoy`: directory path for saving output files from the analyses
"""
self.database = None
self.speciesList = speciesList
self.reactionList = reactionList
self.speciesSourcesDict = None
self.reactionSourcesDict = None
self.allThermoSources = None
self.allKineticSources = None
self.thermoInputUncertainties = None
self.kineticInputUncertainties = None
self.outputDirectory = outputDirectory if outputDirectory else os.getcwd()
# Make output directory if it does not yet exist:
if not os.path.exists(self.outputDirectory):
try:
os.makedirs(self.outputDirectory)
except:
raise Exception('Uncertainty output directory could not be created.')
def loadDatabase(self, kineticsFamilies='all',kineticsDepositories=None,thermoLibraries=None, reactionLibraries=None):
"""
This function loads a single copy of the RMGDatabase with full verbose averaging
of the rate rule to trace kinetics sources.
By default, this function loads all the kinetics families, only the training kinetics depository,
the primaryThermoLibrary, and no reaction libraries.
"""
from rmgpy.data.rmg import RMGDatabase
from rmgpy import settings
if not kineticsDepositories:
kineticsDepositories = ['training']
if not thermoLibraries:
thermoLibraries = ['primaryThermoLibrary']
if not reactionLibraries:
reactionLibraries = []
self.database = RMGDatabase()
self.database.load(settings['database.directory'],
kineticsFamilies=kineticsFamilies,
kineticsDepositories=kineticsDepositories,
thermoLibraries=thermoLibraries,
reactionLibraries=reactionLibraries,
)
# Prepare the database by loading training reactions but not averaging the rate rules
for familyLabel, family in self.database.kinetics.families.iteritems():
family.addKineticsRulesFromTrainingSet(thermoDatabase=self.database.thermo)
family.fillKineticsRulesByAveragingUp(verbose=True)
def loadModel(self, chemkinPath, dictionaryPath, transportPath=None):
"""
Load a RMG-generated model into the Uncertainty class
`chemkinPath`: path to the chem_annotated.inp CHEMKIN mechanism
`dictionaryPath`: path to the species_dictionary.txt file
`transportPath`: path to the tran.dat file (optional)
Then create dictionaries stored in self.thermoGroups and self.rateRules
containing information about the source of the thermodynamic and kinetic
parameters
"""
from rmgpy.chemkin import loadChemkinFile
self.speciesList, self.reactionList = loadChemkinFile(chemkinPath,
dictionaryPath=dictionaryPath,
transportPath=transportPath)
def extractSourcesFromModel(self):
"""
Extract the source data from the model using its comments.
Must be done after loading model and database to work.
"""
self.speciesSourcesDict = {}
for species in self.speciesList:
source = self.database.thermo.extractSourceFromComments(species)
# Now prep the source data
# Do not alter the GAV information, but reassign QM and Library sources to the species indices that they came from
if len(source.keys()) == 1:
# The thermo came from a single source, so we know it comes from a value describing the exact species
if 'Library' in source:
source['Library'] = self.speciesList.index(species) # Use just the species index in self.speciesList, for better shorter printouts when debugging
if 'QM' in source:
source['QM'] = self.speciesList.index(species)
#.........这里部分代码省略.........
示例13: RMGDatabase
# 需要导入模块: from rmgpy.data.rmg import RMGDatabase [as 别名]
# 或者: from rmgpy.data.rmg.RMGDatabase import load [as 别名]
"""
import math
import os.path
import sys
import time
import subprocess
import os
from rmgpy.kinetics import KineticsData
from rmgpy.data.kinetics import KineticsDatabase, KineticsGroups
from rmgpy.data.rmg import RMGDatabase
################################################################################
if __name__ == '__main__':
# Set the import and export paths
oldPath = 'input'
newPath = 'input_new'
print 'Loading old RMG-Py database...'
database = RMGDatabase()
database.load(oldPath, kineticsFamilies='all', kineticsDepositories='all')
print 'Saving the new RMG-Py database...'
database.save(newPath)
print "Done!"
示例14: RMGDatabase
# 需要导入模块: from rmgpy.data.rmg import RMGDatabase [as 别名]
# 或者: from rmgpy.data.rmg.RMGDatabase import load [as 别名]
from rmgpy.rmg.model import Species
from rmgpy import settings
################################################################################
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"library", metavar="LIBRARYNAME", type=str, nargs=1, help="the name of the kinetic library to be exported"
)
args = parser.parse_args()
libraryName = args.library[0]
print "Loading RMG-Py database..."
database = RMGDatabase()
database.load(settings["database.directory"], kineticsFamilies="all", kineticsDepositories="all")
print "Loading {0} library".format(libraryName)
kineticLibrary = database.kinetics.libraries[libraryName]
reactionList = []
for index, entry in kineticLibrary.entries.iteritems():
reaction = entry.item
reaction.kinetics = entry.data
library_reaction = LibraryReaction(
index=reaction.index,
reactants=reaction.reactants,
products=reaction.products,
reversible=reaction.reversible,
kinetics=reaction.kinetics,
library=libraryName,
示例15: checkFamilies
# 需要导入模块: from rmgpy.data.rmg import RMGDatabase [as 别名]
# 或者: from rmgpy.data.rmg.RMGDatabase import load [as 别名]
for group in problems[5]:
outputFile.write(group + '\n')
outputFile.write('\n\n')
if __name__ == '__main__':
#Thermo stuff
# ThermoDatabase=ThermoDatabase()
# ThermoDatabase.load(path)
# ThermoDatabase.save(r'C:\RMG-database\input\thermo_test')
# ThermoDatabase.save(path)
FullDatabase=RMGDatabase()
# path=r'C:\RMG-database\input\thermo'
path='C:\RMG-database\input'
# FullDatabase.load(thermoLibraries=)
FullDatabase.load(path)
checkFamilies(FullDatabase)
# trialDir=r'C:\Users\User1\Dropbox\Research\RMG\kinetics\LeaveOneOut\test'
# trialDir=r'C:\RMG-database\input_test'
# family=FullDatabase.kinetics.families['Disproportionation']
# entryKey='Y_1centerbirad;O_Cdrad'
#
# test=getKineticsFromRules(family, entryKey)
#
# print test.comment
# print test
# NISTExact(FullDatabase, trialDir)
# countNodesAll(NISTDatabase, trialDir)
# consistencyTest(FullDatabase)
# LeaveOneOut(FullDatabase, trialDir)