Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix and enhance geometric node features #305

Merged
merged 28 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
eb951a8
Remove obsolete `remove_insertions`
anton-bushuiev Apr 16, 2023
40ffc43
Fix case when beta-carbon is missing in PDB
anton-bushuiev Apr 16, 2023
0aaab28
Fix case when side-chain atoms are missing in PDB
anton-bushuiev Apr 16, 2023
1f46f8c
Test handling of missing beta-carbons
anton-bushuiev Apr 16, 2023
ab05e0f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 16, 2023
b2c4d4b
Merge branch 'a-r-j:master' into insertions
anton-bushuiev Apr 16, 2023
dd4d014
Merge
anton-bushuiev Apr 16, 2023
7401b1e
Merge
anton-bushuiev Apr 16, 2023
b03389d
Remove `main`
anton-bushuiev Apr 16, 2023
82166f2
Fix data types.
anton-bushuiev Apr 16, 2023
cf7b9b8
Implement `add_virtual_beta_carbon_vector`
anton-bushuiev Apr 16, 2023
6d50733
Enhance visalization of PyG data
anton-bushuiev Apr 16, 2023
502022b
Test `test_add_virtual_beta_carbon_vector`
anton-bushuiev Apr 16, 2023
94f3641
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 16, 2023
5790b3c
Update changelog
anton-bushuiev Apr 16, 2023
0e434b8
Merge branch 'insertions' of https://github.com/anton-bushuiev/graphe…
anton-bushuiev Apr 16, 2023
74824e1
Merge branch 'master' into insertions
a-r-j Apr 16, 2023
8414d5b
Update changelog
a-r-j Apr 17, 2023
0277a93
Merge branch 'master' into insertions
a-r-j Apr 17, 2023
6190f9a
Merge branch 'master' into insertions
a-r-j Apr 29, 2023
1b44fd6
Generalize vector visualization for PyG format
anton-bushuiev Jul 4, 2023
fd9570b
Do not convert Tensor to Tensor
anton-bushuiev Jul 4, 2023
e558ce3
Fix k-NN graph on df with dropped residues
anton-bushuiev Jul 4, 2023
c5594ef
Merge branch 'insertions' of https://github.com/anton-bushuiev/graphe…
anton-bushuiev Jul 4, 2023
07bb871
Update changelog
anton-bushuiev Jul 4, 2023
3357662
Merge branch 'master' into insertions
a-r-j Jul 31, 2023
b9e83d0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 31, 2023
018cc67
Fix outdated test
a-r-j Jul 31, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions graphein/protein/features/nodes/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ def add_sidechain_vector(
if d["residue_name"] == "GLY":
# If GLY, set vector to 0
vec = np.array([0, 0, 0])
elif n not in sc_centroid.index:
vec = np.array([0, 0, 0])
log.warning(
f"Non-glycine residue {n} does not have side-chain atoms."
)
else:
if reverse:
vec = d["coords"] - np.array(
Expand Down Expand Up @@ -94,6 +99,11 @@ def add_beta_carbon_vector(
for n, d in g.nodes(data=True):
if d["residue_name"] == "GLY":
vec = np.array([0, 0, 0])
elif n not in c_beta_coords.index:
vec = np.array([0, 0, 0])
log.warning(
f"Non-glycine residue {n} does not have a beta-carbon."
)
else:
if reverse:
vec = d["coords"] - np.array(
Expand Down
2 changes: 1 addition & 1 deletion graphein/protein/graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ def initialise_graph_with_metadata(
chain_ids=list(protein_df["chain_id"].unique()),
pdb_df=protein_df,
raw_pdb_df=raw_pdb_df,
rgroup_df=compute_rgroup_dataframe(remove_insertions(raw_pdb_df)),
rgroup_df=compute_rgroup_dataframe(raw_pdb_df),
coords=np.asarray(protein_df[["x_coord", "y_coord", "z_coord"]]),
)

Expand Down
9 changes: 9 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import pytest
from loguru import logger


@pytest.fixture
def caplog(caplog):
handler_id = logger.add(caplog.handler, format="{message}")
yield caplog
logger.remove(handler_id)
18 changes: 12 additions & 6 deletions tests/protein/nodes/features/test_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from functools import partial

import numpy as np
from loguru import logger

from graphein.protein.config import ProteinGraphConfig
from graphein.protein.features.nodes.geometry import (
Expand All @@ -17,7 +18,7 @@
from graphein.protein.graphs import construct_graph


def test_add_beta_carbon_vector():
def test_add_beta_carbon_vector(caplog):
config = ProteinGraphConfig(
edge_construction_functions=[
partial(add_beta_carbon_vector, scale=True)
Expand Down Expand Up @@ -76,6 +77,16 @@ def test_add_beta_carbon_vector():
for n, d in g.nodes(data=True):
assert d["c_beta_vector"].shape == (3,)

# Test handling of missing beta-carbons
g = construct_graph(config=config, pdb_code="3se8")
assert "H:CYS:104" in caplog.text # Test warning is raised
for n, d in g.nodes(data=True):
assert d["c_beta_vector"].shape == (3,)
if n == "H:CYS:104":
np.testing.assert_equal(
d["c_beta_vector"], np.array([0.0, 0.0, 0.0])
)


def test_add_sidechain_vector():
config = ProteinGraphConfig(
Expand Down Expand Up @@ -127,8 +138,3 @@ def test_add_sidechain_vector():
np.testing.assert_almost_equal(
sc_true, d["coords"] + d["sidechain_vector"]
)


if __name__ == "__main__":
test_add_beta_carbon_vector()
test_add_sidechain_vector()