From PyMOLWiki
Revision as of 12:03, 5 April 2014 by Desastre (talk | contribs) (Add script repo entry)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
Type Python Script
Author(s) Jason Vertrees
License -
This code has been put under version control in the project Pymol-script-repo


toGroup will convert a multistate object into a group of single-state objects. Be warned, by default it deletes your original object (since it's extracting a copy).

PyMOL does a great job at handling multistate objects and grouping them together. One thing that I found myself doing over and over again was

  • loading a multistate object (say a PDBQT file with 100 ligand poses)
  • splitting that object into all 100 states, with some given prefix
  • then grouping them into their own group
  • and then finally removing the original.

This became tedious, so I automated that with this script.


# A multistate object (20 NMR states)
fetch 1nmr

# Create the group called,  "nmrEnsemble"
# from '1nmr' and name all the new states state1,
# state2, state3, etc.
toGroup nmrEnsemble, 1nmr, prefix=state

The Code

import pymol
from pymol import cmd

def toGroup(groupName,sel,prefix="",delOrig=True):
    toGroup will take a multistate object and extract it
    to a group with N objects all in state #1.  It essentially
    performs the following:

    split_states myObj, prefix=somePrefix
    group newGroup, somePrefix*
    delete myObj

    groupName (string)
        The name of the group to create

    sel (string)
        The name of the selection/object from which
        to make the group

    prefix (string)
        The prefix of the names of each of split states.
        For example, if your prefix is ''obj'' and is in
        states 1 through 100 then the states will be labeled
        obj1, obj2, obj3, ..., obj100.

    delOrig (string/boolean)
        If true then delete the original selection, otherwise not.


    Nothing, it makes a new group.

    if prefix=="":

    cmd.split_states(sel, prefix=prefix),prefix+"*")
    if delOrig:

cmd.extend("toGroup", toGroup)

See Also

group, saveGroup, select,, split_states, delete, extend.