Skip to content

Commit

Permalink
Fix ValueError and prevent numpy.RuntimeWarning: mean of empty slice
Browse files Browse the repository at this point in the history
  • Loading branch information
yokochi47 committed Feb 27, 2024
1 parent 3d2387b commit 5beab31
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 25 deletions.
6 changes: 4 additions & 2 deletions wwpdb/utils/nmr/io/CifReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
47 changes: 24 additions & 23 deletions wwpdb/utils/nmr/mr/ParserListenerUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down

0 comments on commit 5beab31

Please sign in to comment.