This is a read-only mirror of pymolwiki.org

Split object

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

split_object takes a multi-molecular object and converts it into a multi-state object. Similar to split_states but for molecules instead of states and the result of this is a multi-state object.

import pymol

def split_object(target_obj=None, source_obj=None, max_iter=500, quiet=1, _self=cmd):
    """
DESCRIPTION

    Splits a multi-molecular object into one multi-state object

ARGUMENTS

    target_obj

        (string) name of target object
        
    source_obj

        (string) name of source object
    
    max_iter

        (int) maximum number of object to process; set to 0 to unlimit
    
    """
    if source_object==None:
        print "Error: Please provide a source object."
        return

    # ensure the user gave us one object; save for prefix

    obj_list = _self.get_object_list(target_obj)

    if len(obj_list)>1:
        print " Error: Please provide only one object at a time."
        return

    if target_object==None:
        target_object = _self.get_unused_name(source_obj, alwaysnumber=0)

    # grab unused selection name
        
    s = cmd.get_unused_name("_store")

    # make original selection which we'll pare down

    cmd.select(s, source_obj)

    count = 0

    while cmd.count_atoms(s) and count<max_iter:
        count+=1

        # create the object from the first molecular
        # object inside pfx
        cmd.create(pfx, "bm. first " + s, 1, count)

        # remove the first molecular object from
        # the source selection and re-iterate
        cmd.select(s, "%s and not bm. first %s" % (s,s))

    if not quiet:
        print " Created new object %s." % target_obj

cmd.extend("split_object", split_object)

See Also