added add_h parameter in conversion
This commit is contained in:
@@ -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)
|
||||
|
||||
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)})
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user