Skip to content

Commit

Permalink
fix: SDF block encoding and return as Dict
Browse files Browse the repository at this point in the history
  • Loading branch information
Kohulan committed Aug 25, 2023
1 parent 6c1cb58 commit 9ab58cf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
3 changes: 2 additions & 1 deletion app/modules/toolkits/rdkit_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,8 @@ def getProperties(sdf_file):
is returned.
"""
# Create an SDMolSupplier to read the SDF file
suppl = Chem.SDMolSupplier(sdf_file)
suppl = Chem.SDMolSupplier()
suppl.SetData(sdf_file.encode("utf-8"))

# Check if the SDF file contains a valid molecule
if len(suppl) == 1 and suppl[0]:
Expand Down
12 changes: 9 additions & 3 deletions app/routers/chem.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ async def HOSE_Codes(
@router.post(
"/standardize",
summary="Standardize molblock using the ChEMBL curation pipeline",
response_model=StandardizedResult,
response_model=Dict,
responses={400: {"model": ErrorResponse}},
)
async def standardize_mol(
Expand Down Expand Up @@ -325,7 +325,12 @@ async def standardize_mol(
"""
try:
if data:
standardized_mol = standardizer.standardize_molblock(data)
suppl = Chem.SDMolSupplier()
suppl.SetData(data.encode("utf-8"))
if len(suppl) == 1 and suppl[0]:
mol_data = suppl[0]
mol = Chem.MolToMolBlock(mol_data)
standardized_mol = standardizer.standardize_molblock(mol)
rdkit_mol = Chem.MolFromMolBlock(standardized_mol)

else:
Expand All @@ -340,7 +345,8 @@ async def standardize_mol(
inchikey=Chem.inchi.MolToInchiKey(rdkit_mol),
)
original_properties = getProperties(data)
return response.update(original_properties)
response.update(original_properties)
return response

except Exception as e:
raise HTTPException(status_code=400, detail=str(e))
Expand Down

0 comments on commit 9ab58cf

Please sign in to comment.