Skip to content

Commit d600474

Browse files
committed
is_alkyl fg prop
1 parent 9f40c83 commit d600474

3 files changed

Lines changed: 31 additions & 7 deletions

File tree

chebai_graph/preprocessing/properties/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
AtomNodeLevel,
2525
AtomFunctionalGroup,
2626
AtomRingSize,
27+
IsHydrogenBondDonorFG,
28+
IsHydrogenBondAcceptorFG,
29+
IsFGAlkyl,
2730
BondLevel,
2831
AugAtomType,
2932
AugNumAtomBonds,
@@ -59,6 +62,9 @@
5962
"AtomNodeLevel",
6063
"AtomFunctionalGroup",
6164
"AtomRingSize",
65+
"IsHydrogenBondDonorFG",
66+
"IsHydrogenBondAcceptorFG",
67+
"IsFGAlkyl",
6268
"BondLevel",
6369
"AugAtomType",
6470
"AugNumAtomBonds",

chebai_graph/preprocessing/properties/augmented_properties.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,14 @@ def get_atom_value(self, atom: Chem.rdchem.Atom | Dict):
145145
return fg in self._hydrogen_bond_acceptor
146146

147147

148+
class IsFGAlkyl(AugmentedAtomProperty):
149+
def __init__(self, encoder: Optional[PropertyEncoder] = None):
150+
super().__init__(encoder or BoolEncoder(self))
151+
152+
def get_atom_value(self, atom: Chem.rdchem.Atom | Dict):
153+
return int(self._check_modify_atom_prop_value(atom, "is_alkyl"))
154+
155+
148156
class AugNodeValueDefaulter(AugmentedAtomProperty, FrozenPropertyAlias, ABC):
149157
def get_atom_value(self, atom: Chem.rdchem.Atom | Dict):
150158
if isinstance(atom, Chem.rdchem.Atom):

chebai_graph/preprocessing/reader/augmented_reader.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import re
12
import sys
23
from abc import ABC, abstractmethod
34
from 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

Comments
 (0)