This is a read-only mirror of pymolwiki.org

SaveGroup

From PyMOL Wiki
Revision as of 03:49, 28 March 2014 by Bell (talk | contribs) (1 revision)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This script creates the command "saveGroup". saveGroup will save the specified group to disk as one file with all group objects in it, or as many files one pdb in each file. To save to one file just call

saveGroup groupName

to save to many files call

saveGroup groupName, oneFile=False

.

The Code

import pymol
from pymol import cmd, stored


def saveGroup(g, oneFile=None):
    """
    Save all files inside group 'g' to either
    one file or a list of files
    
    PARAMS
    g
        name of the group to save

    oneFile
        if not specified or None, saves each protein in the group
        to its own file, if oneFile=True, then saves all the files
        in the group to just one file.
        
    RETURNS
        None
    """

    oneFile = (oneFile!=None)

    if cmd.get_type(g) != "object:group":
        print "Error: please provide a group name to save."
        return

    stored.models = set()
    cmd.iterate(g, 'stored.models.add(model)')
    
    if oneFile:
        cmd.save( g + ".pdb", g)
    else:
        for x in stored.models:
            cmd.save( x + ".pdb", x)


cmd.extend("saveGroup", saveGroup)

See Also

group toGroup