added add_h parameter in conversion

This commit is contained in:
2026-02-01 13:47:23 +03:00
parent 8cff37ce4a
commit 73a6cbcbc7
2 changed files with 5 additions and 4 deletions

View File

@@ -6,7 +6,7 @@ from fastapi.exceptions import HTTPException
from fastapi.middleware.cors import CORSMiddleware
# from fastapi.requests import Request
from fastapi.responses import Response
from fastapi.responses import JSONResponse
from fastapi_cache import FastAPICache
from fastapi_cache.backends.redis import RedisBackend
from fastapi_cache.decorator import cache
@@ -54,8 +54,8 @@ def convert_molecule(req: ConvertRequest):
# Rad the string and format from request
mol = pybel.readstring(req.format, req.text)
mol.addh()
if req.add_hydrogen:
mol.addh()
if req.convert_3d:
mol.make3D()
if req.optimize_geometry:
@@ -79,7 +79,7 @@ def convert_molecule(req: ConvertRequest):
)
mol2string = mol.write("xyz")
return Response({"molfile": mol2string}, 200)
return JSONResponse({"molfile": mol2string}, 200)
except Exception as e:
raise HTTPException(status_code=400, detail={"error": str(e)})

View File

@@ -4,6 +4,7 @@ from pydantic import BaseModel
class ConvertRequest(BaseModel):
text: str
format: str # e.g. "mol", "smi", "sdf", "inchi", etc.
add_hydrogen: bool = False
convert_3d: bool = False
optimize_geometry: bool = False