Spaces:
Sleeping
Sleeping
Create rdkit_utils.py
Browse files- rdkit_utils.py +23 -0
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
|