1+ from functools import lru_cache
12from typing import Optional
23
34import 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- XMolecularEntityClassifier ,
16- OrganoXCompoundClassifier ,
17- )
18- from functools import lru_cache
195
206from .base_predictor import BasePredictor
217
4733
4834
4935class ChemlogExtraPredictor (BasePredictor ):
50-
51- CHEMLOG_CLASSIFIER = None
52-
5336 def __init__ (self , model_name : str , ** kwargs ):
5437 super ().__init__ (model_name , ** kwargs )
5538 self .chebi_graph = kwargs .get ("chebi_graph" , None )
56- self .classifier = self . CHEMLOG_CLASSIFIER ()
39+ self .classifier = None
5740
5841 def predict_smiles_tuple (self , smiles_list : tuple [str ]) -> list :
42+ from chemlog .cli import _smiles_to_mol
43+
5944 mol_list = [_smiles_to_mol (smiles ) for smiles in smiles_list ]
6045 res = self .classifier .classify (mol_list )
6146 if self .chebi_graph is not None :
@@ -72,17 +57,29 @@ def predict_smiles_tuple(self, smiles_list: tuple[str]) -> list:
7257
7358
7459class ChemlogXMolecularEntityPredictor (ChemlogExtraPredictor ):
60+ def __init__ (self , model_name : str , ** kwargs ):
61+ from chemlog_extra .alg_classification .by_element_classification import (
62+ XMolecularEntityClassifier ,
63+ )
7564
76- CHEMLOG_CLASSIFIER = XMolecularEntityClassifier
65+ super ().__init__ (model_name , ** kwargs )
66+ self .classifier = XMolecularEntityClassifier ()
7767
7868
7969class ChemlogOrganoXCompoundPredictor (ChemlogExtraPredictor ):
70+ def __init__ (self , model_name : str , ** kwargs ):
71+ from chemlog_extra .alg_classification .by_element_classification import (
72+ OrganoXCompoundClassifier ,
73+ )
8074
81- CHEMLOG_CLASSIFIER = OrganoXCompoundClassifier
75+ super ().__init__ (model_name , ** kwargs )
76+ self .classifier = OrganoXCompoundClassifier ()
8277
8378
8479class ChemlogPeptidesPredictor (BasePredictor ):
8580 def __init__ (self , model_name : str , ** kwargs ):
81+ from chemlog .cli import CLASSIFIERS
82+
8683 super ().__init__ (model_name , ** kwargs )
8784 self .strategy = "algo"
8885 self .chebi_graph = kwargs .get ("chebi_graph" , None )
@@ -99,6 +96,8 @@ def __init__(self, model_name: str, **kwargs):
9996
10097 @lru_cache (maxsize = 100 )
10198 def predict_smiles (self , smiles : str ) -> Optional [dict ]:
99+ from chemlog .cli import _smiles_to_mol , strategy_call
100+
102101 mol = _smiles_to_mol (smiles )
103102 if mol is None :
104103 return None
@@ -134,6 +133,19 @@ def predict_smiles_tuple(self, smiles_list: tuple[str]) -> list:
134133
135134 def get_chemlog_result_info (self , smiles ):
136135 """Get classification for single molecule with additional information."""
136+ from chemlog .alg_classification .charge_classifier import get_charge_category
137+ from chemlog .alg_classification .peptide_size_classifier import (
138+ get_n_amino_acid_residues ,
139+ )
140+ from chemlog .alg_classification .proteinogenics_classifier import (
141+ get_proteinogenic_amino_acids ,
142+ )
143+ from chemlog .alg_classification .substructure_classifier import (
144+ is_diketopiperazine ,
145+ is_emericellamide ,
146+ )
147+ from chemlog .cli import _smiles_to_mol
148+
137149 mol = _smiles_to_mol (smiles )
138150 if mol is None or not smiles :
139151 return {"error" : "Failed to parse SMILES" }
0 commit comments