From: Vermaas, Joshua (Joshua.Vermaas_at_nrel.gov)
Date: Wed Dec 20 2017 - 12:21:47 CST

Normally you open a file at the top, write the file line by line as you
go over each frame, and then close the file at the end. Atomselections
happen outside the loop, and you'd update them as needed within the loop.

set nf [molinfo top get numframes]
set fout [open "datafilename.txt" "w"]
puts $fout "#Frame_number Distance"
set seltext1 "name CG and resid 26"
set sel1 [atomselect top "$seltext1"]
set seltext2 "name CG and resid 30"
set sel2 [atomselect top "$seltext2"]
for {set i 0} {$i < $nf} {incr i} {
#Update the frame used for each atomselection
$sel1 frame $i
$sel2 frame $i
#Measure the distance between the atoms at this frame
set distance [measure bond [$sel1 get index] [$sel2 get index]] ; #If
the selections only have one atom, you don't need the lindex part.
puts $fout "$i $distance" ; #This does the actual writing to the file.
}
close $fout

-Josh

On 12/19/2017 09:01 PM, $BK\B<H%(B wrote:
> Thank you for your help.
> The following script worked well.
>
> set seltext1 "name CG and resid 26"
> set sel1 [atomselect top "$seltext1"]
> set seltext2 "name CG and resid 30"
> set sel2 [atomselect top "$seltext2"]
> measure bond [lindex [$sel1 get index] 0] [lindex [$sel2 get index] 0]
>
> Next, I would like to output the distances of all frames to txt file (or dat file).
> However, I do not know how to use the data frame in VMD command.
> How should I export them to txt file?
> I have an following idea.
> Could you tell me the completed script?
>
> mol load psf ***.psf dcd ***.dcd
> set nf [molinfo top get numframes]
> (make a data frame)
> for {set i 0} {$i < $nf} {incr i} {
> (select frame i)
> set seltext1 "name CG and resid 26"
> set sel1 [atomselect top "$seltext1"]
> set seltext2 "name CG and resid 30"
> set sel2 [atomselect top "$seltext2"]
> measure bond [lindex [$sel1 get index] 0] [lindex [$sel2 get index] 0]
> (input to a data frame)
> }
> (export a data frame as a txt file)
> ______________________________
> $B6e=#Bg3XBg3X1!(B $B%7%9%F%`@8L?2J3XI\(B
> $B%7%9%F%`@8L?2J3X_at_l96(B2$BG/(B
> $B3X_at_RHV9f(B3SL16068S
> $B_at_8BNKI8f0e3X8&5f=j(B
> $B?@ED8&5f<<(B $BK\B<H%(B
> E-mail$B!'(Bh-motomura_at_bioreg.kyushu-u.ac.jp
> E-mail$B!J7HBS!K!'(Bhajime.motomura.bioreg.kyushu_at_gmail.com
> TEL$B!J7HBS!K!'(B090-7443-4138
>
>> 2017/12/20 3:09$B!"(BVermaas, Joshua <Joshua.Vermaas_at_nrel.gov>$B$N%a!<%k(B:
>>
>> If you want the distance between selections, the easiest thing to do is to measure the distance between the center of the selections:
>>
>> veclength [vecsub [measure center $sel1] [measure center $sel2]]
>>
>> Measure bond works on atomic indices. So if you wanted to get the distance between the first atoms in two selections, you could do something like this:
>>
>> measure bond [lindex [$sel1 get index] 0] [lindex [$sel2 get index] 0]
>>
>> -Josh
>>
>> On 12/19/2017 06:12 AM, Ashar Malik wrote:
>> Now $sel1 and $sel2 are the selections. But the documentation of the measure bond says:
>>
>> The atoms are specified in form of a list of atom indexes
>>
>> Not selections of atom themselves. So you need to get the index of the atoms.
>>
>> You can do this:
>>
>> set seltext1 "name CG and resid 26"
>> set sel1 [[atomselect top "$seltext1"] get index]
>> set seltext2 "name CG and resid 30"
>> set sel2 [[atomselect top "$seltext2"] get index]
>> measure bond [list $sel1 $sel2]
>>
>> I am not sure since I haven't tried this - but it shoudl theoretically work.
>>
>> On Tue, Dec 19, 2017 at 10:03 PM, $BK\B<H%(B <h-motomura_at_bioreg.kyushu-u.ac.jp<mailto:h-motomura_at_bioreg.kyushu-u.ac.jp>> wrote:
>> I am sorry, I corrected my script.
>>
>> vmd > set seltext1 "name CG and resid 26"
>> vmd > set sel1 [atomselect top "$seltext1"]
>> vmd > set seltext2 "name CG and resid 30"
>> vmd > set sel2 [atomselect top "$seltext2"]
>> vmd > measure bond {$sel1 $sel2}
>> expected integer but got "$sel1" measure bond: bad atom index
>>
>>> 2017/12/19 17:42$B!"(BAshar Malik <asharjm_at_gmail.com<mailto:asharjm_at_gmail.com>>$B$N%a!<%k(B:
>>>
>>> I didn't have a detailed look at this but
>>>
>>> vmd > set seltext1 "name CG and resid 26$B!I(B
>>> vmd > set seltext2 "name CG and resid 30$B!I(B
>>> vmd > measure bond {$sel1 $sel2}
>>>
>>> what is $sel1 and $sel2???
>>>
>>> your selections are called seltext1 and seltext2 not sel1 and sel2.
>>>
>>> On Tue, Dec 19, 2017 at 8:56 PM, $BK\B<H%(B <h-motomura_at_bioreg.kyushu-u.ac.jp<mailto:h-motomura_at_bioreg.kyushu-u.ac.jp>> wrote:
>>> Dear all,
>>>
>>> I would like to measure bond length with $B!H(Bname ** and resid **$B!I(B in scripts.
>>>
>>> vmd > set seltext1 "name CG and resid 26$B!I(B
>>> vmd > set seltext2 "name CG and resid 30$B!I(B
>>> vmd > measure bond {$sel1 $sel2}
>>> expected integer but got "$sel1" measure bond: bad atom index
>>>
>>> However the following command succeed.
>>> vmd > measure bond {113 140}
>>> 11.772942543029785
>>>
>>> I configured that the above atoms existed.
>>> How can I measure bond length with $B!H(Bname ** and resid **" in scripts?
>>>
>>> Sincerely,
>>> Hajime Motomura
>>>
>>>
>>>
>>>
>>> --
>>> Best,
>>> /A
>>
>>
>>
>>
>> --
>> Best,
>> /A
>