Firstly, I would preface that the PyMOL command line in the GUI is great, but you can run PyMOL as a regular Python library (calling the appropriate python). This makes life so much simpler for more complex manipulations. You can do really complex manipulations with it. I cannot suggest it enough.
The API version of the commands works only marginally differently, but you can do API calls in the GUI cmd.
) and PyMOLWiki documentation is only slightly weaker for them (help()
fills the gaps).
But if you really want to use the GUI route...
Let's get the names of the models in the selection
onames = cmd.get_object_list('chains')
print onames
Now, you want to save subsets of 5 chains (technically, objects or models). That is, you do not care about the order they are in and you don't want the same one twice (actually selections with 4 or less), so you want all combinations. Make sure to do the following
print len(onames)
And google that number as <n> choose 5
. That is how many files you will get. I am pretty sure most of these sets will be meaningful and will be useless.
In a script a loop is easy, while in the gui you have to keep it simple or use a list coprehension hackishly.
from itertools import combinations
for s in combinations(onames, 5): cmd.save('-'.join(s)+'.pdb', ' or '.join(s))
Obviously, you could alternatively use an enumerate method around the iterator and get an index for the file. But do note f-strings will not work.
for i, s in enumerate(combinations(onames, 5)): cmd.save(str(i)+'.pdb', ' or '.join(s))