From 9e4ae4d9a70897d3fec1b2e827bc441585867608 Mon Sep 17 00:00:00 2001 From: richard gowers Date: Fri, 8 Mar 2024 15:03:01 +0000 Subject: [PATCH] silences warning in plan_radial_network when int passed previously would warn about duplicates when not necessary --- openfe/setup/ligand_network_planning.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/openfe/setup/ligand_network_planning.py b/openfe/setup/ligand_network_planning.py index 99aa2ee87..de48d50c6 100644 --- a/openfe/setup/ligand_network_planning.py +++ b/openfe/setup/ligand_network_planning.py @@ -88,12 +88,18 @@ def generate_radial_network( # handle central_ligand arg possibilities # after this, central_ligand is resolved to a SmallMoleculeComponent if isinstance(central_ligand, int): + central_ligand_index = central_ligand ligands = list(ligands) try: - central_ligand = ligands[central_ligand] + central_ligand = ligands[central_ligand_index] except IndexError: raise ValueError(f"index '{central_ligand}' out of bounds, there are " f"{len(ligands)} ligands") + # you could do a list comprehension like: + # ligands = [l for l in ligands if l != central] + # but this wouldn't properly catch when multiple identical central ligands have been passed + # so instead slice out the central ligand + ligands = ligands[:central_ligand_index] + ligands[central_ligand_index + 1:] elif isinstance(central_ligand, str): ligands = list(ligands) possibles = [l for l in ligands if l.name == central_ligand]