diff --git a/app/modules/cdkmodules.py b/app/modules/cdkmodules.py index 9280893..f2521d0 100644 --- a/app/modules/cdkmodules.py +++ b/app/modules/cdkmodules.py @@ -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) diff --git a/app/routers/converters.py b/app/routers/converters.py index 98a23fa..9e92420 100644 --- a/app/routers/converters.py +++ b/app/routers/converters.py @@ -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( @@ -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): """