{"id":5995,"date":"2020-09-08T16:53:03","date_gmt":"2020-09-08T15:53:03","guid":{"rendered":"https:\/\/www.blopig.com\/blog\/?p=5995"},"modified":"2020-12-09T13:19:01","modified_gmt":"2020-12-09T13:19:01","slug":"pymol-colouring-proteins-by-property","status":"publish","type":"post","link":"https:\/\/www.blopig.com\/blog\/2020\/09\/pymol-colouring-proteins-by-property\/","title":{"rendered":"PyMOL: colouring proteins by property"},"content":{"rendered":"\n<p>We all love pretty, colourful pictures of proteins. There is quite a variety of programs to produce publication-quality images of proteins, some of the most popular being VMD, PyMOL and Chimera. Each has advantages and disadvantages &#8212; for example, VMD is particularly good to deal with molecular dynamics simulations (perhaps that&#8217;s why it is called &#8220;Visual Molecular Dynamics&#8221;?), and Chimera is able to produce breathtaking graphics with very little user input. In my work, however, I tend to peruse PyMOL: a Python interface is incredibly helpful to produce quick analyses.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>In this post, I am going to tell you about a quick and dirty hack to colour your protein by a property (maybe the distance to a template, solvent accesibility or the flexibility of a position according to some MD simulation; you name it): by changing the B-factor of the protein with a very simple function:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">from pymol import cmd\n\ndef hack_bfactor(mol_id, property_dict):\n    \"\"\"Modify the B-factor of a residue to some\n    other property for the purposes of plotting.\"\"\"\n    for residue_id, property_value in property_dict.items():\n        cmd.select('current_residue', f'{mol_id} AND resi {residue_id}')\n        cmd.alter('current_residue', f'b={property_value}')\n    cmd.rebuild()<\/pre>\n\n\n\n<p>Once you have altered the B-factor values, it is very simple to produce pictures using the <a href=\"https:\/\/pymolwiki.org\/index.php\/Spectrum\">spectrum<\/a> command. Here is an example: human myoglobin, with every residue coloured with the number of binary contacts it takes part on (i.e. how many beta-carbons are there less than 8 angstroms apart from a residue&#8217;s own beta-carbon).<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"625\" height=\"469\" loading=\"lazy\" src=\"https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2020\/08\/myoglobin_contacts.png?resize=625%2C469&#038;ssl=1\" alt=\"\" class=\"wp-image-6005\" srcset=\"https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2020\/08\/myoglobin_contacts.png?w=640&amp;ssl=1 640w, https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2020\/08\/myoglobin_contacts.png?resize=300%2C225&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2020\/08\/myoglobin_contacts.png?resize=624%2C468&amp;ssl=1 624w\" sizes=\"auto, (max-width: 625px) 100vw, 625px\" \/><\/figure>\n\n\n\n<p>Happy plotting!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We all love pretty, colourful pictures of proteins. There is quite a variety of programs to produce publication-quality images of proteins, some of the most popular being VMD, PyMOL and Chimera. Each has advantages and disadvantages &#8212; for example, VMD is particularly good to deal with molecular dynamics simulations (perhaps that&#8217;s why it is called [&hellip;]<\/p>\n","protected":false},"author":57,"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,351,202,221,227],"tags":[],"ppma_author":[486],"class_list":["post-5995","post","type-post","status-publish","format-standard","hentry","category-code","category-molecular-visualization","category-proteins","category-python","category-python-code"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"authors":[{"term_id":486,"user_id":57,"is_guest":0,"slug":"carlos","display_name":"Carlos Outeiral Rubiera","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/c6312c6a392927cb01fb1fec16e7b5aa4b13ea7aab4bd1a745451ac697bc8550?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\/5995","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\/57"}],"replies":[{"embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/comments?post=5995"}],"version-history":[{"count":4,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/posts\/5995\/revisions"}],"predecessor-version":[{"id":6064,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/posts\/5995\/revisions\/6064"}],"wp:attachment":[{"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/media?parent=5995"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/categories?post=5995"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/tags?post=5995"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=5995"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}