This is a read-only mirror of pymolwiki.org

ListSelection2

From PyMOL Wiki
Revision as of 17:39, 13 March 2013 by PietroGattiLafranconi (talk | contribs) (small script to list the content of pymol selections)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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 ]]

Code

from pymol import cmd, stored
 
def listselection (selection, output="N", HOH="Y"):
	"""	
	usage: listselection selection, [output=N/S/P, [HOH=Y/N ]]
	"""
	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)-1):
			if m1.atom[x].resi!=m1.atom[x+1].resi:
				printedselection+="%s\%s\%s\%s\n" % (objs[a], m1.atom[x].chain, m1.atom[x].resi, m1.atom[x].resn)
				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)