{"id":8714,"date":"2022-10-25T15:28:06","date_gmt":"2022-10-25T14:28:06","guid":{"rendered":"https:\/\/www.blopig.com\/blog\/?p=8714"},"modified":"2022-10-25T15:28:08","modified_gmt":"2022-10-25T14:28:08","slug":"how-to-build-a-python-dictionary-of-residues-for-each-molecule-in-pymol","status":"publish","type":"post","link":"https:\/\/www.blopig.com\/blog\/2022\/10\/how-to-build-a-python-dictionary-of-residues-for-each-molecule-in-pymol\/","title":{"rendered":"How to build a Python dictionary of residues for each molecule in PyMOL"},"content":{"rendered":"\n<p>Sometimes it can be handy to work with multiple structures in PyMOL using Python. <\/p>\n\n\n\n<p>Here&#8217;s a snippet of code you might find useful: we iterate over all the \u03b1-carbon atoms in a protein and append to a list tuples such as (&#8216;GLY&#8217;, 1). The dictionary, &#8216;reslist&#8217;, returns a list of residue names and indices for each molecule, where the key is a string containing the name of the molecule. <\/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\n# Create a list of all the objects, called 'mpls':\nmols = cmd.get_object_list('*')\n\n# Create an empty dictionary that will return a list of residues\n# given the name of the molecule object\nreslist = {}\n\n# Set the dictionaries to be empty lists\nfor m in mols:  reslist[m] = []\n\n# Use PyMOL's iterate command to go over every \u03b1-Carbon and append \n# a tuple consisting of the each residue's residue name ('resn') and\n# residue index ('resi '):\nfor m in mols:  cmd.iterate('%s and n. ca'%m, 'reslist[\"%s\"].append((resn,int(resi)))'%m)<\/pre>\n\n\n\n<p>This script assumes you only have protein molecules loaded, and ignores things like chain ID and insertion codes.<\/p>\n\n\n\n<p>Once you have your list of residues, you can use it with the <code>cmd.align<\/code> command, e.g., to align a particular residue to a reference structure.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes it can be handy to work with multiple structures in PyMOL using Python. Here&#8217;s a snippet of code you might find useful: we iterate over all the \u03b1-carbon atoms in a protein and append to a list tuples such as (&#8216;GLY&#8217;, 1). The dictionary, &#8216;reslist&#8217;, returns a list of residue names and indices for [&hellip;]<\/p>\n","protected":false},"author":35,"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,296,14,228,221,227],"tags":[664,132],"ppma_author":[488],"class_list":["post-8714","post","type-post","status-publish","format-standard","hentry","category-code","category-hints-and-tips","category-howto","category-protein-structure","category-python","category-python-code","tag-automation","tag-pymol"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"authors":[{"term_id":488,"user_id":35,"is_guest":0,"slug":"garrett","display_name":"Garrett","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/df625261419c37dd5c5937e37f17a732626acd6eea1e6fabd03d935c25b453bf?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\/8714","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\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/comments?post=8714"}],"version-history":[{"count":1,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/posts\/8714\/revisions"}],"predecessor-version":[{"id":8715,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/posts\/8714\/revisions\/8715"}],"wp:attachment":[{"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/media?parent=8714"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/categories?post=8714"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/tags?post=8714"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=8714"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}