-
Notifications
You must be signed in to change notification settings - Fork 0
/
map_reaction_smiles_using_chytorch_rxnmap.py
145 lines (113 loc) · 3.6 KB
/
map_reaction_smiles_using_chytorch_rxnmap.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
""" The ``scripts`` directory ``map_reaction_smiles_using_chytorch_rxnmap`` script. """
from argparse import ArgumentParser, Namespace
from logging import Formatter, Logger, StreamHandler, getLogger
from pandas import DataFrame, concat, read_csv
from atom_to_atom_mapping.utility import ChytorchRxnMapAtomToAtomMappingUtility
def get_script_arguments() -> Namespace:
"""
Get the script arguments.
:returns: The script arguments.
"""
argument_parser = ArgumentParser()
argument_parser.add_argument(
"-rs",
"--reaction_smiles",
default=None,
type=str,
help="The chemical reaction SMILES string."
)
argument_parser.add_argument(
"-icfp",
"--input_csv_file_path",
default=None,
type=str,
help="The path to the input .csv file."
)
argument_parser.add_argument(
"-rscn",
"--reaction_smiles_column_name",
default=None,
type=str,
help="The name of the chemical reaction SMILES column in the input .csv file."
)
argument_parser.add_argument(
"-ocfp",
"--output_csv_file_path",
default=None,
type=str,
help="The path to the output .csv file."
)
argument_parser.add_argument(
"-np",
"--number_of_processes",
default=1,
type=int,
help="The number of processes."
)
return argument_parser.parse_args()
def get_script_logger() -> Logger:
"""
Get the script logger.
:returns: The script logger.
"""
logger = getLogger(
name="script_logger"
)
logger.setLevel(
level="DEBUG"
)
formatter = Formatter(
fmt="[{name:s} @ {asctime:s}] {levelname:s}: \"{message:s}\"",
style="{"
)
stream_handler = StreamHandler()
stream_handler.setLevel(
level="DEBUG"
)
stream_handler.setFormatter(
fmt=formatter
)
logger.addHandler(
hdlr=stream_handler
)
return logger
if __name__ == "__main__":
script_logger = get_script_logger()
try:
script_arguments = get_script_arguments()
if script_arguments.reaction_smiles is not None:
print({
"reaction_smiles": script_arguments.reaction_smiles,
})
print(ChytorchRxnMapAtomToAtomMappingUtility.map_reaction_smiles(
reaction_smiles=script_arguments.reaction_smiles,
logger=script_logger
))
if (
script_arguments.input_csv_file_path is not None and
script_arguments.reaction_smiles_column_name is not None and
script_arguments.output_csv_file_path is not None
):
input_csv_file_data = read_csv(
filepath_or_buffer=script_arguments.input_csv_file_path
)
concat(
objs=[
input_csv_file_data,
DataFrame(
data=ChytorchRxnMapAtomToAtomMappingUtility.map_reaction_smiles_strings(
reaction_smiles_strings=input_csv_file_data[
script_arguments.reaction_smiles_column_name
].values.tolist(),
number_of_processes=script_arguments.number_of_processes,
logger=script_logger
)
),
],
axis=1
).to_csv(
path_or_buf=script_arguments.output_csv_file_path,
index=False
)
except:
raise