當前位置: 首頁>>代碼示例>>Python>>正文


Python rmg.RMGDatabase類代碼示例

本文整理匯總了Python中rmgpy.data.rmg.RMGDatabase的典型用法代碼示例。如果您正苦於以下問題:Python RMGDatabase類的具體用法?Python RMGDatabase怎麽用?Python RMGDatabase使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了RMGDatabase類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: setUpModule

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)
開發者ID:ReactionMechanismGenerator,項目名稱:RMG-Py,代碼行數:29,代碼來源:kineticsTest.py

示例2: export

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)
開發者ID:eWizardII,項目名稱:RMG-database,代碼行數:13,代碼來源:exportOldDatabase.py

示例3: convertPrIMe

def convertPrIMe(family):

    print 'Loading kinetics families...'
    database = RMGDatabase()
    database.kinetics = KineticsDatabase()
    database.kinetics.loadFamilies('input/kinetics/families')
    database.loadForbiddenStructures('input/forbiddenStructures.py')
    
    for depository in database.kinetics.families[family].depositories:
        if depository.label == '{0}/PrIMe'.format(family):
            break
    else:
        raise Exception('Could not find PrIMe depository in {0} family.'.format(family))
    
    entries = []
    
    print 'Determining unique list of reactions...'
    for entry0 in depository.entries.values():
        for entry in entries:
            if entry.item.isIsomorphic(entry0.item):
                break
        else:
            entries.append(entry0)
    print 'Found {0:d} unique reactions out of {1:d} entries.'.format(len(entries), len(depository.entries))
    
    print 'Sorting unique reactions...'
    entries.sort(key=lambda entry: sum([1 for r in entry.item.reactants for a in r.atoms if a.isNonHydrogen()]))
    
    print 'Saving reactions...'
    for index, entry in enumerate(entries):
        
        label = entry.label
        reaction = entry.item
        
        # Determine degeneracy in both directions
        reactions = database.kinetics.generateReactionsFromFamilies(reaction.reactants, reaction.products, only_families=[family])
        if len(reactions) != 1:
            print 'Warning: could not determine forward degeneracy for reaction #{0:d}.'.format(index+1)
            forwardDegeneracy = 1
        else:
            forwardDegeneracy = reactions[0].degeneracy
        reactions = database.kinetics.generateReactionsFromFamilies(reaction.products, reaction.reactants, only_families=[family])
        if len(reactions) != 1:
            print 'Warning: could not determine reverse degeneracy for reaction #{0:d}.'.format(index+1)
            reverseDegeneracy = 1
        else:
            reverseDegeneracy = reactions[0].degeneracy
        
        saveReaction('input/kinetics/families/{0}/training/{0}.py'.format(family, index+1), index+1, label, reaction, forwardDegeneracy, reverseDegeneracy)
開發者ID:ajalan,項目名稱:RMG-database,代碼行數:49,代碼來源:convertPrIMe.py

示例4: loadDatabase

 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)
開發者ID:ReactionMechanismGenerator,項目名稱:RMG-Py,代碼行數:33,代碼來源:uncertainty.py

示例5: export

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!"
開發者ID:Lyle-zhang,項目名稱:RMG-database,代碼行數:16,代碼來源:exportOldDatabase.py

示例6: loadDatabase

def loadDatabase(component='', section=''):
    """
    Load the requested `component` of the RMG database if modified since last loaded.
    """
    global database
    if not database:
        database = RMGDatabase()
        database.thermo = ThermoDatabase()
        database.kinetics = KineticsDatabase()
        database.loadForbiddenStructures(os.path.join(settings.DATABASE_PATH, 'forbiddenStructures.py'))

    if component in ['thermo', '']:
        if section in ['depository', '']:
            dirpath = os.path.join(settings.DATABASE_PATH, 'thermo', 'depository')
            if isDirModified(dirpath):
                database.thermo.loadDepository(dirpath)
                resetDirTimestamps(dirpath)
        if section in ['libraries', '']:
            dirpath = os.path.join(settings.DATABASE_PATH, 'thermo', 'libraries')
            if isDirModified(dirpath):
                database.thermo.loadLibraries(dirpath)
                # put them in our preferred order, so that when we look up thermo in order to estimate kinetics,
                # we use our favourite values first.
                preferred_order = ['primaryThermoLibrary','DFT_QCI_thermo','GRI-Mech3.0','CBS_QB3_1dHR','KlippensteinH2O2']
                new_order = [i for i in preferred_order if i in database.thermo.libraryOrder]
                for i in database.thermo.libraryOrder:
                    if i not in new_order: new_order.append(i) 
                database.thermo.libraryOrder = new_order
                resetDirTimestamps(dirpath)
        if section in ['groups', '']:
            dirpath = os.path.join(settings.DATABASE_PATH, 'thermo', 'groups')
            if isDirModified(dirpath):
                database.thermo.loadGroups(dirpath)
                resetDirTimestamps(dirpath)
    if component in ['kinetics', '']:
        if section in ['libraries', '']:
            dirpath = os.path.join(settings.DATABASE_PATH, 'kinetics', 'libraries')
            if isDirModified(dirpath):
                database.kinetics.loadLibraries(dirpath)
                resetDirTimestamps(dirpath)
        if section in ['families', '']:
            dirpath = os.path.join(settings.DATABASE_PATH, 'kinetics', 'families')
            if isDirModified(dirpath):
                database.kinetics.loadFamilies(dirpath)
                resetDirTimestamps(dirpath)

    return database
開發者ID:alaraen,項目名稱:RMG-website,代碼行數:47,代碼來源:tools.py

示例7: load

def load():
    tearDown()
    rmg = RMG()#for solvent
    database = RMGDatabase()
    database.loadThermo(os.path.join(settings['database.directory'], 'thermo'))
    database.loadTransport(os.path.join(settings['database.directory'], 'transport'))
    database.loadSolvation(os.path.join(settings['database.directory'], 'solvation'))
開發者ID:PengZhang13,項目名稱:RMG-Py,代碼行數:7,代碼來源:thermoengineTest.py

示例8: __init__

 def __init__(self):
     self.database = RMGDatabase()
     self.database.kinetics = KineticsDatabase()
     self.database.thermo = ThermoDatabase()
     self.database.transport = TransportDatabase()
     self.database.statmech = StatmechDatabase()
     self.database.solvation = SolvationDatabase()
     self.database.loadForbiddenStructures(os.path.join(rmgweb.settings.DATABASE_PATH, 'forbiddenStructures.py'))
     self.timestamps = {}
開發者ID:ReactionMechanismGenerator,項目名稱:RMG-website,代碼行數:9,代碼來源:tools.py

示例9: setUpModule

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)
開發者ID:ReactionMechanismGenerator,項目名稱:RMG-Py,代碼行數:19,代碼來源:isotopesTest.py

示例10: loadNecessaryDatabases

def loadNecessaryDatabases():
    """
    loads transport and statmech databases
    """
    from rmgpy.data.statmech import StatmechDatabase
    from rmgpy.data.transport import TransportDatabase

    #only load if they are not there already.
    try:
        getDB('transport')
        getDB('statmech')
    except DatabaseError:
        logging.info("Databases not found. Making databases")
        db = RMGDatabase()
        db.statmech = StatmechDatabase()
        db.statmech.load(os.path.join(settings['database.directory'],'statmech'))

        db.transport = TransportDatabase()
        db.transport.load(os.path.join(settings['database.directory'],'transport'))
開發者ID:ReactionMechanismGenerator,項目名稱:RMG-Py,代碼行數:19,代碼來源:input.py

示例11: loadDatabase

 def loadDatabase(self):
     
     self.database = RMGDatabase()
     self.database.load(
         path = self.databaseDirectory,
         thermoLibraries = self.thermoLibraries,
         reactionLibraries = [library for library, option in self.reactionLibraries],
         seedMechanisms = self.seedMechanisms,
         kineticsDepositories = self.kineticsDepositories,
         #frequenciesLibraries = self.statmechLibraries,
         depository = False, # Don't bother loading the depository information, as we don't use it
     )
開發者ID:ajalan,項目名稱:RMG-Py,代碼行數:12,代碼來源:main.py

示例12: loadDatabase

 def loadDatabase(self):
     
     self.database = RMGDatabase()
     self.database.load(
         path = self.databaseDirectory,
         thermoLibraries = self.thermoLibraries,
         reactionLibraries = [library for library, option in self.reactionLibraries],
         seedMechanisms = self.seedMechanisms,
         kineticsFamilies = self.kineticsFamilies,
         kineticsDepositories = self.kineticsDepositories,
         #frequenciesLibraries = self.statmechLibraries,
         depository = False, # Don't bother loading the depository information, as we don't use it
     )
     if self.kineticsEstimator == 'rate rules':
         logging.info('Adding rate rules from training set in kinetics families...')
         for family in self.database.kinetics.families.values():
             family.addKineticsRulesFromTrainingSet(thermoDatabase=self.database.thermo)
         logging.info('Filling in rate rules in kinetics families by averaging...')
         for family in self.database.kinetics.families.values():
             family.fillKineticsRulesByAveragingUp()
開發者ID:jbarlow3,項目名稱:RMG-Py,代碼行數:20,代碼來源:main.py

示例13: obtainKineticsFamilyStatistics

                # Save to csv file
                csvwriter.writerow([familyName, QDict[familyName]])
     
    return


if __name__ == '__main__':
    from rmgpy import settings
    
    # Create the data evaluation directory
    trialDir = os.path.join(settings['database.directory'],'..','testing','eval')
    if not os.path.exists(trialDir):
        os.makedirs(trialDir)
        
    print 'Loading the RMG database...'
    FullDatabase=RMGDatabase()
    FullDatabase.load(settings['database.directory'], 
                      kineticsFamilies='all', 
                      kineticsDepositories='all',
                      thermoLibraries=['primaryThermoLibrary'],   # Use just the primary thermo library, which contains necessary small molecular thermo
                      reactionLibraries=[],
                      )

    # Prepare the database by loading training reactions but not averaging the rate rules
    for family in FullDatabase.kinetics.families.values():
        family.addKineticsRulesFromTrainingSet(thermoDatabase=FullDatabase.thermo)
    
    print '--------------------------------------------'
    print 'Obtaining statistics for the families...'
    obtainKineticsFamilyStatistics(FullDatabase, trialDir)
    
開發者ID:ReactionMechanismGenerator,項目名稱:RMG-database,代碼行數:30,代碼來源:evaluateKinetics.py

示例14: Generator


#.........這裏部分代碼省略.........
        self.reactionModel.kineticsEstimator = self.kineticsEstimator
        if self.pressureDependence:
            # If the output directory is not yet set, then set it to the same
            # directory as the input file by default
            if not self.outputDirectory:
                self.outputDirectory = os.path.dirname(path)
            self.pressureDependence.outputFile = self.outputDirectory
            self.reactionModel.pressureDependence = self.pressureDependence
        
    def checkInput(self):
        """
        Check for a few common mistakes in the input file.
        """
        if self.pressureDependence:
            for index, reactionSystem in enumerate(self.reactionSystems):
                assert (reactionSystem.T.value_si < self.pressureDependence.Tmax.value_si), "Reaction system T is above pressureDependence range."
                assert (reactionSystem.T.value_si > self.pressureDependence.Tmin.value_si), "Reaction system T is below pressureDependence range."
                assert (reactionSystem.P.value_si < self.pressureDependence.Pmax.value_si), "Reaction system P is above pressureDependence range."
                assert (reactionSystem.P.value_si > self.pressureDependence.Pmin.value_si), "Reaction system P is below pressureDependence range."
            assert any([not s.reactive for s in reactionSystem.initialMoleFractions.keys()]), \
                "Pressure Dependence calculations require at least one inert (nonreacting) species for the bath gas."

    def saveInput(self, path=None):
        """
        Save an RMG job to the input file located at `path`, or
        from the `outputFile` attribute if not given as a parameter.
        """
        from input import saveInputFile
        if path is None: path = self.outputFile
        saveInputFile(path, self)
        
    def loadDatabase(self):
        
        self.database = RMGDatabase()
        self.database.load(
            path = self.databaseDirectory,
            thermoLibraries = self.thermoLibraries,
            reactionLibraries = [library for library, option in self.reactionLibraries],
            seedMechanisms = self.seedMechanisms,
            kineticsFamilies = self.kineticsFamilies,
            kineticsDepositories = self.kineticsDepositories,
            #frequenciesLibraries = self.statmechLibraries,
            depository = False, # Don't bother loading the depository information, as we don't use it
        )
        if self.kineticsEstimator == 'rate rules':
            logging.info('Adding rate rules from training set in kinetics families...')
            for family in self.database.kinetics.families.values():
                family.addKineticsRulesFromTrainingSet(thermoDatabase=self.database.thermo)
            logging.info('Filling in rate rules in kinetics families by averaging...')
            for family in self.database.kinetics.families.values():
                family.fillKineticsRulesByAveragingUp()
    
    def initialize(self, args):
        """
        Initialize an RMG job using the command-line arguments `args` as returned
        by the :mod:`argparse` package.
        """
    
        # Save initialization time
        self.initializationTime = time.time()
    
        # Log start timestamp
        logging.info('RMG execution initiated at ' + time.asctime() + '\n')
    
        # Print out RMG header
        self.logHeader()
開發者ID:jbarlow3,項目名稱:RMG-Py,代碼行數:67,代碼來源:main.py

示例15: RMGWebDatabase

class RMGWebDatabase(object):
    """Wrapper class for RMGDatabase that provides loading functionality."""

    def __init__(self):
        self.database = RMGDatabase()
        self.database.kinetics = KineticsDatabase()
        self.database.thermo = ThermoDatabase()
        self.database.transport = TransportDatabase()
        self.database.statmech = StatmechDatabase()
        self.database.solvation = SolvationDatabase()
        self.database.loadForbiddenStructures(os.path.join(rmgweb.settings.DATABASE_PATH, 'forbiddenStructures.py'))
        self.timestamps = {}

    @property
    def kinetics(self):
        """Get the kinetics database."""
        return self.database.kinetics

    @property
    def thermo(self):
        """Get the thermo database."""
        return self.database.thermo

    @property
    def transport(self):
        """Get the transport database."""
        return self.database.transport

    @property
    def statmech(self):
        """Get the statmech database."""
        return self.database.statmech

    @property
    def solvation(self):
        """Get the solvation database."""
        return self.database.solvation

    def reset_timestamp(self, path):
        """
        Reset the files timestamp in the dictionary of timestamps.
        """
        mtime = os.stat(path).st_mtime
        self.timestamps[path] = mtime

    def reset_dir_timestamps(self, dirpath):
        """
        Walk the directory tree from dirpath, calling reset_timestamp(file) on each file.
        """
        print "Resetting 'last loaded' timestamps for {0} in process {1}".format(dirpath, os.getpid())
        for root, dirs, files in os.walk(dirpath):
            for name in files:
                self.reset_timestamp(os.path.join(root, name))

    def is_file_modified(self, path):
        """
        Return True if the file at `path` has been modified since `reset_timestamp(path)` was last called.
        """
        # If path doesn't denote a file and were previously
        # tracking it, then it has been removed or the file type
        # has changed, so return True.
        if not os.path.isfile(path):
            return path in self.timestamps

        # If path wasn't being tracked then it's new, so return True
        elif path not in self.timestamps:
            return True

        # Force restart when modification time has changed, even
        # if time now older, as that could indicate older file
        # has been restored.
        elif os.stat(path).st_mtime != self.timestamps[path]:
            return True

        # All the checks have been passed, so the file was not modified
        else:
            return False

    def is_dir_modified(self, dirpath):
        """
        Returns True if anything in the directory at dirpath has been modified since reset_dir_timestamps(dirpath).
        """
        to_check = set([path for path in self.timestamps if path.startswith(dirpath)])
        for root, dirs, files in os.walk(dirpath):
            for name in files:
                path = os.path.join(root, name)
                if self.is_file_modified(path):
                    return True
                to_check.remove(path)
        # If there's anything left in to_check, it's probably now gone and this will return True:
        for path in to_check:
            if self.is_file_modified(path):
                return True
        # Passed all tests.
        return False

    ################################################################################

    def load(self, component='', section=''):
        """
#.........這裏部分代碼省略.........
開發者ID:ReactionMechanismGenerator,項目名稱:RMG-website,代碼行數:101,代碼來源:tools.py


注:本文中的rmgpy.data.rmg.RMGDatabase類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。