From 5beab314d62e1b3a8986201477c55808bc861810 Mon Sep 17 00:00:00 2001 From: yokochi47 Date: Tue, 27 Feb 2024 12:39:05 +0900 Subject: [PATCH] Fix ValueError and prevent numpy.RuntimeWarning: mean of empty slice --- wwpdb/utils/nmr/io/CifReader.py | 6 ++- wwpdb/utils/nmr/mr/ParserListenerUtil.py | 47 ++++++++++++------------ 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/wwpdb/utils/nmr/io/CifReader.py b/wwpdb/utils/nmr/io/CifReader.py index 2fe13473d..afdae3377 100644 --- a/wwpdb/utils/nmr/io/CifReader.py +++ b/wwpdb/utils/nmr/io/CifReader.py @@ -1437,7 +1437,8 @@ def __calculateRmsd(self, chain_ids, lengths, total_models=1, eff_model_ids: lis _rmsd.append(_rmsd_) - item['mean_rmsd'] = float(f"{np.mean(np.array(_rmsd)):.4f}") + if len(_rmsd) > 0: + item['mean_rmsd'] = float(f"{np.mean(np.array(_rmsd)):.4f}") _, v = np.linalg.eig(r) x = np.delete(np.abs(v), np.s_[1:], 1) @@ -1466,7 +1467,8 @@ def __calculateRmsd(self, chain_ids, lengths, total_models=1, eff_model_ids: lis _rmsd.append(calculate_rmsd(_bb_atom_site_p, _bb_atom_site_q)) - item['medoid_rmsd'] = float(f"{np.mean(np.array(_rmsd)):.4f}") + if len(_rmsd) > 0: + item['medoid_rmsd'] = float(f"{np.mean(np.array(_rmsd)):.4f}") _item = copy.copy(item) diff --git a/wwpdb/utils/nmr/mr/ParserListenerUtil.py b/wwpdb/utils/nmr/mr/ParserListenerUtil.py index 3d3767932..15fb68cf5 100644 --- a/wwpdb/utils/nmr/mr/ParserListenerUtil.py +++ b/wwpdb/utils/nmr/mr/ParserListenerUtil.py @@ -5729,7 +5729,7 @@ def retrieve_label_comp_id(_seqId, _compId): starAtom['chain_id'], starAtom['seq_id'], starAtom['entity_id'], _ = authToStarSeq[seqKey] return starAtom - if chainId in offsetHolder: + if chainId in offsetHolder and seqId is not None: offset = offsetHolder[chainId] seqKey = (chainId, seqId + offset, compId) if has_aux_atom: @@ -5739,7 +5739,7 @@ def retrieve_label_comp_id(_seqId, _compId): atom['seq_id'] = seqId + offset return starAtom - elif f'_{chainId}' in offsetHolder: + elif f'_{chainId}' in offsetHolder and seqId is not None: offset = offsetHolder[f'_{chainId}'] seqKey = (chainId, seqId + offset, compId) if seqKey in authToStarSeq: @@ -5751,27 +5751,28 @@ def retrieve_label_comp_id(_seqId, _compId): starAtom['chain_id'], starAtom['seq_id'], starAtom['entity_id'], _ = authToStarSeq[seqKey] return starAtom - for offset in range(1, 1000): - seqKey = (chainId, seqId + offset, compId) - if has_aux_atom: - auxSeqKey = (auxChainId, auxSeqId + offset, auxCompId) - if seqKey in authToStarSeq and (not has_aux_atom or (has_aux_atom and auxSeqKey in authToStarSeq)): - starAtom['chain_id'], starAtom['seq_id'], starAtom['entity_id'], _ = authToStarSeq[seqKey] - offsetHolder[chainId] = offset - if has_aux_atom and compId in monDict3 and auxCompId in monDict3: - offsetHolder[f'_{chainId}'] = offset - atom['seq_id'] = seqId + offset - return starAtom - seqKey = (chainId, seqId - offset, compId) - if has_aux_atom: - auxSeqKey = (auxChainId, auxSeqId + offset, auxCompId) - if seqKey in authToStarSeq and (not has_aux_atom or (has_aux_atom and auxSeqKey in authToStarSeq)): - starAtom['chain_id'], starAtom['seq_id'], starAtom['entity_id'], _ = authToStarSeq[seqKey] - offsetHolder[chainId] = -offset - if has_aux_atom and compId in monDict3 and auxCompId in monDict3: - offsetHolder[f'_{chainId}'] = -offset - atom['seq_id'] = seqId - offset - return starAtom + if seqId is not None: + for offset in range(1, 1000): + seqKey = (chainId, seqId + offset, compId) + if has_aux_atom: + auxSeqKey = (auxChainId, auxSeqId + offset, auxCompId) + if seqKey in authToStarSeq and (not has_aux_atom or (has_aux_atom and auxSeqKey in authToStarSeq)): + starAtom['chain_id'], starAtom['seq_id'], starAtom['entity_id'], _ = authToStarSeq[seqKey] + offsetHolder[chainId] = offset + if has_aux_atom and compId in monDict3 and auxCompId in monDict3: + offsetHolder[f'_{chainId}'] = offset + atom['seq_id'] = seqId + offset + return starAtom + seqKey = (chainId, seqId - offset, compId) + if has_aux_atom: + auxSeqKey = (auxChainId, auxSeqId + offset, auxCompId) + if seqKey in authToStarSeq and (not has_aux_atom or (has_aux_atom and auxSeqKey in authToStarSeq)): + starAtom['chain_id'], starAtom['seq_id'], starAtom['entity_id'], _ = authToStarSeq[seqKey] + offsetHolder[chainId] = -offset + if has_aux_atom and compId in monDict3 and auxCompId in monDict3: + offsetHolder[f'_{chainId}'] = -offset + atom['seq_id'] = seqId - offset + return starAtom _seqKey = next((_seqKey for _seqKey in authToStarSeq if chainId == _seqKey[0] and seqId == _seqKey[1]), None) if has_aux_atom: