[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

@ -1593,6 +1593,7 @@ class Pathway(EnviPathModel, AliasMixin, ScenarioMixin):
setting = models.ForeignKey(
"epdb.Setting", verbose_name="Setting", on_delete=models.CASCADE, null=True, blank=True
)
predicted = models.BooleanField(default=False, null=False)
@property
def root_nodes(self):
@ -1804,6 +1805,7 @@ class Pathway(EnviPathModel, AliasMixin, ScenarioMixin):
smiles: str,
name: Optional[str] = None,
description: Optional[str] = None,
predicted: bool = False,
):
pw = Pathway()
pw.package = package
@ -1816,6 +1818,7 @@ class Pathway(EnviPathModel, AliasMixin, ScenarioMixin):
pw.name = name
if description is not None and description.strip() != "":
pw.description = nh3.clean(description, tags=s.ALLOWED_HTML_TAGS).strip()
pw.predicted = predicted
pw.save()
try:
@ -1946,6 +1949,7 @@ class Node(EnviPathModel, AliasMixin, ScenarioMixin):
)
out_edges = models.ManyToManyField("epdb.Edge", verbose_name="Outgoing Edges")
depth = models.IntegerField(verbose_name="Node depth", null=False, blank=False)
stereo_removed = models.BooleanField(default=False, null=False)
def _url(self):
return "{}/node/{}".format(self.pathway.url, self.uuid)
@ -1955,6 +1959,7 @@ class Node(EnviPathModel, AliasMixin, ScenarioMixin):
return {
"depth": self.depth,
"stereo_removed": self.stereo_removed,
"url": self.url,
"node_label_id": self.default_node_label.url,
"image": f"{self.url}?image=svg",
@ -1980,12 +1985,17 @@ class Node(EnviPathModel, AliasMixin, ScenarioMixin):
name: Optional[str] = None,
description: Optional[str] = None,
):
stereo_removed = False
if pathway.predicted and FormatConverter.has_stereo(smiles):
smiles = FormatConverter.standardize(smiles, remove_stereo=True)
stereo_removed = True
c = Compound.create(pathway.package, smiles, name=name, description=description)
if Node.objects.filter(pathway=pathway, default_node_label=c.default_structure).exists():
return Node.objects.get(pathway=pathway, default_node_label=c.default_structure)
n = Node()
n.stereo_removed = stereo_removed
n.pathway = pathway
n.depth = depth