This is a read-only mirror of pymolwiki.org
Difference between revisions of "ToGroup"
Jump to navigation
Jump to search
m (2 revisions) |
m (1 revision) |
||
(One intermediate revision by one other user not shown) | |||
Line 1: | Line 1: | ||
+ | {{Infobox script-repo | ||
+ | |type = script | ||
+ | |filename = togroup.py | ||
+ | |author = [[User:Inchoate|Jason Vertrees]] | ||
+ | |license = - | ||
+ | }} | ||
= Overview = | = Overview = | ||
[[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). | [[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). |
Latest revision as of 04:32, 8 April 2014
Type | Python Script |
---|---|
Download | togroup.py |
Author(s) | Jason Vertrees |
License | - |
This code has been put under version control in the project Pymol-script-repo |
Overview
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.
Examples
# 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):
"""
DESCRIPTION
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
PARAMETERS:
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.
RETURN
Nothing, it makes a new group.
"""
if prefix=="":
prefix="grouped"
cmd.split_states(sel, prefix=prefix)
cmd.group(groupName,prefix+"*")
if delOrig:
cmd.delete(sel)
cmd.extend("toGroup", toGroup)