Skip to content

Commit 08be7d6

Browse files
committed
plot molecule
1 parent 17b5034 commit 08be7d6

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

kora/viz/chem.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import os
2+
os.system('pip install py3Dmol')
3+
import kora.install.rdkit
4+
5+
from rdkit import Chem
6+
from rdkit.Chem import AllChem
7+
import py3Dmol
8+
9+
10+
def plot(smiles, size=(200,200), style='stick'):
11+
"""
12+
Visualize a molecule from its formula (smiles)
13+
Adapted from https://birdlet.github.io/2019/10/02/py3dmol_example
14+
"""
15+
mol = Chem.MolFromSmiles(smiles)
16+
mol = Chem.AddHs(mol)
17+
AllChem.EmbedMolecule(mol)
18+
AllChem.MMFFOptimizeMolecule(mol)
19+
block = Chem.MolToMolBlock(mol)
20+
21+
viewer = py3Dmol.view(width=size[0], height=size[1])
22+
viewer.addModel(block, 'mol')
23+
viewer.setStyle({style:{}})
24+
viewer.zoomTo()
25+
viewer.show()

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name="kora",
8-
version="0.6.9",
8+
version="0.6.10",
99
author="Korakot Chaovavanich",
1010
author_email="korakot@gmail.com",
1111
description="Convenient tools for Colab",

0 commit comments

Comments
 (0)