11from typing import Optional
22
33import 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
204
215from .base_predictor import BasePredictor
6+ from .. import modelwise_smiles_lru_cache
227
238AA_DICT = {
249 "A" : "L-alanine" ,
4833
4934
5035class ChemlogExtraPredictor (BasePredictor ):
51- CHEMLOG_CLASSIFIER = None
5236
5337 def __init__ (self , model_name : str , ** kwargs ):
5438 super ().__init__ (model_name , ** kwargs )
5539 self .chebi_graph = kwargs .get ("chebi_graph" , None )
56- self .classifier = self . CHEMLOG_CLASSIFIER ()
40+ self .classifier = None
5741
5842 @modelwise_smiles_lru_cache .batch_decorator
5943 def predict_smiles_list (self , smiles_list : list [str ]) -> list :
44+ from chemlog .cli import _smiles_to_mol
45+
6046 mol_list = [_smiles_to_mol (smiles ) for smiles in smiles_list ]
6147 res = self .classifier .classify (mol_list )
6248 if self .chebi_graph is not None :
@@ -73,15 +59,29 @@ def predict_smiles_list(self, smiles_list: list[str]) -> list:
7359
7460
7561class 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 ()
7769
7870
7971class 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 ()
8179
8280
8381class ChemlogPeptidesPredictor (BasePredictor ):
8482 def __init__ (self , model_name : str , ** kwargs ):
83+ from chemlog .cli import CLASSIFIERS
84+
8585 super ().__init__ (model_name , ** kwargs )
8686 self .strategy = "algo"
8787 self .chebi_graph = kwargs .get ("chebi_graph" , None )
@@ -97,6 +97,8 @@ def __init__(self, model_name: str, **kwargs):
9797 print (f"Initialised ChemLog model { self .model_name } " )
9898
9999 def predict_smiles (self , smiles : str ) -> Optional [dict ]:
100+ from chemlog .cli import _smiles_to_mol , strategy_call
101+
100102 mol = _smiles_to_mol (smiles )
101103 if mol is None :
102104 return None
@@ -133,6 +135,19 @@ def predict_smiles_list(self, smiles_list: list[str]) -> list:
133135
134136 def get_chemlog_result_info (self , smiles ):
135137 """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+
136151 mol = _smiles_to_mol (smiles )
137152 if mol is None or not smiles :
138153 return {"error" : "Failed to parse SMILES" }
0 commit comments