parvalijaved commited on
Commit
c663e94
β€’
1 Parent(s): 72fa6b6

Create smiles2iupac.py

Browse files
Files changed (1) hide show
  1. interfaces/smiles2iupac.py +38 -0
interfaces/smiles2iupac.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from rdkit_utils import plot_mol
3
+ from chemicalconverters import NamesConverter
4
+
5
+ def convert(chemical_name, style, validate, plot):
6
+ # Initialize the ChemicalConverter
7
+ converter = NamesConverter("knowledgator/SMILES2IUPAC-canonical-base")
8
+ converted_name = ""
9
+ validation_score = ""
10
+ plot_image = None
11
+ style_prefix = "<" + style[:4] + ">"
12
+ if validate:
13
+ converted_name, validation_score = converter.smiles_to_iupac(style_prefix + chemical_name, validate=True)
14
+ else:
15
+ converted_name = converter.smiles_to_iupac(style_prefix + chemical_name)
16
+ if plot:
17
+ plot_image = plot_mol(chemical_name)
18
+ return converted_name[0], validation_score, plot_image
19
+
20
+ smiles2iupac = gr.Interface(
21
+ fn=convert,
22
+ allow_flagging='auto',
23
+ inputs=[
24
+ gr.Textbox(label="Enter your SMILES name", placeholder="Enter your SMILES name here"),
25
+ gr.Radio(
26
+ choices=["BASE", "SYSTEMATIC", "TRADITIONAL"],
27
+ label="Choose desired IUPAC style",
28
+ ),
29
+ gr.Checkbox(label="Validate with molecular similarity", value=False),
30
+ gr.Checkbox(label="Plot molecule", value=True)
31
+ ],
32
+ outputs=[gr.Text(label="Converted Name"),
33
+ gr.Text(label="Input-Target similarity score"),
34
+ gr.Image(type='pil', label="Molecule Plot", height=170, width=890)],
35
+ examples=[
36
+ ["CCO", "BASE", True, True]
37
+ ],
38
+ )