forked from enviPath/enviPy
**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>
187 lines
5.8 KiB
Python
187 lines
5.8 KiB
Python
from django.conf import settings as s
|
|
from django.test import TestCase, override_settings
|
|
|
|
from epdb.logic import PackageManager
|
|
from epdb.models import Compound, User, Reaction, Rule
|
|
|
|
|
|
@override_settings(MODEL_DIR=s.FIXTURE_DIRS[0] / "models", CELERY_TASK_ALWAYS_EAGER=True)
|
|
class ReactionTest(TestCase):
|
|
fixtures = ["test_fixtures_incl_model.jsonl.gz"]
|
|
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
super(ReactionTest, cls).setUpClass()
|
|
cls.user = User.objects.get(username="anonymous")
|
|
cls.package = PackageManager.create_package(cls.user, "Anon Test Package", "No Desc")
|
|
|
|
def test_smoke(self):
|
|
educt = Compound.create(
|
|
self.package,
|
|
smiles="C(CCl)Cl",
|
|
name="1,2-Dichloroethane",
|
|
description="Eawag BBD compound c0001",
|
|
).default_structure
|
|
|
|
product = Compound.create(
|
|
self.package,
|
|
smiles="C(CO)Cl",
|
|
name="2-Chloroethanol",
|
|
description="Eawag BBD compound c0005",
|
|
).default_structure
|
|
|
|
r = Reaction.create(
|
|
package=self.package,
|
|
name="Eawag BBD reaction r0001",
|
|
educts=[educt],
|
|
products=[product],
|
|
multi_step=False,
|
|
)
|
|
|
|
self.assertEqual(r.smirks(), "C(CCl)Cl>>C(CO)Cl")
|
|
self.assertEqual(r.name, "Eawag BBD reaction r0001")
|
|
self.assertEqual(r.description, "no description")
|
|
|
|
def test_string_educts_and_products(self):
|
|
r = Reaction.create(
|
|
package=self.package,
|
|
name="Eawag BBD reaction r0001",
|
|
educts=["C(CCl)Cl"],
|
|
products=["C(CO)Cl"],
|
|
multi_step=False,
|
|
)
|
|
|
|
self.assertEqual(r.smirks(), "C(CCl)Cl>>C(CO)Cl")
|
|
|
|
def test_missing_smiles(self):
|
|
educt = Compound.create(
|
|
self.package,
|
|
smiles="C(CCl)Cl",
|
|
name="1,2-Dichloroethane",
|
|
description="Eawag BBD compound c0001",
|
|
).default_structure
|
|
|
|
product = Compound.create(
|
|
self.package,
|
|
smiles="C(CO)Cl",
|
|
name="2-Chloroethanol",
|
|
description="Eawag BBD compound c0005",
|
|
).default_structure
|
|
|
|
with self.assertRaises(ValueError):
|
|
_ = Reaction.create(
|
|
package=self.package,
|
|
name="Eawag BBD reaction r0001",
|
|
educts=[educt],
|
|
products=[],
|
|
multi_step=False,
|
|
)
|
|
|
|
with self.assertRaises(ValueError):
|
|
_ = Reaction.create(
|
|
package=self.package,
|
|
name="Eawag BBD reaction r0001",
|
|
educts=[],
|
|
products=[product],
|
|
multi_step=False,
|
|
)
|
|
|
|
with self.assertRaises(ValueError):
|
|
_ = Reaction.create(
|
|
package=self.package,
|
|
name="Eawag BBD reaction r0001",
|
|
educts=[],
|
|
products=[],
|
|
multi_step=False,
|
|
)
|
|
|
|
def test_empty_name_and_description_are_ignored(self):
|
|
r = Reaction.create(
|
|
package=self.package,
|
|
name="",
|
|
description="",
|
|
educts=["C(CCl)Cl"],
|
|
products=["C(CO)Cl"],
|
|
multi_step=False,
|
|
)
|
|
|
|
self.assertEqual(r.name, "no name")
|
|
self.assertEqual(r.description, "no description")
|
|
|
|
def test_deduplication(self):
|
|
rule = Rule.create(
|
|
package=self.package,
|
|
rule_type="SimpleAmbitRule",
|
|
name="bt0022-2833",
|
|
description="Dihalomethyl derivative + Halomethyl derivative > 1-Halo-1-methylalcohol derivative + 1-Methylalcohol derivative",
|
|
smirks="[H:5][C:1]([#6:6])([#1,#9,#17,#35,#53:4])[#9,#17,#35,#53]>>[H:5][C:1]([#6:6])([#8])[#1,#9,#17,#35,#53:4]",
|
|
)
|
|
|
|
r1 = Reaction.create(
|
|
package=self.package,
|
|
name="Eawag BBD reaction r0001",
|
|
educts=["C(CCl)Cl"],
|
|
products=["C(CO)Cl"],
|
|
rules=[rule],
|
|
multi_step=False,
|
|
)
|
|
|
|
r2 = Reaction.create(
|
|
package=self.package,
|
|
name="Eawag BBD reaction r0001",
|
|
educts=["C(CCl)Cl"],
|
|
products=["C(CO)Cl"],
|
|
rules=[rule],
|
|
multi_step=False,
|
|
)
|
|
|
|
# Check if create detects that this Compound already exist
|
|
# In this case the existing object should be returned
|
|
self.assertEqual(r1.pk, r2.pk)
|
|
self.assertEqual(len(self.package.reactions), 1)
|
|
|
|
def test_deduplication_without_rules(self):
|
|
r1 = Reaction.create(
|
|
package=self.package,
|
|
name="Eawag BBD reaction r0001",
|
|
educts=["C(CCl)Cl"],
|
|
products=["C(CO)Cl"],
|
|
multi_step=False,
|
|
)
|
|
|
|
r2 = Reaction.create(
|
|
package=self.package,
|
|
name="Eawag BBD reaction r0001",
|
|
educts=["C(CCl)Cl"],
|
|
products=["C(CO)Cl"],
|
|
multi_step=False,
|
|
)
|
|
|
|
# Check if create detects that this Compound already exist
|
|
# In this case the existing object should be returned
|
|
self.assertEqual(r1.pk, r2.pk)
|
|
self.assertEqual(len(self.package.reactions), 1)
|
|
|
|
def test_wrong_smiles(self):
|
|
with self.assertRaises(ValueError):
|
|
_ = Reaction.create(
|
|
package=self.package,
|
|
name="Eawag BBD reaction r0001",
|
|
educts=["ASDF"],
|
|
products=["C(CO)Cl"],
|
|
multi_step=False,
|
|
)
|
|
|
|
def test_delete(self):
|
|
r = Reaction.create(
|
|
package=self.package,
|
|
name="Eawag BBD reaction r0001",
|
|
educts=["C(CCl)Cl"],
|
|
products=["C(CO)Cl"],
|
|
multi_step=False,
|
|
)
|
|
|
|
r.delete()
|
|
|
|
self.assertEqual(Reaction.objects.filter(package=self.package).count(), 0)
|