Chain renaming in PyMOL

For some reason, I wanted to rename all the chains in a PyMOL session to be unique once. Here’s a script to do so.

from string import ascii_uppercase

i = 0

for model in cmd.get_object_list():\
    if i > 25:\
        chain_id = "A" + ascii_uppercase[i-26]\
    else:\
        chain_id = ascii_uppercase[i]\
    cmd.alter(model, f"chain=\"{chain_id}\"")\
    i = i + 1



Enjoy Reading This Article?

Here are some more articles you might like to read next:

  • Google Gemini updates: Flash 1.5, Gemma 2 and Project Astra
  • Displaying External Posts on Your al-folio Blog
  • De-spaghettification
  • PyMOL mapping notes
  • Note to self