Difference between revisions of "Split chains"

From PyMOLWiki
Jump to: navigation, search
(Infobox psico)
(PyMOL 1.6.0.0)
 
(One intermediate revision by one other user not shown)
Line 4: Line 4:
  
 
'''split_chains''' is a script that creates for each chain in selection its own object.
 
'''split_chains''' is a script that creates for each chain in selection its own object.
 +
 +
''This is a core command since PyMOL 1.6.0.0''
  
 
== Usage ==
 
== Usage ==
Line 37: Line 39:
 
     for model in models:
 
     for model in models:
 
         for chain in cmd.get_chains('(%s) and model %s' % (selection, model)):
 
         for chain in cmd.get_chains('(%s) and model %s' % (selection, model)):
 +
            if chain == '':
 +
                chain = "''"
 
             count += 1
 
             count += 1
 
             if not prefix:
 
             if not prefix:

Latest revision as of 07:39, 23 August 2013

Included in psico
This command or function is available from psico, which is a PyMOL extension.

Module psico.editing

split_chains is a script that creates for each chain in selection its own object.

This is a core command since PyMOL 1.6.0.0

Usage

split_chains [ selection [, prefix ]]

Example

fetch 2yko 2ykp 2ykq, async=0
split_chains
delete 2yko 2ykp 2ykq
alignto 2yko_A

The Script

from pymol import cmd, CmdException

def split_chains(selection='(all)', prefix=None):
    '''
DESCRIPTION

    Create a single object for each chain in selection

SEE ALSO

    split_states, http://pymolwiki.org/index.php/Split_object
    '''
    count = 0
    models = cmd.get_object_list('(' + selection + ')')
    for model in models:
        for chain in cmd.get_chains('(%s) and model %s' % (selection, model)):
            if chain == '':
                chain = "''"
            count += 1
            if not prefix:
                name = '%s_%s' % (model, chain)
            else:
                name = '%s%04d' % (prefix, count)
            cmd.create(name, '(%s) and model %s and chain %s' % (selection, model, chain))
        cmd.disable(model)

cmd.extend('split_chains', split_chains)

See Also