-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmilesToImg.py
30 lines (24 loc) · 988 Bytes
/
smilesToImg.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
import csv
from rdkit import Chem
from rdkit.Chem import Draw
from PIL.PngImagePlugin import PngImageFile, PngInfo
with open("chembl25_smiles.csv") as csv_file:
csv_reader = csv.reader(csv_file, delimiter=",")
line_count = 0
for row in csv_reader:
if line_count == 0:
line_count += 1
elif line_count > 8192:
break
else:
smiles_str = row[0]
m = Chem.MolFromSmiles(f"{row[0]}")
Draw.MolToFile(m, f"imagesFromSmilesLite/img{line_count}.png", size=(512, 512))
image = PngImageFile(f"imagesFromSmilesLite/img{line_count}.png")
metadata = PngInfo()
metadata.add_text("SMILES", f"{row[0]}")
image.save(f"imagesFromSmilesLite/img{line_count}.png", pnginfo=metadata)
image = PngImageFile(f"imagesFromSmilesLite/img{line_count}.png")
print(image.text)
line_count += 1
print(f'Processed {line_count} lines.')