This is a read-only mirror of pymolwiki.org

Difference between revisions of "ListSelection2"

From PyMOL Wiki
Jump to navigation Jump to search
m (small code update)
m (1 revision)
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 +
{{Infobox script-repo
 +
|type      = script
 +
|download  = [http://dx.doi.org/10.6084/m9.figshare.1031599 figshare]
 +
|author    = [[User:PietroGattiLafranconi|Pietro Gatti-Lafranconi]]
 +
|license  = [http://creativecommons.org/licenses/by/4.0/ CC BY 4.0]
 +
}}
 +
 
= Overview =
 
= Overview =
 
Alternative script to [[List_Selection]] that will:
 
Alternative script to [[List_Selection]] that will:
Line 27: Line 34:
 
<source lang="python">
 
<source lang="python">
 
PyMOL>listselection sele, output=S, HOH=N
 
PyMOL>listselection sele, output=S, HOH=N
Residues in 'sele, without HOH': 5
+
Residues in 'sele, without HOH': 7
2P9H\A\101\ARG
+
1LBH/A/ARG/86
2P9H\A\102\SER
+
1LBH/A/ALA/87
2P9H\A\103\GLY
+
1LBH/A/ASP/88
2P9H\A\104\VAL
+
1LBH/A/GLN/89
2P9H\A\105\GLU
+
1LBH/A/LEU/90
 +
1LBH/A/GLY/91
 +
1LBH/A/ALA/92
 
</source>
 
</source>
  
Line 38: Line 47:
 
<source lang="python">
 
<source lang="python">
 
PyMOL>listselection 1efa and resn LEU, output=S
 
PyMOL>listselection 1efa and resn LEU, output=S
Residues in '1EFA and resn LEU': 108
+
Residues in '1efa and resn LEU': 108
1efa\A\6\LEU
+
1efa/A/LEU/6
1efa\A\45\LEU
+
1efa/A/LEU/45
 +
1efa/A/LEU/56
 
[...]
 
[...]
1efa\C\323\LEU
+
1efa/C/LEU/323
1efa\C\330\LEU
+
1efa/C/LEU/330
 
</source>
 
</source>
  
Line 56: Line 66:
 
"""
 
"""
 
usage: listselection selection, [output=N/S/P, [HOH=Y/N ]]
 
usage: listselection selection, [output=N/S/P, [HOH=Y/N ]]
 +
 +
More information at: PymolWiki: http://http://pymolwiki.org/index.php/ListSelection2
 +
AUTHOR: Pietro Gatti-Lafranconi, 2013
 +
Please inform me if you use/improve/like/dislike/publish with this script.
 +
CC BY-NC-SA
 
"""
 
"""
 
printedselection=""
 
printedselection=""
Line 71: Line 86:
 
for x in range(len(m1.atom)):
 
for x in range(len(m1.atom)):
 
if m1.atom[x-1].resi!=m1.atom[x].resi:
 
if m1.atom[x-1].resi!=m1.atom[x].resi:
printedselection+="%s\%s\%s\%s\n" % (objs[a], m1.atom[x].chain, m1.atom[x].resi, m1.atom[x].resn)
+
printedselection+="%s/%s/%s/%s\n" % (objs[a], m1.atom[x].chain, m1.atom[x].resn, m1.atom[x].resi)
 
counter+=1
 
counter+=1
 
 
Line 85: Line 100:
 
cmd.extend('listselection',listselection)
 
cmd.extend('listselection',listselection)
 
</source>
 
</source>
[[Category:Script_Library|List Selection]]
+
 
 +
[[Category:Script_Library]]
 
[[Category:ObjSel_Scripts]]
 
[[Category:ObjSel_Scripts]]
 +
[[Category:Biochemical_Scripts]]

Latest revision as of 23:33, 26 May 2014

Type Python Script
Download figshare
Author(s) Pietro Gatti-Lafranconi
License CC BY 4.0

Overview

Alternative script to List_Selection that will:

  • list multiple residues once
  • include water and hetatoms
  • account for different chains/objects
  • produce a screen/printed output


Usage

listselection selection, [output=N/S/P, [HOH=Y/N ]]

where:

  • selection can be any existing or newly-defined selection
  • output controls if the list is hidden (default), printed on screen (S) or saved in a file (P)
  • HOH (default Y) allows to exclude (N) water residues from the list


Examples

PyMOL>listselection 1efa, output=P
Residues in '1efa': 1043
Results saved in listselection_1efa.txt


PyMOL>listselection sele, output=S, HOH=N
Residues in 'sele, without HOH': 7
1LBH/A/ARG/86
1LBH/A/ALA/87
1LBH/A/ASP/88
1LBH/A/GLN/89
1LBH/A/LEU/90
1LBH/A/GLY/91
1LBH/A/ALA/92


PyMOL>listselection 1efa and resn LEU, output=S
Residues in '1efa and resn LEU': 108
1efa/A/LEU/6
1efa/A/LEU/45
1efa/A/LEU/56
[...]
1efa/C/LEU/323
1efa/C/LEU/330


Code

Copy the following text and save it as listselection.py

from pymol import cmd, stored
 
def listselection (selection, output="N", HOH="Y"):
	"""	
	usage: listselection selection, [output=N/S/P, [HOH=Y/N ]]
	
	More information at: PymolWiki: http://http://pymolwiki.org/index.php/ListSelection2
	AUTHOR: Pietro Gatti-Lafranconi, 2013
	Please inform me if you use/improve/like/dislike/publish with this script.
	CC BY-NC-SA
	"""
	printedselection=""
	extra=""
	counter=0
	sel=selection
	objs=cmd.get_object_list(sel)

	if HOH=="N":
		sel=selection+" and not resn HOH"
		extra=", without HOH"
	
	for a in range(len(objs)):
		m1=cmd.get_model(sel+" and "+objs[a])
		for x in range(len(m1.atom)):
			if m1.atom[x-1].resi!=m1.atom[x].resi:
				printedselection+="%s/%s/%s/%s\n" % (objs[a], m1.atom[x].chain, m1.atom[x].resn, m1.atom[x].resi)
				counter+=1
				
	print "Residues in '%s%s': %s" % (selection, extra, counter)
	if output=="S": print printedselection
	if output=="P":
		f=open('listselection_'+selection+'.txt','w')
		f.write("Residues in '%s%s': %s\n" % (selection, extra, counter))
		f.write(printedselection)
		f.close()
		print "Results saved in listselection_%s.txt" % selection
		
cmd.extend('listselection',listselection)