List Selection: Difference between revisions

From PyMOLWiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(2 intermediate revisions by 2 users not shown)
Line 18: Line 18:
cmd.iterate("(name ca)","stored.list.append((resi,resn))")
cmd.iterate("(name ca)","stored.list.append((resi,resn))")
print stored.list
print stored.list
[('1', 'ASP'), ('2', 'CYS'), ('3', 'ALA'), ('4', 'TRP'), ('5', 'HIS'), ('6', '
LEU'), ('7', 'GLY'), ('8', 'GLU'), ('9', 'LEU'), ('10', 'VAL'), ('11', 'TRP'),
('12', 'CYS'), ('13', 'THR')]
# Note from Warren:
#
# The above approach uses a the global pymol variable "stored"
# In recent versions, "cmd.iterate" has been extended to take a dictionary
# as an argument so that you no longer have to use a global variable.
# Avoiding globals helps prevent conflicts between scripts.
#
from pymol import cmd
my_dict = { 'my_list' : [] }
cmd.iterate("(name ca)","my_list.append((resi,resn))",space=my_dict)
print my_dict['my_list']


[('1', 'ASP'), ('2', 'CYS'), ('3', 'ALA'), ('4', 'TRP'), ('5', 'HIS'), ('6', '
[('1', 'ASP'), ('2', 'CYS'), ('3', 'ALA'), ('4', 'TRP'), ('5', 'HIS'), ('6', '
Line 24: Line 40:


</source>
</source>
[[Category:Scripting_Script_Library|List Selection]]
[[Category:Script_Library|List Selection]]
[[Category:ObjSel_Scripts]]

Latest revision as of 07:34, 30 April 2009

# Using PyMOL commands:
#
list=[]
iterate (name ca),list.append((resi,resn))
print list

[('ASP', '1'), ('CYS', '2'), ('ALA', '3'), ('TRP', '4'), ('HIS', '5'), ('LEU',
 '6'), ('GLY', '7'), ('GLU', '8'), ('LEU', '9'), ('VAL', '10'), ('TRP', '11'), 
('CYS', '12'), ('THR', '13')]

#!/usr/bin/python
#
# as Python script:
#
from pymol import cmd,stored
stored.list=[]
cmd.iterate("(name ca)","stored.list.append((resi,resn))")
print stored.list

[('1', 'ASP'), ('2', 'CYS'), ('3', 'ALA'), ('4', 'TRP'), ('5', 'HIS'), ('6', '
LEU'), ('7', 'GLY'), ('8', 'GLU'), ('9', 'LEU'), ('10', 'VAL'), ('11', 'TRP'), 
('12', 'CYS'), ('13', 'THR')]

# Note from Warren: 
#
# The above approach uses a the global pymol variable "stored"
# In recent versions, "cmd.iterate" has been extended to take a dictionary
# as an argument so that you no longer have to use a global variable.
# Avoiding globals helps prevent conflicts between scripts.
#
from pymol import cmd
my_dict = { 'my_list' : [] }
cmd.iterate("(name ca)","my_list.append((resi,resn))",space=my_dict)
print my_dict['my_list']

[('1', 'ASP'), ('2', 'CYS'), ('3', 'ALA'), ('4', 'TRP'), ('5', 'HIS'), ('6', '
LEU'), ('7', 'GLY'), ('8', 'GLU'), ('9', 'LEU'), ('10', 'VAL'), ('11', 'TRP'), 
('12', 'CYS'), ('13', 'THR')]