Skip to content

Commit 82064e6

Browse files
authored
soft rdkit import (#21)
* hook for ray's tensorflow import * removing additional tf import statements * remove hard rdkit import
1 parent 93d1710 commit 82064e6

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

nfp/preprocessing/mol_preprocessor.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1+
from __future__ import annotations
2+
13
from typing import Callable, Dict, Hashable, Optional
24

35
import networkx as nx
46
import numpy as np
5-
import rdkit.Chem
67
from nfp.frameworks import tf
78
from nfp.preprocessing import features
89
from nfp.preprocessing.preprocessor import Preprocessor
910
from nfp.preprocessing.tokenizer import Tokenizer
1011

12+
try:
13+
import rdkit.Chem
14+
except ImportError:
15+
rdkit = None
16+
1117

1218
class MolPreprocessor(Preprocessor):
1319
def __init__(
@@ -113,6 +119,7 @@ class SmilesPreprocessor(MolPreprocessor):
113119
def __init__(self, *args, explicit_hs: bool = True, **kwargs):
114120
super(SmilesPreprocessor, self).__init__(*args, **kwargs)
115121
self.explicit_hs = explicit_hs
122+
assert rdkit is not None, "rdkit required for SmilesPreprocessor"
116123

117124
def create_nx_graph(self, smiles: str, *args, **kwargs) -> nx.DiGraph:
118125
mol = rdkit.Chem.MolFromSmiles(smiles)

nfp/preprocessing/xtb_preprocessor.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1+
from __future__ import annotations
2+
13
import json
2-
from typing import Dict, List, Optional
4+
from typing import TYPE_CHECKING, Dict, List, Optional
35

46
import networkx as nx
57
import numpy as np
6-
import rdkit.Chem
78
from nfp.frameworks import tf
89
from nfp.preprocessing import features
910
from nfp.preprocessing.mol_preprocessor import MolPreprocessor, SmilesPreprocessor
1011

12+
if TYPE_CHECKING: # only for type checking
13+
import rdkit.Chem
14+
1115

1216
class xTBPreprocessor(MolPreprocessor):
1317
def __init__(

0 commit comments

Comments
 (0)