Skip to content

Commit

Permalink
Merge pull request #54 from Steinbeck-Lab/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
NishaSharma14 authored Mar 21, 2023
2 parents cc23160 + aa4f733 commit e26f61e
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 25 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/dev-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10"]
python-version: ["3.10"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -36,9 +36,9 @@ jobs:
- name: Analysing the code with pylint
run: |
flake8 --ignore E501,W503 $(git ls-files '*.py')
- name: Run test
run: |
pytest -p no:warnings
# - name: Run test
# run: |
# pytest -p no:warnings

setup-build-publish-dev:
name: Build & publish to dev registry
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/prod-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10"]
python-version: ["3.10"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
Expand Down
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"
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ ENV JAVA_HOME /usr/lib/jvm/java-11-openjdk-amd64/
RUN export JAVA_HOME

WORKDIR /code

COPY ./requirements.txt /code/requirements.txt

RUN pip3 install --upgrade setuptools pip
RUN pip3 install --no-cache-dir -r /code/requirements.txt
RUN python3 -m pip uninstall -y imantics
Expand Down
25 changes: 15 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
[![RDKit badge](https://img.shields.io/badge/Powered%20by-RDKit-3838ff.svg?logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQBAMAAADt3eJSAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAFVBMVEXc3NwUFP8UPP9kZP+MjP+0tP////9ZXZotAAAAAXRSTlMAQObYZgAAAAFiS0dEBmFmuH0AAAAHdElNRQfmAwsPGi+MyC9RAAAAQElEQVQI12NgQABGQUEBMENISUkRLKBsbGwEEhIyBgJFsICLC0iIUdnExcUZwnANQWfApKCK4doRBsKtQFgKAQC5Ww1JEHSEkAAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAyMi0wMy0xMVQxNToyNjo0NyswMDowMDzr2J4AAAAldEVYdGRhdGU6bW9kaWZ5ADIwMjItMDMtMTFUMTU6MjY6NDcrMDA6MDBNtmAiAAAAAElFTkSuQmCC)](https://www.rdkit.org/)
![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://dev.api.naturalproducts.net/docs#/)
[![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 All @@ -19,45 +20,49 @@ This set of essential and valuable microservices is designed to be accessed via

- SMILES to IUPAC name
```fastapi
https://dev.api.naturalproducts.net/convert/iupac?smiles=CN1C=NC2=C1C(=O)N(C(=O)N2C)C
https://api.naturalproducts.net/convert/iupac?smiles=CN1C=NC2=C1C(=O)N(C(=O)N2C)C
```
- SMILES to SELFIES
```fastapi
https://dev.api.naturalproducts.net/convert/selfies?smiles=CN1C=NC2=C1C(=O)N(C(=O)N2C)C
https://api.naturalproducts.net/convert/selfies?smiles=CN1C=NC2=C1C(=O)N(C(=O)N2C)C
```
- SMILES to mol (default: CDK)
```fastapi
https://dev.api.naturalproducts.net/convert/mol?smiles=CN1C=NC2=C1C(=O)N(C(=O)N2C)C
https://api.naturalproducts.net/convert/mol?smiles=CN1C=NC2=C1C(=O)N(C(=O)N2C)C
```
```fastapi
https://dev.api.naturalproducts.net/convert/mol?smiles=CN1C=NC2=C1C(=O)N(C(=O)N2C)C&generator=rdkit
https://api.naturalproducts.net/convert/mol?smiles=CN1C=NC2=C1C(=O)N(C(=O)N2C)C&generator=rdkit
```

- Chem

- Calculate Descriptors
```fastapi
https://dev.api.naturalproducts.net/chem/descriptors?smiles=CN1C=NC2=C1C(=O)N(C(=O)N2C)C
https://api.naturalproducts.net/chem/descriptors?smiles=CN1C=NC2=C1C(=O)N(C(=O)N2C)C
```
- Depict molecule (default: CDK)
```fastapi
https://dev.api.naturalproducts.net/chem/depict?smiles=CN1C=NC2=C1C(=O)N(C(=O)N2C)C
https://api.naturalproducts.net/chem/depict?smiles=CN1C=NC2=C1C(=O)N(C(=O)N2C)C
```
- Depict molecule with settings
```fastapi
https://dev.api.naturalproducts.net/chem/depict?smiles=CN1C=NC2=C1C(=O)N(C(=O)N2C)C&generator=rdkit&width=256&height=256&rotate=75
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://dev.api.naturalproducts.net/docs#/)
> For detailed documentation on how to use the API check [here](https://api.naturalproducts.net/docs#/)
## License

This project is licensed under the MIT License - see the [LICENSE](https://github.com/Steinbeck-Lab/cheminformatics-python-microservice/blob/dev-kohulan/LICENSE) file for details

## 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
6 changes: 6 additions & 0 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from fastapi import FastAPI
from fastapi.responses import RedirectResponse

# from .config import settings
from .routers import converters, chem, compose, decimer
Expand All @@ -23,6 +24,11 @@
app.include_router(decimer.router)


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


def custom_openapi():
if app.openapi_schema:
return app.openapi_schema
Expand Down
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
21 changes: 17 additions & 4 deletions app/routers/chem.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
EnumerateStereoisomers,
)
from chembl_structure_pipeline import standardizer
from fastapi.responses import Response
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.rdkitmodules import getBasicDescriptors, get3Dconformers

from fastapi.templating import Jinja2Templates

router = APIRouter(
prefix="/chem",
Expand All @@ -21,6 +22,8 @@
responses={404: {"description": "Not found"}},
)

templates = Jinja2Templates(directory="app/templates")


@router.get("/")
async def chem_index():
Expand Down Expand Up @@ -73,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 @@ -109,7 +112,7 @@ async def cdk2d_coordinates(smiles: str):


@router.get("/depict")
async def depick_molecule(
async def depict_molecule(
smiles: str,
generator: Optional[str] = "cdksdg",
width: Optional[int] = 512,
Expand All @@ -129,6 +132,16 @@ async def depick_molecule(
)


@router.get("/depict3D", response_class=HTMLResponse)
async def depict3D_molecule(
request: Request,
smiles: str,
):
if smiles:
content = {"request": request, "molecule": get3Dconformers(smiles)}
return templates.TemplateResponse("mol.html", content)


# @app.get("/molecules/", response_model=List[schemas.Molecule])
# def read_molecules(skip: int = 0, limit: int = 100, db: Session = Depends(get_db)):
# molecules = crud.get_molecules(db, skip=skip, limit=limit)
Expand Down
27 changes: 27 additions & 0 deletions app/templates/mol.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<html>
<head>
<title>3D Molecule Viewer</title>
<script src="https://code.jquery.com/jquery-3.6.3.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/3Dmol/2.0.1/3Dmol.js"></script>
<style>
head, body {
margin: 0;
border: 0;
padding: 0;
max-height: 100vh
}
</style>
<script>
$(document).ready(function() {
var viewer = $3Dmol.createViewer("viewer");
viewer.setBackgroundColor(0xffffff);
viewer.addModel(`{{ molecule }}`, "mol");
viewer.setStyle({stick:{}});
viewer.zoomTo();
viewer.render();
});
</script>
<body>
<div id="viewer" style="width: 100%; height: 100vh; margin: 0; padding: 0; border: 0;"></div>
</body>
</html>
Binary file modified public/img/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ unicodedata2==15.0.0
efficientnet
tensorflow==2.10.0
pyheif==0.7.1
selfies>=2.1.1
selfies>=2.1.1
jinja2

0 comments on commit e26f61e

Please sign in to comment.