I'm trying to make a script that will take a MTZ file (reflections), convert it into a CCP4 map, then pare that map down to only encompass a desired area to cut down on the size of my PyMol session files so they're email-able (a.k.a. not 200 MB) and ease the burden on my POS computer.

I currently have a Python script that can fft (CCP4) to create the map and mapmask to fix unit cell tiling issues. What I want to add now is something that can take a PDB file and strip out most of it except, for example, residues within 10 Å of #123.

I've been looking at ProDy, but not quite sure where to start. I would also be open to using something in the CCP4 toolkit.

  • $\begingroup$ I'm curious in the PDB format as well. If you already have a PDB file output, you could try removing all information other than the ATOM lines, and further, remove all the ATOM lines that list atoms from residues outside the range of a subset of your structure. If you could view it in PyMol then perhaps that's good enough? $\endgroup$
    – user560
    Commented Mar 25, 2012 at 0:20
  • $\begingroup$ @leonardo some sort of manual hack like that may work (as mapmask seems to expand a little anyway), but doesn't seem that optimal. I'll beat on this for a while and let you know what I come up with. $\endgroup$
    – Nick T
    Commented Mar 25, 2012 at 0:37
  • 1
    $\begingroup$ Is it possible to use a PDB viewing program to select a subregion of a single chain and save a new PDB? If so, you might want to compare the source file to the subregion file and see if it is indeed this simple and then hack yourself a solution. $\endgroup$
    – user560
    Commented Mar 25, 2012 at 0:50
  • 1
    $\begingroup$ Pymol has a selection operator that matches everthing in a specific distance around an atom, is should be possible to use that for this purpose. $\endgroup$ Commented Mar 25, 2012 at 8:55
  • $\begingroup$ @MadScientist from within a script running outside of PyMol? $\endgroup$
    – Nick T
    Commented Mar 25, 2012 at 17:21

2 Answers 2


With the program RasMol, you can select, as Mad Scientist explained it for PyMol, everything in a specific distance around an atom. RasMol can be run from command line, using a script (with the -script option under UNIX).


ProDy works quite well, especially from within an existing Python script.

The following code takes an existing PDB file, performs some selection query on it, then saves it to another file.

import prody

def pdbsubset(inpdb, outpdb, selection):
    with open(inpdb) as protf:
        prot = prody.parsePDBStream(protf)
    atoms = prot.select(selection)
    prody.writePDB(outpdb, atoms)

An example selection query builder

  • residues is a list e.g. ['A12', 'A39'] with each element in the form <chain><residue number>. They were captured from the command line using argparse with

        parser.add_argument('-i', '--residues', nargs='+')
    • so you would specify -i A12 A39 or whatever.
  • pdb and outpdb are file paths
  • radius is the distance in angstroms to expand the selection by.
reslist = ["(chid {0} and resid {1})".format(res[0], res[1:]) for res in residues]
selector = 'within {0} of ({1})'.format(radius, ' or '.join(reslist))

# and running it:
pdbsubset(pdb, outpdb, selector)

The documentation on ProDy selection queries is not the most straightforward, but fairly analogous to PyMol, so doable.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .