{"id":11798,"date":"2024-10-09T15:52:41","date_gmt":"2024-10-09T14:52:41","guid":{"rendered":"https:\/\/www.blopig.com\/blog\/?p=11798"},"modified":"2024-10-09T15:52:43","modified_gmt":"2024-10-09T14:52:43","slug":"mdanalysis-work-with-dynamics-trajectories-of-proteins","status":"publish","type":"post","link":"https:\/\/www.blopig.com\/blog\/2024\/10\/mdanalysis-work-with-dynamics-trajectories-of-proteins\/","title":{"rendered":"MDAnalysis: Work with dynamics trajectories of proteins"},"content":{"rendered":"\n<p>For a long time crystallographers and subsequently the authors of AlphaFold2 had you believe that proteins are a static group of atoms written to a .pdb file. Turns out this was a HOAX. If you don&#8217;t want to miss out on the latest trend of working with dynamic structural ensembles of proteins this blog post is exactly right for you. MDAnalysis is a python package which as the name says was designed to analyse molecular dyanmics simulation and lets you work with trajectories of protein structures easily. <\/p>\n\n\n\n<!--more-->\n\n\n\n<p>Before we start install MDAnalysis through pip.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pip install MDAnalysis<\/code><\/pre>\n\n\n\n<p>The main data structure MDAnalysis uses is the <code><mark style=\"background-color:#fff\" class=\"has-inline-color has-medium-gray-color\">Universe<\/mark><\/code>. You can create a <code><mark style=\"background-color:#fff\" class=\"has-inline-color has-medium-gray-color\">Universe<\/mark><\/code> by loading a trajectory file and a topology file. The trajectory file contains the trajectory of the protein structure as a list of coordinates. Typical formats are .xtc or .dcd. The topology file provides information on the identity of atoms and their connectivity. A pdb file can be used to this purpose.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import MDAnalysis as mda\n\nu = mda.Universe('topology.pdb', 'trajectory.xtc')<\/code><\/pre>\n\n\n\n<p>The <code><mark style=\"background-color:#fff\" class=\"has-inline-color has-medium-gray-color\">Universe<\/mark><\/code> now contains all the information of the protein trajectory and lets you perform operations on it.<\/p>\n\n\n\n<p>Through the <code><mark style=\"background-color:#fff\" class=\"has-inline-color has-medium-gray-color\">Universe<\/mark><\/code> specific groups of residues and atoms and individual atoms can be accessed. Residues and atoms can be selected by indexing or a string selection.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong># select all residues<\/strong>\nprint(u.residues)\n<mark style=\"background-color:#fff\" class=\"has-inline-color has-blue-color\">&lt;ResidueGroup with 259 residues&gt;<\/mark>\n\n<strong># select all C-alphas of alanine and glutamate residues<\/strong>\nprint(u.select_atoms('resname ALA or resname GLU and name CA'))\n<mark style=\"background-color:#fff\" class=\"has-inline-color has-blue-color\">&lt;AtomGroup with 25 atoms&gt;<\/mark>\n\n<strong># select first atom<\/strong>\nu.atoms&#91;0]\n<mark style=\"background-color:#fff\" class=\"has-inline-color has-blue-color\">&lt;Atom 1: N of type N of resname ASP, resid 1 and segid P000 and altLoc &gt;<\/mark><\/code><\/pre>\n\n\n\n<p>Information can be accessed from <code><mark style=\"background-color:#fff\" class=\"has-inline-color has-medium-gray-color\">ResidueGroup<\/mark><\/code>, <code><mark style=\"background-color:#fff\" class=\"has-inline-color has-medium-gray-color\">AtomGroup<\/mark><\/code> and <code><mark style=\"background-color:#fff\" class=\"has-inline-color has-medium-gray-color\">Atom<\/mark><\/code> objects.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong># residue names<\/strong>\nu.residues&#91;:3].resnames\n<mark style=\"background-color:#fff\" class=\"has-inline-color has-blue-color\">array(&#91;'ASP', 'ILE', 'GLN'], dtype=object)<\/mark>\n\n<strong># atom coordinates in initial frame<\/strong>\nu.atoms&#91;:3].positions\n<mark style=\"background-color:#fff\" class=\"has-inline-color has-blue-color\">array(&#91;&#91;224.13002 ,  30.02    , 729.97003 ],\n       &#91;224.34003 ,  29.250002, 730.65    ],\n       &#91;223.12    ,  30.260002, 730.04004 ],\n       ...,\n       &#91;240.33002 ,  61.730003, 749.9     ],\n       &#91;240.64001 ,  62.640003, 749.09    ],\n       &#91;241.05002 ,  60.720005, 750.13    ]], dtype=float32)<\/mark><\/code><\/pre>\n\n\n\n<p>Accessing atom coordinates as above will return the positions in the first frame in the trajectory. If you want to access subsequent frames you need to work with the Universe.trajectory attribute. Information on frames is accessed by iterating through the trajectory or indexing it. At any stage the <code><mark style=\"background-color:#fff\" class=\"has-inline-color has-medium-gray-color\">Universe<\/mark><\/code> will only contain information of a single timestep.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong><mark style=\"background-color:#fff\" class=\"has-inline-color has-dark-gray-color\">### radius of gyration over time<\/mark><\/strong>\nrgyr = &#91;]\ntime = &#91;]\nprotein = u.select_atoms('protein')\n\nfor ts in u.trajectory: <strong># loop through individual frames in the trajectory<\/strong>\n    time.append(u.trajectory.time)\n    rgyr.append(protein.radius_of_gyration())\n\n\n<strong>### backbone RMSD against time<\/strong>\nfrom MDAnalysis.analysis import rms\n\nu.trajectory&#91;0] <strong># access first frame by indexing<\/strong>\nbb_0 = u.select_atoms('backbone').positions\n\ntime = &#91;]\nrmsd = &#91;]\nfor ts in u.trajectory:\n    time.append(u.trajectory.time)\n    bb_t = u.select_atoms('backbone').positions\n    rmsd.append(rms.rmsd(bb_0, bb_t))<\/code><\/pre>\n\n\n\n<p>For more informtioin and tutorials on how to use the package checkout the MDAnalysis documentation: <a href=\"https:\/\/www.mdanalysis.org\/\">https:\/\/www.mdanalysis.org\/<\/a><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>For a long time crystallographers and subsequently the authors of AlphaFold2 had you believe that proteins are a static group of atoms written to a .pdb file. Turns out this was a HOAX. If you don&#8217;t want to miss out on the latest trend of working with dynamic structural ensembles of proteins this blog post [&hellip;]<\/p>\n","protected":false},"author":96,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","wikipediapreview_detectlinks":true,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"ngg_post_thumbnail":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[29,14,647,227],"tags":[],"ppma_author":[719],"class_list":["post-11798","post","type-post","status-publish","format-standard","hentry","category-code","category-howto","category-molecular-dynamics","category-python-code"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"authors":[{"term_id":719,"user_id":96,"is_guest":0,"slug":"fabian","display_name":"Fabian Spoendlin","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/fe8656437d6201bf7b19b9b2aa6e524d88dd85f3c7dd8f5b8fc091d7df337957?s=96&d=mm&r=g","0":null,"1":"","2":"","3":"","4":"","5":"","6":"","7":"","8":""}],"_links":{"self":[{"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/posts\/11798","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/users\/96"}],"replies":[{"embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/comments?post=11798"}],"version-history":[{"count":4,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/posts\/11798\/revisions"}],"predecessor-version":[{"id":11812,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/posts\/11798\/revisions\/11812"}],"wp:attachment":[{"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/media?parent=11798"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/categories?post=11798"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/tags?post=11798"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=11798"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}