From: Peter Freddolino (
Date: Mon Apr 27 2009 - 07:02:18 CDT

Hi Dimitry,
you might want to have a look at how autoionize does it, since the code
is available...

set sel [atomselect top all]
set charge [vecsum [$sel get charge]]

What makes your method so slow is that you're making a new atom
selection for each atom; forming atom selections is an expensive operation.

Also, I'll take the opportunity to note that in your loop, you appear to
be calling delete on the charge (a list) but not the atomselect object;
what you really need to do is delete the atom selection on each loop
iteration, in order to avoid a memory leak.


DimitryASuplatov wrote:
> Hello,
> I want to calculate net system charge of my system given pdb and psf
> files. I also want to be able to do it automatically via script.
> I tried using something like:
> mol load psf $fname.psf pdb $fname.pdb
> set ev [atomselect top all]
> set indices [$ev get index]
> set netcharge 0
> foreach ind $indices {
> set at [atomselect top "index $ind"]
> set charge [$at get charge]
> set netcharge [ expr $netcharge + $charge ]
> $charge delete
> }
> puts "$netcharge"
> It works and outputs the correct value though it works some 5-10
> seconds compared to autoioize plugin which does the complete job
> including ionization in less then 5 seconds.
> So my question is
> Is there a one-word command to quickly
> calculate system net charge give charmm topology and pdb coordinates?
> Thank you for your time.