コード例 #1
0
 def setUpClass(self):
     utils_general.set_default_device_cuda()
     lm_enums = LoggingModeEnum()
     rm_enums = RunningModeEnum()
     self.workfolder = MAIN_TEST_PATH
     self.output_file = os.path.join(self.workfolder, "sample.smi")
     if not os.path.isdir(self.workfolder):
         os.makedirs(self.workfolder)
     self.config = SampleFromModelConfiguration(
         model_path=RANDOM_PRIOR_PATH,
         output_smiles_path=self.output_file,
         num_smiles=100,
         batch_size=100,
         with_likelihood=True)
     self.logging = SamplingLoggerConfiguration(
         sender="http://10.59.162.10:8081",
         recipient=lm_enums.LOCAL,
         logging_path=f"{self.workfolder}/log",
         job_name="test_job")
     self.configurationenvelope = GeneralConfigurationEnvelope(
         parameters=vars(self.config),
         logging=vars(self.logging),
         run_type=rm_enums.SAMPLING,
         version="2.0")
     self.logger = LocalSamplingLogger(self.configurationenvelope)
コード例 #2
0
 def _resolve_logger(self, configuration: GeneralConfigurationEnvelope):
     logging_mode_enum = LoggingModeEnum()
     create_model_config = CreateModelLoggerConfiguration(**configuration.logging)
     if create_model_config.recipient == logging_mode_enum.LOCAL:
         logger = CreateModelLogger(configuration)
     else:
         logger = RemoteCreateModelLogger(configuration)
     return logger
コード例 #3
0
 def __new__(cls, configuration: GeneralConfigurationEnvelope):
     logging_mode_enum = LoggingModeEnum()
     scoring_config = ScoringLoggerConfiguration(**configuration.logging)
     if scoring_config.recipient == logging_mode_enum.LOCAL:
         logger = LocalScoringLogger(configuration)
     else:
         logger = RemoteScoringLogger(configuration)
     return logger
コード例 #4
0
    def setUpClass(self):
        utils_general.set_default_device_cuda()
        lm_enum = LoggingModeEnum()
        run_mode_enum = RunningModeEnum()
        sf_enum = ScoringFunctionNameEnum()
        sf_component_enum = ScoringFunctionComponentNameEnum()
        filter_enum = ScaffoldFilterEnum()
        self.workfolder = MAIN_TEST_PATH
        smiles = ["CCC", "c1ccccc1CCC"]
        ts_parameters = vars(
            ComponentParameters(
                name="tanimoto similarity",
                weight=1,
                smiles=smiles,
                model_path="",
                specific_parameters={},
                component_type=sf_component_enum.TANIMOTO_SIMILARITY))

        sf_parameters = ScoringFuncionParameters(name=sf_enum.CUSTOM_SUM,
                                                 parameters=[ts_parameters])
        scoring_function = ScoringFunctionFactory(sf_parameters)

        logging = ReinforcementLoggerConfiguration(
            sender="1",
            recipient=lm_enum.LOCAL,
            logging_path=f"{self.workfolder}/log",
            resultdir=self.workfolder,
            logging_frequency=0,
            job_name="unit_test_job")

        rl_config = ReinforcementLearningConfiguration(prior=RANDOM_PRIOR_PATH,
                                                       agent=RANDOM_PRIOR_PATH,
                                                       n_steps=3)

        scaffold_parameters = ScaffoldParameters(
            filter_enum.IDENTICAL_MURCKO_SCAFFOLD, 0.05, 25, 0.4)
        scaffold_filter = self._setup_scaffold_filter(scaffold_parameters)
        inception_config = InceptionConfiguration(smiles, 100, 10)
        inception = Inception(inception_config, scoring_function,
                              Model.load_from_file(rl_config.prior))
        parameters = ReinforcementLearningComponents(
            scoring_function=vars(scoring_function),
            diversity_filter=vars(scaffold_filter),
            reinforcement_learning=vars(rl_config),
            inception=vars(inception_config))
        configuration = GeneralConfigurationEnvelope(
            parameters=vars(parameters),
            logging=vars(logging),
            run_type=run_mode_enum.REINFORCEMENT_LEARNING,
            version="2.0")

        self.runner = ReinforcementRunner(configuration,
                                          config=rl_config,
                                          scaffold_filter=scaffold_filter,
                                          scoring_function=scoring_function,
                                          inception=inception)
コード例 #5
0
 def __new__(
     cls, configuration: GeneralConfigurationEnvelope
 ) -> BaseTransferLearningLogger:
     logging_mode_enum = LoggingModeEnum()
     tl_config = TransferLearningLoggerConfig(**configuration.logging)
     if tl_config.recipient == logging_mode_enum.LOCAL:
         logger = LocalTransferLearningLogger(configuration)
     else:
         logger = RemoteTransferLearningLogger(configuration)
     return logger
コード例 #6
0
 def __new__(
     cls, configuration: GeneralConfigurationEnvelope
 ) -> BaseReinforcementLogger:
     logging_mode_enum = LoggingModeEnum()
     rl_config = ReinforcementLoggerConfiguration(**configuration.logging)
     if rl_config.recipient == logging_mode_enum.LOCAL:
         logger_instance = LocalReinforcementLogger(configuration)
     else:
         logger_instance = RemoteReinforcementLogger(configuration)
     return logger_instance
コード例 #7
0
 def setUpClass(self):
     self.rm_enums = RunningModeEnum()
     self.lm_enum = LoggingModeEnum()
     self.workfolder = MAIN_TEST_PATH
     self.output_file = os.path.join(self.workfolder, "new_model.ckpt")
     if not os.path.isdir(self.workfolder):
         os.makedirs(self.workfolder)
     self.config = CreateModelConfiguration(input_smiles_path=SMILES_SET_PATH, output_model_path=self.output_file, standardize=True)
     log_conf = CreateModelLoggerConfiguration(sender="1",
                                        recipient=self.lm_enum.LOCAL,
                                        logging_path=f"{MAIN_TEST_PATH}/log",
                                        job_name="create_model_test",
                                        job_id="1")
     self.configuration_envelope = GeneralConfigurationEnvelope(parameters=vars(self.config),
                                                                logging=vars(log_conf),
                                                                run_type=self.rm_enums.VALIDATION,
                                                                version="2.0")
コード例 #8
0
 def setUp(self):
     self.rm_enums = RunningModeEnum()
     self.cs_enum = ComponentSpecificParametersEnum()
     self.tf_enum = TransformationTypeEnum()
     self.sfc_enum = ScoringFunctionComponentNameEnum()
     self.lm_enum = LoggingModeEnum()
     self.parameters = create_activity_component_regression()
     log_conf = BaseLoggerConfiguration(
         sender="http://10.59.162.10:8081",
         recipient=self.lm_enum.LOCAL,
         logging_path=f"{MAIN_TEST_PATH}/log",
         job_name="model_validation_test",
         job_id="1")
     self.configuration_envelope = GeneralConfigurationEnvelope(
         parameters=vars(self.parameters),
         logging=vars(log_conf),
         run_type=self.rm_enums.VALIDATION,
         version="2.0")
コード例 #9
0
    def setUpClass(cls):
        lm_enum = LoggingModeEnum()
        run_mode_enum = RunningModeEnum()
        sf_enum = ScoringFunctionNameEnum()
        sf_component_enum = ScoringFunctionComponentNameEnum()
        cls.workfolder = MAIN_TEST_PATH
        if not os.path.exists(cls.workfolder):
            os.mkdir(cls.workfolder)
        if not os.path.exists(os.path.join(cls.workfolder, "log")):
            os.mkdir(os.path.join(cls.workfolder, "log"))

        # write some smiles out to a file and also store their tanimoto similarity to the specified smiles below
        smiles = [
            "CCC", "O=S(=O)(c3ccc(n1nc(cc1c2ccc(cc2)C)C(F)(F)F)cc3)N",
            "O=S(=O)(c3ccc(n1nc(cc1c2ccc(cc2)C)C(F)(F)F)cc3)N", "CCXC"
        ]
        path_input = os.path.join(cls.workfolder, "test.smi")

        with open(path_input, "w+") as writer:
            for smile in smiles:
                row = [smile]
                writer.write("{}\n".format("\t".join(row)))
            writer.close()

        # set up tanimoto similarity and custom aller scoring function
        ts_parameters = vars(
            ComponentParameters(
                name="tanimoto_similarity",
                weight=1,
                smiles=["CCC"],
                model_path="",
                specific_parameters={},
                component_type=sf_component_enum.TANIMOTO_SIMILARITY))
        matching_substructure = vars(
            ComponentParameters(
                component_type=sf_component_enum.MATCHING_SUBSTRUCTURE,
                name="matching_substructure_name",
                weight=1.,
                smiles=["c1ccccc1C"],
                model_path="",
                specific_parameters={}))
        scoring_function = cls._setup_scoring_function(
            ScoringFuncionParameters(
                name=sf_enum.CUSTOM_SUM,
                parameters=[ts_parameters, matching_substructure]))

        # set logging
        cls.logging = ScoringLoggerConfiguration(sender="local",
                                                 recipient=lm_enum.LOCAL,
                                                 logging_path=cls.workfolder,
                                                 job_name="unit_test_job",
                                                 job_id="38jsdfilnsdfklj")
        cls.scored_smiles = os.path.join(cls.logging.logging_path,
                                         "scored_smiles.csv")

        # do the other fixtures
        scoring_config = ScoringRunnerConfiguration(input=path_input)
        parameters = ScoringRunnerComponents(
            scoring=vars(scoring_config),
            scoring_function=vars(scoring_function))
        configuration = GeneralConfigurationEnvelope(
            parameters=vars(parameters),
            logging=vars(cls.logging),
            run_type=run_mode_enum.SCORING,
            version="2.0")
        cls.runner = ScoringRunner(configuration=configuration,
                                   config=scoring_config,
                                   scoring_function=scoring_function)