From 40f5c479681ed086d0bbc8ed079c7e43bf2bbdff Mon Sep 17 00:00:00 2001 From: Rachel Clune Date: Mon, 24 Aug 2026 15:51:29 -0700 Subject: [PATCH 1/2] Use get_motif_features() for is_motif_atom lookup Replace direct attribute access on atom_array with get_motif_features() from conditioning_base to retrieve is_motif_atom, making the hbonds_hbplus transform consistent with how motif features are obtained elsewhere. --- models/rfd3/src/rfd3/transforms/hbonds_hbplus.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/models/rfd3/src/rfd3/transforms/hbonds_hbplus.py b/models/rfd3/src/rfd3/transforms/hbonds_hbplus.py index 4ade17cf6..889aa609d 100644 --- a/models/rfd3/src/rfd3/transforms/hbonds_hbplus.py +++ b/models/rfd3/src/rfd3/transforms/hbonds_hbplus.py @@ -15,6 +15,8 @@ from biotite.structure import AtomArray from biotite.structure.io.pdb import PDBFile +from rfd3.transforms.conditioning_base import get_motif_features + def save_atomarray_to_pdb(atom_array, output_path): def _handle_nan_coords(atom_array, noise_level=1e-3): @@ -133,6 +135,8 @@ def calculate_hbonds( donor_mask = np.bool_(donor_array) acceptor_mask = np.bool_(acceptor_array) + is_motif_atom = get_motif_features(atom_array)["is_motif_atom"] + motif_hbonds = [] for item in hbonds: current_donor_mask = ( @@ -156,8 +160,8 @@ def calculate_hbonds( f"Unable to uniquely identify an acceptor atom with chain_iid={item['a_chain']}, res_id={item['a_resi']}, atom_name={item['a_atom']}." ) - current_donor_is_motif = atom_array.is_motif_atom[current_donor_mask][0] - current_acceptor_is_motif = atom_array.is_motif_atom[current_acceptor_mask][0] + current_donor_is_motif = is_motif_atom[current_donor_mask][0] + current_acceptor_is_motif = is_motif_atom[current_acceptor_mask][0] # Only keep hbonds between the motif and diffused regions if current_donor_is_motif != current_acceptor_is_motif: @@ -205,9 +209,10 @@ def forward(self, data: dict) -> dict: hbond_types = np.vstack((atom_array.active_donor, atom_array.active_acceptor)).T + is_motif_atom = np.array(get_motif_features(atom_array)["is_motif_atom"]) final_hbond_types = hbond_types - final_hbond_types[:, 0] *= np.array(atom_array.is_motif_atom) - final_hbond_types[:, 1] *= np.array(atom_array.is_motif_atom) + final_hbond_types[:, 0] *= is_motif_atom + final_hbond_types[:, 1] *= is_motif_atom log_dict["hbond_total_count"] = np.sum(final_hbond_types) if data["conditions"]["hbond_subsample"] and np.sum(final_hbond_types) > 3: From 1c8886fe8174558559e7d414697883661eec882d Mon Sep 17 00:00:00 2001 From: Rachel Clune Date: Tue, 25 Aug 2026 09:04:14 -0700 Subject: [PATCH 2/2] Use get_motif_features() for is_motif_atom lookup Replace direct atom_array.is_motif_atom attribute access with get_motif_features() helper in both rfd3na and rfd3 hbonds_hbplus transforms. Also adds the missing import and usage of get_motif_features in rfd3na, which was previously absent. --- models/rfd3/src/rfd3/transforms/hbonds_hbplus.py | 1 - models/rfd3na/src/rfd3na/transforms/hbonds_hbplus.py | 12 ++++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/models/rfd3/src/rfd3/transforms/hbonds_hbplus.py b/models/rfd3/src/rfd3/transforms/hbonds_hbplus.py index 889aa609d..b00680d07 100644 --- a/models/rfd3/src/rfd3/transforms/hbonds_hbplus.py +++ b/models/rfd3/src/rfd3/transforms/hbonds_hbplus.py @@ -14,7 +14,6 @@ from atomworks.ml.transforms.base import Transform from biotite.structure import AtomArray from biotite.structure.io.pdb import PDBFile - from rfd3.transforms.conditioning_base import get_motif_features diff --git a/models/rfd3na/src/rfd3na/transforms/hbonds_hbplus.py b/models/rfd3na/src/rfd3na/transforms/hbonds_hbplus.py index 4ade17cf6..da2c5d6b6 100644 --- a/models/rfd3na/src/rfd3na/transforms/hbonds_hbplus.py +++ b/models/rfd3na/src/rfd3na/transforms/hbonds_hbplus.py @@ -14,6 +14,7 @@ from atomworks.ml.transforms.base import Transform from biotite.structure import AtomArray from biotite.structure.io.pdb import PDBFile +from rfd3na.transforms.conditioning_base import get_motif_features def save_atomarray_to_pdb(atom_array, output_path): @@ -133,6 +134,8 @@ def calculate_hbonds( donor_mask = np.bool_(donor_array) acceptor_mask = np.bool_(acceptor_array) + is_motif_atom = get_motif_features(atom_array)["is_motif_atom"] + motif_hbonds = [] for item in hbonds: current_donor_mask = ( @@ -156,8 +159,8 @@ def calculate_hbonds( f"Unable to uniquely identify an acceptor atom with chain_iid={item['a_chain']}, res_id={item['a_resi']}, atom_name={item['a_atom']}." ) - current_donor_is_motif = atom_array.is_motif_atom[current_donor_mask][0] - current_acceptor_is_motif = atom_array.is_motif_atom[current_acceptor_mask][0] + current_donor_is_motif = is_motif_atom[current_donor_mask][0] + current_acceptor_is_motif = is_motif_atom[current_acceptor_mask][0] # Only keep hbonds between the motif and diffused regions if current_donor_is_motif != current_acceptor_is_motif: @@ -205,9 +208,10 @@ def forward(self, data: dict) -> dict: hbond_types = np.vstack((atom_array.active_donor, atom_array.active_acceptor)).T + is_motif_atom = np.array(get_motif_features(atom_array)["is_motif_atom"]) final_hbond_types = hbond_types - final_hbond_types[:, 0] *= np.array(atom_array.is_motif_atom) - final_hbond_types[:, 1] *= np.array(atom_array.is_motif_atom) + final_hbond_types[:, 0] *= is_motif_atom + final_hbond_types[:, 1] *= is_motif_atom log_dict["hbond_total_count"] = np.sum(final_hbond_types) if data["conditions"]["hbond_subsample"] and np.sum(final_hbond_types) > 3: