-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSmilesVisualizer.py
37 lines (28 loc) · 1.11 KB
/
SmilesVisualizer.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
from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import QLabel, QMainWindow
from PIL.ImageQt import ImageQt
from rdkit import Chem
from rdkit.Chem.Draw import MolToImage
class SmilesVisualizer(QMainWindow):
def __init__(self, smiles):
super().__init__()
# Create a RDKit molecule object from the SMILES string
self.mol = Chem.MolFromSmiles(smiles)
# Create the UI elements
self.label = QLabel()
self.setCentralWidget(self.label)
# Set the window title
self.setWindowTitle("SMILES Visualizer")
# Display the molecule image
if self.mol is not None:
self.display_molecule()
else:
print('The predicted SMILES does not correspond to a valid molecule')
def display_molecule(self):
# Generate an image of the molecule using RDKit
image = MolToImage(self.mol)
# Convert the image to a QImage for display in PyQt5
qimage = ImageQt(image.convert('RGBA'))
pixmap = QPixmap.fromImage(qimage)
# Display the QPixmap in the label widget
self.label.setPixmap(pixmap)