“undo” restores the previous state of the object currently being edited.
If you're a PyMOL script writer, please see below for important hints on performance.
“undo” before PyMOL v1.5.0 only supports:
“undo” in PyMOL v1.5.0 and later supports:
undo was written to be fast and flexible. For example, on one of our test machines, undoing the addition of 60,683 hydrogens on a large complex took only 0.107 seconds. Redoing the same action took 0.0737 seconds. Speed constraints with regard to editing small molecules should not be an issue.
undo takes up memory. To disable undo on any given object, simply set
suspend_undo on that object. For example,
# tell undo to ignore the large protein '1aon' set suspend_undo, on, 1aon # tell undo to not ignore the smaller protein '1rx1' set suspend_undo, off, 1rx1
# undo the previous molecular change undo # redo the next molecular change redo
# disable the undo system in PyMOL set suspend_undo, on
Important When writing scripts that do not require undo and that automate some task across many files, use the following
at the top of your script. This will stop PyMOL from saving undo data which drastically reduces the amount of memory required for tasks like this.
When writing scripts that need to support undo, such as executing a combination of actions that can be undone in one action, it is necessary to tell PyMOL what is changing. Here are some examples of how to do this:
Old Way (still supported):
cmd.push_undo(obj_name) # do something to update coordinates of obj_name
New Way (updates/adds/deletes of atoms of selection):
# get current value of suspend_undo for setting back suspend_undo = cmd.get("suspend_undo") fin = 0 try: # the undo_selection tells PyMOL what to keep track of for # the undo action (which is created in the 2nd push_undo call # if finish_undo is 1 cmd.push_undo(undo_selection, just_coordinates=0, finish_undo=0) # turn off undo for any actions that happen inside this block cmd.set("suspend_undo", 1, updates=0) # Do some action(s) on undo_selection without undo actions created fin = 1 finally: # reset suspend_undo back to original setting before this operation cmd.set("suspend_undo", suspend_undo, updates=0) # if suspend_undo is not set, then create undo action for the # changes in the undo_selection cmd.push_undo("" , just_coordinates=0, finish_undo=fin)