From: Ashar Malik (asharjm_at_gmail.com)
Date: Tue Feb 28 2017 - 15:27:07 CST

there are a few problems here:

1) $com is not the right data type to be assigned to x y z
2) assuming this reflects your entire code - when it works you will only
get 1 file com.pdb which will hold the last frames values only
3) your selA will have all the atoms in the residue - which will have the
same coordinates of the center assigned to them. I think that is
unnecessary.

Try the code below.
It makes some assumptions 1) you are doing this only for proteins
(otherwise modify according) 2) you don't have alternate conformer in your
system
In summary the script below will assign the x,y,z of center of mass to
alpha carbon of each residue and save only those.
Also note that it will generate as many PDBs as you have frames loaded in
your trajectory. So ensure that the number of frames are manageable.
I have inserted comments in the code - which should make it self
explanatory.

set m_id [molinfo top get id]
set nf [molinfo $m_id get numframes]
# Get a list of all CA in protein
# we will iterate over the resid of CAs in this list
set CA_list [atomselect $m_id "protein and name CA"]
set list_ [$CA_list get resid]
# iterate over all frames
for {set i 0} {$i < $nf} {incr i} {
#iterate over all residues in each frame
foreach j $list_ {
# select j-th residue in i-th frame
set res [atomselect $m_id "resid $j" frame $i]
# get property of selection
set cen [measure center $res weight mass]
# alpha carbon of current residue chosen
set CA [atomselect $m_id "resid $j and name CA" frame $i]
# create a list of list
set c_CA [list [list [lindex $cen 0] [lindex $cen 1] [lindex $cen 2]]]
# replace current alpha carbons coordinates with the list above
# which contains the coordinates for center of residue
$CA set {x y z} $c_CA
# delete selections for memory management
$res delete
$CA delete
}
# After the above loop all CAs coordinates have been modified to
# hold the coordinates of the center of mass of residue
# only select these and write these out as PDB files
set all [atomselect $m_id "name CA" frame $i]
$all writepdb frame_$i.pdb
# delete selections for memory management
$all delete
}

Best,
/A

p.s. please note that this is probably not the only way to do this and I am
sure there is a more smarter way to do this as well, but it will get your
job done for you.

On Wed, Mar 1, 2017 at 8:22 AM, Mehdi Bagherpour <mehdi.bpour_at_gmail.com>
wrote:

> Dear VMD users,
>
> I am trying to write the center of mass of residues in a separate .pdb
> file (for all frames).
> I have written this code but it does not work.
> I get the error:
> *atomselect: set: 3 data items doesn't match 24 selected atoms.*
>
> 0 to 181 are number of residues.
>
> *set mol [molinfo top] *
> *set nf [molinfo $mol get numframes] *
> *############# *
> *for {set i 0} {$i < $nf} {incr i} {*
> *for {set x 0} {$x <= 181} {incr x} {*
> *set selA [atomselect $mol "residue $x"]*
> *#############*
> *$selA frame $i*
> *set com [measure center $selA weight mass] *
> *$selA set {x y z} $com *
> *$selA writepdb "com.pdb"*
> *} *
> *}*
>
> Please let me know if you have any suggestion to this problem.
>
> Cheers,
> Mahdi
>
>

-- 
Best,
/A