Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help
Special pages
SBGrid Resources
SBGrid Consortium
SBGrid Data Bank
Software Webinars
PyMOL Webinar
PyMOL Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Simple Scripting
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Getting PyMOL Data into your Script == To get PyMOL data into your script you will need to somehow get access to the PyMOL objects and pull out the data. For example, if you want the atomic coordinates of a selection of alpha carbon atoms your Python function may do something like this (see also [[iterate_state]]): <source lang="python"> # Import PyMOL's stored module. This will allow us with a # way to pull out the PyMOL data and modify it in our script. # See below. from pymol import stored def functionName( userSelection ): # this array will be used to hold the coordinates. It # has access to PyMOL objects and, we have access to it. stored.alphaCarbons = [] # let's just get the alpha carbons, so make the # selection just for them userSelection = userSelection + " and n. CA" # iterate over state 1, or the userSelection -- this just means # for each item in the selection do what the next parameter says. # And, that is to append the (x,y,z) coordinates to the stored.alphaCarbon # array. cmd.iterate_state(1, selector.process(userSelection), "stored.alphaCarbons.append([x,y,z])") # stored.alphaCarbons now has the data you want. ... do something to your coordinates ... </source> === Getting Data From your Script into PyMOL === Usually this step is easier. To get your data into PyMOL, it's usually through modifying some object, rotating a molecule, for example. To do that, you can use the [[alter]] or [[alter_state]] commands. Let's say for example, that we have translated the molecular coordinates from the last example by some vector (we moved the alpha carbons). Now, we want to make the change and see it in PyMOL. To write the coordinates back we do: <source lang="python"> # we need to know which PyMOL object to modify. There could be many molecules and objects # in the session, and we don't want to ruin them. The following line, gets the object # name from PyMOL objName = cmd.identify(sel2,1)[0][0] # Now, we alter each (x,y,z) array for the object, by popping out the values # in stored.alphaCarbons. PyMOL should now reflect the changed coordinates. cmd.alter_state(1,objName,"(x,y,z)=stored.alphaCarbons.pop(0)") </source>
Summary:
Please note that all contributions to PyMOL Wiki are considered to be released under the GNU Free Documentation License 1.2 (see
PyMOL Wiki:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Simple Scripting
(section)
Add topic