-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecoder.py
97 lines (80 loc) · 2.33 KB
/
decoder.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from rdmc.conformer_generation.task import Task
from rdmc.mol import RDKitMol
class MolDecoder(Task):
"""base class for decoding representations to RDKitMol object"""
def post_run(self, **kwargs):
"""
Set the SMILES as the name of the RDKitMol object.
"""
self.n_success = 1 # no error raise during run
mol = self.last_result
mol.SetProp("Name",
mol.ToSmiles(removeHs=False,
removeAtomMap=False,)
)
def run(self,
*,
reps: str,
**kwargs):
"""
Decode representation (reps) to RDKitMol object.
All child classes should implement this method and has at least `repr`
as the argument.
Args:
reps (str): representation string
"""
raise NotImplementedError
class SmilesDecoder(MolDecoder):
""" Decode SMILES to RDKitMol object """
@MolDecoder.timer
def run(self,
*,
reps: str,
**kwargs):
"""
Decode SMILES to RDKitMol object.
Args:
reps (str): SMILES string
"""
return RDKitMol.FromSmiles(reps, **kwargs)
class InchiDecoder(MolDecoder):
""" Decode InChI to RDKitMol object """
@MolDecoder.timer
def run(self,
*,
reps: str,
**kwargs):
"""
Decode InChI to RDKitMol object.
Args:
reps (str): InChI string
"""
return RDKitMol.FromInchi(reps, **kwargs)
class SmartsDecoder(MolDecoder):
""" Decode SMARTS to RDKitMol object """
@MolDecoder.timer
def run(self,
*,
reps: str,
**kwargs):
"""
Decode SMARTS to RDKitMol object.
Args:
reps (str): SMARTS string
"""
return RDKitMol.FromSmarts(reps, **kwargs)
class RxnSmilesDecoder(Task):
""" Decode reaction SMILES to RDKitMol object """
@MolDecoder.timer
def run(self,
*,
reps: str,
**kwargs,):
"""
Decode reaction SMILES to RDKitMol object.
Args:
reps (str): reaction SMILES string
"""
return [RDKitMol.FromSmiles(smi, **kwargs) for smi in reps.split(".")]