1+ import re
12import sys
23from abc import ABC , abstractmethod
34from typing import Dict , List , Optional , Tuple
@@ -379,9 +380,10 @@ def _construct_fg_to_atom_structure(
379380 fg_to_atoms_map = {}
380381
381382 molecule_atoms_set = set ()
382- for _ , fg_group in structure .items ():
383+ for fg_smiles , fg_group in structure .items ():
383384 fg_to_atoms_map [self ._num_of_nodes ] = fg_group
384385 is_ring_fg = fg_group ["is_ring_fg" ]
386+ is_alkyl = 0
385387
386388 connected_atoms = []
387389 # Build edge index for fg to atom nodes connections
@@ -406,7 +408,7 @@ def _construct_fg_to_atom_structure(
406408 if is_ring_fg :
407409 self ._set_ring_fg_prop (connected_atoms , fg_nodes )
408410 else :
409- self ._set_fg_prop (connected_atoms , fg_nodes )
411+ self ._set_fg_prop (connected_atoms , fg_nodes , fg_smiles )
410412
411413 self ._num_of_nodes += 1
412414
@@ -419,6 +421,7 @@ def _set_ring_fg_prop(self, connected_atoms, fg_nodes):
419421 k .NODE_LEVEL : k .FG_NODE_LEVEL ,
420422 "FG" : f"RING_{ ring_size } " ,
421423 "RING" : ring_size ,
424+ "is_alkyl" : "0" ,
422425 }
423426 # In this case, all atoms of Ring/Fused Ring are assigned the ring size as functional group
424427 for atom in connected_atoms :
@@ -429,8 +432,9 @@ def _set_ring_fg_prop(self, connected_atoms, fg_nodes):
429432 # An atom belonging to multiple rings in fused Ring has size "5-6", indicating size of each ring
430433 max_ring_size = max (list (map (int , ring_prop .split ("-" ))))
431434 atom .SetProp ("FG" , f"RING_{ max_ring_size } " )
435+ atom .SetProp ("is_alkyl" , "0" )
432436
433- def _set_fg_prop (self , connected_atoms , fg_nodes ):
437+ def _set_fg_prop (self , connected_atoms , fg_nodes , fg_smiles ):
434438 fg_set = {atom .GetProp ("FG" ) for atom in connected_atoms }
435439 if not fg_set :
436440 raise ValueError (
@@ -458,17 +462,23 @@ def _set_fg_prop(self, connected_atoms, fg_nodes):
458462 "All Connected atoms must belong to one functional group or None"
459463 )
460464
461- # Select any one connected atom to get FG type and ring size
462- representative_atom = next (
463- (atom for atom in connected_atoms if atom .GetProp ("FG" )), None
464- )
465+ check = re .sub (r"[CH\-\(\)\[\]/\\@]" , "" , fg_smiles )
466+ is_alkyl = "1" if len (check ) == 0 else "0"
467+
468+ representative_atom = None
469+ for atom in connected_atoms :
470+ if atom .GetProp ("FG" ):
471+ representative_atom = atom
472+ atom .SetProp ("is_alkyl" , is_alkyl )
473+
465474 if representative_atom is None :
466475 raise AssertionError ("Expected at least one atom with a functional group." )
467476
468477 fg_nodes [self ._num_of_nodes ] = {
469478 k .NODE_LEVEL : k .FG_NODE_LEVEL ,
470479 "FG" : representative_atom .GetProp ("FG" ),
471480 "RING" : 0 ,
481+ "is_alkyl" : is_alkyl ,
472482 }
473483
474484 def _construct_fg_level_structure (
0 commit comments