From: fan li (fanliqmul_at_gmail.com)
Date: Thu Aug 16 2018 - 10:24:54 CDT

Hi everyone

The suggestions from Ashar and Alex work fine for the part of code I posed
in last email. But I can only get the right results for the first few
frames and the results for other frames are not correct when I used their
suggestions for my real script. The following is the real script I used.

#########################################
set zmin 30.3

set nf [molinfo top get numframes]
for {set i 0} {$i < $nf} {incr i} {

        #select sub2 and get the center
        set sub2($i) [atomselect top "resname sub2"]
        $sub2($i) frame $i
        $sub2($i) update

        #puts "$sub2 num\t"

        set cen_sub2 [measure center $sub2($i)]

        set x0 [lindex $cen_sub2 0]

        set y0 [lindex $cen_sub2 1]

        set z0 [lindex $cen_sub2 2]

        set xmin [expr $x0-10]

        set xmax [expr $x0+10]

        set ymin [expr $y0-10]

        set ymax [expr $y0+10]

        set zmax [expr $z0-10]

        puts "i=$i\t"
        puts "xmin=$xmin xmax=$xmax ymin=$ymin ymax=$ymax zmin=$zmin
zmax=$zmax\t"

        #select water atoms within the region defined by the position
condition
        set sel_water($i) [atomselect top "resname SOL and (x>$xmin and
x<$xmax) and (y>$ymin and y<$ymax) and (z>$zmin and z<$zmax)"]

        $sel_water($i) frame $i
        $sel_water($i) update

        #reset the resname of the selected water
        $sel_water($i) set resname den

        puts "num of interested water=$sel_water($i)\t"

        set system($i) [atomselect top "all"]
        $system($i) frame $i
        $system($i) update
        $system($i) writegro "water_interest$i.gro"

        puts "num of all atoms=$system($i)\t"

        $sub2($i) delete
        $sel_water($i) delete
        $system($i) delete

}

#############################################################

I have no idea what is going wrong? Could some one point the bug in the
script?

Fan

Giacomo Fiorin <giacomo.fiorin_at_gmail.com> 于2018年8月16日周四 下午3:10写道:

> Each VMD atom selection object contains internally vectors that are as
> long as the total number of atoms in the molecule, and the memory usage of
> these vectors will not change with the selection keyword. I think it'd be
> safer to always delete an atom selection as soon as it's not needed.
>
> Giacomo
>
>
> On Thu, Aug 16, 2018 at 10:00 AM João Ribeiro <jribeiro_at_ks.uiuc.edu>
> wrote:
>
>> Also, if you need to create atom selections inside the loop (e.g. if
>> zmin value changes), you should definitely delete the selection before the
>> next iteration ("$sel_water($i) delete"), unless you need the atom
>> selection for another operation outside the loop, or the selections don't
>> take that much memory.
>>
>> Best
>>
>> João
>>
>> On Thu, Aug 16, 2018 at 8:14 AM Axel Kohlmeyer <akohlmey_at_gmail.com>
>> wrote:
>>
>>>
>>>
>>> On Thu, Aug 16, 2018 at 7:17 AM fan li <fanliqmul_at_gmail.com> wrote:
>>>
>>>> Hi everyone
>>>> I am trying to select atoms with specific region of SOL of each frame
>>>> and change the selected atom's resname. I list part of my code below.
>>>>
>>>> ############################################
>>>> set zmin 30.3
>>>>
>>>> set nf [molinfo top get numframes]
>>>> for {set i 0} {$i < [expr (3-1)]} {incr i} {
>>>>
>>>> set sel_water($i) [atomselect top "resname SOL and z<$zmin"]
>>>> $sel_water($i) frame $i
>>>>
>>>> #reset the resname of the selected water
>>>> $sel_water($i) set resname den
>>>>
>>>> $sel_water($i) writegro "water_interest$i.gro"
>>>>
>>>> }
>>>>
>>>>
>>>>
>>>> ########################################
>>>> This "set sel_water($i) [atomselect top "resname SOL and z<$zmin"]"
>>>> selection is not working properly as the outcome is not the region I
>>>> specified.
>>>>
>>>> Then I removed the "z<$zmin" and changed it to "set sel_water($i)
>>>> [atomselect top "resname SOL"]", it woks fine as the entire water is
>>>> selected.
>>>>
>>>> So could someone tell me why the selection is not working with the
>>>> position selected condition is not working?
>>>>
>>>> As position selected condition changes over each frame in the actual
>>>> code, so I can not put the selection outside the loop?
>>>>
>>>
>>> that last statement is not correct something like this:
>>>
>>> $sel frame $i
>>> $sel update
>>>
>>> will re-evaluate the selection stored in $sel for the frame $i (that is,
>>> for as long as $zmin doesn't change, as the selection string will evaluate
>>> variables when the selection is defined and not re-evaluate it when
>>> updated).
>>>
>>> axel.
>>>
>>>
>>>
>>>>
>>>> Fan
>>>>
>>>
>>>
>>> --
>>> Dr. Axel Kohlmeyer akohlmey_at_gmail.com http://goo.gl/1wk0
>>> College of Science & Technology, Temple University, Philadelphia PA, USA
>>> International Centre for Theoretical Physics, Trieste. Italy.
>>>
>>
>>
>> --
>> ……………………………………………………...
>> João Vieira Ribeiro
>> Theoretical and Computational Biophysics Group
>> Beckman Institute, University of Illinois
>> http://www.ks.uiuc.edu/~jribeiro/
>> jribeiro_at_ks.uiuc.edu
>> +1 (217) 3005851
>>
>
>
> --
> Giacomo Fiorin
> Associate Professor of Research, Temple University, Philadelphia, PA
> Contractor, National Institutes of Health, Bethesda, MD
> http://goo.gl/Q3TBQU
> https://github.com/giacomofiorin
>