Ejemplo n.º 1
0
 def setUp(self):
     rmg_database = RMGDatabase()
     rmg_database.load(
         rmgpy.settings['database.directory'],
         kinetics_families=[
         "R_Addition_MultipleBond",
         "H_Abstraction",
         "intra_H_migration"
     ],
         transport_libraries=[],
         reaction_libraries=[],
         seed_mechanisms=[],
         thermo_libraries=[
             'primaryThermoLibrary',
             'thermo_DFT_CCSDTF12_BAC',
             'CBS_QB3_1dHR'],
         solvation=False,
     )
     self.rmg_database = rmg_database
     ts_database = TransitionStates()
     path = os.path.join(autotst.settings["tst_database_path"], "H_Abstraction")
     global_context = {'__builtins__': None}
     local_context = {'DistanceData': DistanceData}
     family = self.rmg_database.kinetics.families["H_Abstraction"]
     ts_database.family = family
     ts_database.load(path, local_context, global_context)
     self.ts_database = ts_database
Ejemplo n.º 2
0
    def set_TS_training_data(self, rmg_database):
        """
        Loads Database, sets it as class attribute, sets training_set from database
        """
        from autotst.data.base import DistanceData, TransitionStateDepository, TSGroups, TransitionStates
        ts_database = TransitionStates()

        #path = os.path.join(os.path.expandvars("$RMGpy"), "..", "AutoTST", "database", self.family)
        path = self.path

        global_context = {'__builtins__': None}
        local_context = {'DistanceData': DistanceData}

        assert self.family in list(rmg_database.kinetics.families.keys(
        )), "{} not found in kinetics families. Could not Load".format(family)
        family = rmg_database.kinetics.families[self.family]
        ts_database.family = family
        ts_database.load(path, local_context, global_context)
        self.database = ts_database
        # Reaction must be a template reaction... found above

        logging.info("Getting Training Data for {}".format(family))
        training_data = [
            (entry.item, entry.data.distances) for entry in list(
                ts_database.depository.entries.values())]

        self.training_set = training_data
        logging.info("Total Distances Count: {}".format(
            len(self.training_set)))

        return
Ejemplo n.º 3
0
    def test_load(self):

        ts_database = TransitionStates()
        path = os.path.join(autotst.settings["tst_database_path"], "H_Abstraction")
        global_context = {'__builtins__': None}
        local_context = {'DistanceData': DistanceData}
        family = self.rmg_database.kinetics.families["H_Abstraction"]
        ts_database.family = family
        ts_database.load(path, local_context, global_context)

        self.assertIsInstance(ts_database.depository, TransitionStateDepository)
        self.assertIsInstance(ts_database.groups, TSGroups)
Ejemplo n.º 4
0
    def load_databases(self, force_reload=False):
        """
        Load the RMG and AutoTST databases, if they have not already been loaded,
        into the class level variables where they are stored.

        Variables:
        - force_reload (bool):if set to True then forces a reload, even if already loaded.

        Returns:
        - None
        """
        if self.rmg_database and self.ts_databases and not force_reload:
            return self.rmg_database, self.ts_databases

        rmg_database = RMGDatabase()
        database_path = rmgpy.settings['database.directory']

        logging.info("Loading RMG database from '{}'".format(database_path))

        self.possible_families = [  # These families (and only these) will be loaded from both RMG and AutoTST databases
            "R_Addition_MultipleBond", "H_Abstraction", "intra_H_migration"
        ]
        try:
            rmg_database.load(
                database_path,
                kineticsFamilies=self.possible_families,
                transportLibraries=[],
                reactionLibraries=[],
                seedMechanisms=[],
                thermoLibraries=[
                    'primaryThermoLibrary', 'thermo_DFT_CCSDTF12_BAC',
                    'CBS_QB3_1dHR'
                ],
                solvation=False,
            )
        except IOError:
            logging.info(
                "RMG database not found at '{}'. This can occur if a git repository of the database is being"
                "used rather than the binary version".format(database_path))
            database_path = os.path.join(database_path, 'input')
            logging.info(
                "Loading RMG database instead from '{}'".format(database_path))
            rmg_database.load(
                database_path,
                kineticsFamilies=self.possible_families,
                transportLibraries=[],
                reactionLibraries=[],
                seedMechanisms=[],
                thermoLibraries=[
                    'primaryThermoLibrary', 'thermo_DFT_CCSDTF12_BAC',
                    'CBS_QB3_1dHR'
                ],
                solvation=False,
            )

        self.rmg_database = rmg_database

        self.ts_databases = dict()
        for reaction_family in self.possible_families:
            ts_database = TransitionStates()
            path = os.path.join(autotst.settings['tst_database_path'],
                                reaction_family)
            global_context = {'__builtins__': None}
            local_context = {'DistanceData': DistanceData}
            family = rmg_database.kinetics.families[reaction_family]
            ts_database.family = family
            ts_database.load(path, local_context, global_context)

            self.ts_databases[reaction_family] = ts_database

        return self.rmg_database, self.ts_databases