Save sep: Difference between revisions

From PyMOLWiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
== Description ==
Saves all objects as separate PDB files. Useful if you want to do things like combine separate *.pse files.
== Code ==
<source lang="python">
<source lang="python">
from pymol import cmd
from pymol import cmd

Revision as of 17:29, 14 April 2009

Description

Saves all objects as separate PDB files. Useful if you want to do things like combine separate *.pse files.

Code

from pymol import cmd
import glob
import re

def save_sep(prefix=''):
  """
  save_sep <prefix>

  saves multiple objects into multiple files using an optional prefix name.

  e.g. save_sep prefix
  """
  obj_list = cmd.get_names('models')

  if obj_list:
    for i in range(len(obj_list)):
#      if ( obj == '' ):
      obj_name = "%s%s.pdb" % (prefix, obj_list[i])
      cmd.save(obj_name, obj_list[i])
      print "Saving %s" %  obj_name
  else:
    print "No objects found"
    
cmd.extend('save_sep',save_sep)