Skip to content

Commit

Permalink
Merge commit 'aa4f7334ea2380489dd1dae40b3866ed36531a5c' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
CS76 committed Mar 21, 2023
2 parents 961aa11 + aa4f733 commit 72e00a4
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 63 deletions.
4 changes: 2 additions & 2 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ authors:
given-names: "Kohulan"
orcid: "https://orcid.org/0000-0003-1066-7792"
title: "cheminformatics-python-microservice"
version: v0.1.0 - prerelease
doi: 10.5281/zenodo.7745988
version: v0.3.0 - prerelease
doi: 10.5281/zenodo.7747862
date-released: 2023-03-16
url: "https://github.com/Steinbeck-Lab/cheminformatics-python-microservice"
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
![Workflow](https://github.com/Steinbeck-Lab/cheminformatics-python-microservice/actions/workflows/dev-build.yml/badge.svg)
[![framework](https://img.shields.io/badge/Framework-FastAPI-blue?style)](https://fastapi.tiangolo.com/)
[![FastAPI Documentation](https://img.shields.io/badge/docs-fastapi-blue)](https://api.naturalproducts.net/docs#/)
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.7747862.svg)](https://doi.org/10.5281/zenodo.7747862)
## Overview of Cheminformatics Micro Services

This set of essential and valuable microservices is designed to be accessed via API calls to support cheminformatics. Generally, it is designed to work with SMILES-based inputs and could be used to translate between different machine-readable representations, get Natural Product (NP) likeliness scores, visualize chemical structures, and generate descriptors. In addition, the microservices also host an instance of [STOUT](https://github.com/Kohulan/Smiles-TO-iUpac-Translator) and another instance of [DECIMER](https://github.com/Kohulan/DECIMER-Image_Transformer) (two deep learning models for IUPAC name generation and optical chemical structure recognition, respectively).
Expand Down Expand Up @@ -47,6 +48,10 @@ This set of essential and valuable microservices is designed to be accessed via
```fastapi
https://api.naturalproducts.net/chem/depict?smiles=CN1C=NC2=C1C(=O)N(C(=O)N2C)C&generator=rdkit&width=256&height=256&rotate=75
```
- Visualize molecule in 3D
```fastapi
https://api.naturalproducts.net/chem/depict3D?smiles=CN1C=NC2=C1C(=O)N(C(=O)N2C)C
```

> **Note**
> For detailed documentation on how to use the API check [here](https://api.naturalproducts.net/docs#/)
Expand All @@ -57,7 +62,7 @@ This project is licensed under the MIT License - see the [LICENSE](https://githu

## Citation

Venkata, C., Sharma, N., & Rajan, K. (2023). cheminformatics-python-microservice (Version v0.1.0 - prerelease) [Computer software]. https://doi.org/10.5281/zenodo.7745988
Venkata, C., Sharma, N., & Rajan, K. (2023). cheminformatics-python-microservice (Version v0.3.0 - prerelease) [Computer software]. https://doi.org/10.5281/zenodo.7747862

## Maintained by

Expand Down
2 changes: 1 addition & 1 deletion app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

@app.get("/", include_in_schema=False)
async def docs_redirect():
return RedirectResponse(url='/docs')
return RedirectResponse(url="/docs")


def custom_openapi():
Expand Down
48 changes: 0 additions & 48 deletions app/modules/depict3D.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from rdkit import Chem
from rdkit.Chem import Descriptors, QED, Lipinski, rdMolDescriptors, rdmolops
from rdkit.Chem import AllChem, Descriptors, QED, Lipinski, rdMolDescriptors, rdmolops


def checkRo5Violations(mol):
Expand All @@ -20,7 +20,7 @@ def checkRo5Violations(mol):
return num_of_violations


def GetBasicDescriptors(smiles):
def getBasicDescriptors(smiles):
"""Take an input SMILES and generates a selected set of molecular
descriptors as a dictionary
Args (str): SMILES string
Expand Down Expand Up @@ -62,3 +62,21 @@ def GetBasicDescriptors(smiles):
}

return AllDescriptors


def get3Dconformers(smiles):
"""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)
mol = Chem.AddHs(mol)
AllChem.EmbedMolecule(mol, randomSeed=0xF00D)
AllChem.MMFFOptimizeMolecule(mol, maxIters=200)
return Chem.MolToMolBlock(mol)
else:
return None
11 changes: 4 additions & 7 deletions app/routers/chem.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
from fastapi.responses import Response, HTMLResponse
from rdkit.Chem.Scaffolds import MurckoScaffold
from app.modules.npscorer import getnp_score
from app.modules.descriptor_calculator import GetBasicDescriptors
from app.modules.classyfire import classify, result
from app.modules.cdkmodules import getCDKSDGMol
from app.modules.depict import getRDKitDepiction, getCDKDepiction
from app.modules.depict3D import get3Dconformers
from app.modules.rdkitmodules import getBasicDescriptors, get3Dconformers

from fastapi.templating import Jinja2Templates

Expand Down Expand Up @@ -77,7 +76,7 @@ async def smiles_descriptors(smiles: str):
- **smiles**: required (query)
"""
if smiles:
return GetBasicDescriptors(smiles)
return getBasicDescriptors(smiles)


@router.get("/npscore")
Expand Down Expand Up @@ -137,12 +136,10 @@ async def depict_molecule(
async def depict3D_molecule(
request: Request,
smiles: str,
width: Optional[int] = 512,
height: Optional[int] = 512,
style: Optional[str] = "stick",
):
if smiles:
return templates.TemplateResponse("mol.html", {"request": request, "molecule": Chem.MolToMolBlock(get3Dconformers(smiles))})
content = {"request": request, "molecule": get3Dconformers(smiles)}
return templates.TemplateResponse("mol.html", content)


# @app.get("/molecules/", response_model=List[schemas.Molecule])
Expand Down
2 changes: 1 addition & 1 deletion app/templates/mol.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
$(document).ready(function() {
var viewer = $3Dmol.createViewer("viewer");
viewer.setBackgroundColor(0xffffff);
viewer.addModel(`{{ molecule }}`, "sdf");
viewer.addModel(`{{ molecule }}`, "mol");
viewer.setStyle({stick:{}});
viewer.zoomTo();
viewer.render();
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@ efficientnet
tensorflow==2.10.0
pyheif==0.7.1
selfies>=2.1.1
py3Dmol
jinja2

0 comments on commit 72e00a4

Please sign in to comment.