[Fix] Stereochemistry prediction handling (#228 and #238) (#250)

**This pull request will need a separate migration pull-request**

I have added an alert box in two places when the user tries to predict with stereo chemistry.

When a user predicts a pathway with stereo chemistry an alert box is shown in that node's hover.
To do this I added two new fields. Pathway now has a "predicted" BooleanField indicating whether it was predicted or not. It is set to True if the pathway mode for prediction is "predict" or "incremental" and False if it is "build". I think it is a flag that could be useful in the future, perhaps for analysing how many predicted pathways are in enviPath?
Node now has a `stereo_removed` BooleanField which is set to True if the Node's parent Pathways has "predicted" as true and the node SMILES has stereochemistry.
<img width="500" alt="{927AC9FF-DBC9-4A19-9E6E-0EDD3B08C7AC}.png" src="attachments/69ea29bc-c2d2-4cd2-8e98-aae5c5737f69">

When a user does a prediction on a model's page it shows at the top of the list. This did not require any new fields as the entered SMILES does not get saved anywhere.
<img width="500" alt="{BED66F12-5F07-419E-AAA6-FE1FE5B4F266}.png" src="attachments/5fcc3a9b-4d1a-4e48-acac-76b7571f6507">

I think the alert box is an alright solution but if you have a great idea for something that looks/fits better please change it or let me know.

Co-authored-by: Tim Lorsbach <tim@lorsba.ch>
Reviewed-on: enviPath/enviPy#250
Co-authored-by: Liam Brydon <lbry121@aucklanduni.ac.nz>
Co-committed-by: Liam Brydon <lbry121@aucklanduni.ac.nz>
This commit is contained in:
2025-12-03 10:19:34 +13:00
committed by jebus
parent 69df139256
commit 901de4640c
23 changed files with 126 additions and 49 deletions

View File

@ -961,9 +961,9 @@ def package_model(request, package_uuid, model_uuid):
# Check if smiles is non empty and valid
if smiles == "":
return JsonResponse({"error": "Received empty SMILES"}, status=400)
stereo = FormatConverter.has_stereo(smiles)
try:
stand_smiles = FormatConverter.standardize(smiles)
stand_smiles = FormatConverter.standardize(smiles, remove_stereo=True)
except ValueError:
return JsonResponse({"error": f'"{smiles}" is not a valid SMILES'}, status=400)
@ -974,7 +974,7 @@ def package_model(request, package_uuid, model_uuid):
current_user, predict_simple, current_model.pk, stand_smiles
)
res = []
res = {"pred": [], "stereo": stereo}
for pr in pred_res:
if len(pr) > 0:
@ -983,7 +983,7 @@ def package_model(request, package_uuid, model_uuid):
logger.debug(f"Checking {prod_set}")
products.append(tuple([x for x in prod_set]))
res.append(
res["pred"].append(
{
"products": list(set(products)),
"probability": pr.probability,
@ -1931,7 +1931,6 @@ def package_pathways(request, package_uuid):
"Pathway prediction failed!",
"Pathway prediction failed due to missing or empty SMILES",
)
try:
stand_smiles = FormatConverter.standardize(smiles)
except ValueError:
@ -1954,8 +1953,13 @@ def package_pathways(request, package_uuid):
prediction_setting = SettingManager.get_setting_by_url(current_user, prediction_setting)
else:
prediction_setting = current_user.prediction_settings()
pw = Pathway.create(current_package, stand_smiles, name=name, description=description)
pw = Pathway.create(
current_package,
stand_smiles,
name=name,
description=description,
predicted=pw_mode in {"predict", "incremental"},
)
# set mode
pw.kv.update({"mode": pw_mode})