From f6e39f35f150499fa13db5aaa2e99c9e9f814bb2 Mon Sep 17 00:00:00 2001 From: Xavier Robin <xavier.robin@unibas.ch> Date: Wed, 28 Jun 2023 14:31:10 +0200 Subject: [PATCH] fix: residue may be invalid if an EntityView was given as input --- modules/mol/alg/pymod/ligand_scoring.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/mol/alg/pymod/ligand_scoring.py b/modules/mol/alg/pymod/ligand_scoring.py index 895c0875a..34308410a 100644 --- a/modules/mol/alg/pymod/ligand_scoring.py +++ b/modules/mol/alg/pymod/ligand_scoring.py @@ -417,9 +417,13 @@ class LigandScorer: def _process_ligand_residue(res, rename_chain): """Copy or fetch the residue. Return the residue handle.""" + new_res = None if res.entity.handle == old_entity.handle: - # Residue is already in copied entity. We only need to grab it + # Residue is part of the old_entity handle. + # However it may not be in the copied one, for instance it may have been a view + # We try to grab it grab it first, othewise we copyp it new_res = new_entity.FindResidue(res.chain.name, res.number) + if new_res and new_res.valid: LogVerbose("Ligand residue %s already in entity" % res.handle.qualified_name) else: # Residue is not part of the entity, need to copy it first -- GitLab