diff --git a/ippisite/ippidb/models.py b/ippisite/ippidb/models.py index a94fc95e3785f9ee80671bae19e9ecb177c826ec..429dc911a293c62f9c6afb70302ea6e74d462c89 100644 --- a/ippisite/ippidb/models.py +++ b/ippisite/ippidb/models.py @@ -1345,7 +1345,7 @@ class Contribution(models.Model): return reverse('contribution-detail', kwargs={'contribution_pk': self.pk}) def update_compound_cached_properties(): - return Compound.objects.update( + Compound.objects.update( pubs=Subquery( Compound.objects.filter( id=OuterRef('id') @@ -1409,21 +1409,6 @@ def update_compound_cached_properties(): _lipinsky_a_log_p=Case(When(a_log_p__lte=5, then=True), default=False, output_field=BooleanField()) ).values('_lipinsky_a_log_p')[:1] ), - lipinsky_score=Subquery( - Compound.objects.filter( - id=OuterRef('id') - ).annotate( - _lipinsky_score=Cast(F('lipinsky_mw'), IntegerField()) + Cast(F('lipinsky_hba'), IntegerField()) + - Cast(F('lipinsky_hbd'), IntegerField()) + Cast(F('lipinsky_a_log_p'), IntegerField()) - ).values('_lipinsky_score')[:1] - ), - lipinsky=Subquery( - Compound.objects.filter( - id=OuterRef('id') - ).annotate( - _lipinsky=Case(When(lipinsky_score__gte=3, then=True), default=False, output_field=BooleanField()) - ).values('_lipinsky')[:1] - ), hba_hbd=Subquery( Compound.objects.filter( id=OuterRef('id') @@ -1431,13 +1416,6 @@ def update_compound_cached_properties(): _hba_hbd=F('nb_acceptor_h')+F('nb_donor_h'), ).values('_hba_hbd')[:1] ), - veber_hba_hbd=Subquery( - Compound.objects.filter( - id=OuterRef('id') - ).annotate( - _veber_hba_hbd=Case(When(hba_hbd__lte=12, then=True), default=False, output_field=BooleanField()), - ).values('_veber_hba_hbd')[:1] - ), veber_tpsa=Subquery( Compound.objects.filter( id=OuterRef('id') @@ -1452,13 +1430,6 @@ def update_compound_cached_properties(): _veber_rb=Case(When(nb_rotatable_bonds__lte=10, then=True), default=False, output_field=BooleanField()), ).values('_veber_rb')[:1] ), - veber=Subquery( - Compound.objects.filter( - id=OuterRef('id') - ).annotate( - _veber=Case(When(Q(Q(nb_rotatable_bonds__lte=10) & (Q(hba_hbd__lte=12) | Q(tpsa__lte=140))), then=True), default=False, output_field=BooleanField()), - ).values('_veber')[:1] - ), pfizer_a_log_p=Subquery( Compound.objects.filter( id=OuterRef('id') @@ -1564,4 +1535,37 @@ def update_compound_cached_properties(): _tests_av=Count('compoundactivityresult', distinct=True), ).values('_tests_av')[:1] ) + ) + Compound.objects.update( + lipinsky_score=Subquery( + Compound.objects.filter( + id=OuterRef('id') + ).annotate( + _lipinsky_score=Cast(F('lipinsky_mw'), IntegerField()) + Cast(F('lipinsky_hba'), IntegerField()) + + Cast(F('lipinsky_hbd'), IntegerField()) + Cast(F('lipinsky_a_log_p'), IntegerField()) + ).values('_lipinsky_score')[:1] + ), + veber_hba_hbd=Subquery( + Compound.objects.filter( + id=OuterRef('id') + ).annotate( + _veber_hba_hbd=Case(When(hba_hbd__lte=12, then=True), default=False, output_field=BooleanField()), + ).values('_veber_hba_hbd')[:1] + ), + veber=Subquery( + Compound.objects.filter( + id=OuterRef('id') + ).annotate( + _veber=Case(When(Q(Q(nb_rotatable_bonds__lte=10) & (Q(hba_hbd__lte=12) | Q(tpsa__lte=140))), then=True), default=False, output_field=BooleanField()), + ).values('_veber')[:1] + ), + ) + return Compound.objects.update( + lipinsky=Subquery( + Compound.objects.filter( + id=OuterRef('id') + ).annotate( + _lipinsky=Case(When(lipinsky_score__gte=3, then=True), default=False, output_field=BooleanField()) + ).values('_lipinsky')[:1] + ), ) \ No newline at end of file