Skip to content

Commit

Permalink
feat: implemented surge - structure generator
Browse files Browse the repository at this point in the history
  • Loading branch information
CS76 committed Jun 13, 2023
1 parent f224750 commit 2b1fbc0
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ RUN apt-get update && \
apt-get update -y && \
apt-get install -y openjdk-11-jre

RUN wget -O surge "https://github.com/StructureGenerator/surge/releases/download/v1.0/surge-linux-v1.0"
RUN chmod +x surge
RUN mv surge /usr/bin

RUN conda install -c conda-forge python>=PYTHON_VERSION
RUN conda install -c conda-forge rdkit>=RDKIT_VERSION
RUN conda install -c conda-forge openbabel>=OPENBABEL_VERSION
Expand Down Expand Up @@ -41,4 +45,4 @@ RUN pip3 install --no-cache-dir chembl_structure_pipeline --no-deps

COPY ./app /code/app

CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80", "--workers", "4"]
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80", "--workers", "4"]
5 changes: 3 additions & 2 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from fastapi.responses import RedirectResponse
from fastapi_versioning import VersionedFastAPI

from .routers import chem, converters, depict, ocsr
from .routers import chem, converters, depict, tools # , ocsr
from fastapi.middleware.cors import CORSMiddleware

from prometheus_fastapi_instrumentator import Instrumentator
Expand Down Expand Up @@ -35,7 +35,8 @@
app.include_router(chem.router)
app.include_router(converters.router)
app.include_router(depict.router)
app.include_router(ocsr.router)
app.include_router(tools.router)
# app.include_router(ocsr.router)

app = VersionedFastAPI(
app,
Expand Down
20 changes: 20 additions & 0 deletions app/modules/tools/surge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from subprocess import Popen, PIPE


def generateStructures(mf: str):
"""This function uses the sugar removal utility and checks
whether a molecule has ring or linear sugars
Args:
smiles (string): SMILES string given by the user.
Returns:
(boolean): True or false values whtehr or not molecule has sugar.
"""
smiles = []
process = Popen(
["surge", "-P", "-T", "-B1,2,3,4,5,7,9", "-t0", "-f0", "-S", mf],
stdout=PIPE,
stderr=PIPE,
)
for line in iter(process.stdout.readline, b""):
smiles.append(line.decode("utf-8").rstrip())
return smiles
24 changes: 24 additions & 0 deletions app/routers/tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from fastapi import APIRouter
from app.modules.tools.surge import generateStructures

router = APIRouter(
prefix="/tools",
tags=["tools"],
dependencies=[],
responses={404: {"description": "Not found"}},
)


@router.get("/")
async def tools_index():
return {"module": "tools", "message": "Successful", "status": 200}


@router.get("/generate-structures")
async def Generate_Structures(molecular_formula: str):
"""
Extract chemical structure depictions and convert them into SMILES using DECIMER:
- **Images**: required (query)
"""
return generateStructures(molecular_formula)

0 comments on commit 2b1fbc0

Please sign in to comment.