From c563bf97bcff76bd0cdf451c50a2e29eaa7d4d92 Mon Sep 17 00:00:00 2001 From: diogom Date: Sat, 11 Jan 2025 18:42:57 -0800 Subject: [PATCH] rename Bond's cycle_break to breakable --- meeko/molsetup.py | 12 ++++++------ meeko/preparation.py | 2 +- test/json_serialization_test.py | 15 +++++++++++++++ test/macrocycle_test.py | 12 ++++++------ 4 files changed, 28 insertions(+), 13 deletions(-) diff --git a/meeko/molsetup.py b/meeko/molsetup.py index 88824ab6..5c67fb49 100644 --- a/meeko/molsetup.py +++ b/meeko/molsetup.py @@ -51,7 +51,7 @@ DEFAULT_GRAPH = [] DEFAULT_BOND_ROTATABLE = False -DEFAULT_BOND_CYCLE_BREAK = False +DEFAULT_BOND_BREAKABLE = False DEFAULT_RING_CLOSURE_BONDS_REMOVED = [] DEFAULT_RING_CLOSURE_PSEUDOS_BY_ATOM = defaultdict @@ -279,7 +279,7 @@ class Bond(BaseJSONParsable): index1: int index2: int rotatable: bool = DEFAULT_BOND_ROTATABLE - cycle_break: bool = DEFAULT_BOND_CYCLE_BREAK + breakable: bool = DEFAULT_BOND_BREAKABLE def __post_init__(self): self.canon_id = self.get_bond_id(self.index1, self.index2) @@ -293,12 +293,12 @@ def json_encoder(cls, obj: "Bond") -> Optional[dict[str, Any]]: "index1": obj.index1, "index2": obj.index2, "rotatable": obj.rotatable, - "cycle_break": obj.cycle_break, + "breakable": obj.breakable, } return output_dict # Keys to check for deserialized JSON - expected_json_keys = {"canon_id", "index1", "index2", "rotatable", "cycle_break"} + expected_json_keys = {"canon_id", "index1", "index2", "rotatable"} @classmethod def _decode_object(cls, obj: dict[str, Any]): @@ -307,8 +307,8 @@ def _decode_object(cls, obj: dict[str, Any]): index1 = obj["index1"] index2 = obj["index2"] rotatable = obj["rotatable"] - cycle_break = obj["cycle_break"] - output_bond = cls(index1, index2, rotatable, cycle_break) + breakable = obj.get("breakable", DEFAULT_BOND_BREAKABLE) + output_bond = cls(index1, index2, rotatable, breakable) return output_bond # endregion diff --git a/meeko/preparation.py b/meeko/preparation.py index 1b5100bf..2f4cbcf4 100644 --- a/meeko/preparation.py +++ b/meeko/preparation.py @@ -336,7 +336,7 @@ def calc_flex( for atom1, atom2 in bonds_to_break: bond_id = Bond.get_bond_id(atom1, atom2) - setup.bond_info[bond_id].cycle_break = True + setup.bond_info[bond_id].breakable = True return diff --git a/test/json_serialization_test.py b/test/json_serialization_test.py index e153d1cb..b2b3627c 100644 --- a/test/json_serialization_test.py +++ b/test/json_serialization_test.py @@ -341,6 +341,21 @@ def test_dihedral_equality(): check_molsetup_equality(starting_molsetup, decoded_molsetup) return + +def test_broken_bond(): + fn = str(pkgdir / "test" / "macrocycle_data" / "lorlatinib.mol") + mol = Chem.MolFromMolFile(fn, removeHs=False) + mk_prep_untyped = MoleculePreparation(untyped_macrocycles=True) + starting_molsetup = mk_prep_untyped(mol)[0] + decoded_molsetup = RDKitMoleculeSetup.from_json(starting_molsetup.to_json()) + count_rotatable = 0 + count_breakable = 0 + for bond_id, bond_info in decoded_molsetup.bond_info.items(): + count_rotatable += bond_info.rotatable + count_breakable += bond_info.breakable + assert count_rotatable == 10 + assert count_breakable == 1 + # endregion diff --git a/test/macrocycle_test.py b/test/macrocycle_test.py index f1556fe5..28f02512 100644 --- a/test/macrocycle_test.py +++ b/test/macrocycle_test.py @@ -109,19 +109,19 @@ def test_untyped_macrocycle(): mk_prep_typed = MoleculePreparation() molsetup_typed = mk_prep_typed(mol)[0] count_rotatable = 0 - count_broken = 0 + count_breakable = 0 for bond_id, bond_info in molsetup_typed.bond_info.items(): count_rotatable += bond_info.rotatable - count_broken += bond_info.cycle_break + count_breakable += bond_info.breakable assert count_rotatable == 2 - assert count_broken == 0 + assert count_breakable == 0 mk_prep_untyped = MoleculePreparation(untyped_macrocycles=True) molsetup_untyped = mk_prep_untyped(mol)[0] count_rotatable = 0 - count_broken = 0 + count_breakable = 0 for bond_id, bond_info in molsetup_untyped.bond_info.items(): count_rotatable += bond_info.rotatable - count_broken += bond_info.cycle_break + count_breakable += bond_info.breakable assert count_rotatable == 10 - assert count_broken == 1 + assert count_breakable == 1