@@ -1059,11 +1059,11 @@ def process_canon_site_conf(
1059
1059
"canon_site" : canon_site ,
1060
1060
}
1061
1061
1062
- # members = extract(key="members")
1062
+ members = extract (key = "members" )
1063
1063
ref_ligands = extract (key = "reference_ligand_id" )
1064
1064
1065
1065
index_fields = {
1066
- # "members": members,
1066
+ "members" : members ,
1067
1067
"reference_ligands" : ref_ligands ,
1068
1068
}
1069
1069
@@ -1518,24 +1518,51 @@ def process_bundle(self):
1518
1518
canon_site_confs = canon_site_conf_objects ,
1519
1519
)
1520
1520
1521
- tag_categories = (
1522
- "ConformerSites" ,
1523
- "CanonSites" ,
1524
- "XtalformSites" ,
1525
- "Quatassemblies" ,
1526
- "Xtalforms" ,
1527
- )
1528
-
1529
- for cat in tag_categories :
1530
- self ._tag_site_observations (site_observation_objects , cat )
1531
-
1532
1521
# final remaining fk, attach reference site observation to canon_site_conf
1533
1522
for val in canon_site_conf_objects .values (): # pylint: disable=no-member
1534
1523
val .instance .ref_site_observation = site_observation_objects [
1535
1524
val .index_data ["reference_ligands" ]
1536
1525
].instance
1537
1526
val .instance .save ()
1538
1527
1528
+ # tag site observations
1529
+ for val in canon_site_conf_objects .values (): # pylint: disable=no-member
1530
+ tag = "conf_site: " + "," .join (val .instance .residues [:3 ])
1531
+ so_list = [
1532
+ site_observation_objects [k ].instance for k in val .index_data ["members" ]
1533
+ ]
1534
+ self ._tag_observations (tag , "ConformerSites" , so_list )
1535
+
1536
+ for val in canon_site_objects .values (): # pylint: disable=no-member
1537
+ tag = "canon_site: " + "," .join (val .instance .residues [:3 ])
1538
+ so_list = SiteObservation .objects .filter (
1539
+ canon_site_conf__canon_site = val .instance
1540
+ )
1541
+ self ._tag_observations (tag , "ConformerSites" , so_list )
1542
+
1543
+ for val in xtalform_sites_objects .values (): # pylint: disable=no-member
1544
+ tag = "xtalform_site: " + "," .join (val .instance .residues [:3 ])
1545
+ so_list = [
1546
+ site_observation_objects [k ].instance for k in val .index_data ["residues" ]
1547
+ ]
1548
+ self ._tag_observations (tag , "ConformerSites" , so_list )
1549
+
1550
+ for val in quat_assembly_objects .values (): # pylint: disable=no-member
1551
+ tag = "quatassembly: " + val .instance .name
1552
+ so_list = SiteObservation .objects .filter (
1553
+ xtalform_site__xtalform__in = XtalformQuatAssembly .objects .filter (
1554
+ quat_assembly = val .instance
1555
+ ).values ("xtalform" )
1556
+ )
1557
+ self ._tag_observations (tag , "ConformerSites" , so_list )
1558
+
1559
+ for val in xtalform_objects .values (): # pylint: disable=no-member
1560
+ tag = "xtalform: " + val .instance .name
1561
+ so_list = SiteObservation .objects .filter (
1562
+ xtalform_site__xtalform = val .instance
1563
+ )
1564
+ self ._tag_observations (tag , "ConformerSites" , so_list )
1565
+
1539
1566
def _load_yaml (self , yaml_file : Path ) -> dict | None :
1540
1567
contents = None
1541
1568
try :
@@ -1592,96 +1619,49 @@ def _extract(
1592
1619
1593
1620
return result
1594
1621
1595
- def _tag_site_observations (self , site_observation_objects , category ):
1596
- # this is an attempt to replicate tag creation from previous
1597
- # loader. as there are plenty of differences, I cannot just
1598
- # use the same functions..
1599
-
1600
- logger .debug ("Getting category %s" , category )
1601
- groups : Dict [str , Any ] = {}
1602
- for _ , obj in site_observation_objects .items ():
1603
- if category == "ConformerSites" :
1604
- tags = [
1605
- "conf_site: " + "," .join (obj .instance .canon_site_conf .residues [:3 ]),
1606
- ]
1607
- elif category == "CanonSites" :
1608
- tags = [
1609
- "canon_site: "
1610
- + "," .join (obj .instance .xtalform_site .canon_site .residues [:3 ]),
1611
- ]
1612
- elif category == "XtalformSites" :
1613
- tags = [
1614
- "xtalform_site: "
1615
- + "," .join (obj .instance .xtalform_site .residues [:3 ]),
1616
- ]
1617
- # tricky one. connected via m2m
1618
- elif category == "Quatassemblies" :
1619
- tags = [
1620
- "quatassembly: " + qa .name
1621
- for qa in obj .instance .xtalform_site .xtalform .quat_assembly .all ()
1622
- ]
1623
-
1624
- elif category == "Xtalforms" :
1625
- tags = [
1626
- "xtalform: " + obj .instance .xtalform_site .xtalform .name ,
1627
- ]
1628
- else :
1629
- tags = [
1630
- "Unspecified" ,
1631
- ]
1632
-
1633
- for tag in tags :
1634
- if tag not in groups .keys ():
1635
- groups [tag ] = [obj .instance ]
1636
- else :
1637
- groups [tag ].append (obj .instance )
1638
-
1639
- # I suspect I need to group them by site..
1640
- for tag , so_list in groups .items ():
1641
- try :
1642
- # memo to self: description is set to tag, but there's
1643
- # no fk to tag, instead, tag has a fk to
1644
- # group. There's no uniqueness requirement on
1645
- # description so there's no certainty that this will
1646
- # be unique (or remain searchable at all because user
1647
- # is allowed to change the tag name). this feels like
1648
- # poor design but I don't understand the principles of
1649
- # this system to know if that's indeed the case or if
1650
- # it is in fact a truly elegant solution
1651
- so_group = SiteObservationGroup .objects .get (
1652
- target = self .target , description = tag
1653
- )
1654
- except SiteObservationGroup .DoesNotExist :
1655
- assert self .target
1656
- so_group = SiteObservationGroup (target = self .target )
1657
- so_group .save ()
1658
- except MultipleObjectsReturned :
1659
- SiteObservationGroup .objects .filter (
1660
- target = self .target , description = tag
1661
- ).delete ()
1662
- assert self .target
1663
- so_group = SiteObservationGroup (target = self .target )
1664
- so_group .save ()
1622
+ def _tag_observations (self , tag , category , so_list ):
1623
+ try :
1624
+ # memo to self: description is set to tag, but there's
1625
+ # no fk to tag, instead, tag has a fk to
1626
+ # group. There's no uniqueness requirement on
1627
+ # description so there's no certainty that this will
1628
+ # be unique (or remain searchable at all because user
1629
+ # is allowed to change the tag name). this feels like
1630
+ # poor design but I don't understand the principles of
1631
+ # this system to know if that's indeed the case or if
1632
+ # it is in fact a truly elegant solution
1633
+ so_group = SiteObservationGroup .objects .get (
1634
+ target = self .target , description = tag
1635
+ )
1636
+ except SiteObservationGroup .DoesNotExist :
1637
+ assert self .target
1638
+ so_group = SiteObservationGroup (target = self .target )
1639
+ so_group .save ()
1640
+ except MultipleObjectsReturned :
1641
+ SiteObservationGroup .objects .filter (
1642
+ target = self .target , description = tag
1643
+ ).delete ()
1644
+ assert self .target
1645
+ so_group = SiteObservationGroup (target = self .target )
1646
+ so_group .save ()
1665
1647
1666
- try :
1667
- so_tag = SiteObservationTag .objects .get (tag = tag , target = self .target )
1668
- # Tag already exists
1669
- # Apart from the new mol_group and molecules, we shouldn't be
1670
- # changing anything.
1671
- so_tag .mol_group = so_group
1672
- except SiteObservationTag .DoesNotExist :
1673
- so_tag = SiteObservationTag ()
1674
- so_tag .tag = tag
1675
- so_tag .category = TagCategory .objects .get (category = category )
1676
- so_tag .target = self .target
1677
- so_tag .mol_group = so_group
1678
-
1679
- so_tag .save ()
1680
-
1681
- for site_obvs in so_list :
1682
- logger .debug ("site_obvs_id=%s" , site_obvs .id )
1683
- so_group .site_observation .add (site_obvs )
1684
- so_tag .site_observations .add (site_obvs )
1648
+ try :
1649
+ so_tag = SiteObservationTag .objects .get (tag = tag , target = self .target )
1650
+ # Tag already exists
1651
+ # Apart from the new mol_group and molecules, we shouldn't be
1652
+ # changing anything.
1653
+ so_tag .mol_group = so_group
1654
+ except SiteObservationTag .DoesNotExist :
1655
+ so_tag = SiteObservationTag ()
1656
+ so_tag .tag = tag
1657
+ so_tag .category = TagCategory .objects .get (category = category )
1658
+ so_tag .target = self .target
1659
+ so_tag .mol_group = so_group
1660
+
1661
+ so_tag .save ()
1662
+
1663
+ so_group .site_observation .add (* so_list )
1664
+ so_tag .site_observations .add (* so_list )
1685
1665
1686
1666
def _is_already_uploaded (self , target_created , project_created ):
1687
1667
if target_created or project_created :
0 commit comments