diff --git a/wwpdb/utils/nmr/ann/OneDepAnnTasks.py b/wwpdb/utils/nmr/ann/OneDepAnnTasks.py index b8f87ed2..c185178c 100644 --- a/wwpdb/utils/nmr/ann/OneDepAnnTasks.py +++ b/wwpdb/utils/nmr/ann/OneDepAnnTasks.py @@ -2187,16 +2187,20 @@ def replace_none(array, default: str = '.'): # merge categories of model file as secondary source of NMRIF if cR is not None: - existing_categories, target_categories = [], [] - - for categories in cifObj.getCategoryNameList(self.__entryId): - existing_categories.extend(categories) + primary_categories = cifObj.getCategoryNameList(self.__entryId) + secondary_categories = cR.getCategoryNameList() + target_categories = [] for cif_page in self.__cifPages: - if not any(cif_category in existing_categories for cif_category in self.__cifRequirements[cif_page]): + if not any(cif_category in primary_categories for cif_category in self.__cifRequirements[cif_page]): for cif_category in self.__cifRequirements[cif_page]: if cif_category not in target_categories: target_categories.append(cif_category) + else: + for cif_category in self.__cifRequirements[cif_page]: + if cif_category not in primary_categories and cif_category in secondary_categories: + if cif_category not in target_categories: + target_categories.append(cif_category) if len(target_categories) > 0: for cif_category in target_categories: diff --git a/wwpdb/utils/nmr/io/CifReader.py b/wwpdb/utils/nmr/io/CifReader.py index ea460051..e71a7699 100644 --- a/wwpdb/utils/nmr/io/CifReader.py +++ b/wwpdb/utils/nmr/io/CifReader.py @@ -441,17 +441,23 @@ def getDataBlock(self, blockId: Optional[str] = None) -> Optional[DataContainer] return dBlock if self.__setDataBlock(dBlock) else None - def hasCategory(self, catName: str, blockId: Optional[str] = None) -> bool: - """ Return whether a given category exists. + def getCategoryNameList(self, blockId: Optional[str] = None) -> List[str]: + """ Return all category names in a given datablock. """ if blockId is not None and self.__dBlock is not None and self.__dBlock.getName() != blockId: self.__setDataBlock(self.getDataBlock(blockId)) if self.__dBlock is None: - return False + return [] + + return self.__dBlock.getObjNameList() + + def hasCategory(self, catName: str, blockId: Optional[str] = None) -> bool: + """ Return whether a given category exists. + """ - return catName in self.__dBlock.getObjNameList() + return catName in self.getCategoryNameList(blockId) def hasItem(self, catName: str, itName: str, blockId: Optional[str] = None) -> bool: """ Return whether a given item exists in a category. diff --git a/wwpdb/utils/nmr/io/mmCIFUtil.py b/wwpdb/utils/nmr/io/mmCIFUtil.py index 45cc8c60..0695cf72 100644 --- a/wwpdb/utils/nmr/io/mmCIFUtil.py +++ b/wwpdb/utils/nmr/io/mmCIFUtil.py @@ -398,6 +398,12 @@ def getCategoryNameList(self, blockName: str, ext: int = 1) -> List[str]: return self.__dBlockList[self.__dBlockMap[get_ext_block_name(blockName, ext)]].getObjNameList() + def hasCategory(self, blockName: str, catName: str, ext: int = 1) -> bool: + """ Return whether a given category exists. + """ + + return catName in self.getCategoryNameList(blockName, ext) + def getAttributeList(self, blockName: str, catName: str, ext: int = 1) -> List[str]: """ Get item names in given datablock and category. """ @@ -412,6 +418,12 @@ def getAttributeList(self, blockName: str, catName: str, ext: int = 1) -> List[s return catObj.getAttributeList() + def hasItem(self, blockName: str, catName: str, itName: str, ext: int = 1) -> bool: + """ Return whether a given item exists in a category. + """ + + return itName in self.getAttributeList(blockName, catName, ext) + def getRowLength(self, blockName: str, catName: str, ext: int = 1) -> int: """ Return length of rows of a given datablock and category. """