Skip to content

Commit

Permalink
rename Bond's cycle_break to breakable
Browse files Browse the repository at this point in the history
  • Loading branch information
diogomart committed Jan 12, 2025
1 parent d166afc commit c563bf9
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 13 deletions.
12 changes: 6 additions & 6 deletions meeko/molsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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]):
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion meeko/preparation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 15 additions & 0 deletions test/json_serialization_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
12 changes: 6 additions & 6 deletions test/macrocycle_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit c563bf9

Please sign in to comment.