From 62a2de77729cc170314eb55e395d8308d9da8410 Mon Sep 17 00:00:00 2001 From: yokochi47 Date: Fri, 1 Mar 2024 20:58:02 +0900 Subject: [PATCH] Split implict ins_code of atom_site and allow safe retrieval from both auth and label sequence schemes (2kny) --- wwpdb/utils/nmr/NmrDpUtility.py | 106 +++++++++++- wwpdb/utils/nmr/mr/AmberMRParserListener.py | 58 +++---- wwpdb/utils/nmr/mr/AriaMRParserListener.py | 107 +++++++----- wwpdb/utils/nmr/mr/BiosymMRParserListener.py | 77 +++++---- wwpdb/utils/nmr/mr/CharmmMRParserListener.py | 99 ++++++----- wwpdb/utils/nmr/mr/CnsMRParserListener.py | 99 ++++++----- wwpdb/utils/nmr/mr/CyanaMRParserListener.py | 155 +++++++++++------- wwpdb/utils/nmr/mr/DynamoMRParserListener.py | 79 +++++---- wwpdb/utils/nmr/mr/IsdMRParserListener.py | 75 +++++---- wwpdb/utils/nmr/mr/ParserListenerUtil.py | 34 +++- wwpdb/utils/nmr/mr/RosettaMRParserListener.py | 18 +- wwpdb/utils/nmr/mr/SybylMRParserListener.py | 75 +++++---- wwpdb/utils/nmr/mr/XplorMRParserListener.py | 98 ++++++----- wwpdb/utils/nmr/mr/XplorMRReader.py | 5 + 14 files changed, 692 insertions(+), 393 deletions(-) diff --git a/wwpdb/utils/nmr/NmrDpUtility.py b/wwpdb/utils/nmr/NmrDpUtility.py index 7335494af..15ccc84fd 100644 --- a/wwpdb/utils/nmr/NmrDpUtility.py +++ b/wwpdb/utils/nmr/NmrDpUtility.py @@ -24959,7 +24959,111 @@ def fill_cs_row(lp, index, _row, prefer_auth_atom_name, coord_atom_site, _seq_ke else: resolved = False - if not resolved: + if not resolved and has_auth_seq and row[auth_asym_id_col] == 'UNMAPPED': # 2kny: leave data as is + + is_valid, cc_name, _ = self.__getChemCompNameAndStatusOf(comp_id) + comp_id_bmrb_only = not is_valid and cc_name is not None and 'processing site' in cc_name + + chain_id = row[chain_id_col] + if chain_id in emptyValue: + chain_id = 'A' + + if chain_id in copied_chain_ids: + continue + + entity_id = None + if (self.__combined_mode or (self.__bmrb_only and self.__internal_mode)) and entity_id_col != -1: + try: + entity_id = int(row[entity_id_col]) + except (ValueError, TypeError): + entity_id = None + + seq_id = auth_seq_id + + _row[1], _row[2], _row[3], _row[4], _row[5] = chain_id, entity_id, seq_id, seq_id, comp_id + + # DAOTHER-9065 + if details_col != -1 and row[details_col] == 'UNMAPPED': + if isinstance(_row[1], int) and str(_row[1]) in seq_id_offset_for_unmapped: + offset = None + if isinstance(_row[17], int): + offset = _row[3] - _row[17] + elif isinstance(_row[17], str) and _row[17].isdigit(): + offset = _row[3] - int(_row[17]) + if offset is not None and offset != seq_id_offset_for_unmapped[str(_row[1])]: + if isinstance(_row[17], int): + _row[3] = _row[17] + seq_id_offset_for_unmapped[str(_row[1])] + _row[4] = _row[3] + else: + _row[3] = int(_row[17]) + seq_id_offset_for_unmapped[str(_row[1])] + _row[4] = _row[3] + elif isinstance(_row[1], str) and _row[1] in seq_id_offset_for_unmapped: + offset = None + if isinstance(_row[17], int): + offset = _row[3] - _row[17] + elif isinstance(_row[17], str) and _row[17].isdigit(): + offset = _row[3] - int(_row[17]) + if offset is not None and offset != seq_id_offset_for_unmapped[_row[1]]: + if isinstance(_row[17], int): + _row[3] = _row[17] + seq_id_offset_for_unmapped[_row[1]] + _row[4] = _row[3] + else: + _row[3] = int(_row[17]) + seq_id_offset_for_unmapped[_row[1]] + _row[4] = _row[3] + elif trial == 0: + regenerate_request = True + + atom_ids = self.__getAtomIdListInXplor(comp_id, atom_id) + if len(atom_ids) == 0 or atom_ids[0] not in self.__csStat.getAllAtoms(comp_id): + atom_ids = self.__getAtomIdListInXplor(comp_id, translateToStdAtomName(atom_id, comp_id, ccU=self.__ccU)) + len_atom_ids = len(atom_ids) + if len_atom_ids == 0 or comp_id_bmrb_only: + _row[6] = atom_id + _row[7] = 'H' if atom_id[0] in pseProBeginCode else atom_id[0] + if _row[7] in ISOTOPE_NUMBERS_OF_NMR_OBS_NUCS: + _row[8] = ISOTOPE_NUMBERS_OF_NMR_OBS_NUCS[_row[7]][0] + else: + _row[6] = atom_ids[0] + _row[19] = None + fill_auth_atom_id = _row[18] not in emptyValue + if self.__ccU.updateChemCompDict(comp_id): + cca = next((cca for cca in self.__ccU.lastAtomList if cca[self.__ccU.ccaAtomId] == _row[6]), None) + if cca is not None: + _row[7] = cca[self.__ccU.ccaTypeSymbol] + if _row[7] in ISOTOPE_NUMBERS_OF_NMR_OBS_NUCS: + _row[8] = ISOTOPE_NUMBERS_OF_NMR_OBS_NUCS[_row[7]][0] + else: + _row[7] = 'H' if _row[6][0] in protonBeginCode else atom_id[0] + if _row[7] in ISOTOPE_NUMBERS_OF_NMR_OBS_NUCS: + _row[8] = ISOTOPE_NUMBERS_OF_NMR_OBS_NUCS[_row[7]][0] + else: + _row[7] = 'H' if atom_id[0] in pseProBeginCode else atom_id[0] + if _row[7] in ISOTOPE_NUMBERS_OF_NMR_OBS_NUCS: + _row[8] = ISOTOPE_NUMBERS_OF_NMR_OBS_NUCS[_row[7]][0] + + if len_atom_ids > 1: + __row = copy.copy(_row) + lp.add_data(__row) + + for _atom_id in atom_ids[1:-1]: + __row = copy.copy(_row) + + index += 1 + + __row[0] = index + __row[6] = _atom_id + + lp.add_data(__row) + + index += 1 + + _row[0] = index + _row[6] = atom_ids[-1] + + if fill_auth_atom_id: + _row[19] = _row[6] + + elif not resolved: chain_id = row[chain_id_col] if chain_id in emptyValue: diff --git a/wwpdb/utils/nmr/mr/AmberMRParserListener.py b/wwpdb/utils/nmr/mr/AmberMRParserListener.py index 68f440438..5074ddebf 100644 --- a/wwpdb/utils/nmr/mr/AmberMRParserListener.py +++ b/wwpdb/utils/nmr/mr/AmberMRParserListener.py @@ -3856,7 +3856,7 @@ def getAtomNumberDictFromAmbmaskInfo(self, seqId, atomId, order=0, enableWarning compId = ps['comp_id'][idx] cifSeqId = None if useDefault and not enforceAuthSeq else ps['seq_id'][ps['auth_seq_id'].index(seqId)] - seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId if cifSeqId is None else cifSeqId, cifCheck, + seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId if cifSeqId is None else cifSeqId, cifCheck=cifCheck, asis=(not hasAuthSeqScheme or enforceAuthSeq or not self.__preferAuthSeq)) if compId not in monDict3 and self.__mrAtomNameMapping is not None: @@ -3889,7 +3889,7 @@ def getAtomNumberDictFromAmbmaskInfo(self, seqId, atomId, order=0, enableWarning found = True self.__authAtomId = 'auth_atom_id' elif self.__preferAuthSeq: - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId if cifSeqId is None else cifSeqId, cifCheck, asis=False) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId if cifSeqId is None else cifSeqId, cifCheck=cifCheck, asis=False) if _coordAtomSite is not None: if _atomId in _coordAtomSite['atom_id']: found = True @@ -3904,7 +3904,7 @@ def getAtomNumberDictFromAmbmaskInfo(self, seqId, atomId, order=0, enableWarning seqKey = _seqKey elif self.__preferAuthSeq: - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId if cifSeqId is None else cifSeqId, cifCheck, asis=False) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId if cifSeqId is None else cifSeqId, cifCheck=cifCheck, asis=False) if _coordAtomSite is not None: if _atomId in _coordAtomSite['atom_id']: found = True @@ -4012,7 +4012,7 @@ def getAtomNumberDictFromAmbmaskInfo(self, seqId, atomId, order=0, enableWarning idx = ps['seq_id'].index(seqId) compId = ps['comp_id'][idx] - seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck) + seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck=cifCheck) if compId not in monDict3 and self.__mrAtomNameMapping is not None: origCompId = ps['auth_comp_id'][idx] @@ -4044,7 +4044,7 @@ def getAtomNumberDictFromAmbmaskInfo(self, seqId, atomId, order=0, enableWarning found = True self.__authAtomId = 'auth_atom_id' elif self.__preferAuthSeq: - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck, asis=False) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck=cifCheck, asis=False) if _coordAtomSite is not None: if _atomId in _coordAtomSite['atom_id']: found = True @@ -4059,7 +4059,7 @@ def getAtomNumberDictFromAmbmaskInfo(self, seqId, atomId, order=0, enableWarning seqKey = _seqKey elif self.__preferAuthSeq: - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck, asis=False) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck=cifCheck, asis=False) if _coordAtomSite is not None: if _atomId in _coordAtomSite['atom_id']: found = True @@ -4266,7 +4266,7 @@ def updateSanderAtomNumberDict(self, factor, cifCheck=True, useDefault=True): if (((authCompId in (compId, origCompId, 'None') or compId not in monDict3) and useDefault) or not useDefault)\ or compId == translateToStdResName(authCompId, compId, self.__ccU): - seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId if cifSeqId is None else cifSeqId, cifCheck, + seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId if cifSeqId is None else cifSeqId, cifCheck=cifCheck, asis=(not hasAuthSeqScheme or enforceAuthSeq or not self.__preferAuthSeq)) if coordAtomSite is not None and _authAtomId in coordAtomSite['atom_id']: authAtomId = _authAtomId @@ -4307,7 +4307,7 @@ def updateSanderAtomNumberDict(self, factor, cifCheck=True, useDefault=True): found = True self.__authAtomId = 'auth_atom_id' elif self.__preferAuthSeq: - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId if cifSeqId is None else cifSeqId, cifCheck, asis=False) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId if cifSeqId is None else cifSeqId, cifCheck=cifCheck, asis=False) if _coordAtomSite is not None: if _atomId in _coordAtomSite['atom_id']: found = True @@ -4322,7 +4322,7 @@ def updateSanderAtomNumberDict(self, factor, cifCheck=True, useDefault=True): seqKey = _seqKey elif self.__preferAuthSeq: - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId if cifSeqId is None else cifSeqId, cifCheck, asis=False) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId if cifSeqId is None else cifSeqId, cifCheck=cifCheck, asis=False) if _coordAtomSite is not None: if _atomId in _coordAtomSite['atom_id']: found = True @@ -4415,7 +4415,7 @@ def updateSanderAtomNumberDict(self, factor, cifCheck=True, useDefault=True): found = True self.__authAtomId = 'auth_atom_id' elif self.__preferAuthSeq: - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId if cifSeqId is None else cifSeqId, cifCheck, asis=False) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId if cifSeqId is None else cifSeqId, cifCheck=cifCheck, asis=False) if _coordAtomSite is not None: if _atomId in _coordAtomSite['atom_id']: found = True @@ -4430,7 +4430,7 @@ def updateSanderAtomNumberDict(self, factor, cifCheck=True, useDefault=True): seqKey = _seqKey elif self.__preferAuthSeq: - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId if cifSeqId is None else cifSeqId, cifCheck, asis=False) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId if cifSeqId is None else cifSeqId, cifCheck=cifCheck, asis=False) if _coordAtomSite is not None: if _atomId in _coordAtomSite['atom_id']: found = True @@ -4518,7 +4518,7 @@ def updateSanderAtomNumberDict(self, factor, cifCheck=True, useDefault=True): authCompId = factor['auth_comp_id'].upper() if 'auth_comp_id' in factor else 'None' authAtomId = factor['auth_atom_id'].upper() - seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck) + seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck=cifCheck) if compId not in monDict3 and self.__mrAtomNameMapping is not None: _, _, authAtomId = retrieveAtomIdentFromMRMap(self.__mrAtomNameMapping, seqId, authCompId, authAtomId, compId, coordAtomSite) @@ -4556,7 +4556,7 @@ def updateSanderAtomNumberDict(self, factor, cifCheck=True, useDefault=True): found = True self.__authAtomId = 'auth_atom_id' elif self.__preferAuthSeq: - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck, asis=False) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck=cifCheck, asis=False) if _coordAtomSite is not None: if _atomId in _coordAtomSite['atom_id']: found = True @@ -4571,7 +4571,7 @@ def updateSanderAtomNumberDict(self, factor, cifCheck=True, useDefault=True): seqKey = _seqKey elif self.__preferAuthSeq: - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck, asis=False) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck=cifCheck, asis=False) if _coordAtomSite is not None: if _atomId in _coordAtomSite['atom_id']: found = True @@ -4657,7 +4657,7 @@ def updateSanderAtomNumberDict(self, factor, cifCheck=True, useDefault=True): found = True self.__authAtomId = 'auth_atom_id' elif self.__preferAuthSeq: - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck, asis=False) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck=cifCheck, asis=False) if _coordAtomSite is not None: if _atomId in _coordAtomSite['atom_id']: found = True @@ -4672,7 +4672,7 @@ def updateSanderAtomNumberDict(self, factor, cifCheck=True, useDefault=True): seqKey = _seqKey elif self.__preferAuthSeq: - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck, asis=False) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck=cifCheck, asis=False) if _coordAtomSite is not None: if _atomId in _coordAtomSite['atom_id']: found = True @@ -4879,7 +4879,7 @@ def updateSanderAtomNumberDictWithAmbigCode(self, factor, cifCheck=True, useDefa if (((authCompId in (compId, origCompId, 'None') or compId not in monDict3) and useDefault) or not useDefault)\ or compId == translateToStdResName(authCompId, compId, self.__ccU): - seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId if cifSeqId is None else cifSeqId, cifCheck, + seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId if cifSeqId is None else cifSeqId, cifCheck=cifCheck, asis=(not hasAuthSeqScheme or enforceAuthSeq or not self.__preferAuthSeq)) if coordAtomSite is not None and _authAtomId_ in coordAtomSite['atom_id']: authAtomId = _authAtomId_ @@ -4904,7 +4904,7 @@ def updateSanderAtomNumberDictWithAmbigCode(self, factor, cifCheck=True, useDefa found = True self.__authAtomId = 'auth_atom_id' elif self.__preferAuthSeq: - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId if cifSeqId is None else cifSeqId, cifCheck, asis=False) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId if cifSeqId is None else cifSeqId, cifCheck=cifCheck, asis=False) if _coordAtomSite is not None: if _atomId in _coordAtomSite['atom_id']: found = True @@ -4919,7 +4919,7 @@ def updateSanderAtomNumberDictWithAmbigCode(self, factor, cifCheck=True, useDefa seqKey = _seqKey elif self.__preferAuthSeq: - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId if cifSeqId is None else cifSeqId, cifCheck, asis=False) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId if cifSeqId is None else cifSeqId, cifCheck=cifCheck, asis=False) if _coordAtomSite is not None: if _atomId in _coordAtomSite['atom_id']: found = True @@ -5004,7 +5004,7 @@ def updateSanderAtomNumberDictWithAmbigCode(self, factor, cifCheck=True, useDefa found = True self.__authAtomId = 'auth_atom_id' elif self.__preferAuthSeq: - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId if cifSeqId is None else cifSeqId, cifCheck, asis=False) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId if cifSeqId is None else cifSeqId, cifCheck=cifCheck, asis=False) if _coordAtomSite is not None: if _atomId in _coordAtomSite['atom_id']: found = True @@ -5019,7 +5019,7 @@ def updateSanderAtomNumberDictWithAmbigCode(self, factor, cifCheck=True, useDefa seqKey = _seqKey elif self.__preferAuthSeq: - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId if cifSeqId is None else cifSeqId, cifCheck, asis=False) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId if cifSeqId is None else cifSeqId, cifCheck=cifCheck, asis=False) if _coordAtomSite is not None: if _atomId in _coordAtomSite['atom_id']: found = True @@ -5092,7 +5092,7 @@ def updateSanderAtomNumberDictWithAmbigCode(self, factor, cifCheck=True, useDefa seqId = np['seq_id'][idx] compId = np['comp_id'][idx] - seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck) + seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck=cifCheck) if compId not in monDict3 and self.__mrAtomNameMapping is not None: origCompId = np['auth_comp_id'][idx] @@ -5118,7 +5118,7 @@ def updateSanderAtomNumberDictWithAmbigCode(self, factor, cifCheck=True, useDefa found = True self.__authAtomId = 'auth_atom_id' elif self.__preferAuthSeq: - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck, asis=False) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck=cifCheck, asis=False) if _coordAtomSite is not None: if _atomId in _coordAtomSite['atom_id']: found = True @@ -5133,7 +5133,7 @@ def updateSanderAtomNumberDictWithAmbigCode(self, factor, cifCheck=True, useDefa seqKey = _seqKey elif self.__preferAuthSeq: - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck, asis=False) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck=cifCheck, asis=False) if _coordAtomSite is not None: if _atomId in _coordAtomSite['atom_id']: found = True @@ -5219,7 +5219,7 @@ def updateSanderAtomNumberDictWithAmbigCode(self, factor, cifCheck=True, useDefa found = True self.__authAtomId = 'auth_atom_id' elif self.__preferAuthSeq: - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck, asis=False) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck=cifCheck, asis=False) if _coordAtomSite is not None: if _atomId in _coordAtomSite['atom_id']: found = True @@ -5234,7 +5234,7 @@ def updateSanderAtomNumberDictWithAmbigCode(self, factor, cifCheck=True, useDefa seqKey = _seqKey elif self.__preferAuthSeq: - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck, asis=False) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck=cifCheck, asis=False) if _coordAtomSite is not None: if _atomId in _coordAtomSite['atom_id']: found = True @@ -9037,7 +9037,7 @@ def assignCoordPolymerSequenceWithoutCompId(self, seqId, atomId=None): _seqId = seqId for ps in self.__polySeq: - chainId, seqId = self.getRealChainSeqId(ps, _seqId, None) + chainId, seqId = self.getRealChainSeqId(ps, _seqId) if seqId in ps['auth_seq_id']: idx = ps['auth_seq_id'].index(seqId) cifCompId = ps['comp_id'][idx] @@ -9072,7 +9072,7 @@ def assignCoordPolymerSequenceWithoutCompId(self, seqId, atomId=None): if self.__hasNonPolySeq: for np in self.__nonPolySeq: - chainId, seqId = self.getRealChainSeqId(np, _seqId, None, False) + chainId, seqId = self.getRealChainSeqId(np, _seqId, isPolySeq=False) if seqId in np['auth_seq_id']: idx = np['auth_seq_id'].index(seqId) cifCompId = np['comp_id'][idx] @@ -9153,7 +9153,7 @@ def selectCoordAtoms(self, chainAssign, seqId, compId, atomId, allowAmbig=True, cifSeqId += offset cifCompId = compId - seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, cifSeqId, self.__hasCoord) + seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, cifSeqId, cifCheck=self.__hasCoord) _atomId, _, details = self.__nefT.get_valid_star_atom_in_xplor(cifCompId, atomId, leave_unmatched=True) if details is not None and len(atomId) > 1 and not atomId[-1].isalpha(): diff --git a/wwpdb/utils/nmr/mr/AriaMRParserListener.py b/wwpdb/utils/nmr/mr/AriaMRParserListener.py index c1de9f511..79235b8bb 100644 --- a/wwpdb/utils/nmr/mr/AriaMRParserListener.py +++ b/wwpdb/utils/nmr/mr/AriaMRParserListener.py @@ -854,16 +854,16 @@ def getRealChainSeqId(self, ps, seqId, compId, isPolySeq=True): if seqKey in self.__labelToAuthSeq: _chainId, _seqId = self.__labelToAuthSeq[seqKey] if _seqId in ps['auth_seq_id']: - return _chainId, _seqId + return _chainId, _seqId, ps['comp_id'][ps['seq_id'].index(seqId)] if seqId in ps['auth_seq_id']: - idx = ps['auth_seq_id'].index(seqId) - if compId in (ps['comp_id'][idx], ps['auth_comp_id'][idx], 'MTS', 'ORI'): - return ps['auth_chain_id'], seqId + for idx in [_idx for _idx, _seqId in enumerate(ps['auth_seq_id']) if _seqId == seqId]: + if compId in (ps['comp_id'][idx], ps['auth_comp_id'][idx], 'MTS', 'ORI'): + return ps['auth_chain_id'], seqId, ps['comp_id'][idx] # if seqId in ps['seq_id']: # idx = ps['seq_id'].index(seqId) # if compId in (ps['comp_id'][idx], ps['auth_comp_id'][idx]): # return ps['auth_chain_id'], ps['auth_seq_id'][idx] - return ps['chain_id' if isPolySeq else 'auth_chain_id'], seqId + return ps['chain_id' if isPolySeq else 'auth_chain_id'], seqId, None def assignCoordPolymerSequence(self, seqId, compId, atomId): """ Assign polymer sequences of the coordinates. @@ -921,7 +921,7 @@ def assignCoordPolymerSequence(self, seqId, compId, atomId): for ps in self.__polySeq: if preferNonPoly: continue - chainId, seqId = self.getRealChainSeqId(ps, _seqId, compId) + chainId, seqId, cifCompId = self.getRealChainSeqId(ps, _seqId, compId) if self.__reasons is not None: if fixedChainId is not None: if fixedChainId != chainId: @@ -931,7 +931,11 @@ def assignCoordPolymerSequence(self, seqId, compId, atomId): elif fixedSeqId is not None: seqId = fixedSeqId if seqId in ps['auth_seq_id']: - idx = ps['auth_seq_id'].index(seqId) + if cifCompId is not None: + idx = next((_idx for _idx, (_seqId_, _cifCompId_) in enumerate(zip(ps['auth_seq_id'], ps['comp_id'])) + if _seqId_ == seqId and _cifCompId_ == cifCompId), ps['auth_seq_id'].index(seqId)) + else: + idx = ps['auth_seq_id'].index(seqId) cifCompId = ps['comp_id'][idx] origCompId = ps['auth_comp_id'][idx] if cifCompId != compId: @@ -941,7 +945,7 @@ def assignCoordPolymerSequence(self, seqId, compId, atomId): origCompId = next(origCompId for _seqId, _compId, origCompId in zip(ps['auth_seq_id'], ps['comp_id'], ps['auth_comp_id']) if _seqId == seqId and _compId == compId) if self.__mrAtomNameMapping is not None and origCompId not in monDict3: - _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, self.__hasCoord) + _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCompId, cifCheck=self.__hasCoord) atomId = retrieveAtomIdFromMRMap(self.__mrAtomNameMapping, seqId, origCompId, atomId, coordAtomSite) if compId in (cifCompId, origCompId, 'MTS', 'ORI'): if len(self.__nefT.get_valid_star_atom(cifCompId, atomId)[0]) > 0: @@ -983,7 +987,7 @@ def assignCoordPolymerSequence(self, seqId, compId, atomId): origCompId = next(origCompId for _seqId, _compId, origCompId in zip(ps['auth_seq_id'], ps['comp_id'], ps['auth_comp_id']) if _seqId == seqId and _compId == compId) if self.__mrAtomNameMapping is not None and origCompId not in monDict3: - _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId_, self.__hasCoord) + _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId_, cifCompId, cifCheck=self.__hasCoord) atomId = retrieveAtomIdFromMRMap(self.__mrAtomNameMapping, seqId, origCompId, atomId, coordAtomSite) if compId in (cifCompId, origCompId, 'MTS', 'ORI'): if len(self.__nefT.get_valid_star_atom(cifCompId, atomId)[0]) > 0: @@ -995,7 +999,7 @@ def assignCoordPolymerSequence(self, seqId, compId, atomId): if self.__hasNonPolySeq: for np in self.__nonPolySeq: - chainId, seqId = self.getRealChainSeqId(np, _seqId, compId, False) + chainId, seqId, cifCompId = self.getRealChainSeqId(np, _seqId, compId, False) if self.__reasons is not None: if fixedChainId is not None: if fixedChainId != chainId: @@ -1005,11 +1009,15 @@ def assignCoordPolymerSequence(self, seqId, compId, atomId): elif fixedSeqId is not None: seqId = fixedSeqId if seqId in np['auth_seq_id']: - idx = np['auth_seq_id'].index(seqId) + if cifCompId is not None: + idx = next((_idx for _idx, (_seqId_, _cifCompId_) in enumerate(zip(np['auth_seq_id'], np['comp_id'])) + if _seqId_ == seqId and _cifCompId_ == cifCompId), np['auth_seq_id'].index(seqId)) + else: + idx = np['auth_seq_id'].index(seqId) cifCompId = np['comp_id'][idx] origCompId = np['auth_comp_id'][idx] if self.__mrAtomNameMapping is not None and origCompId not in monDict3: - _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, self.__hasCoord) + _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCompId, cifCheck=self.__hasCoord) atomId = retrieveAtomIdFromMRMap(self.__mrAtomNameMapping, seqId, origCompId, atomId, coordAtomSite) if 'alt_auth_seq_id' in np and seqId in np['auth_seq_id'] and seqId not in np['alt_auth_seq_id']: seqId = next(_altSeqId for _seqId, _altSeqId in zip(np['auth_seq_id'], np['alt_auth_seq_id']) if _seqId == seqId) @@ -1040,7 +1048,7 @@ def assignCoordPolymerSequence(self, seqId, compId, atomId): origCompId = next(origCompId for _seqId, _compId, origCompId in zip(ps['auth_seq_id'], ps['comp_id'], ps['auth_comp_id']) if _seqId == seqId and _compId == compId) if self.__mrAtomNameMapping is not None and origCompId not in monDict3: - _, coordAtomSite = self.getCoordAtomSiteOf(chainId, _seqId, self.__hasCoord) + _, coordAtomSite = self.getCoordAtomSiteOf(chainId, _seqId, cifCompId, cifCheck=self.__hasCoord) atomId = retrieveAtomIdFromMRMap(self.__mrAtomNameMapping, seqId, origCompId, atomId, coordAtomSite) if compId in (cifCompId, origCompId, 'MTS', 'ORI'): if len(self.__nefT.get_valid_star_atom(cifCompId, atomId)[0]) > 0: @@ -1068,7 +1076,7 @@ def assignCoordPolymerSequence(self, seqId, compId, atomId): cifCompId = np['comp_id'][idx] origCompId = np['auth_comp_id'][idx] if self.__mrAtomNameMapping is not None and origCompId not in monDict3: - _, coordAtomSite = self.getCoordAtomSiteOf(chainId, _seqId, self.__hasCoord) + _, coordAtomSite = self.getCoordAtomSiteOf(chainId, _seqId, cifCompId, cifCheck=self.__hasCoord) atomId = retrieveAtomIdFromMRMap(self.__mrAtomNameMapping, seqId, origCompId, atomId, coordAtomSite) if compId in (cifCompId, origCompId, 'MTS', 'ORI'): if len(self.__nefT.get_valid_star_atom(cifCompId, atomId)[0]) > 0: @@ -1109,7 +1117,7 @@ def assignCoordPolymerSequence(self, seqId, compId, atomId): if seqKey in self.__labelToAuthSeq: _, seqId = self.__labelToAuthSeq[seqKey] if seqId in ps['auth_seq_id']: - idx = ps['auth_seq_id'].index(seqId) + idx = ps['seq_id'].index(_seqId) cifCompId = ps['comp_id'][idx] origCompId = ps['auth_comp_id'][idx] if cifCompId != compId: @@ -1119,7 +1127,7 @@ def assignCoordPolymerSequence(self, seqId, compId, atomId): origCompId = next(origCompId for _seqId, _compId, origCompId in zip(ps['auth_seq_id'], ps['comp_id'], ps['auth_comp_id']) if _seqId == seqId and _compId == compId) if self.__mrAtomNameMapping is not None and origCompId not in monDict3: - _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, self.__hasCoord) + _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCompId, cifCheck=self.__hasCoord) atomId = retrieveAtomIdFromMRMap(self.__mrAtomNameMapping, seqId, origCompId, atomId, coordAtomSite) if compId in (cifCompId, origCompId, 'MTS', 'ORI'): if len(self.__nefT.get_valid_star_atom(cifCompId, atomId)[0]) > 0: @@ -1230,7 +1238,7 @@ def assignCoordPolymerSequenceWithChainId(self, refChainId, seqId, compId, atomI for ps in self.__polySeq: if preferNonPoly: continue - chainId, seqId = self.getRealChainSeqId(ps, _seqId, compId) + chainId, seqId, cifCompId = self.getRealChainSeqId(ps, _seqId, compId) if fixedChainId is None and refChainId is not None and refChainId != chainId and refChainId in self.__chainNumberDict: if chainId != self.__chainNumberDict[refChainId]: continue @@ -1243,7 +1251,11 @@ def assignCoordPolymerSequenceWithChainId(self, refChainId, seqId, compId, atomI elif fixedSeqId is not None: seqId = fixedSeqId if seqId in ps['auth_seq_id']: - idx = ps['auth_seq_id'].index(seqId) + if cifCompId is not None: + idx = next((_idx for _idx, (_seqId_, _cifCompId_) in enumerate(zip(ps['auth_seq_id'], ps['comp_id'])) + if _seqId_ == seqId and _cifCompId_ == cifCompId), ps['auth_seq_id'].index(seqId)) + else: + idx = ps['auth_seq_id'].index(seqId) cifCompId = ps['comp_id'][idx] origCompId = ps['auth_comp_id'][idx] if cifCompId != compId: @@ -1253,7 +1265,7 @@ def assignCoordPolymerSequenceWithChainId(self, refChainId, seqId, compId, atomI origCompId = next(origCompId for _seqId, _compId, origCompId in zip(ps['auth_seq_id'], ps['comp_id'], ps['auth_comp_id']) if _seqId == seqId and _compId == compId) if self.__mrAtomNameMapping is not None and origCompId not in monDict3: - _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, self.__hasCoord) + _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCompId, cifCheck=self.__hasCoord) atomId = retrieveAtomIdFromMRMap(self.__mrAtomNameMapping, seqId, origCompId, atomId, coordAtomSite) if compId in (cifCompId, origCompId, 'MTS', 'ORI'): if len(self.__nefT.get_valid_star_atom(cifCompId, atomId)[0]) > 0: @@ -1299,7 +1311,7 @@ def assignCoordPolymerSequenceWithChainId(self, refChainId, seqId, compId, atomI origCompId = next(origCompId for _seqId, _compId, origCompId in zip(ps['auth_seq_id'], ps['comp_id'], ps['auth_comp_id']) if _seqId == seqId and _compId == compId) if self.__mrAtomNameMapping is not None and origCompId not in monDict3: - _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId_, self.__hasCoord) + _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId_, cifCompId, cifCheck=self.__hasCoord) atomId = retrieveAtomIdFromMRMap(self.__mrAtomNameMapping, seqId, origCompId, atomId, coordAtomSite) if compId in (cifCompId, origCompId, 'MTS', 'ORI'): if len(self.__nefT.get_valid_star_atom(cifCompId, atomId)[0]) > 0: @@ -1311,7 +1323,7 @@ def assignCoordPolymerSequenceWithChainId(self, refChainId, seqId, compId, atomI if self.__hasNonPolySeq: for np in self.__nonPolySeq: - chainId, seqId = self.getRealChainSeqId(np, _seqId, compId, False) + chainId, seqId, cifCompId = self.getRealChainSeqId(np, _seqId, compId, False) if fixedChainId is None and refChainId is not None and refChainId != chainId and refChainId in self.__chainNumberDict: if chainId != self.__chainNumberDict[refChainId]: continue @@ -1324,11 +1336,15 @@ def assignCoordPolymerSequenceWithChainId(self, refChainId, seqId, compId, atomI elif fixedSeqId is not None: seqId = fixedSeqId if seqId in np['auth_seq_id']: - idx = np['auth_seq_id'].index(seqId) + if cifCompId is not None: + idx = next((_idx for _idx, (_seqId_, _cifCompId_) in enumerate(zip(np['auth_seq_id'], np['comp_id'])) + if _seqId_ == seqId and _cifCompId_ == cifCompId), np['auth_seq_id'].index(seqId)) + else: + idx = np['auth_seq_id'].index(seqId) cifCompId = np['comp_id'][idx] origCompId = np['auth_comp_id'][idx] if self.__mrAtomNameMapping is not None and origCompId not in monDict3: - _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, self.__hasCoord) + _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCompId, cifCheck=self.__hasCoord) atomId = retrieveAtomIdFromMRMap(self.__mrAtomNameMapping, seqId, origCompId, atomId, coordAtomSite) if 'alt_auth_seq_id' in np and seqId in np['auth_seq_id'] and seqId not in np['alt_auth_seq_id']: seqId = next(_altSeqId for _seqId, _altSeqId in zip(np['auth_seq_id'], np['alt_auth_seq_id']) if _seqId == seqId) @@ -1367,7 +1383,7 @@ def assignCoordPolymerSequenceWithChainId(self, refChainId, seqId, compId, atomI origCompId = next(origCompId for _seqId, _compId, origCompId in zip(ps['auth_seq_id'], ps['comp_id'], ps['auth_comp_id']) if _seqId == seqId and _compId == compId) if self.__mrAtomNameMapping is not None and origCompId not in monDict3: - _, coordAtomSite = self.getCoordAtomSiteOf(chainId, _seqId, self.__hasCoord) + _, coordAtomSite = self.getCoordAtomSiteOf(chainId, _seqId, cifCompId, cifCheck=self.__hasCoord) atomId = retrieveAtomIdFromMRMap(self.__mrAtomNameMapping, seqId, origCompId, atomId, coordAtomSite) if compId in (cifCompId, origCompId, 'MTS', 'ORI'): if len(self.__nefT.get_valid_star_atom(cifCompId, atomId)[0]) > 0: @@ -1403,7 +1419,7 @@ def assignCoordPolymerSequenceWithChainId(self, refChainId, seqId, compId, atomI cifCompId = np['comp_id'][idx] origCompId = np['auth_comp_id'][idx] if self.__mrAtomNameMapping is not None and origCompId not in monDict3: - _, coordAtomSite = self.getCoordAtomSiteOf(chainId, _seqId, self.__hasCoord) + _, coordAtomSite = self.getCoordAtomSiteOf(chainId, _seqId, cifCompId, cifCheck=self.__hasCoord) atomId = retrieveAtomIdFromMRMap(self.__mrAtomNameMapping, seqId, origCompId, atomId, coordAtomSite) if compId in (cifCompId, origCompId, 'MTS', 'ORI'): if len(self.__nefT.get_valid_star_atom(cifCompId, atomId)[0]) > 0: @@ -1462,7 +1478,7 @@ def assignCoordPolymerSequenceWithChainId(self, refChainId, seqId, compId, atomI if seqKey in self.__labelToAuthSeq: _, seqId = self.__labelToAuthSeq[seqKey] if seqId in ps['auth_seq_id']: - idx = ps['auth_seq_id'].index(seqId) + idx = ps['seq_id'].index(_seqId) cifCompId = ps['comp_id'][idx] origCompId = ps['auth_comp_id'][idx] if cifCompId != compId: @@ -1472,7 +1488,7 @@ def assignCoordPolymerSequenceWithChainId(self, refChainId, seqId, compId, atomI origCompId = next(origCompId for _seqId, _compId, origCompId in zip(ps['auth_seq_id'], ps['comp_id'], ps['auth_comp_id']) if _seqId == seqId and _compId == compId) if self.__mrAtomNameMapping is not None and origCompId not in monDict3: - _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, self.__hasCoord) + _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCompId, cifCheck=self.__hasCoord) atomId = retrieveAtomIdFromMRMap(self.__mrAtomNameMapping, seqId, origCompId, atomId, coordAtomSite) if compId in (cifCompId, origCompId, 'MTS', 'ORI'): if len(self.__nefT.get_valid_star_atom(cifCompId, atomId)[0]) > 0: @@ -1560,7 +1576,7 @@ def selectCoordAtoms(self, chainAssign, seqId, compId, atomId, allowAmbig=True, cifSeqId += offset cifCompId = compId - seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, cifSeqId, self.__hasCoord, asis=self.__preferAuthSeq) + seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, cifSeqId, cifCompId, asis=self.__preferAuthSeq) if self.__cur_subtype == 'dist' and _compId is not None and (_compId.startswith('MTS') or _compId.startswith('ORI')) and cifCompId != _compId: if _atomId[0] in ('O', 'N'): @@ -1595,7 +1611,7 @@ def selectCoordAtoms(self, chainAssign, seqId, compId, atomId, allowAmbig=True, if _seqId != cifSeqId: _, _, atomId = retrieveAtomIdentFromMRMap(self.__mrAtomNameMapping, _seqId, cifCompId, atomId, None, coordAtomSite) - seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, cifSeqId, self.__hasCoord) + seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, cifSeqId, cifCompId) if atomId != _atomId and coordAtomSite is not None and _atomId in coordAtomSite['atom_id']: atomId = _atomId @@ -1632,7 +1648,7 @@ def selectCoordAtoms(self, chainAssign, seqId, compId, atomId, allowAmbig=True, for np in self.__nonPolySeq: if np['auth_chain_id'] == chainId and cifSeqId in np['auth_seq_id']: cifSeqId = np['seq_id'][np['auth_seq_id'].index(cifSeqId)] - seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, cifSeqId, self.__hasCoord) + seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, cifSeqId, cifCompId) if coordAtomSite is not None: break except ValueError: @@ -1652,7 +1668,7 @@ def selectCoordAtoms(self, chainAssign, seqId, compId, atomId, allowAmbig=True, cifCompId = compId if not multiChain and not insCode: if self.__preferAuthSeq: - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, cifSeqId, asis=False) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, cifSeqId, cifCompId, asis=False) if _coordAtomSite is not None and _coordAtomSite['comp_id'] == compId: if lenAtomId > 0 and _atomId[0] in _coordAtomSite['atom_id']: self.__authSeqId = 'label_seq_id' @@ -1726,7 +1742,7 @@ def testCoordAtomIdConsistency(self, chainId, seqId, compId, atomId, seqKey, coo # self.__authAtomId = 'auth_atom_id' elif self.__preferAuthSeq: - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, asis=False) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, compId, asis=False) if _coordAtomSite is not None and _coordAtomSite['comp_id'] == compId: if atomId in _coordAtomSite['atom_id']: found = True @@ -1744,7 +1760,7 @@ def testCoordAtomIdConsistency(self, chainId, seqId, compId, atomId, seqKey, coo else: self.__preferAuthSeq = True - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, compId) if _coordAtomSite is not None and _coordAtomSite['comp_id'] == compId: if atomId in _coordAtomSite['atom_id']: found = True @@ -1763,7 +1779,7 @@ def testCoordAtomIdConsistency(self, chainId, seqId, compId, atomId, seqKey, coo self.__preferAuthSeq = False elif self.__preferAuthSeq: - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, asis=False) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, compId, asis=False) if _coordAtomSite is not None and _coordAtomSite['comp_id'] == compId: if atomId in _coordAtomSite['atom_id']: found = True @@ -1781,7 +1797,7 @@ def testCoordAtomIdConsistency(self, chainId, seqId, compId, atomId, seqKey, coo else: self.__preferAuthSeq = True - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, compId) if _coordAtomSite is not None and _coordAtomSite['comp_id'] == compId: if atomId in _coordAtomSite['atom_id']: found = True @@ -1805,7 +1821,7 @@ def testCoordAtomIdConsistency(self, chainId, seqId, compId, atomId, seqKey, coo if chainId in self.__chainNumberDict.values(): if self.__preferAuthSeq: - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, asis=False) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, compId, asis=False) if _coordAtomSite is not None and _coordAtomSite['comp_id'] == compId: if atomId in _coordAtomSite['atom_id']: found = True @@ -1822,7 +1838,7 @@ def testCoordAtomIdConsistency(self, chainId, seqId, compId, atomId, seqKey, coo self.__setLocalSeqScheme() else: self.__preferAuthSeq = True - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, compId) if _coordAtomSite is not None and _coordAtomSite['comp_id'] == compId: if atomId in _coordAtomSite['atom_id']: found = True @@ -1982,20 +1998,27 @@ def selectRealisticBondConstraint(self, atom1, atom2, alt_atom_id1, alt_atom_id2 return atom1, atom2 - def getCoordAtomSiteOf(self, chainId, seqId, cifCheck=True, asis=True): + def getCoordAtomSiteOf(self, chainId, seqId, compId=None, cifCheck=True, asis=True): seqKey = (chainId, seqId) - coordAtomSite = None if cifCheck: preferAuthSeq = self.__preferAuthSeq if asis else not self.__preferAuthSeq if preferAuthSeq: + if compId is not None: + _seqKey = (chainId, seqId, compId) + if _seqKey in self.__coordAtomSite: + return seqKey, self.__coordAtomSite[_seqKey] if seqKey in self.__coordAtomSite: - coordAtomSite = self.__coordAtomSite[seqKey] + return seqKey, self.__coordAtomSite[seqKey] else: if seqKey in self.__labelToAuthSeq: seqKey = self.__labelToAuthSeq[seqKey] + if cifCheck and compId is not None: + _seqKey = (seqKey[0], seqKey[1], compId) + if _seqKey in self.__coordAtomSite: + return seqKey, self.__coordAtomSite[_seqKey] if seqKey in self.__coordAtomSite: - coordAtomSite = self.__coordAtomSite[seqKey] - return seqKey, coordAtomSite + return seqKey, self.__coordAtomSite[seqKey] + return seqKey, None # Enter a parse tree produced by AriaMRParser#contribution. def enterContribution(self, ctx: AriaMRParser.ContributionContext): diff --git a/wwpdb/utils/nmr/mr/BiosymMRParserListener.py b/wwpdb/utils/nmr/mr/BiosymMRParserListener.py index e55a19c91..f4e05719f 100644 --- a/wwpdb/utils/nmr/mr/BiosymMRParserListener.py +++ b/wwpdb/utils/nmr/mr/BiosymMRParserListener.py @@ -986,16 +986,16 @@ def getRealChainSeqId(self, ps, seqId, compId, isPolySeq=True): if seqKey in self.__labelToAuthSeq: _chainId, _seqId = self.__labelToAuthSeq[seqKey] if _seqId in ps['auth_seq_id']: - return _chainId, _seqId + return _chainId, _seqId, ps['comp_id'][ps['seq_id'].index(seqId)] if seqId in ps['auth_seq_id']: - idx = ps['auth_seq_id'].index(seqId) - if compId in (ps['comp_id'][idx], ps['auth_comp_id'][idx], 'MTS', 'ORI'): - return ps['auth_chain_id'], seqId + for idx in [_idx for _idx, _seqId in enumerate(ps['auth_seq_id']) if _seqId == seqId]: + if compId in (ps['comp_id'][idx], ps['auth_comp_id'][idx], 'MTS', 'ORI'): + return ps['auth_chain_id'], seqId, ps['comp_id'][idx] # if seqId in ps['seq_id']: # idx = ps['seq_id'].index(seqId) # if compId in (ps['comp_id'][idx], ps['auth_comp_id'][idx]): # return ps['auth_chain_id'], ps['auth_seq_id'][idx] - return ps['chain_id' if isPolySeq else 'auth_chain_id'], seqId + return ps['chain_id' if isPolySeq else 'auth_chain_id'], seqId, None def assignCoordPolymerSequence(self, refChainId, seqId, compId, atomId): """ Assign polymer sequences of the coordinates. @@ -1071,7 +1071,7 @@ def assignCoordPolymerSequence(self, refChainId, seqId, compId, atomId): for ps in self.__polySeq: if preferNonPoly: continue - chainId, seqId = self.getRealChainSeqId(ps, _seqId, compId) + chainId, seqId, cifCompId = self.getRealChainSeqId(ps, _seqId, compId) if fixedChainId is None and refChainId is not None and refChainId != chainId and refChainId in self.__chainNumberDict: if chainId != self.__chainNumberDict[refChainId]: continue @@ -1084,7 +1084,11 @@ def assignCoordPolymerSequence(self, refChainId, seqId, compId, atomId): elif fixedSeqId is not None: seqId = fixedSeqId if seqId in ps['auth_seq_id']: - idx = ps['auth_seq_id'].index(seqId) + if cifCompId is not None: + idx = next((_idx for _idx, (_seqId_, _cifCompId_) in enumerate(zip(ps['auth_seq_id'], ps['comp_id'])) + if _seqId_ == seqId and _cifCompId_ == cifCompId), ps['auth_seq_id'].index(seqId)) + else: + idx = ps['auth_seq_id'].index(seqId) cifCompId = ps['comp_id'][idx] origCompId = ps['auth_comp_id'][idx] if cifCompId != compId: @@ -1094,7 +1098,7 @@ def assignCoordPolymerSequence(self, refChainId, seqId, compId, atomId): origCompId = next(origCompId for _seqId, _compId, origCompId in zip(ps['auth_seq_id'], ps['comp_id'], ps['auth_comp_id']) if _seqId == seqId and _compId == compId) if self.__mrAtomNameMapping is not None and origCompId not in monDict3: - _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, self.__hasCoord) + _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCompId, cifCheck=self.__hasCoord) atomId = retrieveAtomIdFromMRMap(self.__mrAtomNameMapping, seqId, origCompId, atomId, coordAtomSite) if compId in (cifCompId, origCompId, 'MTS', 'ORI'): if len(self.__nefT.get_valid_star_atom(cifCompId, atomId)[0]) > 0: @@ -1140,7 +1144,7 @@ def assignCoordPolymerSequence(self, refChainId, seqId, compId, atomId): origCompId = next(origCompId for _seqId, _compId, origCompId in zip(ps['auth_seq_id'], ps['comp_id'], ps['auth_comp_id']) if _seqId == seqId and _compId == compId) if self.__mrAtomNameMapping is not None and origCompId not in monDict3: - _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId_, self.__hasCoord) + _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId_, cifCompId, cifCheck=self.__hasCoord) atomId = retrieveAtomIdFromMRMap(self.__mrAtomNameMapping, seqId, origCompId, atomId, coordAtomSite) if compId in (cifCompId, origCompId, 'MTS', 'ORI'): if len(self.__nefT.get_valid_star_atom(cifCompId, atomId)[0]) > 0: @@ -1156,7 +1160,7 @@ def assignCoordPolymerSequence(self, refChainId, seqId, compId, atomId): if self.__hasNonPolySeq: for np in self.__nonPolySeq: - chainId, seqId = self.getRealChainSeqId(np, _seqId, compId, False) + chainId, seqId, cifCompId = self.getRealChainSeqId(np, _seqId, compId, False) if fixedChainId is None and refChainId is not None and refChainId != chainId and refChainId in self.__chainNumberDict: if chainId != self.__chainNumberDict[refChainId]: continue @@ -1169,11 +1173,15 @@ def assignCoordPolymerSequence(self, refChainId, seqId, compId, atomId): elif fixedSeqId is not None: seqId = fixedSeqId if seqId in np['auth_seq_id']: - idx = np['auth_seq_id'].index(seqId) + if cifCompId is not None: + idx = next((_idx for _idx, (_seqId_, _cifCompId_) in enumerate(zip(np['auth_seq_id'], np['comp_id'])) + if _seqId_ == seqId and _cifCompId_ == cifCompId), np['auth_seq_id'].index(seqId)) + else: + idx = np['auth_seq_id'].index(seqId) cifCompId = np['comp_id'][idx] origCompId = np['auth_comp_id'][idx] if self.__mrAtomNameMapping is not None and origCompId not in monDict3: - _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, self.__hasCoord) + _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCompId, cifCheck=self.__hasCoord) atomId = retrieveAtomIdFromMRMap(self.__mrAtomNameMapping, seqId, origCompId, atomId, coordAtomSite) if 'alt_auth_seq_id' in np and seqId in np['auth_seq_id'] and seqId not in np['alt_auth_seq_id']: seqId = next(_altSeqId for _seqId, _altSeqId in zip(np['auth_seq_id'], np['alt_auth_seq_id']) if _seqId == seqId) @@ -1211,7 +1219,7 @@ def assignCoordPolymerSequence(self, refChainId, seqId, compId, atomId): origCompId = next(origCompId for _seqId, _compId, origCompId in zip(ps['auth_seq_id'], ps['comp_id'], ps['auth_comp_id']) if _seqId == seqId and _compId == compId) if self.__mrAtomNameMapping is not None and origCompId not in monDict3: - _, coordAtomSite = self.getCoordAtomSiteOf(chainId, _seqId, self.__hasCoord) + _, coordAtomSite = self.getCoordAtomSiteOf(chainId, _seqId, cifCompId, cifCheck=self.__hasCoord) atomId = retrieveAtomIdFromMRMap(self.__mrAtomNameMapping, seqId, origCompId, atomId, coordAtomSite) if compId in (cifCompId, origCompId, 'MTS', 'ORI'): if len(self.__nefT.get_valid_star_atom(cifCompId, atomId)[0]) > 0: @@ -1246,7 +1254,7 @@ def assignCoordPolymerSequence(self, refChainId, seqId, compId, atomId): cifCompId = np['comp_id'][idx] origCompId = np['auth_comp_id'][idx] if self.__mrAtomNameMapping is not None and origCompId not in monDict3: - _, coordAtomSite = self.getCoordAtomSiteOf(chainId, _seqId, self.__hasCoord) + _, coordAtomSite = self.getCoordAtomSiteOf(chainId, _seqId, cifCompId, cifCheck=self.__hasCoord) atomId = retrieveAtomIdFromMRMap(self.__mrAtomNameMapping, seqId, origCompId, atomId, coordAtomSite) if compId in (cifCompId, origCompId, 'MTS', 'ORI'): if len(self.__nefT.get_valid_star_atom(cifCompId, atomId)[0]) > 0: @@ -1299,7 +1307,7 @@ def assignCoordPolymerSequence(self, refChainId, seqId, compId, atomId): if seqKey in self.__labelToAuthSeq: _, seqId = self.__labelToAuthSeq[seqKey] if seqId in ps['auth_seq_id']: - idx = ps['auth_seq_id'].index(seqId) + idx = ps['seq_id'].index(_seqId) cifCompId = ps['comp_id'][idx] origCompId = ps['auth_comp_id'][idx] if cifCompId != compId: @@ -1309,7 +1317,7 @@ def assignCoordPolymerSequence(self, refChainId, seqId, compId, atomId): origCompId = next(origCompId for _seqId, _compId, origCompId in zip(ps['auth_seq_id'], ps['comp_id'], ps['auth_comp_id']) if _seqId == seqId and _compId == compId) if self.__mrAtomNameMapping is not None and origCompId not in monDict3: - _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, self.__hasCoord) + _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCompId, cifCheck=self.__hasCoord) atomId = retrieveAtomIdFromMRMap(self.__mrAtomNameMapping, seqId, origCompId, atomId, coordAtomSite) if compId in (cifCompId, origCompId, 'MTS', 'ORI'): if len(self.__nefT.get_valid_star_atom(cifCompId, atomId)[0]) > 0: @@ -1392,7 +1400,7 @@ def selectCoordAtoms(self, chainAssign, seqId, compId, atomId, allowAmbig=True, cifSeqId += offset cifCompId = compId - seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, cifSeqId, self.__hasCoord, asis=self.__preferAuthSeq) + seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, cifSeqId, cifCompId, asis=self.__preferAuthSeq) if self.__cur_subtype == 'dist' and _compId is not None and (_compId.startswith('MTS') or _compId.startswith('ORI')) and cifCompId != _compId: if _atomId[0] in ('O', 'N'): @@ -1427,7 +1435,7 @@ def selectCoordAtoms(self, chainAssign, seqId, compId, atomId, allowAmbig=True, if _seqId != cifSeqId: _, _, atomId = retrieveAtomIdentFromMRMap(self.__mrAtomNameMapping, _seqId, cifCompId, atomId, None, coordAtomSite) - seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, cifSeqId, self.__hasCoord) + seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, cifSeqId, cifCompId) if atomId != _atomId and coordAtomSite is not None and _atomId in coordAtomSite['atom_id']: atomId = _atomId @@ -1464,7 +1472,7 @@ def selectCoordAtoms(self, chainAssign, seqId, compId, atomId, allowAmbig=True, for np in self.__nonPolySeq: if np['auth_chain_id'] == chainId and cifSeqId in np['auth_seq_id']: cifSeqId = np['seq_id'][np['auth_seq_id'].index(cifSeqId)] - seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, cifSeqId, self.__hasCoord) + seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, cifSeqId, cifCompId) if coordAtomSite is not None: break except ValueError: @@ -1484,7 +1492,7 @@ def selectCoordAtoms(self, chainAssign, seqId, compId, atomId, allowAmbig=True, cifCompId = compId if not multiChain and not insCode: if self.__preferAuthSeq: - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, cifSeqId, asis=False) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, cifSeqId, cifCompId, asis=False) if _coordAtomSite is not None and _coordAtomSite['comp_id'] == compId: if lenAtomId > 0 and _atomId[0] in _coordAtomSite['atom_id']: self.__authSeqId = 'label_seq_id' @@ -1558,7 +1566,7 @@ def testCoordAtomIdConsistency(self, chainId, seqId, compId, atomId, seqKey, coo # self.__authAtomId = 'auth_atom_id' elif self.__preferAuthSeq: - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, asis=False) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, compId, asis=False) if _coordAtomSite is not None and _coordAtomSite['comp_id'] == compId: if atomId in _coordAtomSite['atom_id']: found = True @@ -1576,7 +1584,7 @@ def testCoordAtomIdConsistency(self, chainId, seqId, compId, atomId, seqKey, coo else: self.__preferAuthSeq = True - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, compId) if _coordAtomSite is not None and _coordAtomSite['comp_id'] == compId: if atomId in _coordAtomSite['atom_id']: found = True @@ -1595,7 +1603,7 @@ def testCoordAtomIdConsistency(self, chainId, seqId, compId, atomId, seqKey, coo self.__preferAuthSeq = False elif self.__preferAuthSeq: - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, asis=False) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, compId, asis=False) if _coordAtomSite is not None and _coordAtomSite['comp_id'] == compId: if atomId in _coordAtomSite['atom_id']: found = True @@ -1613,7 +1621,7 @@ def testCoordAtomIdConsistency(self, chainId, seqId, compId, atomId, seqKey, coo else: self.__preferAuthSeq = True - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, compId) if _coordAtomSite is not None and _coordAtomSite['comp_id'] == compId: if atomId in _coordAtomSite['atom_id']: found = True @@ -1637,7 +1645,7 @@ def testCoordAtomIdConsistency(self, chainId, seqId, compId, atomId, seqKey, coo if chainId in self.__chainNumberDict.values(): if self.__preferAuthSeq: - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, asis=False) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, compId, asis=False) if _coordAtomSite is not None and _coordAtomSite['comp_id'] == compId: if atomId in _coordAtomSite['atom_id']: found = True @@ -1654,7 +1662,7 @@ def testCoordAtomIdConsistency(self, chainId, seqId, compId, atomId, seqKey, coo self.__setLocalSeqScheme() else: self.__preferAuthSeq = True - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, compId) if _coordAtomSite is not None and _coordAtomSite['comp_id'] == compId: if atomId in _coordAtomSite['atom_id']: found = True @@ -1982,20 +1990,27 @@ def selectRealisticChi2AngleConstraint(self, atom1, atom2, atom3, atom4, dst_fun return dst_func - def getCoordAtomSiteOf(self, chainId, seqId, cifCheck=True, asis=True): + def getCoordAtomSiteOf(self, chainId, seqId, compId=None, cifCheck=True, asis=True): seqKey = (chainId, seqId) - coordAtomSite = None if cifCheck: preferAuthSeq = self.__preferAuthSeq if asis else not self.__preferAuthSeq if preferAuthSeq: + if compId is not None: + _seqKey = (chainId, seqId, compId) + if _seqKey in self.__coordAtomSite: + return seqKey, self.__coordAtomSite[_seqKey] if seqKey in self.__coordAtomSite: - coordAtomSite = self.__coordAtomSite[seqKey] + return seqKey, self.__coordAtomSite[seqKey] else: if seqKey in self.__labelToAuthSeq: seqKey = self.__labelToAuthSeq[seqKey] + if cifCheck and compId is not None: + _seqKey = (seqKey[0], seqKey[1], compId) + if _seqKey in self.__coordAtomSite: + return seqKey, self.__coordAtomSite[_seqKey] if seqKey in self.__coordAtomSite: - coordAtomSite = self.__coordAtomSite[seqKey] - return seqKey, coordAtomSite + return seqKey, self.__coordAtomSite[seqKey] + return seqKey, None # Enter a parse tree produced by BiosymMRParser#dihedral_angle_restraints. def enterDihedral_angle_restraints(self, ctx: BiosymMRParser.Dihedral_angle_restraintsContext): # pylint: disable=unused-argument diff --git a/wwpdb/utils/nmr/mr/CharmmMRParserListener.py b/wwpdb/utils/nmr/mr/CharmmMRParserListener.py index 505f46c29..219a25a28 100644 --- a/wwpdb/utils/nmr/mr/CharmmMRParserListener.py +++ b/wwpdb/utils/nmr/mr/CharmmMRParserListener.py @@ -2718,7 +2718,7 @@ def __consumeFactor_expressions(self, _factor, clauseName='atom selection expres _atomIdSelect.add(realAtomId) for nonPolyCompId in _nonPolyCompIdSelect: - _, coordAtomSite = self.getCoordAtomSiteOf(nonPolyCompId['chain_id'], nonPolyCompId['seq_id'], cifCheck) + _, coordAtomSite = self.getCoordAtomSiteOf(nonPolyCompId['chain_id'], nonPolyCompId['seq_id'], cifCheck=cifCheck) if coordAtomSite is not None: for realAtomId in coordAtomSite['atom_id']: _atomIdSelect.add(realAtomId) @@ -2773,7 +2773,7 @@ def __consumeFactor_expressions(self, _factor, clauseName='atom selection expres _atomIdSelect.add(realAtomId) for nonPolyCompId in _nonPolyCompIdSelect: - _, coordAtomSite = self.getCoordAtomSiteOf(nonPolyCompId['chain_id'], nonPolyCompId['seq_id'], cifCheck) + _, coordAtomSite = self.getCoordAtomSiteOf(nonPolyCompId['chain_id'], nonPolyCompId['seq_id'], cifCheck=cifCheck) if coordAtomSite is not None: for realAtomId in coordAtomSite['atom_id']: _atomIdSelect.add(realAtomId) @@ -2953,7 +2953,7 @@ def __consumeFactor_expressions__(self, _factor, cifCheck, _atomSelection, continue _seqId_ = seqId - seqId = self.getRealSeqId(ps, seqId, isPolySeq) + seqId, _compId_ = self.getRealSeqId(ps, seqId, isPolySeq) if seqId is None: continue @@ -3016,13 +3016,17 @@ def __consumeFactor_expressions__(self, _factor, cifCheck, _atomSelection, compId = ps['comp_id'][idx] _seqId_ = ps['auth_seq_id'][idx] - seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck) + if self.__authToInsCode is None or len(self.__authToInsCode) == 0 or _compId_ is None: + seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, compId, cifCheck=cifCheck) + else: + compId = _compId_ + seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, _compId_, cifCheck=cifCheck) if compId is None and seqKey in self.__authToLabelSeq: _, seqId = self.__authToLabelSeq[seqKey] if ps is not None and seqId in ps['auth_seq_id']: compId = ps['comp_id'][ps['auth_seq_id'].index(seqId)] - seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck) + seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck=cifCheck) if compId is None and coordAtomSite is not None and ps is not None and seqKey[1] in ps['auth_seq_id']: compId = ps['comp_id'][ps['auth_seq_id'].index(seqKey[1])] @@ -3032,7 +3036,7 @@ def __consumeFactor_expressions__(self, _factor, cifCheck, _atomSelection, idx = ps['auth_seq_id'].index(seqId) seqId = ps['seq_id'][idx] compId = ps['comp_id'][idx] - seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck) + seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck=cifCheck) except ValueError: pass @@ -3049,7 +3053,7 @@ def __consumeFactor_expressions__(self, _factor, cifCheck, _atomSelection, _seqId = seqId if not isPolySeq and 'alt_auth_seq_id' in ps and seqId in ps['auth_seq_id'] and seqId not in ps['alt_auth_seq_id']: seqId = next(_altSeqId for _seqId, _altSeqId in zip(ps['auth_seq_id'], ps['alt_auth_seq_id']) if _seqId == seqId) - seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck) + seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck=cifCheck) if not isPolySeq and isChainSpecified and self.doesNonPolySeqIdMatchWithPolySeqUnobs(_factor['chain_id'][0], _seqId_): continue @@ -3134,7 +3138,7 @@ def __consumeFactor_expressions__(self, _factor, cifCheck, _atomSelection, _atom['type_symbol'] = coordAtomSite['type_symbol'][coordAtomSite['alt_atom_id'].index(_atomId)] self.__authAtomId = 'auth_atom_id' elif self.__preferAuthSeq and atomSpecified: - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck, asis=False) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck=cifCheck, asis=False) if _coordAtomSite is not None: _compId = _coordAtomSite['comp_id'] _atomId = self.getAtomIdList(_factor, _compId, atomId)[0] @@ -3179,7 +3183,7 @@ def __consumeFactor_expressions__(self, _factor, cifCheck, _atomSelection, """ elif _seqId_ in ps['auth_seq_id'] and atomSpecified: self.__preferAuthSeq = True - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, _seqId_, cifCheck) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, _seqId_, cifCheck=cifCheck) if _coordAtomSite is not None: _compId = _coordAtomSite['comp_id'] _atomId = self.getAtomIdList(_factor, _compId, atomId)[0] @@ -3213,7 +3217,7 @@ def __consumeFactor_expressions__(self, _factor, cifCheck, _atomSelection, elif self.__preferAuthSeq and atomSpecified: if len(self.atomSelectionSet) == 0: - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck, asis=False) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck=cifCheck, asis=False) if _coordAtomSite is not None: _compId = _coordAtomSite['comp_id'] _atomId = self.getAtomIdList(_factor, _compId, atomId)[0] @@ -3259,7 +3263,7 @@ def __consumeFactor_expressions__(self, _factor, cifCheck, _atomSelection, elif _seqId_ in ps['auth_seq_id'] and atomSpecified: if len(self.atomSelectionSet) == 0: self.__preferAuthSeq = True - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, _seqId_, cifCheck) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, _seqId_, cifCheck=cifCheck) if _coordAtomSite is not None: _compId = _coordAtomSite['comp_id'] _atomId = self.getAtomIdList(_factor, _compId, atomId)[0] @@ -3396,8 +3400,8 @@ def __consumeFactor_expressions__(self, _factor, cifCheck, _atomSelection, if len(__psList) == 0: continue for __ps in __psList: - __seqId = self.getRealSeqId(__ps, seqId, isPolySeq) - __seqKey, __coordAtomSite = self.getCoordAtomSiteOf(__chainId, __seqId, cifCheck) + __seqId, _ = self.getRealSeqId(__ps, seqId, isPolySeq) + __seqKey, __coordAtomSite = self.getCoordAtomSiteOf(__chainId, __seqId, cifCheck=cifCheck) if __coordAtomSite is not None: __compId = __coordAtomSite['comp_id'] __atomIds = self.getAtomIdList(_factor, __compId, atomId) @@ -3462,8 +3466,8 @@ def __consumeFactor_expressions__(self, _factor, cifCheck, _atomSelection, if len(__psList) == 0: continue for __ps in __psList: - __seqId = self.getRealSeqId(__ps, seqId, isPolySeq) - __seqKey, __coordAtomSite = self.getCoordAtomSiteOf(__chainId, __seqId, cifCheck) + __seqId, _ = self.getRealSeqId(__ps, seqId, isPolySeq) + __seqKey, __coordAtomSite = self.getCoordAtomSiteOf(__chainId, __seqId, cifCheck=cifCheck) if __coordAtomSite is not None: __compId = __coordAtomSite['comp_id'] __atomIds = self.getAtomIdList(_factor, __compId, atomId) @@ -3551,6 +3555,7 @@ def getRealSeqId(self, ps, seqId, isPolySeq=True): offset = 0 if not self.__preferAuthSeq: chainId = ps['chain_id'] + offset = 0 if isPolySeq and self.__reasons is not None and 'label_seq_offset' in self.__reasons and chainId in self.__reasons['label_seq_offset']: offset = self.__reasons['label_seq_offset'][chainId] if isPolySeq and self.__reasons is not None and 'global_sequence_offset' in self.__reasons\ @@ -3571,14 +3576,16 @@ def getRealSeqId(self, ps, seqId, isPolySeq=True): offset = offset[seqId - shift] break if isinstance(offset, dict): - return None + return None, None if seqId + offset in ps['auth_seq_id']: - return seqId + offset + return seqId + offset, ps['comp_id'][ps['auth_seq_id'].index(seqId + offset)] seqKey = (ps['chain_id' if isPolySeq else 'auth_chain_id'], seqId + offset) if seqKey in self.__labelToAuthSeq: _chainId, _seqId = self.__labelToAuthSeq[seqKey] if _seqId in ps['auth_seq_id']: - return _seqId + return _seqId, ps['comp_id'][ps['seq_id'].index(seqId + offset) + if seqId + offset in ps['seq_id'] + else ps['auth_seq_id'].index(seqId)] else: if isPolySeq and self.__reasons is not None and 'global_auth_sequence_offset' in self.__reasons\ and ps['auth_chain_id'] in self.__reasons['global_auth_sequence_offset']: @@ -3595,12 +3602,12 @@ def getRealSeqId(self, ps, seqId, isPolySeq=True): offset = offset[seqId - shift] break if isinstance(offset, dict): - return None + return None, None if seqId + offset in ps['auth_seq_id']: - return seqId + offset + return seqId + offset, ps['comp_id'][ps['auth_seq_id'].index(seqId + offset)] # if seqId in ps['seq_id']: # return ps['auth_seq_id'][ps['seq_id'].index(seqId)] - return seqId + return seqId, None def getRealChainId(self, chainId): if self.__reasons is not None and 'segment_id_mismatch' in self.__reasons and chainId in self.__reasons['segment_id_mismatch']: @@ -3630,12 +3637,20 @@ def updateSegmentIdDict(self, factor, chainId, valid): if chainId in _stats: _stats[chainId] -= 1 - def getCoordAtomSiteOf(self, chainId, seqId, cifCheck=True, asis=True): + def getCoordAtomSiteOf(self, chainId, seqId, compId=None, cifCheck=True, asis=True): seqKey = (chainId, seqId) if asis: + if cifCheck and compId is not None: + _seqKey = (chainId, seqId, compId) + if _seqKey in self.__coordAtomSite: + return seqKey, self.__coordAtomSite[_seqKey] return seqKey, self.__coordAtomSite[seqKey] if cifCheck and seqKey in self.__coordAtomSite else None if seqKey in self.__labelToAuthSeq: seqKey = self.__labelToAuthSeq[seqKey] + if cifCheck and compId is not None: + _seqKey = (seqKey[0], seqKey[1], compId) + if _seqKey in self.__coordAtomSite: + return seqKey, self.__coordAtomSite[_seqKey] return seqKey, self.__coordAtomSite[seqKey] if cifCheck and seqKey in self.__coordAtomSite else None return seqKey, None @@ -4077,13 +4092,13 @@ def exitFactor(self, ctx: CharmmMRParser.FactorContext): if ps is not None: found = False for realSeqId in ps['auth_seq_id']: - realSeqId = self.getRealSeqId(ps, realSeqId) + realSeqId = self.getRealSeqId(ps, realSeqId)[0] if re.match(_seqId, str(realSeqId)): _seqIdSelect.add(realSeqId) found = True if not found: for realSeqId in ps['auth_seq_id']: - realSeqId = self.getRealSeqId(ps, realSeqId) + realSeqId = self.getRealSeqId(ps, realSeqId)[0] seqKey = (chainId, realSeqId) if seqKey in self.__authToLabelSeq: _, realSeqId = self.__authToLabelSeq[seqKey] @@ -4095,13 +4110,13 @@ def exitFactor(self, ctx: CharmmMRParser.FactorContext): for np in npList: found = False for realSeqId in np['auth_seq_id']: - realSeqId = self.getRealSeqId(np, realSeqId, False) + realSeqId = self.getRealSeqId(np, realSeqId, False)[0] if re.match(_seqId, str(realSeqId)): _seqIdSelect.add(realSeqId) found = True if not found: for realSeqId in np['auth_seq_id']: - realSeqId = self.getRealSeqId(np, realSeqId, False) + realSeqId = self.getRealSeqId(np, realSeqId, False)[0] seqKey = (chainId, realSeqId) if seqKey in self.__authToLabelSeq: _, realSeqId = self.__authToLabelSeq[seqKey] @@ -4118,8 +4133,8 @@ def exitFactor(self, ctx: CharmmMRParser.FactorContext): continue for seqId in self.factor['seq_id']: if seqId in ps['auth_seq_id']: - seqId = self.getRealSeqId(ps, seqId) - compId = ps['comp_id'][ps['auth_seq_id'].index(seqId)] + seqId, compId = self.getRealSeqId(ps, seqId) + # compId = ps['comp_id'][ps['auth_seq_id'].index(seqId)] if self.__ccU.updateChemCompDict(compId): if any(cca for cca in self.__ccU.lastAtomList if cca[self.__ccU.ccaAtomId] == atomId): _atomIdSelect.add(atomId) @@ -4129,8 +4144,8 @@ def exitFactor(self, ctx: CharmmMRParser.FactorContext): for np in npList: for seqId in self.factor['seq_id']: if seqId in np['auth_seq_id']: - seqId = self.getRealSeqId(np, seqId, False) - compId = np['comp_id'][np['auth_seq_id'].index(seqId)] + seqId, compId = self.getRealSeqId(np, seqId, False) + # compId = np['comp_id'][np['auth_seq_id'].index(seqId)] if self.__ccU.updateChemCompDict(compId): if any(cca for cca in self.__ccU.lastAtomList if cca[self.__ccU.ccaAtomId] == atomId): _atomIdSelect.add(atomId) @@ -4146,8 +4161,8 @@ def exitFactor(self, ctx: CharmmMRParser.FactorContext): continue for seqId in self.factor['seq_id']: if seqId in ps['auth_seq_id']: - seqId = self.getRealSeqId(ps, seqId) - compId = ps['comp_id'][ps['auth_seq_id'].index(seqId)] + seqId, compId = self.getRealSeqId(ps, seqId) + # compId = ps['comp_id'][ps['auth_seq_id'].index(seqId)] if self.__ccU.updateChemCompDict(compId): for cca in self.__ccU.lastAtomList: if cca[self.__ccU.ccaLeavingAtomFlag] != 'Y': @@ -4160,8 +4175,8 @@ def exitFactor(self, ctx: CharmmMRParser.FactorContext): for np in npList: for seqId in self.factor['seq_id']: if seqId in np['auth_seq_id']: - seqId = self.getRealSeqId(np, seqId, False) - compId = np['comp_id'][np['auth_seq_id'].index(seqId)] + seqId, compId = self.getRealSeqId(np, seqId, False) + # compId = np['comp_id'][np['auth_seq_id'].index(seqId)] if self.__ccU.updateChemCompDict(compId): for cca in self.__ccU.lastAtomList: if cca[self.__ccU.ccaLeavingAtomFlag] != 'Y': @@ -4399,14 +4414,14 @@ def exitFactor(self, ctx: CharmmMRParser.FactorContext): else: ps = next((ps for ps in self.__polySeq if ps['auth_chain_id'] == chainId), None) if ps is not None and seqId in ps['auth_seq_id'] and ps['comp_id'][ps['auth_seq_id'].index(seqId)] == compId: - seqId = self.getRealSeqId(ps, seqId) + seqId = self.getRealSeqId(ps, seqId)[0] if any(cca for cca in self.__ccU.lastAtomList if cca[self.__ccU.ccaAtomId] == _atomId): _atomSelection.append({'chain_id': chainId, 'seq_id': seqId, 'comp_id': compId, 'atom_id': _atomId}) if self.__hasNonPolySeq: npList = [np for np in self.__nonPolySeq if np['auth_chain_id'] == chainId] for np in npList: if seqId in np['auth_seq_id'] and np['comp_id'][np['auth_seq_id'].index(seqId)] == compId: - seqId = self.getRealSeqId(np, seqId, False) + seqId = self.getRealSeqId(np, seqId, False)[0] if any(cca for cca in self.__ccU.lastAtomList if cca[self.__ccU.ccaAtomId] == _atomId): _atomSelection.append({'chain_id': chainId, 'seq_id': seqId, 'comp_id': compId, 'atom_id': _atomId}) @@ -4431,8 +4446,8 @@ def exitFactor(self, ctx: CharmmMRParser.FactorContext): if ps is not None: for _seqId in [seqId - 1, seqId + 1]: if _seqId in ps['auth_seq_id']: - _seqId = self.getRealSeqId(ps, _seqId) - _compId = ps['comp_id'][ps['auth_seq_id'].index(_seqId)] + _seqId, _compId = self.getRealSeqId(ps, _seqId) + # _compId = ps['comp_id'][ps['auth_seq_id'].index(_seqId)] if self.__ccU.updateChemCompDict(_compId): leavingAtomIds = [cca[self.__ccU.ccaAtomId] for cca in self.__ccU.lastAtomList if cca[self.__ccU.ccaLeavingAtomFlag] == 'Y'] @@ -4471,8 +4486,8 @@ def exitFactor(self, ctx: CharmmMRParser.FactorContext): for np in npList: for _seqId in [seqId - 1, seqId + 1]: if _seqId in np['auth_seq_id']: - _seqId = self.getRealSeqId(np, _seqId, False) - _compId = np['comp_id'][np['auth_seq_id'].index(_seqId)] + _seqId, _compId = self.getRealSeqId(np, _seqId, False) + # _compId = np['comp_id'][np['auth_seq_id'].index(_seqId)] if self.__ccU.updateChemCompDict(_compId): leavingAtomIds = [cca[self.__ccU.ccaAtomId] for cca in self.__ccU.lastAtomList if cca[self.__ccU.ccaLeavingAtomFlag] == 'Y'] @@ -4683,7 +4698,7 @@ def exitFactor(self, ctx: CharmmMRParser.FactorContext): else: ps = next((ps for ps in self.__polySeq if ps['auth_chain_id'] == chainId), None) if ps is not None and seqId in ps['auth_seq_id'] and ps['comp_id'][ps['auth_seq_id'].index(seqId)] == compId: - seqId = self.getRealSeqId(ps, seqId) + seqId = self.getRealSeqId(ps, seqId)[0] if self.__ccU.updateChemCompDict(compId): atomIds = [cca[self.__ccU.ccaAtomId] for cca in self.__ccU.lastAtomList if cca[self.__ccU.ccaLeavingAtomFlag] != 'Y'] for atomId in atomIds: @@ -4692,7 +4707,7 @@ def exitFactor(self, ctx: CharmmMRParser.FactorContext): npList = [np for np in self.__nonPolySeq if np['auth_chain_id'] == chainId] for np in npList: if seqId in np['auth_seq_id'] and np['comp_id'][np['auth_seq_id'].index(seqId)] == compId: - seqId = self.getRealSeqId(np, seqId, False) + seqId = self.getRealSeqId(np, seqId, False)[0] if self.__ccU.updateChemCompDict(compId): atomIds = [cca[self.__ccU.ccaAtomId] for cca in self.__ccU.lastAtomList if cca[self.__ccU.ccaLeavingAtomFlag] != 'Y'] for atomId in atomIds: diff --git a/wwpdb/utils/nmr/mr/CnsMRParserListener.py b/wwpdb/utils/nmr/mr/CnsMRParserListener.py index 6024f6f49..4c86f090f 100644 --- a/wwpdb/utils/nmr/mr/CnsMRParserListener.py +++ b/wwpdb/utils/nmr/mr/CnsMRParserListener.py @@ -4895,7 +4895,7 @@ def __consumeFactor_expressions(self, _factor, clauseName='atom selection expres _atomIdSelect.add(realAtomId) for nonPolyCompId in _nonPolyCompIdSelect: - _, coordAtomSite = self.getCoordAtomSiteOf(nonPolyCompId['chain_id'], nonPolyCompId['seq_id'], cifCheck) + _, coordAtomSite = self.getCoordAtomSiteOf(nonPolyCompId['chain_id'], nonPolyCompId['seq_id'], cifCheck=cifCheck) if coordAtomSite is not None: for realAtomId in coordAtomSite['atom_id']: _atomIdSelect.add(realAtomId) @@ -4950,7 +4950,7 @@ def __consumeFactor_expressions(self, _factor, clauseName='atom selection expres _atomIdSelect.add(realAtomId) for nonPolyCompId in _nonPolyCompIdSelect: - _, coordAtomSite = self.getCoordAtomSiteOf(nonPolyCompId['chain_id'], nonPolyCompId['seq_id'], cifCheck) + _, coordAtomSite = self.getCoordAtomSiteOf(nonPolyCompId['chain_id'], nonPolyCompId['seq_id'], cifCheck=cifCheck) if coordAtomSite is not None: for realAtomId in coordAtomSite['atom_id']: _atomIdSelect.add(realAtomId) @@ -5137,7 +5137,7 @@ def __consumeFactor_expressions__(self, _factor, cifCheck, _atomSelection, continue _seqId_ = seqId - seqId = self.getRealSeqId(ps, seqId, isPolySeq) + seqId, _compId_ = self.getRealSeqId(ps, seqId, isPolySeq) if seqId is None: continue @@ -5200,13 +5200,17 @@ def __consumeFactor_expressions__(self, _factor, cifCheck, _atomSelection, compId = ps['comp_id'][idx] _seqId_ = ps['auth_seq_id'][idx] - seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck) + if self.__authToInsCode is None or len(self.__authToInsCode) == 0 or _compId_ is None: + seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, compId, cifCheck=cifCheck) + else: + compId = _compId_ + seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, _compId_, cifCheck=cifCheck) if compId is None and seqKey in self.__authToLabelSeq: _, seqId = self.__authToLabelSeq[seqKey] if ps is not None and seqId in ps['auth_seq_id']: compId = ps['comp_id'][ps['auth_seq_id'].index(seqId)] - seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck) + seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck=cifCheck) if compId is None and coordAtomSite is not None and ps is not None and seqKey[1] in ps['auth_seq_id']: compId = ps['comp_id'][ps['auth_seq_id'].index(seqKey[1])] @@ -5216,7 +5220,7 @@ def __consumeFactor_expressions__(self, _factor, cifCheck, _atomSelection, idx = ps['auth_seq_id'].index(seqId) seqId = ps['seq_id'][idx] compId = ps['comp_id'][idx] - seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck) + seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck=cifCheck) except ValueError: pass @@ -5233,7 +5237,7 @@ def __consumeFactor_expressions__(self, _factor, cifCheck, _atomSelection, _seqId = seqId if not isPolySeq and 'alt_auth_seq_id' in ps and seqId in ps['auth_seq_id'] and seqId not in ps['alt_auth_seq_id']: seqId = next(_altSeqId for _seqId, _altSeqId in zip(ps['auth_seq_id'], ps['alt_auth_seq_id']) if _seqId == seqId) - seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck) + seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck=cifCheck) if not isPolySeq and isChainSpecified and self.doesNonPolySeqIdMatchWithPolySeqUnobs(_factor['chain_id'][0], _seqId_): continue @@ -5351,7 +5355,7 @@ def __consumeFactor_expressions__(self, _factor, cifCheck, _atomSelection, _atom['type_symbol'] = coordAtomSite['type_symbol'][coordAtomSite['alt_atom_id'].index(_atomId)] self.__authAtomId = 'auth_atom_id' elif self.__preferAuthSeq and atomSpecified: - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck, asis=False) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck=cifCheck, asis=False) if _coordAtomSite is not None: _compId = _coordAtomSite['comp_id'] _atomId = self.getAtomIdList(_factor, _compId, atomId)[0] @@ -5396,7 +5400,7 @@ def __consumeFactor_expressions__(self, _factor, cifCheck, _atomSelection, """ elif _seqId_ in ps['auth_seq_id'] and atomSpecified: self.__preferAuthSeq = True - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, _seqId_, cifCheck) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, _seqId_, cifCheck=cifCheck) if _coordAtomSite is not None: _compId = _coordAtomSite['comp_id'] _atomId = self.getAtomIdList(_factor, _compId, atomId)[0] @@ -5426,7 +5430,7 @@ def __consumeFactor_expressions__(self, _factor, cifCheck, _atomSelection, elif self.__preferAuthSeq and atomSpecified: if len(self.atomSelectionSet) == 0: - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck, asis=False) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck=cifCheck, asis=False) if _coordAtomSite is not None: _compId = _coordAtomSite['comp_id'] _atomId = self.getAtomIdList(_factor, _compId, atomId)[0] @@ -5472,7 +5476,7 @@ def __consumeFactor_expressions__(self, _factor, cifCheck, _atomSelection, elif _seqId_ in ps['auth_seq_id'] and atomSpecified: if len(self.atomSelectionSet) == 0: self.__preferAuthSeq = True - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, _seqId_, cifCheck) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, _seqId_, cifCheck=cifCheck) if _coordAtomSite is not None: _compId = _coordAtomSite['comp_id'] _atomId = self.getAtomIdList(_factor, _compId, atomId)[0] @@ -5613,8 +5617,8 @@ def __consumeFactor_expressions__(self, _factor, cifCheck, _atomSelection, if len(__psList) == 0: continue for __ps in __psList: - __seqId = self.getRealSeqId(__ps, seqId, isPolySeq) - __seqKey, __coordAtomSite = self.getCoordAtomSiteOf(__chainId, __seqId, cifCheck) + __seqId, _ = self.getRealSeqId(__ps, seqId, isPolySeq) + __seqKey, __coordAtomSite = self.getCoordAtomSiteOf(__chainId, __seqId, cifCheck=cifCheck) if __coordAtomSite is not None: __compId = __coordAtomSite['comp_id'] __atomIds = self.getAtomIdList(_factor, __compId, atomId) @@ -5679,8 +5683,8 @@ def __consumeFactor_expressions__(self, _factor, cifCheck, _atomSelection, if len(__psList) == 0: continue for __ps in __psList: - __seqId = self.getRealSeqId(__ps, seqId, isPolySeq) - __seqKey, __coordAtomSite = self.getCoordAtomSiteOf(__chainId, __seqId, cifCheck) + __seqId, _ = self.getRealSeqId(__ps, seqId, isPolySeq) + __seqKey, __coordAtomSite = self.getCoordAtomSiteOf(__chainId, __seqId, cifCheck=cifCheck) if __coordAtomSite is not None: __compId = __coordAtomSite['comp_id'] __atomIds = self.getAtomIdList(_factor, __compId, atomId) @@ -5768,6 +5772,7 @@ def getRealSeqId(self, ps, seqId, isPolySeq=True): offset = 0 if not self.__preferAuthSeq: chainId = ps['chain_id'] + offset = 0 if isPolySeq and self.__reasons is not None and 'label_seq_offset' in self.__reasons and chainId in self.__reasons['label_seq_offset']: offset = self.__reasons['label_seq_offset'][chainId] if isPolySeq and self.__reasons is not None and 'global_sequence_offset' in self.__reasons\ @@ -5788,14 +5793,16 @@ def getRealSeqId(self, ps, seqId, isPolySeq=True): offset = offset[seqId - shift] break if isinstance(offset, dict): - return None + return None, None if seqId + offset in ps['auth_seq_id']: - return seqId + offset + return seqId + offset, ps['comp_id'][ps['auth_seq_id'].index(seqId + offset)] seqKey = (ps['chain_id' if isPolySeq else 'auth_chain_id'], seqId + offset) if seqKey in self.__labelToAuthSeq: _chainId, _seqId = self.__labelToAuthSeq[seqKey] if _seqId in ps['auth_seq_id']: - return _seqId + return _seqId, ps['comp_id'][ps['seq_id'].index(seqId + offset) + if seqId + offset in ps['seq_id'] + else ps['auth_seq_id'].index(seqId)] else: if isPolySeq and self.__reasons is not None and 'global_auth_sequence_offset' in self.__reasons\ and ps['auth_chain_id'] in self.__reasons['global_auth_sequence_offset']: @@ -5812,12 +5819,12 @@ def getRealSeqId(self, ps, seqId, isPolySeq=True): offset = offset[seqId - shift] break if isinstance(offset, dict): - return None + return None, None if seqId + offset in ps['auth_seq_id']: - return seqId + offset + return seqId + offset, ps['comp_id'][ps['auth_seq_id'].index(seqId + offset)] # if seqId in ps['seq_id']: # return ps['auth_seq_id'][ps['seq_id'].index(seqId)] - return seqId + return seqId, None def getRealChainId(self, chainId): if self.__reasons is not None and 'segment_id_mismatch' in self.__reasons and chainId in self.__reasons['segment_id_mismatch']: @@ -5847,12 +5854,20 @@ def updateSegmentIdDict(self, factor, chainId, valid): if chainId in _stats: _stats[chainId] -= 1 - def getCoordAtomSiteOf(self, chainId, seqId, cifCheck=True, asis=True): + def getCoordAtomSiteOf(self, chainId, seqId, compId=None, cifCheck=True, asis=True): seqKey = (chainId, seqId) if asis: + if cifCheck and compId is not None: + _seqKey = (chainId, seqId, compId) + if _seqKey in self.__coordAtomSite: + return seqKey, self.__coordAtomSite[_seqKey] return seqKey, self.__coordAtomSite[seqKey] if cifCheck and seqKey in self.__coordAtomSite else None if seqKey in self.__labelToAuthSeq: seqKey = self.__labelToAuthSeq[seqKey] + if cifCheck and compId is not None: + _seqKey = (seqKey[0], seqKey[1], compId) + if _seqKey in self.__coordAtomSite: + return seqKey, self.__coordAtomSite[_seqKey] return seqKey, self.__coordAtomSite[seqKey] if cifCheck and seqKey in self.__coordAtomSite else None return seqKey, None @@ -6387,13 +6402,13 @@ def set_store(num): if ps is not None: found = False for realSeqId in ps['auth_seq_id']: - realSeqId = self.getRealSeqId(ps, realSeqId) + realSeqId = self.getRealSeqId(ps, realSeqId)[0] if re.match(_seqId, str(realSeqId)): _seqIdSelect.add(realSeqId) found = True if not found: for realSeqId in ps['auth_seq_id']: - realSeqId = self.getRealSeqId(ps, realSeqId) + realSeqId = self.getRealSeqId(ps, realSeqId)[0] seqKey = (chainId, realSeqId) if seqKey in self.__authToLabelSeq: _, realSeqId = self.__authToLabelSeq[seqKey] @@ -6405,13 +6420,13 @@ def set_store(num): for np in npList: found = False for realSeqId in np['auth_seq_id']: - realSeqId = self.getRealSeqId(np, realSeqId, False) + realSeqId = self.getRealSeqId(np, realSeqId, False)[0] if re.match(_seqId, str(realSeqId)): _seqIdSelect.add(realSeqId) found = True if not found: for realSeqId in np['auth_seq_id']: - realSeqId = self.getRealSeqId(np, realSeqId, False) + realSeqId = self.getRealSeqId(np, realSeqId, False)[0] seqKey = (chainId, realSeqId) if seqKey in self.__authToLabelSeq: _, realSeqId = self.__authToLabelSeq[seqKey] @@ -6428,8 +6443,8 @@ def set_store(num): continue for seqId in self.factor['seq_id']: if seqId in ps['auth_seq_id']: - seqId = self.getRealSeqId(ps, seqId) - compId = ps['comp_id'][ps['auth_seq_id'].index(seqId)] + seqId, compId = self.getRealSeqId(ps, seqId) + # compId = ps['comp_id'][ps['auth_seq_id'].index(seqId)] if self.__ccU.updateChemCompDict(compId): if any(cca for cca in self.__ccU.lastAtomList if cca[self.__ccU.ccaAtomId] == atomId): _atomIdSelect.add(atomId) @@ -6439,8 +6454,8 @@ def set_store(num): for np in npList: for seqId in self.factor['seq_id']: if seqId in np['auth_seq_id']: - seqId = self.getRealSeqId(np, seqId, False) - compId = np['comp_id'][np['auth_seq_id'].index(seqId)] + seqId, compId = self.getRealSeqId(np, seqId, False) + # compId = np['comp_id'][np['auth_seq_id'].index(seqId)] if self.__ccU.updateChemCompDict(compId): if any(cca for cca in self.__ccU.lastAtomList if cca[self.__ccU.ccaAtomId] == atomId): _atomIdSelect.add(atomId) @@ -6456,8 +6471,8 @@ def set_store(num): continue for seqId in self.factor['seq_id']: if seqId in ps['auth_seq_id']: - seqId = self.getRealSeqId(ps, seqId) - compId = ps['comp_id'][ps['auth_seq_id'].index(seqId)] + seqId, compId = self.getRealSeqId(ps, seqId) + # compId = ps['comp_id'][ps['auth_seq_id'].index(seqId)] if self.__ccU.updateChemCompDict(compId): for cca in self.__ccU.lastAtomList: if cca[self.__ccU.ccaLeavingAtomFlag] != 'Y': @@ -6470,8 +6485,8 @@ def set_store(num): for np in npList: for seqId in self.factor['seq_id']: if seqId in np['auth_seq_id']: - seqId = self.getRealSeqId(np, seqId, False) - compId = np['comp_id'][np['auth_seq_id'].index(seqId)] + seqId, compId = self.getRealSeqId(np, seqId, False) + # compId = np['comp_id'][np['auth_seq_id'].index(seqId)] if self.__ccU.updateChemCompDict(compId): for cca in self.__ccU.lastAtomList: if cca[self.__ccU.ccaLeavingAtomFlag] != 'Y': @@ -6766,14 +6781,14 @@ def set_store(num): else: ps = next((ps for ps in self.__polySeq if ps['auth_chain_id'] == chainId), None) if ps is not None and seqId in ps['auth_seq_id'] and ps['comp_id'][ps['auth_seq_id'].index(seqId)] == compId: - seqId = self.getRealSeqId(ps, seqId) + seqId = self.getRealSeqId(ps, seqId)[0] if any(cca for cca in self.__ccU.lastAtomList if cca[self.__ccU.ccaAtomId] == _atomId): _atomSelection.append({'chain_id': chainId, 'seq_id': seqId, 'comp_id': compId, 'atom_id': _atomId}) if self.__hasNonPolySeq: npList = [np for np in self.__nonPolySeq if np['auth_chain_id'] == chainId] for np in npList: if seqId in np['auth_seq_id'] and np['comp_id'][np['auth_seq_id'].index(seqId)] == compId: - seqId = self.getRealSeqId(np, seqId, False) + seqId = self.getRealSeqId(np, seqId, False)[0] if any(cca for cca in self.__ccU.lastAtomList if cca[self.__ccU.ccaAtomId] == _atomId): _atomSelection.append({'chain_id': chainId, 'seq_id': seqId, 'comp_id': compId, 'atom_id': _atomId}) @@ -6798,8 +6813,8 @@ def set_store(num): if ps is not None: for _seqId in [seqId - 1, seqId + 1]: if _seqId in ps['auth_seq_id']: - _seqId = self.getRealSeqId(ps, _seqId) - _compId = ps['comp_id'][ps['auth_seq_id'].index(_seqId)] + _seqId, _compId = self.getRealSeqId(ps, _seqId) + # _compId = ps['comp_id'][ps['auth_seq_id'].index(_seqId)] if self.__ccU.updateChemCompDict(_compId): leavingAtomIds = [cca[self.__ccU.ccaAtomId] for cca in self.__ccU.lastAtomList if cca[self.__ccU.ccaLeavingAtomFlag] == 'Y'] @@ -6838,8 +6853,8 @@ def set_store(num): for np in npList: for _seqId in [seqId - 1, seqId + 1]: if _seqId in np['auth_seq_id']: - _seqId = self.getRealSeqId(np, _seqId, False) - _compId = np['comp_id'][np['auth_seq_id'].index(_seqId)] + _seqId, _compId = self.getRealSeqId(np, _seqId, False) + # _compId = np['comp_id'][np['auth_seq_id'].index(_seqId)] if self.__ccU.updateChemCompDict(_compId): leavingAtomIds = [cca[self.__ccU.ccaAtomId] for cca in self.__ccU.lastAtomList if cca[self.__ccU.ccaLeavingAtomFlag] == 'Y'] @@ -7050,7 +7065,7 @@ def set_store(num): else: ps = next((ps for ps in self.__polySeq if ps['auth_chain_id'] == chainId), None) if ps is not None and seqId in ps['auth_seq_id'] and ps['comp_id'][ps['auth_seq_id'].index(seqId)] == compId: - seqId = self.getRealSeqId(ps, seqId) + seqId = self.getRealSeqId(ps, seqId)[0] if self.__ccU.updateChemCompDict(compId): atomIds = [cca[self.__ccU.ccaAtomId] for cca in self.__ccU.lastAtomList if cca[self.__ccU.ccaLeavingAtomFlag] != 'Y'] for atomId in atomIds: @@ -7059,7 +7074,7 @@ def set_store(num): npList = [np for np in self.__nonPolySeq if np['auth_chain_id'] == chainId] for np in npList: if seqId in np['auth_seq_id'] and np['comp_id'][np['auth_seq_id'].index(seqId)] == compId: - seqId = self.getRealSeqId(np, seqId, False) + seqId = self.getRealSeqId(np, seqId, False)[0] if self.__ccU.updateChemCompDict(compId): atomIds = [cca[self.__ccU.ccaAtomId] for cca in self.__ccU.lastAtomList if cca[self.__ccU.ccaLeavingAtomFlag] != 'Y'] for atomId in atomIds: diff --git a/wwpdb/utils/nmr/mr/CyanaMRParserListener.py b/wwpdb/utils/nmr/mr/CyanaMRParserListener.py index 319045390..c4320b3af 100644 --- a/wwpdb/utils/nmr/mr/CyanaMRParserListener.py +++ b/wwpdb/utils/nmr/mr/CyanaMRParserListener.py @@ -2054,20 +2054,20 @@ def getRealChainSeqId(self, ps, seqId, compId=None, isPolySeq=True): if seqKey in self.__labelToAuthSeq: _chainId, _seqId = self.__labelToAuthSeq[seqKey] if _seqId in ps['auth_seq_id']: - return _chainId, _seqId + return _chainId, _seqId, ps['comp_id'][ps['seq_id'].index(seqId)] if seqId in ps['auth_seq_id']: if compId is None: - return ps['auth_chain_id'], seqId - idx = ps['auth_seq_id'].index(seqId) - if compId in (ps['comp_id'][idx], ps['auth_comp_id'][idx]): - return ps['auth_chain_id'], seqId + return ps['auth_chain_id'], seqId, ps['auth_seq_id'][ps['auth_seq_id'].index(seqId)] + for idx in [_idx for _idx, _seqId in enumerate(ps['auth_seq_id']) if _seqId == seqId]: + if compId in (ps['comp_id'][idx], ps['auth_comp_id'][idx]): + return ps['auth_chain_id'], seqId, ps['comp_id'][idx] # if seqId in ps['seq_id']: # idx = ps['seq_id'].index(seqId) # if compId is None: # return ps['auth_chain_id'], ps['auth_seq_id'][idx] # if compId in (ps['comp_id'][idx], ps['auth_comp_id'][idx]): # return ps['auth_chain_id'], ps['auth_seq_id'][idx] - return ps['chain_id' if isPolySeq else 'auth_chain_id'], seqId + return ps['chain_id' if isPolySeq else 'auth_chain_id'], seqId, None def assignCoordPolymerSequence(self, seqId, compId, atomId): """ Assign polymer sequences of the coordinates. @@ -2140,7 +2140,7 @@ def assignCoordPolymerSequence(self, seqId, compId, atomId): for ps in self.__polySeq: if preferNonPoly: continue - chainId, seqId = self.getRealChainSeqId(ps, _seqId, compId) + chainId, seqId, cifCompId = self.getRealChainSeqId(ps, _seqId, compId) if self.__reasons is not None: if fixedChainId is not None: if fixedChainId != chainId: @@ -2150,7 +2150,11 @@ def assignCoordPolymerSequence(self, seqId, compId, atomId): elif fixedSeqId is not None: seqId = fixedSeqId if seqId in ps['auth_seq_id']: - idx = ps['auth_seq_id'].index(seqId) + if cifCompId is not None: + idx = next((_idx for _idx, (_seqId_, _cifCompId_) in enumerate(zip(ps['auth_seq_id'], ps['comp_id'])) + if _seqId_ == seqId and _cifCompId_ == cifCompId), ps['auth_seq_id'].index(seqId)) + else: + idx = ps['auth_seq_id'].index(seqId) cifCompId = ps['comp_id'][idx] origCompId = ps['auth_comp_id'][idx] if cifCompId != compId: @@ -2160,7 +2164,7 @@ def assignCoordPolymerSequence(self, seqId, compId, atomId): origCompId = next(origCompId for _seqId, _compId, origCompId in zip(ps['auth_seq_id'], ps['comp_id'], ps['auth_comp_id']) if _seqId == seqId and _compId == compId) if self.__mrAtomNameMapping is not None and origCompId not in monDict3: - _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, self.__hasCoord) + _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCompId, cifCheck=self.__hasCoord) atomId = retrieveAtomIdFromMRMap(self.__mrAtomNameMapping, seqId, origCompId, atomId, coordAtomSite) if compId in (cifCompId, origCompId, 'MTS', 'ORI'): if len(self.__nefT.get_valid_star_atom(cifCompId, atomId)[0]) > 0: @@ -2202,7 +2206,7 @@ def assignCoordPolymerSequence(self, seqId, compId, atomId): origCompId = next(origCompId for _seqId, _compId, origCompId in zip(ps['auth_seq_id'], ps['comp_id'], ps['auth_comp_id']) if _seqId == seqId and _compId == compId) if self.__mrAtomNameMapping is not None and origCompId not in monDict3: - _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId_, self.__hasCoord) + _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId_, cifCompId, cifCheck=self.__hasCoord) atomId = retrieveAtomIdFromMRMap(self.__mrAtomNameMapping, seqId, origCompId, atomId, coordAtomSite) if compId in (cifCompId, origCompId, 'MTS', 'ORI'): if len(self.__nefT.get_valid_star_atom(cifCompId, atomId)[0]) > 0: @@ -2214,7 +2218,7 @@ def assignCoordPolymerSequence(self, seqId, compId, atomId): if self.__hasNonPolySeq: for np in self.__nonPolySeq: - chainId, seqId = self.getRealChainSeqId(np, _seqId, compId, False) + chainId, seqId, cifCompId = self.getRealChainSeqId(np, _seqId, compId, False) if self.__reasons is not None: if fixedChainId is not None: if fixedChainId != chainId: @@ -2224,11 +2228,15 @@ def assignCoordPolymerSequence(self, seqId, compId, atomId): elif fixedSeqId is not None: seqId = fixedSeqId if seqId in np['auth_seq_id']: - idx = np['auth_seq_id'].index(seqId) + if cifCompId is not None: + idx = next((_idx for _idx, (_seqId_, _cifCompId_) in enumerate(zip(np['auth_seq_id'], np['comp_id'])) + if _seqId_ == seqId and _cifCompId_ == cifCompId), np['auth_seq_id'].index(seqId)) + else: + idx = np['auth_seq_id'].index(seqId) cifCompId = np['comp_id'][idx] origCompId = np['auth_comp_id'][idx] if self.__mrAtomNameMapping is not None and origCompId not in monDict3: - _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, self.__hasCoord) + _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCompId, cifCheck=self.__hasCoord) atomId = retrieveAtomIdFromMRMap(self.__mrAtomNameMapping, seqId, origCompId, atomId, coordAtomSite) if 'alt_auth_seq_id' in np and seqId in np['auth_seq_id'] and seqId not in np['alt_auth_seq_id']: seqId = next(_altSeqId for _seqId, _altSeqId in zip(np['auth_seq_id'], np['alt_auth_seq_id']) if _seqId == seqId) @@ -2259,7 +2267,7 @@ def assignCoordPolymerSequence(self, seqId, compId, atomId): origCompId = next(origCompId for _seqId, _compId, origCompId in zip(ps['auth_seq_id'], ps['comp_id'], ps['auth_comp_id']) if _seqId == seqId and _compId == compId) if self.__mrAtomNameMapping is not None and origCompId not in monDict3: - _, coordAtomSite = self.getCoordAtomSiteOf(chainId, _seqId, self.__hasCoord) + _, coordAtomSite = self.getCoordAtomSiteOf(chainId, _seqId, cifCompId, cifCheck=self.__hasCoord) atomId = retrieveAtomIdFromMRMap(self.__mrAtomNameMapping, seqId, origCompId, atomId, coordAtomSite) if compId in (cifCompId, origCompId, 'MTS', 'ORI'): if len(self.__nefT.get_valid_star_atom(cifCompId, atomId)[0]) > 0: @@ -2287,7 +2295,7 @@ def assignCoordPolymerSequence(self, seqId, compId, atomId): cifCompId = np['comp_id'][idx] origCompId = np['auth_comp_id'][idx] if self.__mrAtomNameMapping is not None and origCompId not in monDict3: - _, coordAtomSite = self.getCoordAtomSiteOf(chainId, _seqId, self.__hasCoord) + _, coordAtomSite = self.getCoordAtomSiteOf(chainId, _seqId, cifCompId, cifCheck=self.__hasCoord) atomId = retrieveAtomIdFromMRMap(self.__mrAtomNameMapping, seqId, origCompId, atomId, coordAtomSite) if compId in (cifCompId, origCompId, 'MTS', 'ORI'): if len(self.__nefT.get_valid_star_atom(cifCompId, atomId)[0]) > 0: @@ -2328,7 +2336,7 @@ def assignCoordPolymerSequence(self, seqId, compId, atomId): if seqKey in self.__labelToAuthSeq: _, seqId = self.__labelToAuthSeq[seqKey] if seqId in ps['auth_seq_id']: - idx = ps['auth_seq_id'].index(seqId) + idx = ps['seq_id'].index(_seqId) cifCompId = ps['comp_id'][idx] origCompId = ps['auth_comp_id'][idx] if cifCompId != compId: @@ -2338,7 +2346,7 @@ def assignCoordPolymerSequence(self, seqId, compId, atomId): origCompId = next(origCompId for _seqId, _compId, origCompId in zip(ps['auth_seq_id'], ps['comp_id'], ps['auth_comp_id']) if _seqId == seqId and _compId == compId) if self.__mrAtomNameMapping is not None and origCompId not in monDict3: - _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, self.__hasCoord) + _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCompId, cifCheck=self.__hasCoord) atomId = retrieveAtomIdFromMRMap(self.__mrAtomNameMapping, seqId, origCompId, atomId, coordAtomSite) if compId in (cifCompId, origCompId, 'MTS', 'ORI'): if len(self.__nefT.get_valid_star_atom(cifCompId, atomId)[0]) > 0: @@ -2461,7 +2469,7 @@ def assignCoordPolymerSequenceWithChainId(self, refChainId, seqId, compId, atomI for ps in self.__polySeq: if preferNonPoly: continue - chainId, seqId = self.getRealChainSeqId(ps, _seqId, compId) + chainId, seqId, cifCompId = self.getRealChainSeqId(ps, _seqId, compId) if fixedChainId is None and refChainId is not None and refChainId != chainId and refChainId in self.__chainNumberDict: if chainId != self.__chainNumberDict[refChainId]: continue @@ -2474,7 +2482,11 @@ def assignCoordPolymerSequenceWithChainId(self, refChainId, seqId, compId, atomI elif fixedSeqId is not None: seqId = fixedSeqId if seqId in ps['auth_seq_id']: - idx = ps['auth_seq_id'].index(seqId) + if cifCompId is not None: + idx = next((_idx for _idx, (_seqId_, _cifCompId_) in enumerate(zip(ps['auth_seq_id'], ps['comp_id'])) + if _seqId_ == seqId and _cifCompId_ == cifCompId), ps['auth_seq_id'].index(seqId)) + else: + idx = ps['auth_seq_id'].index(seqId) cifCompId = ps['comp_id'][idx] origCompId = ps['auth_comp_id'][idx] if cifCompId != compId: @@ -2484,7 +2496,7 @@ def assignCoordPolymerSequenceWithChainId(self, refChainId, seqId, compId, atomI origCompId = next(origCompId for _seqId, _compId, origCompId in zip(ps['auth_seq_id'], ps['comp_id'], ps['auth_comp_id']) if _seqId == seqId and _compId == compId) if self.__mrAtomNameMapping is not None and origCompId not in monDict3: - _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, self.__hasCoord) + _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCompId, cifCheck=self.__hasCoord) atomId = retrieveAtomIdFromMRMap(self.__mrAtomNameMapping, seqId, origCompId, atomId, coordAtomSite) if compId in (cifCompId, origCompId, 'MTS', 'ORI'): if len(self.__nefT.get_valid_star_atom(cifCompId, atomId)[0]) > 0: @@ -2530,7 +2542,7 @@ def assignCoordPolymerSequenceWithChainId(self, refChainId, seqId, compId, atomI origCompId = next(origCompId for _seqId, _compId, origCompId in zip(ps['auth_seq_id'], ps['comp_id'], ps['auth_comp_id']) if _seqId == seqId and _compId == compId) if self.__mrAtomNameMapping is not None and origCompId not in monDict3: - _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId_, self.__hasCoord) + _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId_, cifCompId, cifCheck=self.__hasCoord) atomId = retrieveAtomIdFromMRMap(self.__mrAtomNameMapping, seqId, origCompId, atomId, coordAtomSite) if compId in (cifCompId, origCompId, 'MTS', 'ORI'): if len(self.__nefT.get_valid_star_atom(cifCompId, atomId)[0]) > 0: @@ -2542,7 +2554,7 @@ def assignCoordPolymerSequenceWithChainId(self, refChainId, seqId, compId, atomI if self.__hasNonPolySeq: for np in self.__nonPolySeq: - chainId, seqId = self.getRealChainSeqId(np, _seqId, compId, False) + chainId, seqId, cifCompId = self.getRealChainSeqId(np, _seqId, compId, False) if fixedChainId is None and refChainId is not None and refChainId != chainId and refChainId in self.__chainNumberDict: if chainId != self.__chainNumberDict[refChainId]: continue @@ -2555,11 +2567,15 @@ def assignCoordPolymerSequenceWithChainId(self, refChainId, seqId, compId, atomI elif fixedSeqId is not None: seqId = fixedSeqId if seqId in np['auth_seq_id']: - idx = np['auth_seq_id'].index(seqId) + if cifCompId is not None: + idx = next((_idx for _idx, (_seqId_, _cifCompId_) in enumerate(zip(np['auth_seq_id'], np['comp_id'])) + if _seqId_ == seqId and _cifCompId_ == cifCompId), np['auth_seq_id'].index(seqId)) + else: + idx = np['auth_seq_id'].index(seqId) cifCompId = np['comp_id'][idx] origCompId = np['auth_comp_id'][idx] if self.__mrAtomNameMapping is not None and origCompId not in monDict3: - _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, self.__hasCoord) + _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCompId, cifCheck=self.__hasCoord) atomId = retrieveAtomIdFromMRMap(self.__mrAtomNameMapping, seqId, origCompId, atomId, coordAtomSite) if 'alt_auth_seq_id' in np and seqId in np['auth_seq_id'] and seqId not in np['alt_auth_seq_id']: seqId = next(_altSeqId for _seqId, _altSeqId in zip(np['auth_seq_id'], np['alt_auth_seq_id']) if _seqId == seqId) @@ -2598,7 +2614,7 @@ def assignCoordPolymerSequenceWithChainId(self, refChainId, seqId, compId, atomI origCompId = next(origCompId for _seqId, _compId, origCompId in zip(ps['auth_seq_id'], ps['comp_id'], ps['auth_comp_id']) if _seqId == seqId and _compId == compId) if self.__mrAtomNameMapping is not None and origCompId not in monDict3: - _, coordAtomSite = self.getCoordAtomSiteOf(chainId, _seqId, self.__hasCoord) + _, coordAtomSite = self.getCoordAtomSiteOf(chainId, _seqId, cifCompId, cifCheck=self.__hasCoord) atomId = retrieveAtomIdFromMRMap(self.__mrAtomNameMapping, seqId, origCompId, atomId, coordAtomSite) if compId in (cifCompId, origCompId, 'MTS', 'ORI'): if len(self.__nefT.get_valid_star_atom(cifCompId, atomId)[0]) > 0: @@ -2634,7 +2650,7 @@ def assignCoordPolymerSequenceWithChainId(self, refChainId, seqId, compId, atomI cifCompId = np['comp_id'][idx] origCompId = np['auth_comp_id'][idx] if self.__mrAtomNameMapping is not None and origCompId not in monDict3: - _, coordAtomSite = self.getCoordAtomSiteOf(chainId, _seqId, self.__hasCoord) + _, coordAtomSite = self.getCoordAtomSiteOf(chainId, _seqId, cifCompId, cifCheck=self.__hasCoord) atomId = retrieveAtomIdFromMRMap(self.__mrAtomNameMapping, seqId, origCompId, atomId, coordAtomSite) if compId in (cifCompId, origCompId, 'MTS', 'ORI'): if len(self.__nefT.get_valid_star_atom(cifCompId, atomId)[0]) > 0: @@ -2693,7 +2709,7 @@ def assignCoordPolymerSequenceWithChainId(self, refChainId, seqId, compId, atomI if seqKey in self.__labelToAuthSeq: _, seqId = self.__labelToAuthSeq[seqKey] if seqId in ps['auth_seq_id']: - idx = ps['auth_seq_id'].index(seqId) + idx = ps['seq_id'].index(_seqId) cifCompId = ps['comp_id'][idx] origCompId = ps['auth_comp_id'][idx] if cifCompId != compId: @@ -2703,7 +2719,7 @@ def assignCoordPolymerSequenceWithChainId(self, refChainId, seqId, compId, atomI origCompId = next(origCompId for _seqId, _compId, origCompId in zip(ps['auth_seq_id'], ps['comp_id'], ps['auth_comp_id']) if _seqId == seqId and _compId == compId) if self.__mrAtomNameMapping is not None and origCompId not in monDict3: - _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, self.__hasCoord) + _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCompId, cifCheck=self.__hasCoord) atomId = retrieveAtomIdFromMRMap(self.__mrAtomNameMapping, seqId, origCompId, atomId, coordAtomSite) if compId in (cifCompId, origCompId, 'MTS', 'ORI'): if len(self.__nefT.get_valid_star_atom(cifCompId, atomId)[0]) > 0: @@ -2780,7 +2796,7 @@ def assignCoordPolymerSequenceWithoutCompId(self, seqId, atomId=None): seqId = _seqId = fixedSeqId for ps in self.__polySeq: - chainId, seqId = self.getRealChainSeqId(ps, _seqId, None) + chainId, seqId, cifCompId = self.getRealChainSeqId(ps, _seqId, None) if self.__reasons is not None: if 'seq_id_remap' not in self.__reasons and 'chain_seq_id_remap' not in self.__reasons: if fixedChainId != chainId: @@ -2797,7 +2813,11 @@ def assignCoordPolymerSequenceWithoutCompId(self, seqId, atomId=None): if fixedSeqId is not None: seqId = _seqId = fixedSeqId if seqId in ps['auth_seq_id']: - idx = ps['auth_seq_id'].index(seqId) + if cifCompId is not None: + idx = next((_idx for _idx, (_seqId_, _cifCompId_) in enumerate(zip(ps['auth_seq_id'], ps['comp_id'])) + if _seqId_ == seqId and _cifCompId_ == cifCompId), ps['auth_seq_id'].index(seqId)) + else: + idx = ps['auth_seq_id'].index(seqId) cifCompId = ps['comp_id'][idx] if self.__reasons is not None: if 'non_poly_remap' in self.__reasons and cifCompId in self.__reasons['non_poly_remap']\ @@ -2840,7 +2860,7 @@ def assignCoordPolymerSequenceWithoutCompId(self, seqId, atomId=None): if self.__hasNonPolySeq: for np in self.__nonPolySeq: - chainId, seqId = self.getRealChainSeqId(np, _seqId, None, False) + chainId, seqId, cifCompId = self.getRealChainSeqId(np, _seqId, None, False) if self.__reasons is not None: if 'seq_id_remap' not in self.__reasons and 'chain_seq_id_remap' not in self.__reasons: if fixedChainId != chainId: @@ -2857,7 +2877,11 @@ def assignCoordPolymerSequenceWithoutCompId(self, seqId, atomId=None): if fixedSeqId is not None: seqId = _seqId = fixedSeqId if seqId in np['auth_seq_id']: - idx = np['auth_seq_id'].index(seqId) + if cifCompId is not None: + idx = next((_idx for _idx, (_seqId_, _cifCompId_) in enumerate(zip(np['auth_seq_id'], np['comp_id'])) + if _seqId_ == seqId and _cifCompId_ == cifCompId), np['auth_seq_id'].index(seqId)) + else: + idx = np['auth_seq_id'].index(seqId) cifCompId = np['comp_id'][idx] updatePolySeqRst(self.__polySeqRst, chainId, _seqId, cifCompId) if atomId is None or len(self.__nefT.get_valid_star_atom(cifCompId, atomId)[0]) > 0: @@ -2979,7 +3003,7 @@ def assignCoordPolymerSequenceWithChainIdWithoutCompId(self, fixedChainId, seqId seqId = _seqId = fixedSeqId for ps in self.__polySeq: - chainId, seqId = self.getRealChainSeqId(ps, _seqId, None) + chainId, seqId, cifCompId = self.getRealChainSeqId(ps, _seqId, None) if chainId != fixedChainId: continue if self.__reasons is not None: @@ -2998,7 +3022,11 @@ def assignCoordPolymerSequenceWithChainIdWithoutCompId(self, fixedChainId, seqId if fixedSeqId is not None: seqId = _seqId = fixedSeqId if seqId in ps['auth_seq_id']: - idx = ps['auth_seq_id'].index(seqId) + if cifCompId is not None: + idx = next((_idx for _idx, (_seqId_, _cifCompId_) in enumerate(zip(ps['auth_seq_id'], ps['comp_id'])) + if _seqId_ == seqId and _cifCompId_ == cifCompId), ps['auth_seq_id'].index(seqId)) + else: + idx = ps['auth_seq_id'].index(seqId) cifCompId = ps['comp_id'][idx] if self.__reasons is not None: if 'non_poly_remap' in self.__reasons and cifCompId in self.__reasons['non_poly_remap']\ @@ -3041,7 +3069,7 @@ def assignCoordPolymerSequenceWithChainIdWithoutCompId(self, fixedChainId, seqId if self.__hasNonPolySeq: for np in self.__nonPolySeq: - chainId, seqId = self.getRealChainSeqId(np, _seqId, None, False) + chainId, seqId, cifCompId = self.getRealChainSeqId(np, _seqId, None, False) if chainId != fixedChainId: continue if self.__reasons is not None: @@ -3060,7 +3088,11 @@ def assignCoordPolymerSequenceWithChainIdWithoutCompId(self, fixedChainId, seqId if fixedSeqId is not None: seqId = _seqId = fixedSeqId if seqId in np['auth_seq_id']: - idx = np['auth_seq_id'].index(seqId) + if cifCompId is not None: + idx = next((_idx for _idx, (_seqId_, _cifCompId_) in enumerate(zip(np['auth_seq_id'], np['comp_id'])) + if _seqId_ == seqId and _cifCompId_ == cifCompId), np['auth_seq_id'].index(seqId)) + else: + idx = np['auth_seq_id'].index(seqId) cifCompId = np['comp_id'][idx] updatePolySeqRst(self.__polySeqRst, fixedChainId, _seqId, cifCompId) if len(self.__nefT.get_valid_star_atom(cifCompId, atomId)[0]) > 0: @@ -3189,7 +3221,7 @@ def selectCoordAtoms(self, chainAssign, seqId, compId, atomId, allowAmbig=True, cifSeqId = atom['seq_id'] cifCompId = atom['comp_id'] cifAtomId = atom['atom_id'] - seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, cifSeqId, self.__hasCoord) + seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, cifSeqId, cifCompId) self.testCoordAtomIdConsistency(chainId, cifSeqId, cifCompId, cifAtomId, seqKey, coordAtomSite, enableWarning) if len(atomSelection) > 0: self.atomSelectionSet.append(atomSelection) @@ -3198,7 +3230,7 @@ def selectCoordAtoms(self, chainAssign, seqId, compId, atomId, allowAmbig=True, and atomId in self.__reasons['unambig_atom_id_remap'][compId]: atomIds = self.__reasons['unambig_atom_id_remap'][compId][atomId] for chainId, cifSeqId, cifCompId, isPolySeq in chainAssign: - seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, cifSeqId, self.__hasCoord) + seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, cifSeqId, cifCompId) for cifAtomId in atomIds: self.testCoordAtomIdConsistency(chainId, cifSeqId, cifCompId, cifAtomId, seqKey, coordAtomSite, enableWarning) atomSelection.append({'chain_id': chainId, 'seq_id': cifSeqId, 'comp_id': cifCompId, 'atom_id': cifAtomId}) @@ -3214,7 +3246,7 @@ def selectCoordAtoms(self, chainAssign, seqId, compId, atomId, allowAmbig=True, cifSeqId = atom['seq_id'] cifCompId = atom['comp_id'] cifAtomId = atom['atom_id'] - seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, cifSeqId, self.__hasCoord) + seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, cifSeqId, cifCompId) self.testCoordAtomIdConsistency(chainId, cifSeqId, cifCompId, cifAtomId, seqKey, coordAtomSite, enableWarning) if len(atomSelection) > 0: self.atomSelectionSet.append(atomSelection) @@ -3223,7 +3255,7 @@ def selectCoordAtoms(self, chainAssign, seqId, compId, atomId, allowAmbig=True, if compId in self.unambigAtomNameMapping and atomId in self.unambigAtomNameMapping[compId]: atomIds = self.unambigAtomNameMapping[compId][atomId] for chainId, cifSeqId, cifCompId, isPolySeq in chainAssign: - seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, cifSeqId, self.__hasCoord) + seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, cifSeqId, cifCompId) for cifAtomId in atomIds: self.testCoordAtomIdConsistency(chainId, cifSeqId, cifCompId, cifAtomId, seqKey, coordAtomSite, enableWarning) atomSelection.append({'chain_id': chainId, 'seq_id': cifSeqId, 'comp_id': cifCompId, 'atom_id': cifAtomId}) @@ -3239,7 +3271,7 @@ def selectCoordAtoms(self, chainAssign, seqId, compId, atomId, allowAmbig=True, cifSeqId += offset cifCompId = compId - seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, cifSeqId, self.__hasCoord, asis=self.__preferAuthSeq) + seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, cifSeqId, cifCompId, asis=self.__preferAuthSeq) if self.__cur_subtype == 'dist' and _compId is not None and (_compId.startswith('MTS') or _compId.startswith('ORI')) and cifCompId != _compId: if _atomId[0] in ('O', 'N'): @@ -3307,7 +3339,7 @@ def selectCoordAtoms(self, chainAssign, seqId, compId, atomId, allowAmbig=True, for np in self.__nonPolySeq: if np['auth_chain_id'] == chainId and cifSeqId in np['auth_seq_id']: cifSeqId = np['seq_id'][np['auth_seq_id'].index(cifSeqId)] - seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, cifSeqId, self.__hasCoord) + seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, cifSeqId, cifCompId) if coordAtomSite is not None: break except ValueError: @@ -3327,7 +3359,7 @@ def selectCoordAtoms(self, chainAssign, seqId, compId, atomId, allowAmbig=True, cifCompId = compId if not multiChain and not insCode: if self.__preferAuthSeq: - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, cifSeqId, asis=False) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, cifSeqId, cifCompId, asis=False) if _coordAtomSite is not None and _coordAtomSite['comp_id'] == compId: if lenAtomId > 0 and _atomId[0] in _coordAtomSite['atom_id']: self.__authSeqId = 'label_seq_id' @@ -3403,7 +3435,7 @@ def testCoordAtomIdConsistency(self, chainId, seqId, compId, atomId, seqKey, coo self.__authAtomId = 'auth_atom_id' elif self.__preferAuthSeq: - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, asis=False) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, compId, asis=False) if _coordAtomSite is not None and _coordAtomSite['comp_id'] == compId: if atomId in _coordAtomSite['atom_id']: found = True @@ -3421,7 +3453,7 @@ def testCoordAtomIdConsistency(self, chainId, seqId, compId, atomId, seqKey, coo else: self.__preferAuthSeq = True - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, compId) if _coordAtomSite is not None and _coordAtomSite['comp_id'] == compId: if atomId in _coordAtomSite['atom_id']: found = True @@ -3440,7 +3472,7 @@ def testCoordAtomIdConsistency(self, chainId, seqId, compId, atomId, seqKey, coo self.__preferAuthSeq = False elif self.__preferAuthSeq: - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, asis=False) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, compId, asis=False) if _coordAtomSite is not None and _coordAtomSite['comp_id'] == compId: if atomId in _coordAtomSite['atom_id']: found = True @@ -3458,7 +3490,7 @@ def testCoordAtomIdConsistency(self, chainId, seqId, compId, atomId, seqKey, coo else: self.__preferAuthSeq = True - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, compId) if _coordAtomSite is not None and _coordAtomSite['comp_id'] == compId: if atomId in _coordAtomSite['atom_id']: found = True @@ -3480,7 +3512,7 @@ def testCoordAtomIdConsistency(self, chainId, seqId, compId, atomId, seqKey, coo return if self.__preferAuthSeq: - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, asis=False) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, compId, asis=False) if _coordAtomSite is not None and _coordAtomSite['comp_id'] == compId: if atomId in _coordAtomSite['atom_id']: found = True @@ -3498,7 +3530,7 @@ def testCoordAtomIdConsistency(self, chainId, seqId, compId, atomId, seqKey, coo else: self.__preferAuthSeq = True - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, compId) if _coordAtomSite is not None and _coordAtomSite['comp_id'] == compId: if atomId in _coordAtomSite['atom_id']: found = True @@ -3828,20 +3860,27 @@ def selectRealisticChi2AngleConstraint(self, atom1, atom2, atom3, atom4, dst_fun return dst_func - def getCoordAtomSiteOf(self, chainId, seqId, cifCheck=True, asis=True): + def getCoordAtomSiteOf(self, chainId, seqId, compId=None, cifCheck=True, asis=True): seqKey = (chainId, seqId) - coordAtomSite = None if cifCheck: preferAuthSeq = self.__preferAuthSeq if asis else not self.__preferAuthSeq if preferAuthSeq: + if compId is not None: + _seqKey = (chainId, seqId, compId) + if _seqKey in self.__coordAtomSite: + return seqKey, self.__coordAtomSite[_seqKey] if seqKey in self.__coordAtomSite: - coordAtomSite = self.__coordAtomSite[seqKey] + return seqKey, self.__coordAtomSite[seqKey] else: if seqKey in self.__labelToAuthSeq: seqKey = self.__labelToAuthSeq[seqKey] + if cifCheck and compId is not None: + _seqKey = (seqKey[0], seqKey[1], compId) + if _seqKey in self.__coordAtomSite: + return seqKey, self.__coordAtomSite[_seqKey] if seqKey in self.__coordAtomSite: - coordAtomSite = self.__coordAtomSite[seqKey] - return seqKey, coordAtomSite + return seqKey, self.__coordAtomSite[seqKey] + return seqKey, None # Enter a parse tree produced by CyanaMRParser#torsion_angle_restraints. def enterTorsion_angle_restraints(self, ctx: CyanaMRParser.Torsion_angle_restraintsContext): # pylint: disable=unused-argument @@ -4055,7 +4094,7 @@ def exitTorsion_angle_restraint(self, ctx: CyanaMRParser.Torsion_angle_restraint _cifSeqId = cifSeqId + offset _cifCompId = cifCompId if offset == 0 else (ps['comp_id'][ps['auth_seq_id'].index(_cifSeqId)] if _cifSeqId in ps['auth_seq_id'] else None) - seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, _cifSeqId, self.__hasCoord) + seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, _cifSeqId, _cifCompId, cifCheck=self.__hasCoord) if _cifCompId is None: # """ @@ -4094,7 +4133,7 @@ def exitTorsion_angle_restraint(self, ctx: CyanaMRParser.Torsion_angle_restraint _cifSeqId = cifSeqId + offset _cifCompId = cifCompId if offset == 0\ else (ps['comp_id'][ps['auth_seq_id'].index(_cifSeqId)] if _cifSeqId in ps['auth_seq_id'] else None) - seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, _cifSeqId, self.__hasCoord) + seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, _cifSeqId, _cifCompId, cifCheck=self.__hasCoord) if coordAtomSite is not None: cifAtomId = next((_cifAtomId for _cifAtomId in cifAtomIds if _cifAtomId in coordAtomSite['atom_id']), None) @@ -7580,7 +7619,7 @@ def exitTorsion_angle_w_chain_restraint(self, ctx: CyanaMRParser.Torsion_angle_w _cifSeqId = cifSeqId + offset _cifCompId = cifCompId if offset == 0 else (ps['comp_id'][ps['auth_seq_id'].index(_cifSeqId)] if _cifSeqId in ps['auth_seq_id'] else None) - seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, _cifSeqId, self.__hasCoord) + seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, _cifSeqId, _cifCompId, cifCheck=self.__hasCoord) if _cifCompId is None: # """" @@ -7619,7 +7658,7 @@ def exitTorsion_angle_w_chain_restraint(self, ctx: CyanaMRParser.Torsion_angle_w _cifSeqId = cifSeqId + offset _cifCompId = cifCompId if offset == 0\ else (ps['comp_id'][ps['auth_seq_id'].index(_cifSeqId)] if _cifSeqId in ps['auth_seq_id'] else None) - seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, _cifSeqId, self.__hasCoord) + seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, _cifSeqId, _cifCompId, cifCheck=self.__hasCoord) if coordAtomSite is not None: cifAtomId = next((_cifAtomId for _cifAtomId in cifAtomIds if _cifAtomId in coordAtomSite['atom_id']), None) diff --git a/wwpdb/utils/nmr/mr/DynamoMRParserListener.py b/wwpdb/utils/nmr/mr/DynamoMRParserListener.py index 5e5359a1d..52ba2c06d 100644 --- a/wwpdb/utils/nmr/mr/DynamoMRParserListener.py +++ b/wwpdb/utils/nmr/mr/DynamoMRParserListener.py @@ -1282,16 +1282,16 @@ def getRealChainSeqId(self, ps, seqId, compId, isPolySeq=True): if seqKey in self.__labelToAuthSeq: _chainId, _seqId = self.__labelToAuthSeq[seqKey] if _seqId in ps['auth_seq_id']: - return _chainId, _seqId + return _chainId, _seqId, ps['comp_id'][ps['seq_id'].index(seqId)] if seqId in ps['auth_seq_id']: - idx = ps['auth_seq_id'].index(seqId) - if compId in (ps['comp_id'][idx], ps['auth_comp_id'][idx], 'MTS', 'ORI'): - return ps['auth_chain_id'], seqId + for idx in [_idx for _idx, _seqId in enumerate(ps['auth_seq_id']) if _seqId == seqId]: + if compId in (ps['comp_id'][idx], ps['auth_comp_id'][idx], 'MTS', 'ORI'): + return ps['auth_chain_id'], seqId, ps['comp_id'][idx] # if seqId in ps['seq_id']: # idx = ps['seq_id'].index(seqId) # if compId in (ps['comp_id'][idx], ps['auth_comp_id'][idx]): # return ps['auth_chain_id'], ps['auth_seq_id'][idx] - return ps['chain_id' if isPolySeq else 'auth_chain_id'], seqId + return ps['chain_id' if isPolySeq else 'auth_chain_id'], seqId, None def assignCoordPolymerSequence(self, refChainId, seqId, compId, atomId, index=None, group=None): """ Assign polymer sequences of the coordinates. @@ -1389,7 +1389,7 @@ def assignCoordPolymerSequence(self, refChainId, seqId, compId, atomId, index=No for ps in self.__polySeq: if preferNonPoly: continue - chainId, seqId = self.getRealChainSeqId(ps, _seqId, compId) + chainId, seqId, cifCompId = self.getRealChainSeqId(ps, _seqId, compId) if fixedChainId is None and refChainId is not None and refChainId != chainId and refChainId in self.__chainNumberDict: if chainId != self.__chainNumberDict[refChainId]: continue @@ -1402,7 +1402,11 @@ def assignCoordPolymerSequence(self, refChainId, seqId, compId, atomId, index=No elif fixedSeqId is not None: seqId = fixedSeqId if seqId in ps['auth_seq_id']: - idx = ps['auth_seq_id'].index(seqId) + if cifCompId is not None: + idx = next((_idx for _idx, (_seqId_, _cifCompId_) in enumerate(zip(ps['auth_seq_id'], ps['comp_id'])) + if _seqId_ == seqId and _cifCompId_ == cifCompId), ps['auth_seq_id'].index(seqId)) + else: + idx = ps['auth_seq_id'].index(seqId) cifCompId = ps['comp_id'][idx] origCompId = ps['auth_comp_id'][idx] if cifCompId != compId: @@ -1412,7 +1416,7 @@ def assignCoordPolymerSequence(self, refChainId, seqId, compId, atomId, index=No origCompId = next(origCompId for _seqId, _compId, origCompId in zip(ps['auth_seq_id'], ps['comp_id'], ps['auth_comp_id']) if _seqId == seqId and _compId == compId) if self.__mrAtomNameMapping is not None and origCompId not in monDict3: - _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, self.__hasCoord) + _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCompId, cifCheck=self.__hasCoord) atomId = retrieveAtomIdFromMRMap(self.__mrAtomNameMapping, seqId, origCompId, atomId, coordAtomSite) if compId in (cifCompId, origCompId, 'MTS', 'ORI'): if len(self.__nefT.get_valid_star_atom(cifCompId, atomId)[0]) > 0: @@ -1458,7 +1462,7 @@ def assignCoordPolymerSequence(self, refChainId, seqId, compId, atomId, index=No origCompId = next(origCompId for _seqId, _compId, origCompId in zip(ps['auth_seq_id'], ps['comp_id'], ps['auth_comp_id']) if _seqId == seqId and _compId == compId) if self.__mrAtomNameMapping is not None and origCompId not in monDict3: - _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId_, self.__hasCoord) + _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId_, cifCompId, cifCheck=self.__hasCoord) atomId = retrieveAtomIdFromMRMap(self.__mrAtomNameMapping, seqId, origCompId, atomId, coordAtomSite) if compId in (cifCompId, origCompId, 'MTS', 'ORI'): if len(self.__nefT.get_valid_star_atom(cifCompId, atomId)[0]) > 0: @@ -1474,7 +1478,7 @@ def assignCoordPolymerSequence(self, refChainId, seqId, compId, atomId, index=No if self.__hasNonPolySeq: for np in self.__nonPolySeq: - chainId, seqId = self.getRealChainSeqId(np, _seqId, compId, False) + chainId, seqId, cifCompId = self.getRealChainSeqId(np, _seqId, compId, False) if fixedChainId is None and refChainId is not None and refChainId != chainId and refChainId in self.__chainNumberDict: if chainId != self.__chainNumberDict[refChainId]: continue @@ -1487,11 +1491,15 @@ def assignCoordPolymerSequence(self, refChainId, seqId, compId, atomId, index=No elif fixedSeqId is not None: seqId = fixedSeqId if seqId in np['auth_seq_id']: - idx = np['auth_seq_id'].index(seqId) + if cifCompId is not None: + idx = next((_idx for _idx, (_seqId_, _cifCompId_) in enumerate(zip(np['auth_seq_id'], np['comp_id'])) + if _seqId_ == seqId and _cifCompId_ == cifCompId), np['auth_seq_id'].index(seqId)) + else: + idx = np['auth_seq_id'].index(seqId) cifCompId = np['comp_id'][idx] origCompId = np['auth_comp_id'][idx] if self.__mrAtomNameMapping is not None and origCompId not in monDict3: - _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, self.__hasCoord) + _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCompId, cifCheck=self.__hasCoord) atomId = retrieveAtomIdFromMRMap(self.__mrAtomNameMapping, seqId, origCompId, atomId, coordAtomSite) if 'alt_auth_seq_id' in np and seqId in np['auth_seq_id'] and seqId not in np['alt_auth_seq_id']: seqId = next(_altSeqId for _seqId, _altSeqId in zip(np['auth_seq_id'], np['alt_auth_seq_id']) if _seqId == seqId) @@ -1529,7 +1537,7 @@ def assignCoordPolymerSequence(self, refChainId, seqId, compId, atomId, index=No origCompId = next(origCompId for _seqId, _compId, origCompId in zip(ps['auth_seq_id'], ps['comp_id'], ps['auth_comp_id']) if _seqId == seqId and _compId == compId) if self.__mrAtomNameMapping is not None and origCompId not in monDict3: - _, coordAtomSite = self.getCoordAtomSiteOf(chainId, _seqId, self.__hasCoord) + _, coordAtomSite = self.getCoordAtomSiteOf(chainId, _seqId, cifCompId, cifCheck=self.__hasCoord) atomId = retrieveAtomIdFromMRMap(self.__mrAtomNameMapping, seqId, origCompId, atomId, coordAtomSite) if compId in (cifCompId, origCompId, 'MTS', 'ORI'): if len(self.__nefT.get_valid_star_atom(cifCompId, atomId)[0]) > 0: @@ -1564,7 +1572,7 @@ def assignCoordPolymerSequence(self, refChainId, seqId, compId, atomId, index=No cifCompId = np['comp_id'][idx] origCompId = np['auth_comp_id'][idx] if self.__mrAtomNameMapping is not None and origCompId not in monDict3: - _, coordAtomSite = self.getCoordAtomSiteOf(chainId, _seqId, self.__hasCoord) + _, coordAtomSite = self.getCoordAtomSiteOf(chainId, _seqId, cifCompId, cifCheck=self.__hasCoord) atomId = retrieveAtomIdFromMRMap(self.__mrAtomNameMapping, seqId, origCompId, atomId, coordAtomSite) if compId in (cifCompId, origCompId, 'MTS', 'ORI'): if len(self.__nefT.get_valid_star_atom(cifCompId, atomId)[0]) > 0: @@ -1617,7 +1625,7 @@ def assignCoordPolymerSequence(self, refChainId, seqId, compId, atomId, index=No if seqKey in self.__labelToAuthSeq: _, seqId = self.__labelToAuthSeq[seqKey] if seqId in ps['auth_seq_id']: - idx = ps['auth_seq_id'].index(seqId) + idx = ps['seq_id'].index(_seqId) cifCompId = ps['comp_id'][idx] origCompId = ps['auth_comp_id'][idx] if cifCompId != compId: @@ -1627,7 +1635,7 @@ def assignCoordPolymerSequence(self, refChainId, seqId, compId, atomId, index=No origCompId = next(origCompId for _seqId, _compId, origCompId in zip(ps['auth_seq_id'], ps['comp_id'], ps['auth_comp_id']) if _seqId == seqId and _compId == compId) if self.__mrAtomNameMapping is not None and origCompId not in monDict3: - _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, self.__hasCoord) + _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCompId, cifCheck=self.__hasCoord) atomId = retrieveAtomIdFromMRMap(self.__mrAtomNameMapping, seqId, origCompId, atomId, coordAtomSite) if compId in (cifCompId, origCompId, 'MTS', 'ORI'): if len(self.__nefT.get_valid_star_atom(cifCompId, atomId)[0]) > 0: @@ -1710,7 +1718,7 @@ def selectCoordAtoms(self, chainAssign, seqId, compId, atomId, allowAmbig=True, cifSeqId += offset cifCompId = compId - seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, cifSeqId, self.__hasCoord, asis=self.__preferAuthSeq) + seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, cifSeqId, cifCompId, asis=self.__preferAuthSeq) if self.__cur_subtype == 'dist' and _compId is not None and (_compId.startswith('MTS') or _compId.startswith('ORI')) and cifCompId != _compId: if _atomId[0] in ('O', 'N'): @@ -1778,7 +1786,7 @@ def selectCoordAtoms(self, chainAssign, seqId, compId, atomId, allowAmbig=True, for np in self.__nonPolySeq: if np['auth_chain_id'] == chainId and cifSeqId in np['auth_seq_id']: cifSeqId = np['seq_id'][np['auth_seq_id'].index(cifSeqId)] - seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, cifSeqId, self.__hasCoord) + seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, cifSeqId, cifCompId) if coordAtomSite is not None: break except ValueError: @@ -1798,7 +1806,7 @@ def selectCoordAtoms(self, chainAssign, seqId, compId, atomId, allowAmbig=True, cifCompId = compId if not multiChain and not insCode: if self.__preferAuthSeq: - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, cifSeqId, asis=False) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, cifSeqId, cifCompId, asis=False) if _coordAtomSite is not None and _coordAtomSite['comp_id'] == compId: if lenAtomId > 0 and _atomId[0] in _coordAtomSite['atom_id']: self.__authSeqId = 'label_seq_id' @@ -1865,7 +1873,7 @@ def selectAuxCoordAtoms(self, chainAssign, seqId, compId, atomId, allowAmbig=Tru atomSelection = [] for chainId, cifSeqId, cifCompId, isPolySeq in chainAssign: - seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, cifSeqId, self.__hasCoord) + seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, cifSeqId, cifCompId) _atomId, _, details = self.__nefT.get_valid_star_atom_in_xplor(cifCompId, atomId, leave_unmatched=True) if details is not None and len(atomId) > 1 and not atomId[-1].isalpha(): @@ -1900,7 +1908,7 @@ def selectAuxCoordAtoms(self, chainAssign, seqId, compId, atomId, allowAmbig=Tru for np in self.__nonPoly: if np['auth_chain_id'] == chainId and cifSeqId in np['auth_seq_id']: cifSeqId = np['seq_id'][np['auth_seq_id'].index(cifSeqId)] - seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, cifSeqId, self.__hasCoord) + seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, cifSeqId, cifCompId) if coordAtomSite is not None: break except ValueError: @@ -1938,7 +1946,7 @@ def testCoordAtomIdConsistency(self, chainId, seqId, compId, atomId, seqKey, coo # self.__authAtomId = 'auth_atom_id' elif self.__preferAuthSeq: - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, asis=False) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, compId, asis=False) if _coordAtomSite is not None and _coordAtomSite['comp_id'] == compId: if atomId in _coordAtomSite['atom_id']: found = True @@ -1956,7 +1964,7 @@ def testCoordAtomIdConsistency(self, chainId, seqId, compId, atomId, seqKey, coo else: self.__preferAuthSeq = True - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, compId) if _coordAtomSite is not None and _coordAtomSite['comp_id'] == compId: if atomId in _coordAtomSite['atom_id']: found = True @@ -1975,7 +1983,7 @@ def testCoordAtomIdConsistency(self, chainId, seqId, compId, atomId, seqKey, coo self.__preferAuthSeq = False elif self.__preferAuthSeq: - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, asis=False) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, compId, asis=False) if _coordAtomSite is not None and _coordAtomSite['comp_id'] == compId: if atomId in _coordAtomSite['atom_id']: found = True @@ -1993,7 +2001,7 @@ def testCoordAtomIdConsistency(self, chainId, seqId, compId, atomId, seqKey, coo else: self.__preferAuthSeq = True - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, compId) if _coordAtomSite is not None and _coordAtomSite['comp_id'] == compId: if atomId in _coordAtomSite['atom_id']: found = True @@ -2017,7 +2025,7 @@ def testCoordAtomIdConsistency(self, chainId, seqId, compId, atomId, seqKey, coo if chainId in self.__chainNumberDict.values(): if self.__preferAuthSeq: - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, asis=False) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, compId, asis=False) if _coordAtomSite is not None and _coordAtomSite['comp_id'] == compId: if atomId in _coordAtomSite['atom_id']: found = True @@ -2034,7 +2042,7 @@ def testCoordAtomIdConsistency(self, chainId, seqId, compId, atomId, seqKey, coo self.__setLocalSeqScheme() else: self.__preferAuthSeq = True - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, compId) if _coordAtomSite is not None and _coordAtomSite['comp_id'] == compId: if atomId in _coordAtomSite['atom_id']: found = True @@ -2362,20 +2370,27 @@ def selectRealisticChi2AngleConstraint(self, atom1, atom2, atom3, atom4, dst_fun return dst_func - def getCoordAtomSiteOf(self, chainId, seqId, cifCheck=True, asis=True): + def getCoordAtomSiteOf(self, chainId, seqId, compId=None, cifCheck=True, asis=True): seqKey = (chainId, seqId) - coordAtomSite = None if cifCheck: preferAuthSeq = self.__preferAuthSeq if asis else not self.__preferAuthSeq if preferAuthSeq: + if compId is not None: + _seqKey = (chainId, seqId, compId) + if _seqKey in self.__coordAtomSite: + return seqKey, self.__coordAtomSite[_seqKey] if seqKey in self.__coordAtomSite: - coordAtomSite = self.__coordAtomSite[seqKey] + return seqKey, self.__coordAtomSite[seqKey] else: if seqKey in self.__labelToAuthSeq: seqKey = self.__labelToAuthSeq[seqKey] + if cifCheck and compId is not None: + _seqKey = (seqKey[0], seqKey[1], compId) + if _seqKey in self.__coordAtomSite: + return seqKey, self.__coordAtomSite[_seqKey] if seqKey in self.__coordAtomSite: - coordAtomSite = self.__coordAtomSite[seqKey] - return seqKey, coordAtomSite + return seqKey, self.__coordAtomSite[seqKey] + return seqKey, None # Enter a parse tree produced by DynamoMRParser#torsion_angle_restraints. def enterTorsion_angle_restraints(self, ctx: DynamoMRParser.Torsion_angle_restraintsContext): # pylint: disable=unused-argument diff --git a/wwpdb/utils/nmr/mr/IsdMRParserListener.py b/wwpdb/utils/nmr/mr/IsdMRParserListener.py index 9d88e8dbf..380f2bd7e 100644 --- a/wwpdb/utils/nmr/mr/IsdMRParserListener.py +++ b/wwpdb/utils/nmr/mr/IsdMRParserListener.py @@ -816,16 +816,16 @@ def getRealChainSeqId(self, ps, seqId, compId, isPolySeq=True): if seqKey in self.__labelToAuthSeq: _chainId, _seqId = self.__labelToAuthSeq[seqKey] if _seqId in ps['auth_seq_id']: - return _chainId, _seqId + return _chainId, _seqId, ps['comp_id'][ps['seq_id'].index(seqId)] if seqId in ps['auth_seq_id']: - idx = ps['auth_seq_id'].index(seqId) - if compId in (ps['comp_id'][idx], ps['auth_comp_id'][idx], 'MTS', 'ORI'): - return ps['auth_chain_id'], seqId + for idx in [_idx for _idx, _seqId in enumerate(ps['auth_seq_id']) if _seqId == seqId]: + if compId in (ps['comp_id'][idx], ps['auth_comp_id'][idx], 'MTS', 'ORI'): + return ps['auth_chain_id'], seqId, ps['comp_id'][idx] # if seqId in ps['seq_id']: # idx = ps['seq_id'].index(seqId) # if compId in (ps['comp_id'][idx], ps['auth_comp_id'][idx]): # return ps['auth_chain_id'], ps['auth_seq_id'][idx] - return ps['chain_id' if isPolySeq else 'auth_chain_id'], seqId + return ps['chain_id' if isPolySeq else 'auth_chain_id'], seqId, None def assignCoordPolymerSequence(self, seqId, compId, atomId): """ Assign polymer sequences of the coordinates. @@ -883,7 +883,7 @@ def assignCoordPolymerSequence(self, seqId, compId, atomId): for ps in self.__polySeq: if preferNonPoly: continue - chainId, seqId = self.getRealChainSeqId(ps, _seqId, compId) + chainId, seqId, cifCompId = self.getRealChainSeqId(ps, _seqId, compId) if self.__reasons is not None: if fixedChainId is not None: if fixedChainId != chainId: @@ -893,7 +893,11 @@ def assignCoordPolymerSequence(self, seqId, compId, atomId): elif fixedSeqId is not None: seqId = fixedSeqId if seqId in ps['auth_seq_id']: - idx = ps['auth_seq_id'].index(seqId) + if cifCompId is not None: + idx = next((_idx for _idx, (_seqId_, _cifCompId_) in enumerate(zip(ps['auth_seq_id'], ps['comp_id'])) + if _seqId_ == seqId and _cifCompId_ == cifCompId), ps['auth_seq_id'].index(seqId)) + else: + idx = ps['auth_seq_id'].index(seqId) cifCompId = ps['comp_id'][idx] origCompId = ps['auth_comp_id'][idx] if cifCompId != compId: @@ -903,7 +907,7 @@ def assignCoordPolymerSequence(self, seqId, compId, atomId): origCompId = next(origCompId for _seqId, _compId, origCompId in zip(ps['auth_seq_id'], ps['comp_id'], ps['auth_comp_id']) if _seqId == seqId and _compId == compId) if self.__mrAtomNameMapping is not None and cifCompId not in monDict3: - _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, self.__hasCoord) + _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCompId, cifCheck=self.__hasCoord) atomId = retrieveAtomIdFromMRMap(self.__mrAtomNameMapping, seqId, origCompId, atomId, coordAtomSite) if compId in (cifCompId, origCompId, 'MTS', 'ORI'): if len(self.__nefT.get_valid_star_atom(cifCompId, atomId)[0]) > 0: @@ -945,7 +949,7 @@ def assignCoordPolymerSequence(self, seqId, compId, atomId): origCompId = next(origCompId for _seqId, _compId, origCompId in zip(ps['auth_seq_id'], ps['comp_id'], ps['auth_comp_id']) if _seqId == seqId and _compId == compId) if self.__mrAtomNameMapping is not None and cifCompId not in monDict3: - _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId_, self.__hasCoord) + _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId_, cifCompId, cifCheck=self.__hasCoord) atomId = retrieveAtomIdFromMRMap(self.__mrAtomNameMapping, seqId, origCompId, atomId, coordAtomSite) if compId in (cifCompId, origCompId, 'MTS', 'ORI'): if len(self.__nefT.get_valid_star_atom(cifCompId, atomId)[0]) > 0: @@ -957,7 +961,7 @@ def assignCoordPolymerSequence(self, seqId, compId, atomId): if self.__hasNonPolySeq: for np in self.__nonPolySeq: - chainId, seqId = self.getRealChainSeqId(np, _seqId, compId, False) + chainId, seqId, cifCompId = self.getRealChainSeqId(np, _seqId, compId, False) if self.__reasons is not None: if fixedChainId is not None: if fixedChainId != chainId: @@ -969,11 +973,15 @@ def assignCoordPolymerSequence(self, seqId, compId, atomId): if 'alt_auth_seq_id' in np and seqId in np['auth_seq_id'] and seqId not in np['alt_auth_seq_id']: seqId = next(_altSeqId for _seqId, _altSeqId in zip(np['auth_seq_id'], np['alt_auth_seq_id']) if _seqId == seqId) if seqId in np['auth_seq_id']: - idx = np['auth_seq_id'].index(seqId) + if cifCompId is not None: + idx = next((_idx for _idx, (_seqId_, _cifCompId_) in enumerate(zip(np['auth_seq_id'], np['comp_id'])) + if _seqId_ == seqId and _cifCompId_ == cifCompId), np['auth_seq_id'].index(seqId)) + else: + idx = np['auth_seq_id'].index(seqId) cifCompId = np['comp_id'][idx] origCompId = np['auth_comp_id'][idx] if self.__mrAtomNameMapping is not None and cifCompId not in monDict3: - _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, self.__hasCoord) + _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCompId, cifCheck=self.__hasCoord) atomId = retrieveAtomIdFromMRMap(self.__mrAtomNameMapping, seqId, origCompId, atomId, coordAtomSite) if 'alt_auth_seq_id' in np and seqId in np['auth_seq_id'] and seqId not in np['alt_auth_seq_id']: seqId = next(_altSeqId for _seqId, _altSeqId in zip(np['auth_seq_id'], np['alt_auth_seq_id']) if _seqId == seqId) @@ -1004,7 +1012,7 @@ def assignCoordPolymerSequence(self, seqId, compId, atomId): origCompId = next(origCompId for _seqId, _compId, origCompId in zip(ps['auth_seq_id'], ps['comp_id'], ps['auth_comp_id']) if _seqId == seqId and _compId == compId) if self.__mrAtomNameMapping is not None and cifCompId not in monDict3: - _, coordAtomSite = self.getCoordAtomSiteOf(chainId, _seqId, self.__hasCoord) + _, coordAtomSite = self.getCoordAtomSiteOf(chainId, _seqId, cifCompId, cifCheck=self.__hasCoord) atomId = retrieveAtomIdFromMRMap(self.__mrAtomNameMapping, seqId, origCompId, atomId, coordAtomSite) if compId in (cifCompId, origCompId, 'MTS', 'ORI'): if len(self.__nefT.get_valid_star_atom(cifCompId, atomId)[0]) > 0: @@ -1032,7 +1040,7 @@ def assignCoordPolymerSequence(self, seqId, compId, atomId): cifCompId = np['comp_id'][idx] origCompId = np['auth_comp_id'][idx] if self.__mrAtomNameMapping is not None and cifCompId not in monDict3: - _, coordAtomSite = self.getCoordAtomSiteOf(chainId, _seqId, self.__hasCoord) + _, coordAtomSite = self.getCoordAtomSiteOf(chainId, _seqId, cifCompId, cifCheck=self.__hasCoord) atomId = retrieveAtomIdFromMRMap(self.__mrAtomNameMapping, seqId, origCompId, atomId, coordAtomSite) if compId in (cifCompId, origCompId, 'MTS', 'ORI'): if len(self.__nefT.get_valid_star_atom(cifCompId, atomId)[0]) > 0: @@ -1073,7 +1081,7 @@ def assignCoordPolymerSequence(self, seqId, compId, atomId): if seqKey in self.__labelToAuthSeq: _, seqId = self.__labelToAuthSeq[seqKey] if seqId in ps['auth_seq_id']: - idx = ps['aut_seq_id'].index(seqId) + idx = ps['seq_id'].index(_seqId) cifCompId = ps['comp_id'][idx] origCompId = ps['auth_comp_id'][idx] if cifCompId != compId: @@ -1083,7 +1091,7 @@ def assignCoordPolymerSequence(self, seqId, compId, atomId): origCompId = next(origCompId for _seqId, _compId, origCompId in zip(ps['auth_seq_id'], ps['comp_id'], ps['auth_comp_id']) if _seqId == seqId and _compId == compId) if self.__mrAtomNameMapping is not None and cifCompId not in monDict3: - _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, self.__hasCoord) + _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCompId, cifCheck=self.__hasCoord) atomId = retrieveAtomIdFromMRMap(self.__mrAtomNameMapping, seqId, origCompId, atomId, coordAtomSite) if compId in (cifCompId, origCompId, 'MTS', 'ORI'): if len(self.__nefT.get_valid_star_atom(cifCompId, atomId)[0]) > 0: @@ -1156,7 +1164,7 @@ def selectCoordAtoms(self, chainAssign, seqId, compId, atomId, allowAmbig=True, cifSeqId += offset cifCompId = compId - seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, cifSeqId, self.__hasCoord, asis=self.__preferAuthSeq) + seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, cifSeqId, cifCompId, asis=self.__preferAuthSeq) if self.__cur_subtype == 'dist' and _compId is not None and (_compId.startswith('MTS') or _compId.startswith('ORI')) and cifCompId != _compId: if _atomId[0] in ('O', 'N'): @@ -1224,7 +1232,7 @@ def selectCoordAtoms(self, chainAssign, seqId, compId, atomId, allowAmbig=True, for np in self.__nonPolySeq: if np['auth_chain_id'] == chainId and cifSeqId in np['auth_seq_id']: cifSeqId = np['seq_id'][np['auth_seq_id'].index(cifSeqId)] - seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, cifSeqId, self.__hasCoord) + seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, cifSeqId, cifCompId) if coordAtomSite is not None: break except ValueError: @@ -1244,7 +1252,7 @@ def selectCoordAtoms(self, chainAssign, seqId, compId, atomId, allowAmbig=True, cifCompId = compId if not multiChain and not insCode: if self.__preferAuthSeq: - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, cifSeqId, asis=False) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, cifSeqId, cifCompId, asis=False) if _coordAtomSite is not None and _coordAtomSite['comp_id'] == compId: if lenAtomId > 0 and _atomId[0] in _coordAtomSite['atom_id']: self.__authSeqId = 'label_seq_id' @@ -1318,7 +1326,7 @@ def testCoordAtomIdConsistency(self, chainId, seqId, compId, atomId, seqKey, coo # self.__authAtomId = 'auth_atom_id' elif self.__preferAuthSeq: - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, asis=False) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, compId, asis=False) if _coordAtomSite is not None and _coordAtomSite['comp_id'] == compId: if atomId in _coordAtomSite['atom_id']: found = True @@ -1336,7 +1344,7 @@ def testCoordAtomIdConsistency(self, chainId, seqId, compId, atomId, seqKey, coo else: self.__preferAuthSeq = True - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, compId) if _coordAtomSite is not None and _coordAtomSite['comp_id'] == compId: if atomId in _coordAtomSite['atom_id']: found = True @@ -1355,7 +1363,7 @@ def testCoordAtomIdConsistency(self, chainId, seqId, compId, atomId, seqKey, coo self.__preferAuthSeq = False elif self.__preferAuthSeq: - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, asis=False) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, compId, asis=False) if _coordAtomSite is not None and _coordAtomSite['comp_id'] == compId: if atomId in _coordAtomSite['atom_id']: found = True @@ -1373,7 +1381,7 @@ def testCoordAtomIdConsistency(self, chainId, seqId, compId, atomId, seqKey, coo else: self.__preferAuthSeq = True - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, compId) if _coordAtomSite is not None and _coordAtomSite['comp_id'] == compId: if atomId in _coordAtomSite['atom_id']: found = True @@ -1395,7 +1403,7 @@ def testCoordAtomIdConsistency(self, chainId, seqId, compId, atomId, seqKey, coo return if self.__preferAuthSeq: - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, asis=False) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, compId, asis=False) if _coordAtomSite is not None and _coordAtomSite['comp_id'] == compId: if atomId in _coordAtomSite['atom_id']: found = True @@ -1413,7 +1421,7 @@ def testCoordAtomIdConsistency(self, chainId, seqId, compId, atomId, seqKey, coo else: self.__preferAuthSeq = True - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, compId) if _coordAtomSite is not None and _coordAtomSite['comp_id'] == compId: if atomId in _coordAtomSite['atom_id']: found = True @@ -1573,20 +1581,27 @@ def selectRealisticBondConstraint(self, atom1, atom2, alt_atom_id1, alt_atom_id2 return atom1, atom2 - def getCoordAtomSiteOf(self, chainId, seqId, cifCheck=True, asis=True): + def getCoordAtomSiteOf(self, chainId, seqId, compId=None, cifCheck=True, asis=True): seqKey = (chainId, seqId) - coordAtomSite = None if cifCheck: preferAuthSeq = self.__preferAuthSeq if asis else not self.__preferAuthSeq if preferAuthSeq: + if compId is not None: + _seqKey = (chainId, seqId, compId) + if _seqKey in self.__coordAtomSite: + return seqKey, self.__coordAtomSite[_seqKey] if seqKey in self.__coordAtomSite: - coordAtomSite = self.__coordAtomSite[seqKey] + return seqKey, self.__coordAtomSite[seqKey] else: if seqKey in self.__labelToAuthSeq: seqKey = self.__labelToAuthSeq[seqKey] + if cifCheck and compId is not None: + _seqKey = (seqKey[0], seqKey[1], compId) + if _seqKey in self.__coordAtomSite: + return seqKey, self.__coordAtomSite[_seqKey] if seqKey in self.__coordAtomSite: - coordAtomSite = self.__coordAtomSite[seqKey] - return seqKey, coordAtomSite + return seqKey, self.__coordAtomSite[seqKey] + return seqKey, None def __getCurrentRestraint(self): if self.__cur_subtype == 'dist': diff --git a/wwpdb/utils/nmr/mr/ParserListenerUtil.py b/wwpdb/utils/nmr/mr/ParserListenerUtil.py index c7bf7f24a..84c6bd197 100644 --- a/wwpdb/utils/nmr/mr/ParserListenerUtil.py +++ b/wwpdb/utils/nmr/mr/ParserListenerUtil.py @@ -3561,23 +3561,47 @@ def coordAssemblyChecker(verbose=True, log=sys.stdout, compId = next(c['comp_id'] for c in coord if c['chain_id'] == chainId and c['seq_id'] is not None and c['seq_id'] == seqId) atomIds = [c['atom_id'] for c in coord - if c['chain_id'] == chainId and c['seq_id'] is not None and c['seq_id'] == seqId] + if c['chain_id'] == chainId and c['seq_id'] is not None and c['seq_id'] == seqId and c['comp_id'] == compId] typeSymbols = [c['type_symbol'] for c in coord - if c['chain_id'] == chainId and c['seq_id'] is not None and c['seq_id'] == seqId] + if c['chain_id'] == chainId and c['seq_id'] is not None and c['seq_id'] == seqId and c['comp_id'] == compId] coordAtomSite[seqKey] = {'comp_id': compId, 'atom_id': atomIds, 'type_symbol': typeSymbols} if altAuthCompId is not None: altCompIds = [c['comp_id'] for c in coord - if c['chain_id'] == chainId and c['seq_id'] is not None and c['seq_id'] == seqId] + if c['chain_id'] == chainId and c['seq_id'] is not None and c['seq_id'] == seqId and c['comp_id'] == compId] coordAtomSite[seqKey]['alt_comp_id'] = altCompIds if altAuthAtomId is not None: altAtomIds = [c['alt_atom_id'] for c in coord - if c['chain_id'] == chainId and c['seq_id'] is not None and c['seq_id'] == seqId] + if c['chain_id'] == chainId and c['seq_id'] is not None and c['seq_id'] == seqId and c['comp_id'] == compId] coordAtomSite[seqKey]['alt_atom_id'] = altAtomIds - altSeqId = next((c['alt_seq_id'] for c in coord if c['chain_id'] == chainId and c['seq_id'] == seqId), None) + altSeqId = next((c['alt_seq_id'] for c in coord if c['chain_id'] == chainId and c['seq_id'] == seqId and c['comp_id'] == compId), None) if chainId in authToLabelChain and altSeqId is not None and altSeqId.isdigit(): labelToAuthSeq[(authToLabelChain[chainId], int(altSeqId))] = seqKey else: labelToAuthSeq[seqKey] = seqKey + compIds = list(set(c['comp_id'] for c in coord + if c['chain_id'] == chainId and c['seq_id'] is not None and c['seq_id'] == seqId)) + if len(compIds) > 1: # 2kny: split implict ins_code of atom_site + for compId in compIds: + seqKey = (chainId, seqId, compId) + atomIds = [c['atom_id'] for c in coord + if c['chain_id'] == chainId and c['seq_id'] is not None and c['seq_id'] == seqId and c['comp_id'] == compId] + typeSymbols = [c['type_symbol'] for c in coord + if c['chain_id'] == chainId and c['seq_id'] is not None and c['seq_id'] == seqId and c['comp_id'] == compId] + coordAtomSite[seqKey] = {'comp_id': compId, 'atom_id': atomIds, 'type_symbol': typeSymbols} + if altAuthCompId is not None: + altCompIds = [c['comp_id'] for c in coord + if c['chain_id'] == chainId and c['seq_id'] is not None and c['seq_id'] == seqId and c['comp_id'] == compId] + coordAtomSite[seqKey]['alt_comp_id'] = altCompIds + if altAuthAtomId is not None: + altAtomIds = [c['alt_atom_id'] for c in coord + if c['chain_id'] == chainId and c['seq_id'] is not None and c['seq_id'] == seqId and c['comp_id'] == compId] + coordAtomSite[seqKey]['alt_atom_id'] = altAtomIds + altSeqId = next((c['alt_seq_id'] for c in coord if c['chain_id'] == chainId and c['seq_id'] == seqId and c['comp_id'] == compId), None) + if chainId in authToLabelChain and altSeqId is not None and altSeqId.isdigit(): + labelToAuthSeq[(authToLabelChain[chainId], int(altSeqId))] = (chainId, seqId) + else: + _seqKey = (seqKey[0], seqKey[1]) + labelToAuthSeq[_seqKey] = _seqKey # DAOTHER-8817 if compId not in monDict3: diff --git a/wwpdb/utils/nmr/mr/RosettaMRParserListener.py b/wwpdb/utils/nmr/mr/RosettaMRParserListener.py index 276c941a6..6fdef9fdf 100644 --- a/wwpdb/utils/nmr/mr/RosettaMRParserListener.py +++ b/wwpdb/utils/nmr/mr/RosettaMRParserListener.py @@ -1174,7 +1174,7 @@ def assignCoordPolymerSequence(self, seqId, atomId=None, fixedChainId=None): continue updatePolySeqRst(self.__polySeqRst, chainId, _seqId, cifCompId) if atomId is not None and cifCompId not in monDict3 and self.__mrAtomNameMapping: - _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, self.__hasCoord) + _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck=self.__hasCoord) origCompId = ps['auth_comp_id'][idx] atomId = retrieveAtomIdFromMRMap(self.__mrAtomNameMapping, seqId, origCompId, atomId, coordAtomSite) if atomId is None\ @@ -1204,7 +1204,7 @@ def assignCoordPolymerSequence(self, seqId, atomId=None, fixedChainId=None): cifCompId = ps['comp_id'][idx] updatePolySeqRst(self.__polySeqRst, chainId, _seqId, cifCompId) if atomId is not None and cifCompId not in monDict3 and self.__mrAtomNameMapping: - _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId_, self.__hasCoord) + _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId_, cifCheck=self.__hasCoord) origCompId = ps['auth_comp_id'][idx] atomId = retrieveAtomIdFromMRMap(self.__mrAtomNameMapping, seqId, origCompId, atomId, coordAtomSite) if atomId is None\ @@ -1236,7 +1236,7 @@ def assignCoordPolymerSequence(self, seqId, atomId=None, fixedChainId=None): cifCompId = np['comp_id'][idx] updatePolySeqRst(self.__polySeqRst, chainId, _seqId, cifCompId) if atomId is not None and cifCompId not in monDict3 and self.__mrAtomNameMapping: - _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, self.__hasCoord) + _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck=self.__hasCoord) origCompId = np['auth_comp_id'][idx] atomId = retrieveAtomIdFromMRMap(self.__mrAtomNameMapping, seqId, origCompId, atomId, coordAtomSite) if 'alt_auth_seq_id' in np and seqId in np['auth_seq_id'] and seqId not in np['alt_auth_seq_id']: @@ -1258,7 +1258,7 @@ def assignCoordPolymerSequence(self, seqId, atomId=None, fixedChainId=None): cifCompId = ps['comp_id'][idx] updatePolySeqRst(self.__polySeqRst, chainId, _seqId, cifCompId) if atomId is not None and cifCompId not in monDict3 and self.__mrAtomNameMapping: - _, coordAtomSite = self.getCoordAtomSiteOf(chainId, _seqId, self.__hasCoord) + _, coordAtomSite = self.getCoordAtomSiteOf(chainId, _seqId, cifCheck=self.__hasCoord) origCompId = ps['auth_comp_id'][idx] atomId = retrieveAtomIdFromMRMap(self.__mrAtomNameMapping, seqId, origCompId, atomId, coordAtomSite) if atomId is None\ @@ -1280,7 +1280,7 @@ def assignCoordPolymerSequence(self, seqId, atomId=None, fixedChainId=None): cifCompId = np['comp_id'][idx] updatePolySeqRst(self.__polySeqRst, chainId, _seqId, cifCompId) if atomId is not None and cifCompId not in monDict3 and self.__mrAtomNameMapping: - _, coordAtomSite = self.getCoordAtomSiteOf(chainId, _seqId, self.__hasCoord) + _, coordAtomSite = self.getCoordAtomSiteOf(chainId, _seqId, cifCheck=self.__hasCoord) origCompId = np['auth_comp_id'][idx] atomId = retrieveAtomIdFromMRMap(self.__mrAtomNameMapping, seqId, origCompId, atomId, coordAtomSite) if atomId is None\ @@ -1308,11 +1308,11 @@ def assignCoordPolymerSequence(self, seqId, atomId=None, fixedChainId=None): if seqKey in self.__labelToAuthSeq: _, seqId = self.__labelToAuthSeq[seqKey] if seqId in ps['auth_seq_id']: - idx = ps['auth_seq_id'].index(seqId) + idx = ps['seq_id'].index(_seqId) cifCompId = ps['comp_id'][idx] updatePolySeqRst(self.__polySeqRst, chainId, seqId, cifCompId) if atomId is not None and cifCompId not in monDict3 and self.__mrAtomNameMapping: - _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, self.__hasCoord) + _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck=self.__hasCoord) origCompId = ps['auth_comp_id'][idx] atomId = retrieveAtomIdFromMRMap(self.__mrAtomNameMapping, seqId, origCompId, atomId, coordAtomSite) if atomId is None\ @@ -1370,7 +1370,7 @@ def selectCoordAtoms(self, chainAssign, seqId, atomId, allowAmbig=True, subtype_ for chainId, cifSeqId, cifCompId, isPolySeq in chainAssign: - seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, cifSeqId, self.__hasCoord, asis=self.__preferAuthSeq) + seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, cifSeqId, asis=self.__preferAuthSeq) if self.__mrAtomNameMapping is not None and cifCompId not in monDict3: _atomId = retrieveAtomIdFromMRMap(self.__mrAtomNameMapping, cifSeqId, cifCompId, atomId, coordAtomSite) @@ -1419,7 +1419,7 @@ def selectCoordAtoms(self, chainAssign, seqId, atomId, allowAmbig=True, subtype_ for np in self.__nonPolySeq: if np['auth_chain_id'] == chainId and cifSeqId in np['auth_seq_id']: cifSeqId = np['seq_id'][np['auth_seq_id'].index(cifSeqId)] - seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, cifSeqId, self.__hasCoord) + seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, cifSeqId) if coordAtomSite is not None: break except ValueError: diff --git a/wwpdb/utils/nmr/mr/SybylMRParserListener.py b/wwpdb/utils/nmr/mr/SybylMRParserListener.py index d860eb186..90b1b16cc 100644 --- a/wwpdb/utils/nmr/mr/SybylMRParserListener.py +++ b/wwpdb/utils/nmr/mr/SybylMRParserListener.py @@ -822,16 +822,16 @@ def getRealChainSeqId(self, ps, seqId, compId, isPolySeq=True): if seqKey in self.__labelToAuthSeq: _chainId, _seqId = self.__labelToAuthSeq[seqKey] if _seqId in ps['auth_seq_id']: - return _chainId, _seqId + return _chainId, _seqId, ps['comp_id'][ps['seq_id'].index(seqId)] if seqId in ps['auth_seq_id']: - idx = ps['auth_seq_id'].index(seqId) - if compId in (ps['comp_id'][idx], ps['auth_comp_id'][idx], 'MTS', 'ORI'): - return ps['auth_chain_id'], seqId + for idx in [_idx for _idx, _seqId in enumerate(ps['auth_seq_id']) if _seqId == seqId]: + if compId in (ps['comp_id'][idx], ps['auth_comp_id'][idx], 'MTS', 'ORI'): + return ps['auth_chain_id'], seqId, ps['comp_id'][idx] # if seqId in ps['seq_id']: # idx = ps['seq_id'].index(seqId) # if compId in (ps['comp_id'][idx], ps['auth_comp_id'][idx]): # return ps['auth_chain_id'], ps['auth_seq_id'][idx] - return ps['chain_id' if isPolySeq else 'auth_chain_id'], seqId + return ps['chain_id' if isPolySeq else 'auth_chain_id'], seqId, None def assignCoordPolymerSequence(self, seqId, compId, atomId): """ Assign polymer sequences of the coordinates. @@ -889,7 +889,7 @@ def assignCoordPolymerSequence(self, seqId, compId, atomId): for ps in self.__polySeq: if preferNonPoly: continue - chainId, seqId = self.getRealChainSeqId(ps, _seqId, compId) + chainId, seqId, cifCompId = self.getRealChainSeqId(ps, _seqId, compId) if self.__reasons is not None: if fixedChainId is not None: if fixedChainId != chainId: @@ -899,7 +899,11 @@ def assignCoordPolymerSequence(self, seqId, compId, atomId): elif fixedSeqId is not None: seqId = fixedSeqId if seqId in ps['auth_seq_id']: - idx = ps['auth_seq_id'].index(seqId) + if cifCompId is not None: + idx = next((_idx for _idx, (_seqId_, _cifCompId_) in enumerate(zip(ps['auth_seq_id'], ps['comp_id'])) + if _seqId_ == seqId and _cifCompId_ == cifCompId), ps['auth_seq_id'].index(seqId)) + else: + idx = ps['auth_seq_id'].index(seqId) cifCompId = ps['comp_id'][idx] origCompId = ps['auth_comp_id'][idx] if cifCompId != compId: @@ -909,7 +913,7 @@ def assignCoordPolymerSequence(self, seqId, compId, atomId): origCompId = next(origCompId for _seqId, _compId, origCompId in zip(ps['auth_seq_id'], ps['comp_id'], ps['auth_comp_id']) if _seqId == seqId and _compId == compId) if self.__mrAtomNameMapping is not None and cifCompId not in monDict3: - _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, self.__hasCoord) + _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCompId, cifCheck=self.__hasCoord) atomId = retrieveAtomIdFromMRMap(self.__mrAtomNameMapping, seqId, origCompId, atomId, coordAtomSite) if compId in (cifCompId, origCompId, 'MTS', 'ORI'): if len(self.__nefT.get_valid_star_atom(cifCompId, atomId)[0]) > 0: @@ -951,7 +955,7 @@ def assignCoordPolymerSequence(self, seqId, compId, atomId): origCompId = next(origCompId for _seqId, _compId, origCompId in zip(ps['auth_seq_id'], ps['comp_id'], ps['auth_comp_id']) if _seqId == seqId and _compId == compId) if self.__mrAtomNameMapping is not None and cifCompId not in monDict3: - _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId_, self.__hasCoord) + _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId_, cifCompId, cifCheck=self.__hasCoord) atomId = retrieveAtomIdFromMRMap(self.__mrAtomNameMapping, seqId, origCompId, atomId, coordAtomSite) if compId in (cifCompId, origCompId, 'MTS', 'ORI'): if len(self.__nefT.get_valid_star_atom(cifCompId, atomId)[0]) > 0: @@ -963,7 +967,7 @@ def assignCoordPolymerSequence(self, seqId, compId, atomId): if self.__hasNonPolySeq: for np in self.__nonPolySeq: - chainId, seqId = self.getRealChainSeqId(np, _seqId, compId, False) + chainId, seqId, cifCompId = self.getRealChainSeqId(np, _seqId, compId, False) if self.__reasons is not None: if fixedChainId is not None: if fixedChainId != chainId: @@ -975,11 +979,15 @@ def assignCoordPolymerSequence(self, seqId, compId, atomId): if 'alt_auth_seq_id' in np and seqId in np['auth_seq_id'] and seqId not in np['alt_auth_seq_id']: seqId = next(_altSeqId for _seqId, _altSeqId in zip(np['auth_seq_id'], np['alt_auth_seq_id']) if _seqId == seqId) if seqId in np['auth_seq_id']: - idx = np['auth_seq_id'].index(seqId) + if cifCompId is not None: + idx = next((_idx for _idx, (_seqId_, _cifCompId_) in enumerate(zip(np['auth_seq_id'], np['comp_id'])) + if _seqId_ == seqId and _cifCompId_ == cifCompId), np['auth_seq_id'].index(seqId)) + else: + idx = np['auth_seq_id'].index(seqId) cifCompId = np['comp_id'][idx] origCompId = np['auth_comp_id'][idx] if self.__mrAtomNameMapping is not None and cifCompId not in monDict3: - _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, self.__hasCoord) + _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCompId, cifCheck=self.__hasCoord) atomId = retrieveAtomIdFromMRMap(self.__mrAtomNameMapping, seqId, origCompId, atomId, coordAtomSite) if 'alt_auth_seq_id' in np and seqId in np['auth_seq_id'] and seqId not in np['alt_auth_seq_id']: seqId = next(_altSeqId for _seqId, _altSeqId in zip(np['auth_seq_id'], np['alt_auth_seq_id']) if _seqId == seqId) @@ -1010,7 +1018,7 @@ def assignCoordPolymerSequence(self, seqId, compId, atomId): origCompId = next(origCompId for _seqId, _compId, origCompId in zip(ps['auth_seq_id'], ps['comp_id'], ps['auth_comp_id']) if _seqId == seqId and _compId == compId) if self.__mrAtomNameMapping is not None and cifCompId not in monDict3: - _, coordAtomSite = self.getCoordAtomSiteOf(chainId, _seqId, self.__hasCoord) + _, coordAtomSite = self.getCoordAtomSiteOf(chainId, _seqId, cifCompId, cifCheck=self.__hasCoord) atomId = retrieveAtomIdFromMRMap(self.__mrAtomNameMapping, seqId, origCompId, atomId, coordAtomSite) if compId in (cifCompId, origCompId, 'MTS', 'ORI'): if len(self.__nefT.get_valid_star_atom(cifCompId, atomId)[0]) > 0: @@ -1038,7 +1046,7 @@ def assignCoordPolymerSequence(self, seqId, compId, atomId): cifCompId = np['comp_id'][idx] origCompId = np['auth_comp_id'][idx] if self.__mrAtomNameMapping is not None and cifCompId not in monDict3: - _, coordAtomSite = self.getCoordAtomSiteOf(chainId, _seqId, self.__hasCoord) + _, coordAtomSite = self.getCoordAtomSiteOf(chainId, _seqId, cifCompId, cifCheck=self.__hasCoord) atomId = retrieveAtomIdFromMRMap(self.__mrAtomNameMapping, seqId, origCompId, atomId, coordAtomSite) if compId in (cifCompId, origCompId, 'MTS', 'ORI'): if len(self.__nefT.get_valid_star_atom(cifCompId, atomId)[0]) > 0: @@ -1079,7 +1087,7 @@ def assignCoordPolymerSequence(self, seqId, compId, atomId): if seqKey in self.__labelToAuthSeq: _, seqId = self.__labelToAuthSeq[seqKey] if seqId in ps['auth_seq_id']: - idx = ps['auth_seq_id'].index(seqId) + idx = ps['seq_id'].index(_seqId) cifCompId = ps['comp_id'][idx] origCompId = ps['auth_comp_id'][idx] if cifCompId != compId: @@ -1089,7 +1097,7 @@ def assignCoordPolymerSequence(self, seqId, compId, atomId): origCompId = next(origCompId for _seqId, _compId, origCompId in zip(ps['auth_seq_id'], ps['comp_id'], ps['auth_comp_id']) if _seqId == seqId and _compId == compId) if self.__mrAtomNameMapping is not None and cifCompId not in monDict3: - _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, self.__hasCoord) + _, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCompId, cifCheck=self.__hasCoord) atomId = retrieveAtomIdFromMRMap(self.__mrAtomNameMapping, seqId, origCompId, atomId, coordAtomSite) if compId in (cifCompId, origCompId, 'MTS', 'ORI'): if len(self.__nefT.get_valid_star_atom(cifCompId, atomId)[0]) > 0: @@ -1162,7 +1170,7 @@ def selectCoordAtoms(self, chainAssign, seqId, compId, atomId, allowAmbig=True, cifSeqId += offset cifCompId = compId - seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, cifSeqId, self.__hasCoord, asis=self.__preferAuthSeq) + seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, cifSeqId, cifCompId, asis=self.__preferAuthSeq) if self.__cur_subtype == 'dist' and _compId is not None and (_compId.startswith('MTS') or _compId.startswith('ORI')) and cifCompId != _compId: if _atomId[0] in ('O', 'N'): @@ -1230,7 +1238,7 @@ def selectCoordAtoms(self, chainAssign, seqId, compId, atomId, allowAmbig=True, for np in self.__nonPolySeq: if np['auth_chain_id'] == chainId and cifSeqId in np['auth_seq_id']: cifSeqId = np['seq_id'][np['auth_seq_id'].index(cifSeqId)] - seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, cifSeqId, self.__hasCoord) + seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, cifSeqId, cifCompId) if coordAtomSite is not None: break except ValueError: @@ -1250,7 +1258,7 @@ def selectCoordAtoms(self, chainAssign, seqId, compId, atomId, allowAmbig=True, cifCompId = compId if not multiChain and not insCode: if self.__preferAuthSeq: - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, cifSeqId, asis=False) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, cifSeqId, cifCompId, asis=False) if _coordAtomSite is not None and _coordAtomSite['comp_id'] == compId: if lenAtomId > 0 and _atomId[0] in _coordAtomSite['atom_id']: self.__authSeqId = 'label_seq_id' @@ -1324,7 +1332,7 @@ def testCoordAtomIdConsistency(self, chainId, seqId, compId, atomId, seqKey, coo # self.__authAtomId = 'auth_atom_id' elif self.__preferAuthSeq: - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, asis=False) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, compId, asis=False) if _coordAtomSite is not None and _coordAtomSite['comp_id'] == compId: if atomId in _coordAtomSite['atom_id']: found = True @@ -1342,7 +1350,7 @@ def testCoordAtomIdConsistency(self, chainId, seqId, compId, atomId, seqKey, coo else: self.__preferAuthSeq = True - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, compId) if _coordAtomSite is not None and _coordAtomSite['comp_id'] == compId: if atomId in _coordAtomSite['atom_id']: found = True @@ -1361,7 +1369,7 @@ def testCoordAtomIdConsistency(self, chainId, seqId, compId, atomId, seqKey, coo self.__preferAuthSeq = False elif self.__preferAuthSeq: - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, asis=False) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, compId, asis=False) if _coordAtomSite is not None and _coordAtomSite['comp_id'] == compId: if atomId in _coordAtomSite['atom_id']: found = True @@ -1379,7 +1387,7 @@ def testCoordAtomIdConsistency(self, chainId, seqId, compId, atomId, seqKey, coo else: self.__preferAuthSeq = True - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, compId) if _coordAtomSite is not None and _coordAtomSite['comp_id'] == compId: if atomId in _coordAtomSite['atom_id']: found = True @@ -1401,7 +1409,7 @@ def testCoordAtomIdConsistency(self, chainId, seqId, compId, atomId, seqKey, coo return if self.__preferAuthSeq: - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, asis=False) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, compId, asis=False) if _coordAtomSite is not None and _coordAtomSite['comp_id'] == compId: if atomId in _coordAtomSite['atom_id']: found = True @@ -1419,7 +1427,7 @@ def testCoordAtomIdConsistency(self, chainId, seqId, compId, atomId, seqKey, coo else: self.__preferAuthSeq = True - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, compId) if _coordAtomSite is not None and _coordAtomSite['comp_id'] == compId: if atomId in _coordAtomSite['atom_id']: found = True @@ -1579,20 +1587,27 @@ def selectRealisticBondConstraint(self, atom1, atom2, alt_atom_id1, alt_atom_id2 return atom1, atom2 - def getCoordAtomSiteOf(self, chainId, seqId, cifCheck=True, asis=True): + def getCoordAtomSiteOf(self, chainId, seqId, compId=None, cifCheck=True, asis=True): seqKey = (chainId, seqId) - coordAtomSite = None if cifCheck: preferAuthSeq = self.__preferAuthSeq if asis else not self.__preferAuthSeq if preferAuthSeq: + if compId is not None: + _seqKey = (chainId, seqId, compId) + if _seqKey in self.__coordAtomSite: + return seqKey, self.__coordAtomSite[_seqKey] if seqKey in self.__coordAtomSite: - coordAtomSite = self.__coordAtomSite[seqKey] + return seqKey, self.__coordAtomSite[seqKey] else: if seqKey in self.__labelToAuthSeq: seqKey = self.__labelToAuthSeq[seqKey] + if cifCheck and compId is not None: + _seqKey = (seqKey[0], seqKey[1], compId) + if _seqKey in self.__coordAtomSite: + return seqKey, self.__coordAtomSite[_seqKey] if seqKey in self.__coordAtomSite: - coordAtomSite = self.__coordAtomSite[seqKey] - return seqKey, coordAtomSite + return seqKey, self.__coordAtomSite[seqKey] + return seqKey, None # Enter a parse tree produced by SybylMRParser#number. def enterNumber(self, ctx: SybylMRParser.NumberContext): # pylint: disable=unused-argument diff --git a/wwpdb/utils/nmr/mr/XplorMRParserListener.py b/wwpdb/utils/nmr/mr/XplorMRParserListener.py index f09817752..d912eef4f 100644 --- a/wwpdb/utils/nmr/mr/XplorMRParserListener.py +++ b/wwpdb/utils/nmr/mr/XplorMRParserListener.py @@ -8803,7 +8803,7 @@ def __consumeFactor_expressions(self, _factor, clauseName='atom selection expres _atomIdSelect.add(realAtomId) for nonPolyCompId in _nonPolyCompIdSelect: - _, coordAtomSite = self.getCoordAtomSiteOf(nonPolyCompId['chain_id'], nonPolyCompId['seq_id'], cifCheck) + _, coordAtomSite = self.getCoordAtomSiteOf(nonPolyCompId['chain_id'], nonPolyCompId['seq_id'], cifCheck=cifCheck) if coordAtomSite is not None: for realAtomId in coordAtomSite['atom_id']: _atomIdSelect.add(realAtomId) @@ -8858,7 +8858,7 @@ def __consumeFactor_expressions(self, _factor, clauseName='atom selection expres _atomIdSelect.add(realAtomId) for nonPolyCompId in _nonPolyCompIdSelect: - _, coordAtomSite = self.getCoordAtomSiteOf(nonPolyCompId['chain_id'], nonPolyCompId['seq_id'], cifCheck) + _, coordAtomSite = self.getCoordAtomSiteOf(nonPolyCompId['chain_id'], nonPolyCompId['seq_id'], cifCheck=cifCheck) if coordAtomSite is not None: for realAtomId in coordAtomSite['atom_id']: _atomIdSelect.add(realAtomId) @@ -9049,7 +9049,7 @@ def __consumeFactor_expressions__(self, _factor, cifCheck, _atomSelection, continue _seqId_ = seqId - seqId = self.getRealSeqId(ps, seqId, isPolySeq) + seqId, _compId_ = self.getRealSeqId(ps, seqId, isPolySeq) if seqId is None: continue @@ -9112,13 +9112,17 @@ def __consumeFactor_expressions__(self, _factor, cifCheck, _atomSelection, compId = ps['comp_id'][idx] _seqId_ = ps['auth_seq_id'][idx] - seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck) + if self.__authToInsCode is None or len(self.__authToInsCode) == 0 or _compId_ is None: + seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, compId, cifCheck=cifCheck) + else: + compId = _compId_ + seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, _compId_, cifCheck=cifCheck) if compId is None and seqKey in self.__authToLabelSeq: _, seqId = self.__authToLabelSeq[seqKey] if ps is not None and seqId in ps['auth_seq_id']: compId = ps['comp_id'][ps['auth_seq_id'].index(seqId)] - seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck) + seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck=cifCheck) if compId is None and coordAtomSite is not None and ps is not None and seqKey[1] in ps['auth_seq_id']: compId = ps['comp_id'][ps['auth_seq_id'].index(seqKey[1])] @@ -9128,7 +9132,7 @@ def __consumeFactor_expressions__(self, _factor, cifCheck, _atomSelection, idx = ps['auth_seq_id'].index(seqId) seqId = ps['seq_id'][idx] compId = ps['comp_id'][idx] - seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck) + seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck=cifCheck) except ValueError: pass @@ -9145,7 +9149,7 @@ def __consumeFactor_expressions__(self, _factor, cifCheck, _atomSelection, _seqId = seqId if not isPolySeq and 'alt_auth_seq_id' in ps and seqId in ps['auth_seq_id'] and seqId not in ps['alt_auth_seq_id']: seqId = next(_altSeqId for _seqId, _altSeqId in zip(ps['auth_seq_id'], ps['alt_auth_seq_id']) if _seqId == seqId) - seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck) + seqKey, coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck=cifCheck) if not isPolySeq and isChainSpecified and self.doesNonPolySeqIdMatchWithPolySeqUnobs(_factor['chain_id'][0], _seqId_): continue @@ -9267,7 +9271,7 @@ def __consumeFactor_expressions__(self, _factor, cifCheck, _atomSelection, _atom['type_symbol'] = coordAtomSite['type_symbol'][coordAtomSite['alt_atom_id'].index(_atomId)] self.__authAtomId = 'auth_atom_id' elif self.__preferAuthSeq and atomSpecified: - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck, asis=False) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck=cifCheck, asis=False) if _coordAtomSite is not None: _compId = _coordAtomSite['comp_id'] _atomId = self.getAtomIdList(_factor, _compId, atomId)[0] @@ -9312,7 +9316,7 @@ def __consumeFactor_expressions__(self, _factor, cifCheck, _atomSelection, """ elif _seqId_ in ps['auth_seq_id'] and atomSpecified: self.__preferAuthSeq = True - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, _seqId_, cifCheck) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, _seqId_, cifCheck=cifCheck) if _coordAtomSite is not None: _compId = _coordAtomSite['comp_id'] _atomId = self.getAtomIdList(_factor, _compId, atomId)[0] @@ -9342,7 +9346,7 @@ def __consumeFactor_expressions__(self, _factor, cifCheck, _atomSelection, elif self.__preferAuthSeq and atomSpecified: if len(self.atomSelectionSet) == 0: - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck, asis=False) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, seqId, cifCheck=cifCheck, asis=False) if _coordAtomSite is not None: _compId = _coordAtomSite['comp_id'] _atomId = self.getAtomIdList(_factor, _compId, atomId)[0] @@ -9388,7 +9392,7 @@ def __consumeFactor_expressions__(self, _factor, cifCheck, _atomSelection, elif _seqId_ in ps['auth_seq_id'] and atomSpecified: if len(self.atomSelectionSet) == 0: self.__preferAuthSeq = True - _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, _seqId_, cifCheck) + _seqKey, _coordAtomSite = self.getCoordAtomSiteOf(chainId, _seqId_, cifCheck=cifCheck) if _coordAtomSite is not None: _compId = _coordAtomSite['comp_id'] _atomId = self.getAtomIdList(_factor, _compId, atomId)[0] @@ -9529,8 +9533,8 @@ def __consumeFactor_expressions__(self, _factor, cifCheck, _atomSelection, if len(__psList) == 0: continue for __ps in __psList: - __seqId = self.getRealSeqId(__ps, seqId, isPolySeq) - __seqKey, __coordAtomSite = self.getCoordAtomSiteOf(__chainId, __seqId, cifCheck) + __seqId, _ = self.getRealSeqId(__ps, seqId, isPolySeq) + __seqKey, __coordAtomSite = self.getCoordAtomSiteOf(__chainId, __seqId, cifCheck=cifCheck) if __coordAtomSite is not None: __compId = __coordAtomSite['comp_id'] __atomIds = self.getAtomIdList(_factor, __compId, atomId) @@ -9595,8 +9599,8 @@ def __consumeFactor_expressions__(self, _factor, cifCheck, _atomSelection, if len(__psList) == 0: continue for __ps in __psList: - __seqId = self.getRealSeqId(__ps, seqId, isPolySeq) - __seqKey, __coordAtomSite = self.getCoordAtomSiteOf(__chainId, __seqId, cifCheck) + __seqId, _ = self.getRealSeqId(__ps, seqId, isPolySeq) + __seqKey, __coordAtomSite = self.getCoordAtomSiteOf(__chainId, __seqId, cifCheck=cifCheck) if __coordAtomSite is not None: __compId = __coordAtomSite['comp_id'] __atomIds = self.getAtomIdList(_factor, __compId, atomId) @@ -9705,14 +9709,16 @@ def getRealSeqId(self, ps, seqId, isPolySeq=True): offset = offset[seqId - shift] break if isinstance(offset, dict): - return None + return None, None if seqId + offset in ps['auth_seq_id']: - return seqId + offset + return seqId + offset, ps['comp_id'][ps['auth_seq_id'].index(seqId + offset)] seqKey = (ps['chain_id' if isPolySeq else 'auth_chain_id'], seqId + offset) if seqKey in self.__labelToAuthSeq: _chainId, _seqId = self.__labelToAuthSeq[seqKey] if _seqId in ps['auth_seq_id']: - return _seqId + return _seqId, ps['comp_id'][ps['seq_id'].index(seqId + offset) + if seqId + offset in ps['seq_id'] + else ps['auth_seq_id'].index(seqId)] else: if isPolySeq and self.__reasons is not None and 'global_auth_sequence_offset' in self.__reasons\ and ps['auth_chain_id'] in self.__reasons['global_auth_sequence_offset']: @@ -9729,12 +9735,12 @@ def getRealSeqId(self, ps, seqId, isPolySeq=True): offset = offset[seqId - shift] break if isinstance(offset, dict): - return None + return None, None if seqId + offset in ps['auth_seq_id']: - return seqId + offset + return seqId + offset, ps['comp_id'][ps['auth_seq_id'].index(seqId + offset)] # if seqId in ps['seq_id']: # return ps['auth_seq_id'][ps['seq_id'].index(seqId)] - return seqId + return seqId, None def getRealChainId(self, chainId): if self.__reasons is not None and 'segment_id_mismatch' in self.__reasons and chainId in self.__reasons['segment_id_mismatch']: @@ -9764,12 +9770,20 @@ def updateSegmentIdDict(self, factor, chainId, valid): if chainId in _stats: _stats[chainId] -= 1 - def getCoordAtomSiteOf(self, chainId, seqId, cifCheck=True, asis=True): + def getCoordAtomSiteOf(self, chainId, seqId, compId=None, cifCheck=True, asis=True): seqKey = (chainId, seqId) if asis: + if cifCheck and compId is not None: + _seqKey = (chainId, seqId, compId) + if _seqKey in self.__coordAtomSite: + return seqKey, self.__coordAtomSite[_seqKey] return seqKey, self.__coordAtomSite[seqKey] if cifCheck and seqKey in self.__coordAtomSite else None if seqKey in self.__labelToAuthSeq: seqKey = self.__labelToAuthSeq[seqKey] + if cifCheck and compId is not None: + _seqKey = (seqKey[0], seqKey[1], compId) + if _seqKey in self.__coordAtomSite: + return seqKey, self.__coordAtomSite[_seqKey] return seqKey, self.__coordAtomSite[seqKey] if cifCheck and seqKey in self.__coordAtomSite else None return seqKey, None @@ -10304,13 +10318,13 @@ def set_store(num): if ps is not None: found = False for realSeqId in ps['auth_seq_id']: - realSeqId = self.getRealSeqId(ps, realSeqId) + realSeqId = self.getRealSeqId(ps, realSeqId)[0] if re.match(_seqId, str(realSeqId)): _seqIdSelect.add(realSeqId) found = True if not found: for realSeqId in ps['auth_seq_id']: - realSeqId = self.getRealSeqId(ps, realSeqId) + realSeqId = self.getRealSeqId(ps, realSeqId)[0] seqKey = (chainId, realSeqId) if seqKey in self.__authToLabelSeq: _, realSeqId = self.__authToLabelSeq[seqKey] @@ -10322,13 +10336,13 @@ def set_store(num): for np in npList: found = False for realSeqId in np['auth_seq_id']: - realSeqId = self.getRealSeqId(np, realSeqId, False) + realSeqId = self.getRealSeqId(np, realSeqId, False)[0] if re.match(_seqId, str(realSeqId)): _seqIdSelect.add(realSeqId) found = True if not found: for realSeqId in np['auth_seq_id']: - realSeqId = self.getRealSeqId(np, realSeqId, False) + realSeqId = self.getRealSeqId(np, realSeqId, False)[0] seqKey = (chainId, realSeqId) if seqKey in self.__authToLabelSeq: _, realSeqId = self.__authToLabelSeq[seqKey] @@ -10345,8 +10359,8 @@ def set_store(num): continue for seqId in self.factor['seq_id']: if seqId in ps['auth_seq_id']: - seqId = self.getRealSeqId(ps, seqId) - compId = ps['comp_id'][ps['auth_seq_id'].index(seqId)] + seqId, compId = self.getRealSeqId(ps, seqId) + # compId = ps['comp_id'][ps['auth_seq_id'].index(seqId)] if self.__ccU.updateChemCompDict(compId): if any(cca for cca in self.__ccU.lastAtomList if cca[self.__ccU.ccaAtomId] == atomId): _atomIdSelect.add(atomId) @@ -10356,8 +10370,8 @@ def set_store(num): for np in npList: for seqId in self.factor['seq_id']: if seqId in np['auth_seq_id']: - seqId = self.getRealSeqId(np, seqId, False) - compId = np['comp_id'][np['auth_seq_id'].index(seqId)] + seqId, compId = self.getRealSeqId(np, seqId, False) + # compId = np['comp_id'][np['auth_seq_id'].index(seqId)] if self.__ccU.updateChemCompDict(compId): if any(cca for cca in self.__ccU.lastAtomList if cca[self.__ccU.ccaAtomId] == atomId): _atomIdSelect.add(atomId) @@ -10373,8 +10387,8 @@ def set_store(num): continue for seqId in self.factor['seq_id']: if seqId in ps['auth_seq_id']: - seqId = self.getRealSeqId(ps, seqId) - compId = ps['comp_id'][ps['auth_seq_id'].index(seqId)] + seqId, compId = self.getRealSeqId(ps, seqId) + # compId = ps['comp_id'][ps['auth_seq_id'].index(seqId)] if self.__ccU.updateChemCompDict(compId): for cca in self.__ccU.lastAtomList: if cca[self.__ccU.ccaLeavingAtomFlag] != 'Y': @@ -10387,8 +10401,8 @@ def set_store(num): for np in npList: for seqId in self.factor['seq_id']: if seqId in np['auth_seq_id']: - seqId = self.getRealSeqId(np, seqId, False) - compId = np['comp_id'][np['auth_seq_id'].index(seqId)] + seqId, compId = self.getRealSeqId(np, seqId, False) + # compId = np['comp_id'][np['auth_seq_id'].index(seqId)] if self.__ccU.updateChemCompDict(compId): for cca in self.__ccU.lastAtomList: if cca[self.__ccU.ccaLeavingAtomFlag] != 'Y': @@ -10677,14 +10691,14 @@ def set_store(num): else: ps = next((ps for ps in self.__polySeq if ps['auth_chain_id'] == chainId), None) if ps is not None and seqId in ps['auth_seq_id'] and ps['comp_id'][ps['auth_seq_id'].index(seqId)] == compId: - seqId = self.getRealSeqId(ps, seqId) + seqId = self.getRealSeqId(ps, seqId)[0] if any(cca for cca in self.__ccU.lastAtomList if cca[self.__ccU.ccaAtomId] == _atomId): _atomSelection.append({'chain_id': chainId, 'seq_id': seqId, 'comp_id': compId, 'atom_id': _atomId}) if self.__hasNonPolySeq: npList = [np for np in self.__nonPolySeq if np['auth_chain_id'] == chainId] for np in npList: if seqId in np['auth_seq_id'] and np['comp_id'][np['auth_seq_id'].index(seqId)] == compId: - seqId = self.getRealSeqId(np, seqId, False) + seqId = self.getRealSeqId(np, seqId, False)[0] if any(cca for cca in self.__ccU.lastAtomList if cca[self.__ccU.ccaAtomId] == _atomId): _atomSelection.append({'chain_id': chainId, 'seq_id': seqId, 'comp_id': compId, 'atom_id': _atomId}) @@ -10709,8 +10723,8 @@ def set_store(num): if ps is not None: for _seqId in [seqId - 1, seqId + 1]: if _seqId in ps['auth_seq_id']: - _seqId = self.getRealSeqId(ps, _seqId) - _compId = ps['comp_id'][ps['auth_seq_id'].index(_seqId)] + _seqId, _compId = self.getRealSeqId(ps, _seqId) + # _compId = ps['comp_id'][ps['auth_seq_id'].index(_seqId)] if self.__ccU.updateChemCompDict(_compId): leavingAtomIds = [cca[self.__ccU.ccaAtomId] for cca in self.__ccU.lastAtomList if cca[self.__ccU.ccaLeavingAtomFlag] == 'Y'] @@ -10749,8 +10763,8 @@ def set_store(num): for np in npList: for _seqId in [seqId - 1, seqId + 1]: if _seqId in np['auth_seq_id']: - _seqId = self.getRealSeqId(np, _seqId, False) - _compId = np['comp_id'][np['auth_seq_id'].index(_seqId)] + _seqId, _compId = self.getRealSeqId(np, _seqId, False) + # _compId = np['comp_id'][np['auth_seq_id'].index(_seqId)] if self.__ccU.updateChemCompDict(_compId): leavingAtomIds = [cca[self.__ccU.ccaAtomId] for cca in self.__ccU.lastAtomList if cca[self.__ccU.ccaLeavingAtomFlag] == 'Y'] @@ -10961,7 +10975,7 @@ def set_store(num): else: ps = next((ps for ps in self.__polySeq if ps['auth_chain_id'] == chainId), None) if ps is not None and seqId in ps['auth_seq_id'] and ps['comp_id'][ps['auth_seq_id'].index(seqId)] == compId: - seqId = self.getRealSeqId(ps, seqId) + seqId = self.getRealSeqId(ps, seqId)[0] if self.__ccU.updateChemCompDict(compId): atomIds = [cca[self.__ccU.ccaAtomId] for cca in self.__ccU.lastAtomList if cca[self.__ccU.ccaLeavingAtomFlag] != 'Y'] for atomId in atomIds: @@ -10970,7 +10984,7 @@ def set_store(num): npList = [np for np in self.__nonPolySeq if np['auth_chain_id'] == chainId] for np in npList: if seqId in np['auth_seq_id'] and np['comp_id'][np['auth_seq_id'].index(seqId)] == compId: - seqId = self.getRealSeqId(np, seqId, False) + seqId = self.getRealSeqId(np, seqId, False)[0] if self.__ccU.updateChemCompDict(compId): atomIds = [cca[self.__ccU.ccaAtomId] for cca in self.__ccU.lastAtomList if cca[self.__ccU.ccaLeavingAtomFlag] != 'Y'] for atomId in atomIds: diff --git a/wwpdb/utils/nmr/mr/XplorMRReader.py b/wwpdb/utils/nmr/mr/XplorMRReader.py index 5d9615235..1e831e0b5 100644 --- a/wwpdb/utils/nmr/mr/XplorMRReader.py +++ b/wwpdb/utils/nmr/mr/XplorMRReader.py @@ -219,6 +219,11 @@ def parse(self, mrFilePath, cifFilePath=None, isFilePath=True, if __name__ == "__main__": + reader = XplorMRReader(True) + reader.setDebugMode(True) + reader.parse('../../tests-nmr/mock-data-remediation/2kny/2kny-corrected.mr', + '../../tests-nmr/mock-data-remediation/2kny/2kny.cif') + reader = XplorMRReader(True) reader.setDebugMode(True) reader.parse('../../tests-nmr/mock-data-remediation/2ltj/2ltj-corrected.mr',