Exemplo n.º 1
0
 def setUp(self):
     enum = ScoringFunctionComponentNameEnum()
     predictive_property = create_predictive_property_component_regression()
     activity = create_activity_component_regression()
     qed_score = ComponentParameters(component_type=enum.QED_SCORE,
                                     name="qed_score_name",
                                     weight=1.,
                                     smiles=[],
                                     model_path="",
                                     specific_parameters={})
     custom_alerts = ComponentParameters(component_type=enum.CUSTOM_ALERTS,
                                         name="custom_alerts_name",
                                         weight=1.,
                                         smiles=["CCCOOO"],
                                         model_path="",
                                         specific_parameters={})
     matching_substructure = ComponentParameters(
         component_type=enum.MATCHING_SUBSTRUCTURE,
         name="matching_substructure_name",
         weight=1.,
         smiles=["*CCC"],
         model_path="",
         specific_parameters={})
     self.sf_instance = CustomSum(parameters=[
         activity, qed_score, custom_alerts, matching_substructure,
         predictive_property
     ])
    def setUpClass(self):
        csp_enum = ComponentSpecificParametersEnum()
        transf_type = TransformationTypeEnum()
        sf_enum = ScoringFunctionComponentNameEnum()
        activity = create_activity_component_regression()
        activity.specific_parameters[
            csp_enum.TRANSFORMATION_TYPE] = transf_type.DOUBLE_SIGMOID
        activity.specific_parameters[csp_enum.COEF_DIV] = 100.
        activity.specific_parameters[csp_enum.COEF_SI] = 150.
        activity.specific_parameters[csp_enum.COEF_SE] = 150.
        off_activity = create_offtarget_activity_component_regression()

        delta_params = {
            "high": 3.0,
            "k": 0.25,
            "low": 0.0,
            "transformation": True,
            "transformation_type": "sigmoid"
        }

        selectivity = ComponentParameters(
            component_type=sf_enum.SELECTIVITY,
            name="desirability",
            weight=1.,
            smiles=[],
            model_path="",
            specific_parameters={
                "activity_model_path": activity.model_path,
                "offtarget_model_path": off_activity.model_path,
                "activity_specific_parameters":
                activity.specific_parameters.copy(),
                "offtarget_specific_parameters":
                off_activity.specific_parameters,
                "delta_transformation_parameters": delta_params
            })

        qed_score = ComponentParameters(component_type=sf_enum.QED_SCORE,
                                        name="qed_score",
                                        weight=1.,
                                        smiles=[],
                                        model_path="",
                                        specific_parameters={})
        matching_substructure = ComponentParameters(
            component_type=sf_enum.MATCHING_SUBSTRUCTURE,
            name="matching_substructure",
            weight=1.,
            smiles=["[*]n1cccc1CC"],
            model_path="",
            specific_parameters={})

        custom_alerts = create_custom_alerts_configuration()

        self.sf_state = CustomProduct(parameters=[
            activity, selectivity, qed_score, matching_substructure,
            custom_alerts
        ])
    def setUp(self):
        # create a scaffold filter and fill it with a few entries
        smiles = [
            "O=S(=O)(c3ccc(n1nc(cc1c2ccc(cc2)C)C(F)(F)F)cc3)N", "CCC", "CCCCC"
        ]
        scores = np.array([0.7, 0.5, 0.])
        valid_idx = [0, 1, 2]
        component_parameters = ComponentParameters(
            component_type=self.sf_enum.TANIMOTO_SIMILARITY,
            name="tanimoto_similarity",
            weight=1.,
            smiles=smiles,
            model_path="",
            specific_parameters={})
        component_score_summary = ComponentSummary(scores,
                                                   component_parameters)

        final_summary = FinalSummary(scores, smiles, valid_idx,
                                     [component_score_summary],
                                     [component_score_summary])

        sf_parameters = ScaffoldParameters(
            name=self.scaffold_enum.IDENTICAL_MURCKO_SCAFFOLD,
            minscore=0.5,
            minsimilarity=0.4,
            nbmax=1)
        scaffold_filter_factory = ScaffoldFilterFactory()
        self.scaffold_filter = scaffold_filter_factory.load_scaffold_filter(
            sf_parameters)
        self.scaffold_filter.score(final_summary)
Exemplo n.º 4
0
    def setUpClass(self):
        sf_enum = ScoringFunctionComponentNameEnum()
        utils_general.set_default_device_cuda()
        self.log_path = MAIN_TEST_PATH

        if not os.path.isdir(self.log_path):
            os.makedirs(self.log_path)
        smiles = np.array(['CCC', 'CCCC', 'CCCCCC'])
        score = [0, 0.5, 1.]
        prior_likelihood = ts.tensor([0, 10, 100])

        prior = Model.load_from_file(RANDOM_PRIOR_PATH)
        config = InceptionConfiguration(smiles=smiles,
                                        memory_size=4,
                                        sample_size=4)
        scoring = ComponentParameters(
            component_type=sf_enum.JACCARD_DISTANCE,
            name="jaccard_distance",
            weight=1.,
            smiles=[
                "CONN", "O=S(=O)(c3ccc(n1nc(cc1c2ccc(cc2)C)C(F)(F)F)cc3)N"
            ],
            model_path="",
            specific_parameters={})
        scoringfunction = CustomSum(parameters=[scoring])
        self.inception_model = Inception(configuration=config,
                                         scoring_function=scoringfunction,
                                         prior=prior)

        self.inception_model.add(smiles, score, prior_likelihood)
def create_custom_alerts_configuration():
    custom_alerts_list = [
        '[*;r7]',
        '[*;r8]',
        '[*;r9]',
        '[*;r10]',
        '[*;r11]',
        '[*;r12]',
        '[*;r13]',
        '[*;r14]',
        '[*;r15]',
        '[*;r16]',
        '[*;r17]',
        '[#8][#8]',
        '[#6;+]',
        '[#16][#16]',
        '[#7;!n][S;!$(S(=O)=O)]',
        '[#7;!n][#7;!n]',
        'C#C',
        'C(=[O,S])[O,S]',
        '[#7;!n][C;!$(C(=[O,N])[N,O])][#16;!s]',
        '[#7;!n][C;!$(C(=[O,N])[N,O])][#7;!n]',
        '[#7;!n][C;!$(C(=[O,N])[N,O])][#8;!o]',
        '[#8;!o][C;!$(C(=[O,N])[N,O])][#16;!s]',
        '[#8;!o][C;!$(C(=[O,N])[N,O])][#8;!o]',
        '[#16;!s][C;!$(C(=[O,N])[N,O])][#16;!s]']
    sf_enum = ScoringFunctionComponentNameEnum()
    parameters = ComponentParameters(component_type=sf_enum.CUSTOM_ALERTS,
                                     name="custom_alerts",
                                     weight=1.,
                                     smiles=custom_alerts_list,
                                     model_path="",
                                     specific_parameters={})
    return parameters
Exemplo n.º 6
0
    def setUp(self):
        self.scaffold_enum = ScaffoldFilterEnum()
        self.sf_enum = ScoringFunctionComponentNameEnum()
        self.workfolders = [MAIN_TEST_PATH]
        # create a scaffold filter and fill it with a few entries
        smiles = [
            "O=S(=O)(c3ccc(n1nc(cc1c2ccc(cc2)C)C(F)(F)F)cc3)N", "CCC", "CCCCC",
            "CC"
        ]
        scores = np.array([1.0, 0.5, 0.4, 0.3])
        valid_idx = [0, 1, 2, 3]
        component_parameters = ComponentParameters(
            component_type=self.sf_enum.TANIMOTO_SIMILARITY,
            name="tanimoto_similarity",
            weight=1.,
            smiles=smiles,
            model_path="",
            specific_parameters={})
        component_score_summary = ComponentSummary(scores,
                                                   component_parameters)

        final_summary = FinalSummary(scores, smiles, valid_idx,
                                     [component_score_summary],
                                     [component_score_summary])

        sf_parameters = ScaffoldParameters(name=self.scaffold_enum.NO_FILTER,
                                           minscore=0.5,
                                           minsimilarity=0.4,
                                           nbmax=1)
        scaffold_filter_factory = ScaffoldFilterFactory()
        self.scaffold_filter = scaffold_filter_factory.load_scaffold_filter(
            sf_parameters)
        self.scaffold_filter.score(final_summary)
 def setUpClass(cls):
     enum = ScoringFunctionComponentNameEnum()
     parameters = ComponentParameters(component_type=enum.TANIMOTO_SIMILARITY,
                                      name="tanimoto_similarity",
                                      weight=1.,
                                      smiles=["CCC", "O=S(=O)(c3ccc(n1nc(cc1c2ccc(cc2)C)C(F)(F)F)cc3)N"],
                                      model_path="",
                                      specific_parameters={})
     cls.component = TanimotoSimilarity(parameters)
Exemplo n.º 8
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)
def create_activity_component_regression():
    sf_enum = ScoringFunctionComponentNameEnum()
    specific_parameters = _specific_parameters_regression_predictive_model()
    parameters = ComponentParameters(component_type=sf_enum.PREDICTIVE_PROPERTY,
                                     name="activity",
                                     weight=1.,
                                     smiles=[],
                                     model_path=ACTIVITY_REGRESSION,
                                     specific_parameters=specific_parameters)
    return parameters
    def create_scoring_function_instance(
            sf_parameters: ScoringFuncionParameters,
            scoring_function_registry: dict) -> BaseScoringFunction:
        """Returns a scoring function instance"""
        scoring_function = scoring_function_registry[sf_parameters.name]
        parameters = [
            ComponentParameters(**p) for p in sf_parameters.parameters
        ]

        return scoring_function(parameters, sf_parameters.parallel)
Exemplo n.º 11
0
 def setUpClass(cls):
     sf_enum = ScoringFunctionComponentNameEnum()
     cls.matching_pattern = "XXXX"
     cls.parameters = ComponentParameters(
         component_type=sf_enum.MATCHING_SUBSTRUCTURE,
         name="matching_substructure",
         weight=1.,
         smiles=[cls.matching_pattern],
         model_path="",
         specific_parameters={})
def create_predictive_property_component_classification():
    sf_enum = ScoringFunctionComponentNameEnum()
    specific_parameters = _specific_parameters_classifiaction_predictive_model()
    parameters = ComponentParameters(component_type=sf_enum.PREDICTIVE_PROPERTY,
                                     name="predictive_property_classification",
                                     weight=1.,
                                     smiles=[],
                                     model_path=ACTIVITY_CLASSIFICATION,
                                     specific_parameters=specific_parameters)
    return parameters
Exemplo n.º 13
0
 def setUpClass(cls):
     sf_enum = ScoringFunctionComponentNameEnum()
     parameters = ComponentParameters(
         component_type=sf_enum.MATCHING_SUBSTRUCTURE,
         name="matching_substructure",
         weight=1.,
         smiles=["c1ccccc1"],
         model_path="",
         specific_parameters={})
     cls.component = MatchingSubstructure(parameters)
Exemplo n.º 14
0
 def setUpClass(cls):
     sf_enum = ScoringFunctionComponentNameEnum()
     parameters = ComponentParameters(component_type=sf_enum.QED_SCORE,
                                      name="qed_score",
                                      weight=1.,
                                      smiles=[],
                                      model_path="",
                                      specific_parameters={})
     cls.component = QedScore(parameters)
     cls.smile = "C1CCCCCCCCC1"
     cls.mol = Chem.MolFromSmiles(cls.smile)
Exemplo n.º 15
0
 def setUpClass(self):
     sf_enum = ScoringFunctionComponentNameEnum()
     csp_enum = ComponentSpecificParametersEnum()
     ts_parameters = ComponentParameters(
         component_type=sf_enum.NUM_HBD_LIPINSKI,
         name="NumHBD_Lipinski",
         weight=1.,
         smiles=[],
         model_path="",
         specific_parameters={csp_enum.TRANSFORMATION: False})
     self.sf_state = CustomSum(parameters=[ts_parameters])
Exemplo n.º 16
0
 def setUpClass(self):
     sf_enum = ScoringFunctionComponentNameEnum()
     csp_enum = ComponentSpecificParametersEnum()
     ts_parameters = ComponentParameters(
         component_type=sf_enum.MOLECULAR_WEIGHT,
         name="MW",
         weight=1.,
         smiles=[],
         model_path="",
         specific_parameters={csp_enum.TRANSFORMATION: False})
     self.sf_state = CustomSum(parameters=[ts_parameters])
Exemplo n.º 17
0
 def setUpClass(self):
     sf_enum = ScoringFunctionComponentNameEnum()
     csp_enum = ComponentSpecificParametersEnum()
     ts_parameters = ComponentParameters(
         component_type=sf_enum.NUM_ROTATABLE_BONDS,
         name="NumRotatableBonds",
         weight=1.,
         smiles=[],
         model_path="",
         specific_parameters={csp_enum.TRANSFORMATION: False})
     self.sf_state = CustomSum(parameters=[ts_parameters])
Exemplo n.º 18
0
 def setUpClass(self):
     sf_enum = ScoringFunctionComponentNameEnum()
     predictive_property = create_predictive_property_component_regression()
     activity = create_activity_component_regression()
     qed_score = ComponentParameters(component_type=sf_enum.QED_SCORE,
                                     name="qed_score_name",
                                     weight=1.,
                                     smiles=[],
                                     model_path="",
                                     specific_parameters={})
     self.sf_state = CustomProduct(parameters=[activity, qed_score, predictive_property])
Exemplo n.º 19
0
 def setUpClass(cls):
     sf_enum = ScoringFunctionComponentNameEnum()
     parameters = ComponentParameters(
         component_type=sf_enum.JACCARD_DISTANCE,
         name="jaccard_distance",
         weight=1.,
         smiles=[
             "O=S(=O)(c3ccc(n1nc(cc1c2ccc(cc2)C)C(F)(F)F)cc3)N", "CCCCC"
         ],
         model_path="",
         specific_parameters={})
     cls.component = JaccardDistance(parameters)
Exemplo n.º 20
0
 def _prepare_offtarget_parameters(
         self, parameters: ComponentParameters) -> ComponentParameters:
     model_path = parameters.specific_parameters["offtarget_model_path"]
     specific_params = parameters.specific_parameters[
         "offtarget_specific_parameters"]
     offtarget_params = ComponentParameters(
         name=self.parameters.name,
         weight=self.parameters.weight,
         smiles=self.parameters.smiles,
         model_path=model_path,
         component_type=self.parameters.component_type,
         specific_parameters=specific_params)
     return offtarget_params
Exemplo n.º 21
0
 def _prepare_activity_parameters(
         self, parameters: ComponentParameters) -> ComponentParameters:
     model_path = parameters.specific_parameters["activity_model_path"]
     specific_params = parameters.specific_parameters[
         "activity_specific_parameters"]
     activity_params = ComponentParameters(
         name=self.parameters.name,
         weight=self.parameters.weight,
         smiles=self.parameters.smiles,
         model_path=model_path,
         component_type=self.parameters.component_type,
         specific_parameters=specific_params)
     return activity_params
    def setUpClass(self):
        enum = ScoringFunctionComponentNameEnum()
        activity = create_activity_component_regression()
        qed_score = ComponentParameters(component_type=enum.QED_SCORE,
                                        name="qed_score_name",
                                        weight=1.,
                                        smiles=[],
                                        model_path="",
                                        specific_parameters={})

        custom_alerts = create_custom_alerts_configuration()

        matching_substructure = ComponentParameters(
            component_type=enum.MATCHING_SUBSTRUCTURE,
            name="matching_substructure_name",
            weight=1.,
            smiles=["*CCC"],
            model_path="",
            specific_parameters={})
        self.sf_state = CustomProduct(parameters=[
            activity, qed_score, custom_alerts, matching_substructure
        ])
def create_offtarget_activity_component_classification():
    csp_enum = ComponentSpecificParametersEnum()
    sf_enum = ScoringFunctionComponentNameEnum()
    specific_parameters = _specific_parameters_classifiaction_predictive_model()
    specific_parameters[csp_enum.HIGH] = 3
    specific_parameters[csp_enum.LOW] = 0
    specific_parameters[csp_enum.TRANSFORMATION] = False
    parameters = ComponentParameters(component_type=sf_enum.PREDICTIVE_PROPERTY,
                                     name="predictive_property_classification",
                                     weight=1.,
                                     smiles=[],
                                     model_path=ACTIVITY_CLASSIFICATION,
                                     specific_parameters=specific_parameters)
    return parameters
def create_offtarget_activity_component_regression():
    csp_enum = ComponentSpecificParametersEnum()
    sf_enum = ScoringFunctionComponentNameEnum()
    specific_parameters = _specific_parameters_regression_predictive_model()
    specific_parameters[csp_enum.HIGH] = 3
    specific_parameters[csp_enum.LOW] = 0
    specific_parameters[csp_enum.TRANSFORMATION] = False
    parameters = ComponentParameters(component_type=sf_enum.PREDICTIVE_PROPERTY,
                                     name="offtarget_activity",
                                     weight=1.,
                                     smiles=[],
                                     model_path=OFFTARGET_ACTIVITY_REGRESSION,
                                     specific_parameters=specific_parameters)
    return parameters
Exemplo n.º 25
0
 def test_eval_add_2(self):
     sf_enum = ScoringFunctionComponentNameEnum()
     smiles = np.array(['CCC', 'CCCC', 'O=S(=O)(c3ccc(n1nc(cc1c2ccc(cc2)C)C(F)(F)F)cc3)N'])
     scoring = ComponentParameters(component_type=sf_enum.TANIMOTO_SIMILARITY,
                                   name="tanimoto_similarity",
                                   weight=1.,
                                   smiles=["CCC", "CC"],
                                   model_path="",
                                   specific_parameters={})
     scoringfunction = CustomSum(parameters=[scoring])
     prior = Model.load_from_file(RANDOM_PRIOR_PATH)
     self.inception_model.evaluate_and_add(smiles, scoringfunction, prior)
     self.assertEqual(len(self.inception_model.memory), 4)
     nt.assert_almost_equal(np.array(self.inception_model.memory['score'].values),
                            np.array([0.96, 0.9412, 0.9286, 0.0345]), 4)
def create_c_lab_component(somponent_type):
    csp_enum = ComponentSpecificParametersEnum()
    transf_type = TransformationTypeEnum()
    specific_parameters = {csp_enum.CLAB_INPUT_FILE: f"{MAIN_TEST_PATH}/clab_input.json",
                           csp_enum.HIGH: 9,
                           csp_enum.LOW: 4,
                           csp_enum.K: 0.25,
                           csp_enum.TRANSFORMATION: True,
                           csp_enum.TRANSFORMATION_TYPE: transf_type.SIGMOID}
    parameters = ComponentParameters(component_type=somponent_type,
                                     name="c_lab",
                                     weight=1.,
                                     smiles=[],
                                     model_path="",
                                     specific_parameters=specific_parameters)
    return parameters
Exemplo n.º 27
0
 def setUpClass(self):
     sf_enum = ScoringFunctionComponentNameEnum()
     csp_enum = ComponentSpecificParametersEnum()
     tt_enum = TransformationTypeEnum()
     specific_parameters = {
         csp_enum.TRANSFORMATION: True,
         csp_enum.LOW: 0,
         csp_enum.HIGH: 1,
         csp_enum.TRANSFORMATION_TYPE: tt_enum.STEP
     }
     ts_parameters = ComponentParameters(
         component_type=sf_enum.NUM_HBD_LIPINSKI,
         name="NumHBD_Lipinski",
         weight=1.,
         smiles=[],
         model_path="",
         specific_parameters=specific_parameters)
     self.sf_state = CustomSum(parameters=[ts_parameters])
Exemplo n.º 28
0
 def setUpClass(self):
     sf_enum = ScoringFunctionComponentNameEnum()
     csp_enum = ComponentSpecificParametersEnum()
     tt_enum = TransformationTypeEnum()
     specific_parameters = {
         csp_enum.TRANSFORMATION: True,
         csp_enum.LOW: 2,
         csp_enum.HIGH: 5,
         csp_enum.TRANSFORMATION_TYPE: tt_enum.STEP
     }
     ts_parameters = ComponentParameters(
         component_type=sf_enum.NUM_ROTATABLE_BONDS,
         name="NumRotatableBonds",
         weight=1.,
         smiles=[],
         model_path="",
         specific_parameters=specific_parameters)
     self.sf_state = CustomSum(parameters=[ts_parameters])
Exemplo n.º 29
0
 def test_empty_eval_add_1(self):
     sf_enum = ScoringFunctionComponentNameEnum()
     smiles = np.array(['CCC', 'CCCC', 'CC', 'COO'])
     scoring = ComponentParameters(
         component_type=sf_enum.TANIMOTO_SIMILARITY,
         name="tanimoto_similarity",
         weight=1.,
         smiles=["CCC", "CC"],
         model_path="",
         specific_parameters={})
     scoringfunction = CustomSum(parameters=[scoring])
     prior = Model.load_from_file(RANDOM_PRIOR_PATH)
     self.inception_model.evaluate_and_add(smiles, scoringfunction, prior)
     self.assertEqual(len(self.inception_model.memory), 4)
     nt.assert_almost_equal(
         np.array(self.inception_model.memory['score'].values),
         np.array([1, 1, 0.6667, 0.1250]), 4)
     self.assertEqual(
         len(np.array(self.inception_model.memory['likelihood'].values)), 4)
 def test_invalid_addition(self):
     # try to add a smile already present
     smiles = ["CCC"]
     scores = np.array([1.0])
     valid_idx = [0]
     component_parameters = ComponentParameters(
         component_type=self.sf_enum.TANIMOTO_SIMILARITY,
         name="tanimoto_similarity",
         weight=1.,
         smiles=smiles,
         model_path="",
         specific_parameters={})
     component_score_summary = ComponentSummary(scores,
                                                component_parameters)
     final_summary = FinalSummary(scores, smiles, valid_idx,
                                  [component_score_summary],
                                  [component_score_summary])
     self.scaffold_filter.score(final_summary)
     self.assertEqual(2, len(self.scaffold_filter.scaffolds))