Skip to content

Commit

Permalink
Merge pull request #322 from Steinbeck-Lab/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
CS76 authored Aug 25, 2023
2 parents 220e3e2 + 6c1cb58 commit 34f5bb4
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
35 changes: 31 additions & 4 deletions app/modules/toolkits/rdkit_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,10 @@ def getRDKitCXSMILES(smiles: str):
"""This function takes an input as a SMILES string and
returns a CXSMILES with coordinates.
Args (str):
SMILES string.
Returns (str):
CXSMILES with coordinates.
Args:
SMILES string (str): The SMILES string to be converted as input
Returns:
string: CXSMILES with coordinates.
"""
if any(char.isspace() for char in smiles):
Expand All @@ -274,3 +274,30 @@ def getRDKitCXSMILES(smiles: str):
return Chem.MolToCXSmiles(mol)
else:
return "Error reading SMILES string, check again."


def getProperties(sdf_file):
"""
Extracts properties from a single molecule contained in an SDF file.
This function uses the RDKit library to read an SDF (Structure-Data File) and extract properties
from the first molecule in the file. It checks if the supplied SDF file contains a valid molecule
and retrieves its properties as a dictionary.
Args:
sdf_file (str): The path to the SDF file containing the molecule.
Returns:
dict or None: A dictionary containing the properties of the molecule. If the SDF file contains
a valid molecule, the dictionary will have property names as keys and property values as values.
If no valid molecule is found, or if there are no properties associated with the molecule, None
is returned.
"""
# Create an SDMolSupplier to read the SDF file
suppl = Chem.SDMolSupplier(sdf_file)

# Check if the SDF file contains a valid molecule
if len(suppl) == 1 and suppl[0]:
# Extract properties as a dictionary
properties = suppl[0].GetPropsAsDict()
return properties
5 changes: 4 additions & 1 deletion app/routers/chem.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from app.modules.toolkits.rdkit_wrapper import (
getTanimotoSimilarityRDKit,
getRDKitHOSECodes,
getProperties,
)
from app.modules.coconut.descriptors import getCOCONUTDescriptors
from app.modules.alldescriptors import getTanimotoSimilarity
Expand Down Expand Up @@ -338,7 +339,9 @@ async def standardize_mol(
inchi=Chem.inchi.MolToInchi(rdkit_mol),
inchikey=Chem.inchi.MolToInchiKey(rdkit_mol),
)
return response
original_properties = getProperties(data)
return response.update(original_properties)

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

Expand Down

0 comments on commit 34f5bb4

Please sign in to comment.