Skip to content

Commit

Permalink
bugfix to distance edge func #146 (#147)
Browse files Browse the repository at this point in the history
* bugfix to distance edge func #146
  • Loading branch information
a-r-j authored Mar 29, 2022
1 parent 087296d commit 4352f2e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* [Feature] - #144 adds support for chord diagram visualisations.
* [Feature] - #144 adds support for automagically downloading new PDB files for obsolete structures.
* [Misc] - #144 makes visualisation functions accessible in the `graphein.protein` namespace. #138

* [Bugfix] - #147 fixes error in `add_distance_threshold` introduced in v1.2.1 that would prevent the edges being added to the graph. [#146](https://github.com/a-r-j/graphein/issues/146)

### 1.2.1 - 16/3/21

Expand Down
15 changes: 10 additions & 5 deletions graphein/protein/edges/distance.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,10 @@ def add_distance_threshold(
)
dist_mat = compute_distmat(pdb_df)
interacting_nodes = get_interacting_atoms(threshold, distmat=dist_mat)
interacting_nodes = zip(interacting_nodes[0], interacting_nodes[1])
interacting_nodes = list(zip(interacting_nodes[0], interacting_nodes[1]))

log.info(f"Found: {len(list(interacting_nodes))} distance edges")
log.info(f"Found: {len(interacting_nodes)} distance edges")
count = 0
for a1, a2 in interacting_nodes:
n1 = G.graph["pdb_df"].loc[a1, "node_id"]
n2 = G.graph["pdb_df"].loc[a2, "node_id"]
Expand All @@ -491,16 +492,20 @@ def add_distance_threshold(
n1_position = G.graph["pdb_df"].loc[a1, "residue_number"]
n2_position = G.graph["pdb_df"].loc[a2, "residue_number"]

condition_1 = n1_chain != n2_chain
condition_1 = n1_chain == n2_chain
condition_2 = (
abs(n1_position - n2_position) > long_interaction_threshold
abs(n1_position - n2_position) < long_interaction_threshold
)

if condition_1 or condition_2:
if not (condition_1 and condition_2):
count += 1
if G.has_edge(n1, n2):
G.edges[n1, n2]["kind"].add("distance_threshold")
else:
G.add_edge(n1, n2, kind={"distance_threshold"})
log.info(
f"Added {count} distance edges. ({len(list(interacting_nodes)) - count} removed by LIN)"
)


def add_k_nn_edges(
Expand Down

0 comments on commit 4352f2e

Please sign in to comment.