From 0626491680275ed0a82edb5503f01dccf1445554 Mon Sep 17 00:00:00 2001 From: Kohulan Date: Mon, 20 Mar 2023 14:52:24 +0100 Subject: [PATCH] fix: Linter issues on depict3D --- app/modules/depict3D.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/app/modules/depict3D.py b/app/modules/depict3D.py index 2a8067f..07b02ba 100644 --- a/app/modules/depict3D.py +++ b/app/modules/depict3D.py @@ -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) @@ -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