Use of NetworkX algorithms¶
[1]:
import AlloViz
System setup¶
We are going to use the GPCRmd structure and simulations of GPCR Beta-2 adrenergic receptor (B2AR) in the inactive form bound to carazolol (inverse agonist, 160). The network will be built with PyInteraph2_Contacts, which measures the distance-based residue contacts along the trajectory, and will be filtered with the Spatially_distant filter to leave out residue pairs too close to each other, with a minimum distance of 20 Angstroms.
[2]:
system = AlloViz.Protein(pdb="data/160/protein.pdb",
trajs="data/160/traj_1.xtc",
path="data/160")
/home/frann/miniconda3/envs/allovizsonja/lib/python3.9/site-packages/MDAnalysis/coordinates/PDB.py:431: UserWarning: 1 A^3 CRYST1 record, this is usually a placeholder. Unit cell dimensions will be set to None.
warnings.warn("1 A^3 CRYST1 record,"
[3]:
system.calculate(pkgs="PyInteraph2_Contacts")
adding raw data of PyInteraph2_Contacts for data/160/protein.pdb: ['data/160/data/PyInteraph2_Contacts/raw/1.pq']
Please, make sure to correctly cite the package used to compute the network: PyInteraph2 (https://github.com/ELELAB/pyinteraph2)
/home/frann/miniconda3/envs/allovizsonja/lib/python3.9/site-packages/pyarrow/pandas_compat.py:373: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.
if _pandas_api.is_sparse(col):
[3]:
<AlloViz.Wrappers.PyInteraph2_w.PyInteraph2_Contacts at 0x7f6ecb09ab80>
[4]:
system.filter(filterings="Spatially_distant", Interresidue_distance=20)
# the same as doing: system.PyInteraph2_Contacts.filter(filterings="Spatially_distant", Interresidue_distance=20)
NOTE: "GPCR_Interhelix" filtering not available as the protein is not marked as a GPCR
[4]:
<AlloViz.AlloViz.Filtering.Filtering at 0x7f6ecb0c16d0>
Filtered networks are stored as NetworkX Graph objects and can be passed to NetworkX analysis functions.
[5]:
system.PyInteraph2_Contacts.Spatially_distant.graphs
[5]:
{'weight': <networkx.classes.graph.Graph at 0x7f6ecb07deb0>}
[6]:
graph = system.PyInteraph2_Contacts.Spatially_distant.graphs["weight"]
NetworkX¶
To use NetworkX’s functions, we must specify the edge value we wish to use: “graph_weight” or “graph_distance”. For example, if we want to use NetworkX’s shortest paths analysis, we will use “graph_distance”:
[9]:
from networkx.algorithms.shortest_paths.generic import shortest_path
[19]:
paths = shortest_path(graph, weight="graph_distance")
For example, to view all analyzed shortest paths between residue ALA:134 and any other residue that is connected to it, after the network has been filtered:
[23]:
paths["ALA:134"]
[23]:
{'ALA:134': ['ALA:134'],
'GLY:257': ['ALA:134', 'GLY:257'],
'PRO:138': ['ALA:134', 'GLY:257', 'PRO:138'],
'PHE:139': ['ALA:134', 'GLY:257', 'PHE:139'],
'TYR:141': ['ALA:134', 'GLY:257', 'TYR:141'],
'GLN:142': ['ALA:134', 'GLY:257', 'GLN:142'],
'SER:143': ['ALA:134', 'GLY:257', 'SER:143'],
'GLN:229': ['ALA:134', 'GLY:257', 'GLN:229'],
'GLY:238': ['ALA:134', 'GLY:257', 'PRO:138', 'GLY:238'],
'LEU:258': ['ALA:134', 'GLY:257', 'PHE:139', 'LEU:258'],
'ARG:259': ['ALA:134', 'GLY:257', 'GLN:142', 'ARG:259'],
'GLU:225': ['ALA:134', 'GLY:257', 'GLN:142', 'ARG:259', 'GLU:225'],
'VAL:242': ['ALA:134', 'GLY:257', 'GLN:142', 'ARG:259', 'VAL:242'],
'GLN:224': ['ALA:134', 'GLY:257', 'GLN:142', 'ARG:259', 'VAL:242', 'GLN:224'],
'ARG:228': ['ALA:134', 'GLY:257', 'GLN:142', 'ARG:259', 'VAL:242', 'ARG:228'],
'GLN:231': ['ALA:134', 'GLY:257', 'GLN:142', 'ARG:259', 'VAL:242', 'GLN:231'],
'HIS:269': ['ALA:134', 'GLY:257', 'GLN:142', 'ARG:259', 'VAL:242', 'HIS:269'],
'PHE:240': ['ALA:134',
'GLY:257',
'GLN:142',
'ARG:259',
'VAL:242',
'ARG:228',
'PHE:240'],
'HIS:241': ['ALA:134',
'GLY:257',
'GLN:142',
'ARG:259',
'VAL:242',
'ARG:228',
'HIS:241'],
'LEU:266': ['ALA:134',
'GLY:257',
'GLN:142',
'ARG:259',
'VAL:242',
'ARG:228',
'PHE:240',
'LEU:266'],
'LYS:227': ['ALA:134',
'GLY:257',
'GLN:142',
'ARG:259',
'VAL:242',
'ARG:228',
'HIS:241',
'LYS:227']}
Alternative NetworkX’s centrality analyses and visualization¶
AlloViz’s analyze method allows to use any NetworkX analysis that returns a list of node values or edge values (e.g., node or edge centrality analyses), and its posterior visualization with the view method.
The absolute Python import of the analysis function with a custom short name for it, alongside possible arguments used by the function, must be passed as a dictionary to the analyze method. The default node_dict and edge_dict (with “btw” and “cfb”) are already part of the Analysis module:
[12]:
AlloViz.AlloViz.Analysis.nodes_dict
[12]:
{'btw': {'function': 'networkx.algorithms.centrality.betweenness_centrality',
'arguments': {'weight': 'graph_distance', 'seed': 0}},
'cfb': {'function': 'networkx.algorithms.centrality.current_flow_betweenness_centrality',
'arguments': {'weight': 'graph_weight'}}}
Therefore, to use a new centrality analysis function for the nodes, load centrality), the absolute import is passed, then it is specified that it uses distances as edge values (it interprets them as distances or lenghts, according to the documentation). Other arguments of the function for which we could set values are normalized and cutoff, but we can keep
the default behaviour:
[24]:
system.analyze(
elements="nodes", metrics="load",
nodes_dict={'load': {'function': "networkx.algorithms.centrality.load_centrality",
'arguments': {'weight': 'graph_distance'}}}
)
adding analyzed nodes <AlloViz.Wrappers.PyInteraph2_w.PyInteraph2_Contacts object at 0x7f6ecb09ab80> Spatially_distant data of for data/160/protein.pdb
/home/frann/miniconda3/envs/allovizsonja/lib/python3.9/site-packages/pyarrow/pandas_compat.py:373: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.
if _pandas_api.is_sparse(col):
The load centrality of a node is the fraction of all shortest paths that pass through that node. The results can be visualized as a usual:
[25]:
system.view("PyInteraph2_Contacts", "load", "Spatially_distant", "nodes")
/home/frann/miniconda3/envs/allovizsonja/lib/python3.9/site-packages/MDAnalysis/coordinates/PDB.py:431: UserWarning: 1 A^3 CRYST1 record, this is usually a placeholder. Unit cell dimensions will be set to None.
warnings.warn("1 A^3 CRYST1 record,"