Skip to content

Commit

Permalink
Merge pull request #55 from Steinbeck-Lab/dev-kohulan
Browse files Browse the repository at this point in the history
fix: Linter issues on depict3D
  • Loading branch information
CS76 authored Mar 20, 2023
2 parents 48870cd + 0626491 commit 3b611e4
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions app/modules/depict3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
from rdkit import Chem
from rdkit.Chem import AllChem


def get3Dconformers(smiles):
'''Convert SMILES to Mol with 3D coordinates
"""Convert SMILES to Mol with 3D coordinates
Args (str): SMILES string.
Returns (rdkil.mol): A mol object with 3D coodinates
optimized with MMFF94 forcefield.
'''
"""
mol = Chem.MolFromSmiles(smiles)
if mol:
AllChem.Compute2DCoords(mol)
Expand All @@ -19,28 +20,29 @@ def get3Dconformers(smiles):
else:
return None


def get3DDepiction(smiles, size=(512, 512), style="stick", surface=False, opacity=0.5):
"""Draw molecule in 3D
Args:
----
smiles (str): SMILES string.
size (tuple): canvas size.
style (str): Type of drawing molecule
('line', 'stick', 'sphere', 'carton').
('line', 'stick', 'sphere', 'carton').
surface (bool): display SAS.
opacity (float): opacity of surface, range 0.0-1.0.
Return:
----
viewer: py3Dmol.view, a class for constructing embedded 3Dmol.js view.
"""
assert style in ('line', 'stick', 'sphere', 'carton')
assert style in ("line", "stick", "sphere", "carton")
conformers = get3Dconformers(smiles)
mblock = Chem.MolToMolBlock(conformers)
viewer = py3Dmol.view(width=size[0], height=size[1])
viewer.addModel(mblock, 'mol')
viewer.setStyle({style:{}})
viewer.addModel(mblock, "mol")
viewer.setStyle({style: {}})
if surface:
viewer.addSurface(py3Dmol.SAS, {'opacity': opacity})
viewer.addSurface(py3Dmol.SAS, {"opacity": opacity})
viewer.zoomTo()
return viewer

0 comments on commit 3b611e4

Please sign in to comment.