Re: [External Email] Re: Error in calculation dihedral angle

From: Peter Freddolino (petefred_at_umich.edu)
Date: Sat Feb 13 2021 - 22:29:03 CST

Ah my fault, I should have read more carefully, I assumed incorrectly that
the variables named "$sel1", etc in the measure dihed call were atom
selections.
Ok, so a couple of suggestions.
-Every time you make an atom selection, you need to explicitly delete it.
The use of anonymous atom selections, as in your 'set sel1 ...' lines of
code, will leave them hanging around and cause a memory leak.

-Rather than do
  set selA [atomselect top "segname PP5 and name C"]
  ...
  set sel1 [[atomselect top "$selA"] get index]
why not just do
  set selA [atomselect top "segname PP5 and name C"]
  set ind1 [$selA get index]
(and then you'd want to add
  $selA delete
to avoid the memory leak noted above)

-at the end of the day, in tcl, using curly braces ({}) to construct a list
does NOT allow substitution of variables. You'll instead want
  [list $ind1 $ind2 $ind3 $ind4]
or some such

Best,
Peter

On Sat, Feb 13, 2021 at 11:06 PM Jiali Wang <jwang204_at_binghamton.edu> wrote:

> Dear Peter,
> Thank you for your reply. I use "set sel1 [[atomselect top "$selA"] get
> index]" to get index, is there something wrong here?
> I am very new to the script part of calculations. I appreciate your help
> very much.
> best,
> Jiali
>
> On Sat, Feb 13, 2021 at 7:48 PM Peter Freddolino <petefred_at_umich.edu>
> wrote:
>
>> The arguments to `measure dihed` are supposed to be atom indices, not
>> atom selections. See
>> https://www.ks.uiuc.edu/Research/vmd/vmd-1.8.6/ug/node124.html
>>
>> Best,
>> Peter
>>
>> On Sat, Feb 13, 2021 at 1:56 AM jiali wang <jialiwangnamd_at_gmail.com>
>> wrote:
>>
>>> Dear NAMD users,
>>> I have an error when I calculate the dihedral angle, the calculation
>>> performed in the VMD. code as below, but it says "expected integer but got
>>> "$sel1" measure dihed: bad atom index". Do you know what happened?
>>> Thank you so much!!
>>> Jiali
>>>
>>> set selA [atomselect top "segname PP5 and name C"]
>>> set selB [atomselect top "segname PP5 and name CA"]
>>> set selC [atomselect top "segname PP5 and name CB"]
>>> set selD [atomselect top "segname PP5 and name CG"]
>>>
>>> set sel1 [[atomselect top "$selA"] get index]
>>> set sel2 [[atomselect top "$selB"] get index]
>>> set sel3 [[atomselect top "$selC"] get index]
>>> set sel4 [[atomselect top "$selD"] get index]
>>>
>>> set nf [molinfo top get numframes]
>>> set outfile [open dihed-cal.dat w]
>>> for {set i 0} {$i < $nf} {incr i} {
>>>
>>> puts "frame $i of $nf"
>>>
>>> set dihedlist [measure dihed {$sel1 $sel2 $sel3 $sel4}]
>>> puts $outfile "$i $dihedlist"
>>>
>>

This archive was generated by hypermail 2.1.6 : Fri Dec 31 2021 - 23:17:10 CST