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>
191 lines
8.2 KiB
Python
191 lines
8.2 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
|
|
|
|
|
|
@override_settings(MODEL_DIR=s.FIXTURE_DIRS[0] / "models", CELERY_TASK_ALWAYS_EAGER=True)
|
|
class CopyTest(TestCase):
|
|
fixtures = ["test_fixtures_incl_model.jsonl.gz"]
|
|
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
super(CopyTest, cls).setUpClass()
|
|
cls.user = User.objects.get(username="anonymous")
|
|
cls.package = PackageManager.create_package(cls.user, "Source Package", "No Desc")
|
|
cls.AFOXOLANER = Compound.create(
|
|
cls.package,
|
|
smiles="C1C(=NOC1(C2=CC(=CC(=C2)Cl)C(F)(F)F)C(F)(F)F)C3=CC=C(C4=CC=CC=C43)C(=O)NCC(=O)NCC(F)(F)F",
|
|
name="Afoxolaner",
|
|
description="Test compound for copying",
|
|
)
|
|
|
|
cls.FOUR_NITROBENZOIC_ACID = Compound.create(
|
|
cls.package,
|
|
smiles="[O-][N+](=O)c1ccc(C(=O)[O-])cc1", # Normalized: O=C(O)C1=CC=C([N+](=O)[O-])C=C1',
|
|
name="Test Compound",
|
|
description="Compound with multiple structures",
|
|
)
|
|
|
|
cls.ETHANOL = Compound.create(
|
|
cls.package, smiles="CCO", name="Ethanol", description="Simple alcohol"
|
|
)
|
|
cls.target_package = PackageManager.create_package(cls.user, "Target Package", "No Desc")
|
|
|
|
cls.reaction_educt = Compound.create(
|
|
cls.package,
|
|
smiles="C(CCl)Cl",
|
|
name="1,2-Dichloroethane",
|
|
description="Eawag BBD compound c0001",
|
|
).default_structure
|
|
|
|
cls.reaction_product = Compound.create(
|
|
cls.package,
|
|
smiles="C(CO)Cl",
|
|
name="2-Chloroethanol",
|
|
description="Eawag BBD compound c0005",
|
|
).default_structure
|
|
|
|
cls.REACTION = Reaction.create(
|
|
package=cls.package,
|
|
name="Eawag BBD reaction r0001",
|
|
educts=[cls.reaction_educt],
|
|
products=[cls.reaction_product],
|
|
multi_step=False,
|
|
)
|
|
|
|
def test_compound_copy_basic(self):
|
|
"""Test basic compound copying functionality"""
|
|
mapping = dict()
|
|
copied_compound = self.AFOXOLANER.copy(self.target_package, mapping)
|
|
|
|
self.assertNotEqual(self.AFOXOLANER.uuid, copied_compound.uuid)
|
|
self.assertEqual(self.AFOXOLANER.name, copied_compound.name)
|
|
self.assertEqual(self.AFOXOLANER.description, copied_compound.description)
|
|
self.assertEqual(copied_compound.package, self.target_package)
|
|
self.assertEqual(self.AFOXOLANER.package, self.package)
|
|
self.assertEqual(
|
|
self.AFOXOLANER.default_structure.smiles, copied_compound.default_structure.smiles
|
|
)
|
|
|
|
def test_compound_copy_with_multiple_structures(self):
|
|
"""Test copying a compound with multiple structures"""
|
|
|
|
original_structure_count = self.FOUR_NITROBENZOIC_ACID.structures.count()
|
|
|
|
mapping = dict()
|
|
# Copy the compound
|
|
copied_compound = self.FOUR_NITROBENZOIC_ACID.copy(self.target_package, mapping)
|
|
|
|
# Verify all structures were copied
|
|
self.assertEqual(copied_compound.structures.count(), original_structure_count)
|
|
|
|
# Verify default_structure is properly set
|
|
self.assertIsNotNone(copied_compound.default_structure)
|
|
self.assertEqual(
|
|
copied_compound.default_structure.smiles,
|
|
self.FOUR_NITROBENZOIC_ACID.default_structure.smiles,
|
|
)
|
|
|
|
def test_compound_copy_preserves_aliases(self):
|
|
"""Test that compound copying preserves aliases"""
|
|
# Create a compound and add aliases
|
|
original_compound = self.ETHANOL
|
|
|
|
# Add aliases if the method exists
|
|
if hasattr(original_compound, "add_alias"):
|
|
original_compound.add_alias("Ethyl alcohol")
|
|
original_compound.add_alias("Grain alcohol")
|
|
|
|
mapping = dict()
|
|
copied_compound = original_compound.copy(self.target_package, mapping)
|
|
|
|
# Verify aliases were copied if they exist
|
|
if hasattr(original_compound, "aliases") and hasattr(copied_compound, "aliases"):
|
|
original_aliases = original_compound.aliases
|
|
copied_aliases = copied_compound.aliases
|
|
self.assertEqual(original_aliases, copied_aliases)
|
|
|
|
def test_compound_copy_preserves_external_identifiers(self):
|
|
"""Test that external identifiers are preserved during copying"""
|
|
original_compound = self.ETHANOL
|
|
|
|
# Add external identifiers if the methods exist
|
|
if hasattr(original_compound, "add_cas_number"):
|
|
original_compound.add_cas_number("64-17-5")
|
|
if hasattr(original_compound, "add_pubchem_compound_id"):
|
|
original_compound.add_pubchem_compound_id("702")
|
|
|
|
mapping = dict()
|
|
copied_compound = original_compound.copy(self.target_package, mapping)
|
|
|
|
# Verify external identifiers were copied
|
|
original_ext_ids = original_compound.external_identifiers.all()
|
|
copied_ext_ids = copied_compound.external_identifiers.all()
|
|
|
|
self.assertEqual(original_ext_ids.count(), copied_ext_ids.count())
|
|
|
|
# Check that identifier values match
|
|
original_values = set(ext_id.identifier_value for ext_id in original_ext_ids)
|
|
copied_values = set(ext_id.identifier_value for ext_id in copied_ext_ids)
|
|
self.assertEqual(original_values, copied_values)
|
|
|
|
def test_compound_copy_structure_properties(self):
|
|
"""Test that structure properties are properly copied"""
|
|
original_compound = self.ETHANOL
|
|
|
|
mapping = dict()
|
|
copied_compound = original_compound.copy(self.target_package, mapping)
|
|
|
|
# Verify structure properties
|
|
original_structure = original_compound.default_structure
|
|
copied_structure = copied_compound.default_structure
|
|
|
|
self.assertEqual(original_structure.smiles, copied_structure.smiles)
|
|
self.assertEqual(original_structure.canonical_smiles, copied_structure.canonical_smiles)
|
|
self.assertEqual(original_structure.inchikey, copied_structure.inchikey)
|
|
self.assertEqual(
|
|
original_structure.normalized_structure, copied_structure.normalized_structure
|
|
)
|
|
|
|
# Verify they are different objects
|
|
self.assertNotEqual(original_structure.uuid, copied_structure.uuid)
|
|
self.assertEqual(copied_structure.compound, copied_compound)
|
|
|
|
def test_reaction_copy_basic(self):
|
|
"""Test basic reaction copying functionality"""
|
|
mapping = dict()
|
|
copied_reaction = self.REACTION.copy(self.target_package, mapping)
|
|
|
|
self.assertNotEqual(self.REACTION.uuid, copied_reaction.uuid)
|
|
self.assertEqual(self.REACTION.name, copied_reaction.name)
|
|
self.assertEqual(self.REACTION.description, copied_reaction.description)
|
|
self.assertEqual(self.REACTION.multi_step, copied_reaction.multi_step)
|
|
self.assertEqual(copied_reaction.package, self.target_package)
|
|
self.assertEqual(self.REACTION.package, self.package)
|
|
|
|
def test_reaction_copy_structures(self):
|
|
"""Test basic reaction copying functionality"""
|
|
mapping = dict()
|
|
copied_reaction = self.REACTION.copy(self.target_package, mapping)
|
|
|
|
for orig_educt, copy_educt in zip(self.REACTION.educts.all(), copied_reaction.educts.all()):
|
|
self.assertNotEqual(orig_educt.uuid, copy_educt.uuid)
|
|
self.assertEqual(orig_educt.name, copy_educt.name)
|
|
self.assertEqual(orig_educt.description, copy_educt.description)
|
|
self.assertEqual(copy_educt.compound.package, self.target_package)
|
|
self.assertEqual(orig_educt.compound.package, self.package)
|
|
self.assertEqual(orig_educt.smiles, copy_educt.smiles)
|
|
|
|
for orig_product, copy_product in zip(
|
|
self.REACTION.products.all(), copied_reaction.products.all()
|
|
):
|
|
self.assertNotEqual(orig_product.uuid, copy_product.uuid)
|
|
self.assertEqual(orig_product.name, copy_product.name)
|
|
self.assertEqual(orig_product.description, copy_product.description)
|
|
self.assertEqual(copy_product.compound.package, self.target_package)
|
|
self.assertEqual(orig_product.compound.package, self.package)
|
|
self.assertEqual(orig_product.smiles, copy_product.smiles)
|