Skip to content

Commit 9c14835

Browse files
Udpate to match changes of rdkit
1 parent 3c8e1e1 commit 9c14835

6 files changed

Lines changed: 18 additions & 23 deletions

File tree

glyles/glycans/factory/factory_o.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from rdkit.Chem.rdchem import BondType
55

66
from glyles.glycans.utils import Config, Enantiomer, Lactole, Tree, find_longest_c_chain
7+
from glyles.utils import smiles2mol
78

89

910
class OpenFactory:
@@ -180,7 +181,7 @@ def c1_finder(structure, base_smiles):
180181
if end_double_oxy and not start_double_oxy:
181182
return list(reversed(longest_c_chain))
182183

183-
base = Chem.MolFromSmiles(base_smiles)
184+
base = smiles2mol(base_smiles)
184185
if not base.GetNumConformers():
185186
rdDepictor.Compute2DCoords(base)
186187
if not structure.GetNumConformers():

glyles/glycans/mono/monomer.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
from typing import Literal
33

44
import numpy as np
5-
from rdkit.Chem import MolFromSmiles, MolToSmiles, GetAdjacencyMatrix
5+
from rdkit.Chem import MolToSmiles, GetAdjacencyMatrix
66

77
from glyles.glycans.mono.enum_c import enumerate_carbon
88
from glyles.glycans.mono.reactor import SMILESReaktor
99
from glyles.glycans.utils import Config, find_isomorphism_nx
1010
from glyles.iupac.IUPACLexer import IUPACLexer
11+
from glyles.utils import smiles2mol
1112

1213

1314
def shift(d, offset):
@@ -403,7 +404,7 @@ def get_structure(self):
403404
"""
404405
if self.structure is None:
405406
# read the structure from the SMILES string
406-
self.structure = MolFromSmiles(self.smiles)
407+
self.structure = smiles2mol(self.smiles)
407408

408409
# extract some further information from the molecule to not operate always on the molecule
409410
self.adjacency = GetAdjacencyMatrix(self.structure, useBO=True)

glyles/glycans/poly/anltr_error_listener.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,3 @@ def syntaxError(self, recognizer, offendingSymbol, line, column, msg, e):
1414
# Maybe not a good idea for a library to pollute the stderr when the exceptions are handled?
1515
# print(error_msg, file=sys.stderr)
1616
raise ParseError(f"Glycan cannot be parsed:\n{error_msg}")
17-
18-
def reportAmbiguity(self, recognizer, dfa, startIndex, stopIndex, exact, ambigAlts, configs):
19-
print("Ambiguity")
20-
21-
def reportAttemptingFullContext(self, recognizer, dfa, startIndex, stopIndex, conflictingAlts, configs):
22-
print("AttemptingFullContext")
23-
24-
def reportContextSensitivity(self, recognizer, dfa, startIndex, stopIndex, prediction, configs):
25-
print("ContextSensitivity")

glyles/glycans/poly/glycan.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from glyles.glycans.utils import ParseError
2020
from glyles.gwb.GWBLexer import GWBLexer
2121
from glyles.iupac.IUPACLexer import IUPACLexer
22+
from glyles.utils import smiles2mol
2223

2324
if not hasattr(IUPACLexer, "MOD"):
2425
IUPACLexer.MOD = IUPACLexer.QMARK + 1
@@ -154,7 +155,7 @@ def summary(self):
154155
raise ValueError("SMILES string for this glycan is empty, check if the IUPAC is convertable.")
155156

156157
# generate molecule with RDKit and check it's not None
157-
mol = Chem.MolFromSmiles(smiles)
158+
mol = smiles2mol(smiles)
158159
if mol is None:
159160
raise ValueError("Generated SMILES is invalid, rdkit couldn't read it in.")
160161

@@ -240,7 +241,7 @@ def count_protonation(self, grouping):
240241
raise ValueError("SMILES string for this glycan is empty, check if the IUPAC is convertable.")
241242

242243
# generate molecule with RDKit and check it's not None
243-
mol = Chem.MolFromSmiles(smiles)
244+
mol = smiles2mol(smiles)
244245
if mol is None:
245246
raise ValueError("Generated SMILES is invalid, rdkit couldn't read it in.")
246247

@@ -254,7 +255,7 @@ def count_protonation(self, grouping):
254255
matched_atoms = set()
255256
for g, val in group:
256257
# compute the matches against this glycan
257-
matches = mol.GetSubstructMatches(Chem.MolFromSmiles(g))
258+
matches = mol.GetSubstructMatches(smiles2mol(g))
258259
for match in matches:
259260
for aid in match:
260261
# find the core atom of each match, add it to the list of covered atoms and increase the count
@@ -285,17 +286,17 @@ def count_functional_groups(self, groups):
285286
raise ValueError("SMILES string for this glycan is empty, check if the IUPAC is convertable.")
286287

287288
# generate molecule with RDKit and check it's not None
288-
mol = Chem.MolFromSmiles(smiles)
289+
mol = smiles2mol(smiles)
289290
if mol is None:
290291
raise ValueError("Generated SMILES is invalid, rdkit couldn't read it in.")
291292

292293
fgs = []
293294
for group in groups:
294295
# convert the functional group into a RDKit molecule
295296
if group in functional_groups:
296-
tmp = Chem.MolFromSmiles(functional_groups[group])
297+
tmp = smiles2mol(functional_groups[group])
297298
else:
298-
tmp = Chem.MolFromSmiles(group, sanitize=False)
299+
tmp = smiles2mol(group, sanitize=False)
299300

300301
# check the functional groups for validity
301302
if tmp is None:

glyles/glycans/poly/merger.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
import networkx as nx
66
import numpy as np
7-
from rdkit import Chem
87

98
from glyles.glycans.utils import sanitize_smiles
9+
from glyles.utils import smiles2mol
1010

1111

1212
def masked2nx(smiles: str, mask: list[int]) -> nx.Graph:
13-
mol = Chem.MolFromSmiles(smiles)
13+
mol = smiles2mol(smiles)
1414
tmp1, i, read_atom, read_atom_index = defaultdict(list), 0, "", -1
1515
for i in range(len(smiles)):
1616
# check for uppercase, i.e., atoms

glyles/glycans/utils.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
import networkx as nx
66
import numpy as np
77
from networkx.algorithms import isomorphism
8-
from rdkit.Chem import MolFromSmiles
98

109
from itertools import permutations
1110

1211
from rdkit.Chem.rdchem import ChiralType
1312

13+
from glyles.utils import smiles2mol
14+
1415

1516
class Verbosity(Enum):
1617
"""
@@ -386,11 +387,11 @@ def find_isomorphism_nx(mol1, mol2, name, c1_find=None):
386387
"""
387388
# generate the RDKit molecules from the SMILES strings
388389
if isinstance(mol1, str):
389-
mol1_rd = MolFromSmiles(mol1)
390+
mol1_rd = smiles2mol(mol1)
390391
else:
391392
mol1_rd = mol1
392393
if isinstance(mol2, str):
393-
mol2_rd = MolFromSmiles(mol2)
394+
mol2_rd = smiles2mol(mol2)
394395
else:
395396
mol2_rd = mol2
396397

0 commit comments

Comments
 (0)