Skip to content

Commit

Permalink
feat: Add CXSMILES conversion with CDK #156
Browse files Browse the repository at this point in the history
  • Loading branch information
Kohulan committed May 31, 2023
1 parent 1a91133 commit 683d5f2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
18 changes: 18 additions & 0 deletions app/modules/cdkmodules.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,3 +376,21 @@ def getCIPAnnotation(smiles: str):
)

return mol


def getCXSMILES(smiles: str):
"""This function takes the user input SMILES and creates a
CXSMILES string with 2D atom coordinates
Args:
smiles (string): SMILES string given by the user.
Returns:
smiles (string): CXSMILES string.
"""
moleculeSDG = getCDKSDG(smiles)
SmiFlavor = JClass(cdk_base + ".smiles.SmiFlavor")
SmilesGenerator = JClass(cdk_base + ".smiles.SmilesGenerator")(
SmiFlavor.Absolute | SmiFlavor.CxSmilesWithCoords
)
CXSMILES = SmilesGenerator.create(moleculeSDG)
return str(CXSMILES)
18 changes: 17 additions & 1 deletion app/routers/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from rdkit.Chem import AllChem
from typing import Optional
from STOUT import translate_forward, translate_reverse
from app.modules.cdkmodules import getCDKSDGMol
from app.modules.cdkmodules import getCDKSDGMol, getCXSMILES
from app.modules.rdkitmodules import get3Dconformers

router = APIRouter(
Expand Down Expand Up @@ -122,6 +122,22 @@ async def SMILES_to_InChIKey(smiles: str):
return "Error reading SMILES string check again."


@router.get("/cxsmiles")
async def SMILES_to_CXSMILES(smiles: str):
"""
Convert SMILES to CXSMILES:
- **SMILES**: required (query parameter)
"""
if any(char.isspace() for char in smiles):
smiles = smiles.replace(" ", "+")
if smiles:
cxsmiles = getCXSMILES(smiles)
return cxsmiles
else:
return "Error reading SMILES string check again."


@router.get("/formats")
async def SMILES_convert_to_Formats(smiles: str):
"""
Expand Down

0 comments on commit 683d5f2

Please sign in to comment.