1
1
from typing import Optional
2
2
3
3
import tqdm
4
- from chemlog .alg_classification .charge_classifier import get_charge_category
5
- from chemlog .alg_classification .peptide_size_classifier import get_n_amino_acid_residues
6
- from chemlog .alg_classification .proteinogenics_classifier import (
7
- get_proteinogenic_amino_acids ,
8
- )
9
- from chemlog .alg_classification .substructure_classifier import (
10
- is_diketopiperazine ,
11
- is_emericellamide ,
12
- )
13
- from chemlog .cli import CLASSIFIERS , _smiles_to_mol , strategy_call
14
- from chemlog_extra .alg_classification .by_element_classification import (
15
- OrganoXCompoundClassifier ,
16
- XMolecularEntityClassifier ,
17
- )
18
-
19
- from chebifier import modelwise_smiles_lru_cache
20
4
21
5
from .base_predictor import BasePredictor
6
+ from .. import modelwise_smiles_lru_cache
22
7
23
8
AA_DICT = {
24
9
"A" : "L-alanine" ,
48
33
49
34
50
35
class ChemlogExtraPredictor (BasePredictor ):
51
- CHEMLOG_CLASSIFIER = None
52
36
53
37
def __init__ (self , model_name : str , ** kwargs ):
54
38
super ().__init__ (model_name , ** kwargs )
55
39
self .chebi_graph = kwargs .get ("chebi_graph" , None )
56
- self .classifier = self . CHEMLOG_CLASSIFIER ()
40
+ self .classifier = None
57
41
58
42
@modelwise_smiles_lru_cache .batch_decorator
59
43
def predict_smiles_list (self , smiles_list : list [str ]) -> list :
44
+ from chemlog .cli import _smiles_to_mol
45
+
60
46
mol_list = [_smiles_to_mol (smiles ) for smiles in smiles_list ]
61
47
res = self .classifier .classify (mol_list )
62
48
if self .chebi_graph is not None :
@@ -73,15 +59,29 @@ def predict_smiles_list(self, smiles_list: list[str]) -> list:
73
59
74
60
75
61
class ChemlogXMolecularEntityPredictor (ChemlogExtraPredictor ):
76
- CHEMLOG_CLASSIFIER = XMolecularEntityClassifier
62
+ def __init__ (self , model_name : str , ** kwargs ):
63
+ from chemlog_extra .alg_classification .by_element_classification import (
64
+ XMolecularEntityClassifier ,
65
+ )
66
+
67
+ super ().__init__ (model_name , ** kwargs )
68
+ self .classifier = XMolecularEntityClassifier ()
77
69
78
70
79
71
class ChemlogOrganoXCompoundPredictor (ChemlogExtraPredictor ):
80
- CHEMLOG_CLASSIFIER = OrganoXCompoundClassifier
72
+ def __init__ (self , model_name : str , ** kwargs ):
73
+ from chemlog_extra .alg_classification .by_element_classification import (
74
+ OrganoXCompoundClassifier ,
75
+ )
76
+
77
+ super ().__init__ (model_name , ** kwargs )
78
+ self .classifier = OrganoXCompoundClassifier ()
81
79
82
80
83
81
class ChemlogPeptidesPredictor (BasePredictor ):
84
82
def __init__ (self , model_name : str , ** kwargs ):
83
+ from chemlog .cli import CLASSIFIERS
84
+
85
85
super ().__init__ (model_name , ** kwargs )
86
86
self .strategy = "algo"
87
87
self .chebi_graph = kwargs .get ("chebi_graph" , None )
@@ -97,6 +97,8 @@ def __init__(self, model_name: str, **kwargs):
97
97
print (f"Initialised ChemLog model { self .model_name } " )
98
98
99
99
def predict_smiles (self , smiles : str ) -> Optional [dict ]:
100
+ from chemlog .cli import _smiles_to_mol , strategy_call
101
+
100
102
mol = _smiles_to_mol (smiles )
101
103
if mol is None :
102
104
return None
@@ -133,6 +135,19 @@ def predict_smiles_list(self, smiles_list: list[str]) -> list:
133
135
134
136
def get_chemlog_result_info (self , smiles ):
135
137
"""Get classification for single molecule with additional information."""
138
+ from chemlog .alg_classification .charge_classifier import get_charge_category
139
+ from chemlog .alg_classification .peptide_size_classifier import (
140
+ get_n_amino_acid_residues ,
141
+ )
142
+ from chemlog .alg_classification .proteinogenics_classifier import (
143
+ get_proteinogenic_amino_acids ,
144
+ )
145
+ from chemlog .alg_classification .substructure_classifier import (
146
+ is_diketopiperazine ,
147
+ is_emericellamide ,
148
+ )
149
+ from chemlog .cli import _smiles_to_mol
150
+
136
151
mol = _smiles_to_mol (smiles )
137
152
if mol is None or not smiles :
138
153
return {"error" : "Failed to parse SMILES" }
0 commit comments