From b458f41b3c8ea27ac1c1784c0bb07d2ca227265b Mon Sep 17 00:00:00 2001 From: Arian Jamasb Date: Tue, 29 Mar 2022 19:41:32 +0200 Subject: [PATCH] Vector bugfix #148 (#149) * bugfix to distance edge func #146 * bugfix to distance edge func #146 * bugfix for c-beta vectors not handling altlocs * update changelog --- CHANGELOG.md | 3 ++- graphein/protein/features/nodes/geometry.py | 5 ++++- tests/protein/nodes/features/test_geometry.py | 8 ++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 012e7cdf..120482f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,8 @@ * [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) +* [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) +* [Bugfix] - #149 fixes a bug in `add_beta_carbon_vector` that would cause coordinates to be extracted for multiple positions if the residue has an altloc. Resolves [#148](https://github.com/a-r-j/graphein/issues/148) ### 1.2.1 - 16/3/21 diff --git a/graphein/protein/features/nodes/geometry.py b/graphein/protein/features/nodes/geometry.py index c4a4363a..a376bbad 100644 --- a/graphein/protein/features/nodes/geometry.py +++ b/graphein/protein/features/nodes/geometry.py @@ -78,9 +78,12 @@ def add_beta_carbon_vector( :param reverse: Reverse vector. Defaults to ``False``. :type reverse: bool """ + # Get or compute R-Group DF + if "rgroup_df" not in g.graph.keys(): + g.graph["rgroup_df"] = compute_rgroup_dataframe(g.graph["raw_pdb_df"]) c_beta_coords = filter_dataframe( - g.graph["raw_pdb_df"], "atom_name", ["CB"], boolean=True + g.graph["rgroup_df"], "atom_name", ["CB"], boolean=True ) c_beta_coords.index = c_beta_coords["node_id"] diff --git a/tests/protein/nodes/features/test_geometry.py b/tests/protein/nodes/features/test_geometry.py index acaa4f25..a54b76b1 100644 --- a/tests/protein/nodes/features/test_geometry.py +++ b/tests/protein/nodes/features/test_geometry.py @@ -67,6 +67,14 @@ def test_add_beta_carbon_vector(): np.testing.assert_almost_equal( cb_true, d["coords"] + d["c_beta_vector"] ) + # Test altloc handling + g = construct_graph(config=config, pdb_code="6rew") + for n, d in g.nodes(data=True): + assert d["c_beta_vector"].shape == (3,) + + g = construct_graph(config=config, pdb_code="7w9w") + for n, d in g.nodes(data=True): + assert d["c_beta_vector"].shape == (3,) def test_add_sidechain_vector():