Split object

From PyMOLWiki
Revision as of 06:06, 31 August 2011 by Speleo3 (talk | contribs) (see also split_chains)
(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):

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



        (string) name of target object

        (string) name of source object

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

    # 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."

    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:

        # 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