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/alloviznew/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")
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)
[3]:
<AlloViz.Wrappers.PyInteraph2_w.PyInteraph2_Contacts at 0x7fbee7b8c8b0>
[4]:
system.filter(filterings="Spatially_distant", Interresidue_distance=20)
# the same as doing: system.PyInteraph2_Contacts.filter(filterings="Spatially_distant", Interresidue_distance=20)
[4]:
<AlloViz.AlloViz.Filtering.Filtering at 0x7fbee8625a60>
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 0x7fbf740448e0>}
[6]:
graph = system.PyInteraph2_Contacts.Spatially_distant.graphs["weight"]
NetworkX¶
To use NetworkX’s functions, we must specify that the edge weights are stored with the name “weight”. For example, if we want to use NetworkX’s shortest paths analysis:
[7]:
from networkx.algorithms.shortest_paths.generic import shortest_path
[8]:
paths = shortest_path(graph, weight="weight")
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:
[9]:
paths["ALA:134"]
[9]:
{'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'],
'LEU:258': ['ALA:134', 'GLY:257', 'PHE:139', 'LEU:258'],
'ARG:259': ['ALA:134', 'GLY:257', 'GLN:142', 'ARG:259'],
'GLY:238': ['ALA:134', 'GLY:257', 'PRO:138', 'GLY:238'],
'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 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:
[10]:
AlloViz.AlloViz.Analysis.nodes_dict
[10]:
{'btw': 'networkx.algorithms.centrality.betweenness_centrality',
'cfb': 'networkx.algorithms.centrality.current_flow_betweenness_centrality'}
Therefore, a new centrality analysis function for the nodes (e.g., load centrality) can be used with:
[11]:
system.analyze(elements="nodes", metrics="load", nodes_dict={"load": "networkx.algorithms.centrality.load_centrality"})
adding analyzed nodes <AlloViz.Wrappers.PyInteraph2_w.PyInteraph2_Contacts object at 0x7fbee7b8c8b0> Spatially_distant data of for data/160/protein.pdb
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:
[12]:
system.view("PyInteraph2_Contacts", "load", "Spatially_distant", "nodes")
/home/frann/miniconda3/envs/alloviznew/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,"