44
55from chebifier import modelwise_smiles_lru_cache
66from chebifier .prediction_models .base_predictor import BasePredictor
7+ from chebifier .utils import CHEBI_VERSION , get_superclasses , to_mol
78
89AA_DICT = {
910 "A" : "L-alanine" ,
@@ -70,41 +71,41 @@ def predict_list(self, smiles_list: list[str]) -> list:
7071 return self ._predict_smiles_list (smiles_list )
7172
7273 def _predict_smiles_list (self , smiles_list : list [str ]) -> list :
73- from chemlog .cli import _smiles_to_mol
74-
75- mol_list = [_smiles_to_mol (smiles ) for smiles in smiles_list ]
74+ mol_list = [to_mol (molecule ) for molecule in smiles_list ]
7675 res = self .classifier .classify (mol_list )
7776 if self .chebi_graph is not None :
7877 for sample in res :
7978 sample_additions = dict ()
8079 for cls in sample :
8180 if sample [cls ] == 1 :
82- successors = list (self .chebi_graph .predecessors (cls ))
83- if successors :
84- for succ in successors :
85- sample_additions [str (succ )] = 1
81+ for superclass in get_superclasses (self .chebi_graph , cls ):
82+ sample_additions [superclass ] = 1
8683 sample .update (sample_additions )
8784 return res
8885
8986
9087class ChemlogXMolecularEntityPredictor (ChemlogExtraPredictor ):
91- def __init__ (self , model_name : str , ** kwargs ):
88+ def __init__ (self , model_name : str , chebi_version : int = CHEBI_VERSION , ** kwargs ):
9289 from chemlog_extra .alg_classification .by_element_classification import (
9390 XMolecularEntityClassifier ,
9491 )
9592
9693 super ().__init__ (model_name , ** kwargs )
97- self .classifier = XMolecularEntityClassifier (chebi_graph = self .chebi_graph )
94+ self .classifier = XMolecularEntityClassifier (
95+ chebi_graph = self .chebi_graph , chebi_version = chebi_version
96+ )
9897
9998
10099class ChemlogOrganoXCompoundPredictor (ChemlogExtraPredictor ):
101- def __init__ (self , model_name : str , ** kwargs ):
100+ def __init__ (self , model_name : str , chebi_version : int = CHEBI_VERSION , ** kwargs ):
102101 from chemlog_extra .alg_classification .by_element_classification import (
103102 OrganoXCompoundClassifier ,
104103 )
105104
106105 super ().__init__ (model_name , ** kwargs )
107- self .classifier = OrganoXCompoundClassifier (chebi_graph = self .chebi_graph )
106+ self .classifier = OrganoXCompoundClassifier (
107+ chebi_graph = self .chebi_graph , chebi_version = chebi_version
108+ )
108109
109110
110111class ChemlogLopsterPredictor (ChemlogExtraPredictor ):
@@ -142,9 +143,9 @@ def __init__(self, model_name: str, **kwargs):
142143 print (f"Initialised ChemLog model { self .model_name } " )
143144
144145 def predict (self , smiles : str ) -> Optional [dict ]:
145- from chemlog .cli import _smiles_to_mol , strategy_call
146+ from chemlog .cli import strategy_call
146147
147- mol = _smiles_to_mol (smiles )
148+ mol = to_mol (smiles )
148149 if mol is None :
149150 return None
150151 pos_labels = [
@@ -157,9 +158,9 @@ def predict(self, smiles: str) -> Optional[dict]:
157158 ]
158159 if self .chebi_graph :
159160 indirect_pos_labels = [
160- str ( pr )
161+ superclass
161162 for label in pos_labels
162- for pr in self .chebi_graph . predecessors ( label )
163+ for superclass in get_superclasses ( self .chebi_graph , label )
163164 ]
164165 pos_labels = list (set (pos_labels + indirect_pos_labels ))
165166 return {
@@ -181,7 +182,7 @@ def _predict_smiles_list(self, smiles_list: list[str]) -> list:
181182
182183 return results
183184
184- def get_chemlog_result_info (self , smiles ):
185+ def get_chemlog_result_info (self , molecule ):
185186 """Get classification for single molecule with additional information."""
186187 from chemlog .alg_classification .charge_classifier import get_charge_category
187188 from chemlog .alg_classification .peptide_size_classifier import (
@@ -194,10 +195,9 @@ def get_chemlog_result_info(self, smiles):
194195 is_diketopiperazine ,
195196 is_emericellamide ,
196197 )
197- from chemlog .cli import _smiles_to_mol
198198
199- mol = _smiles_to_mol ( smiles )
200- if mol is None or not smiles :
199+ mol = to_mol ( molecule ) if molecule else None
200+ if mol is None :
201201 return {"error" : "Failed to parse SMILES" }
202202
203203 charge_category = get_charge_category (mol )
0 commit comments