BioMike commited on
Commit
ce58ca9
1 Parent(s): fc1023e

Upload 10 files

Browse files
README.md CHANGED
@@ -10,4 +10,4 @@ pinned: false
10
  license: apache-2.0
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
10
  license: apache-2.0
11
  ---
12
 
13
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference"# SMILES2IUPAC_demo"
interfaces/iupac2smiles.py CHANGED
@@ -1,12 +1,13 @@
1
  import gradio as gr
2
- from utils import ChemicalConverter, validate_smiles2iupac, plot_mol, login
 
3
 
4
  def convert(chemical_name, plot):
5
  # Initialize the ChemicalConverter
6
- converter = ChemicalConverter(mode="IUPAC2SMILES")
7
  converted_name = ""
8
  plot_image = None
9
- converted_name = converter.convert(chemical_name)[6:]
10
  if plot:
11
  plot_image = plot_mol(converted_name)
12
  return converted_name, plot_image
 
1
  import gradio as gr
2
+ from rdkit_utils import plot_mol
3
+ from chemicalconverters import NamesConverter
4
 
5
  def convert(chemical_name, plot):
6
  # Initialize the ChemicalConverter
7
+ converter = NamesConverter('knowledgator/IUPAC2SMILES-canonical-small')
8
  converted_name = ""
9
  plot_image = None
10
+ converted_name = converter.iupac_to_smiles(chemical_name)[0][6:]
11
  if plot:
12
  plot_image = plot_mol(converted_name)
13
  return converted_name, plot_image
interfaces/iupac2style.py CHANGED
@@ -1,10 +1,10 @@
1
  import gradio as gr
2
- from utils import ChemicalConverter, validate_smiles2iupac, plot_mol, login
3
 
4
  def convert(chemical_name, plot):
5
  # Initialize the ChemicalConverter
6
- converter = ChemicalConverter(mode="IUPAC2SMILES")
7
- converted_name = converter.convert(chemical_name)[:6]
8
  styles = {"<SYST>": "SYSTEMATIC", "<TRAD>": "TRADITIONAL", "<BASE>": "BASE"}
9
  return styles.get(converted_name, "")
10
 
 
1
  import gradio as gr
2
+ from chemicalconverters import NamesConverter
3
 
4
  def convert(chemical_name, plot):
5
  # Initialize the ChemicalConverter
6
+ converter = NamesConverter('knowledgator/IUPAC2SMILES-canonical-small')
7
+ converted_name = converter.iupac_to_smiles(chemical_name)[0][:6]
8
  styles = {"<SYST>": "SYSTEMATIC", "<TRAD>": "TRADITIONAL", "<BASE>": "BASE"}
9
  return styles.get(converted_name, "")
10
 
interfaces/smiles2iupac.py CHANGED
@@ -1,19 +1,21 @@
1
  import gradio as gr
2
- from utils import ChemicalConverter, validate_smiles2iupac, plot_mol, login
 
3
 
4
  def convert(chemical_name, style, validate, plot):
5
  # Initialize the ChemicalConverter
6
- converter = ChemicalConverter(mode="SMILES2IUPAC")
7
  converted_name = ""
8
  validation_score = ""
9
  plot_image = None
10
  style_prefix = "<" + style[:4] + ">"
11
- converted_name = converter.convert(style_prefix + chemical_name)
12
  if validate:
13
- validation_score = validate_smiles2iupac(chemical_name, converted_name)
 
 
14
  if plot:
15
  plot_image = plot_mol(chemical_name)
16
- return converted_name, validation_score, plot_image
17
 
18
  smiles2iupac = gr.Interface(
19
  fn=convert,
 
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,
rdkit_utils.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from rdkit import Chem
2
+ from rdkit.Chem import Draw
3
+ from PIL import Image
4
+
5
+
6
+ def plot_mol(smiles):
7
+ # Convert the SMILES string to an RDKit molecule object
8
+ mol = Chem.MolFromSmiles(smiles)
9
+
10
+ # Use RDKit to draw the molecule to an image, with original intended size
11
+ img = Draw.MolToImage(mol, size=(185, 185))
12
+
13
+ # Create a new, blank image with the desired final size (800x190 pixels) with a white background
14
+ final_img = Image.new('RGB', (890, 185), 'white')
15
+
16
+ # Calculate the position to paste the original image onto the blank image to keep it centered
17
+ left = (890 - 185) // 2
18
+ top = (185 - 185) // 2 # This will be zero in this case but included for clarity
19
+
20
+ # Paste the original image onto the blank image
21
+ final_img.paste(img, (left, top))
22
+
23
+ return final_img
requirements.txt CHANGED
@@ -1,3 +1,2 @@
1
- transformers
2
- torch
3
- rdkit
 
1
+ gradio
2
+ chemical-converters