From: Axel Kohlmeyer (
Date: Fri Jun 08 2012 - 12:10:36 CDT

On Fri, Jun 8, 2012 at 12:19 PM, Nate Hurley <> wrote:
> Hi all,
> I'm new to VMD as of this week, and I'm trying to write a script that needs
> to determine how many chains exist in a pdb file.  In each of my files there
> is a chain A, and then there are somewhere between 5 and 20 chains Z, Y, X,
> . . . .  Is there a way that I can easily find how many chains I have?

yes. it just needs a little Tcl scripting. i suggest you spend some
time working your way through the Tcl tutorial on
there also is a scripting tutorial section in the VMD user's guide.

the code for this particular problem is simple.
after you have loaded the pdb file type (or copy)
this into the VMD console window:

set sel [atomselect top all]
set chains [lsort -ascii -unique [$sel get chain]]
puts "the current file contains [llength $chains] chain(s)"
$sel delete


> Thanks for your help.
> -Nate Hurley

Dr. Axel Kohlmeyer
College of Science and Technology
Temple University, Philadelphia PA, USA.