From: Maxim Belkin (mbelkin_at_ks.uiuc.edu)
Date: Sun Mar 09 2014 - 11:05:43 CDT

Hi Maria,

On Mar 9, 2014, at 8:28 AM, Maria Pikoula <maria.pikoula_at_eng.ox.ac.uk> wrote:

> Hi Maxim,
>
> Here is the new version of the script
>
>
> for {set i 0} {$i < $n} {incr i} {
> $sel_coor frame $i
> $sel_vel frame $i
> $sel_coor set {vx vy vz} [$sel_vel get {x y z}]
> }
>
> set sel_coor [atomselect 1 "water and oxygen"]

- You re-create atom selection here, but should not.
- Molecule 1 in your original post was velocity molecule.
Remove this line.

> set n [molinfo 0 get numframes]
> set file [open xO_avg_velx_all.txt w]
> puts $file "all vx"
> for { set i 0 } { $i < $n } { incr i } {

The following 4 lines can be improved
 
> set sum 0
> $sel_coor frame $i
> foreach xcoord [$sel_coor get {vx}] {
> set sum [expr $xcoord + $sum]}

Faster solution:
          set allvx [$sel_coor get vx]
          set sum [tcl::mathop::+ {*}$allvx]

> puts $file "$sum [$sel_coor num]"
> }
>
>
> And the output looks like:
> ….
> 0.0 6133
> 0.0 6133
> 0.0 6133
> 0.0 6133
> 0.0 6133
> 0.0 6133
> …
>
> 6133 is the total number of Oxygens. In the case of geometry based selection it would be the number of oxygen in the selection. Still not sure how to do the geometry selection, since it needs to happen via the coordinate file but the velocities need to be taken from the velocity trajectory
>
> Cheers,
>
> Maria
> On 9 Mar 2014, at 08:21, Maxim Belkin wrote:
>
>> Hi Maria,
>>
>> If your selection is geometry-based (e.g. 0<x<5), then you need “$sel update” since atoms can enter and leave that region from frame to frame. If your selection doesn’t change between frames (e.g. "water and oxygen" will always give you the same oxygen atoms), then you do not need that line. Can you show us couple of lines of the output file and the "corrected" script that you use now?
>>
>> Maxim
>>
>>
>>
>> On Mar 8, 2014, at 6:52 PM, Maria Pikoula <maria.pikoula_at_eng.ox.ac.uk> wrote:
>>
>>> Hello Maxim and thanks so much for your input. Please see below for my comments
>>>
>>> On 8 Mar 2014, at 16:50, Maxim Belkin wrote:
>>>
>>>> Hi Maria,
>>>>
>>>> - use "water and oxygen” as the selection (should be more robust)
>>> Will do from now on, thanks!
>>>
>>>> - no need to do "$sel_coor update"
>>> OK I had no idea, was following other instructions..
>>>
>>>> - in "foreach loop" change "sum1" to “sum”
>>> This was a silly typo, cheers!
>>>
>>> Eventually, I run it correctly like you said, but I still got 0.0 at each frame..any ideas why?
>>>> However...
>>>> 1. you don’t need sel_coor at all for what you are doing.
>>>> 2. you don’t need to do "...set {vx vy vz}..." neither.
>>>>
>>> So the reason I am doing sel_coor is because eventually I want to measure the average velocity based on position, so imagine a "slice" of the trajectory, for example for 0.0<x<5.0. This is why I would need to load both but I was experimenting with the simple version first (all oxygens). Any help with that is very much appreciated, I'm very much a VMD newbie.
>>>
>>>> If you want to find average velocity each frame, then you can simply use "measure center":
>>>>
>>>> set Vavr [measure center $sel_vel] ; # Vavr - average velocity
>>>> foreach {vx vy vz} $Vavr {break} ; # break that vector into components
>>>>
>>>> I could imagine that you want to check if you have non-zero flux of water in your simulations. For that you could do:
>>>>
>>>> measure avpos $sel_vel
>>>>
>>>> If you want to compute something else - let us know.
>>>>
>>>> Happy Women's day!
>>> Thanks on behalf of my gender!
>>>> Maxim
>>>>
>>>>
>>>> On Mar 8, 2014, at 5:51 AM, Maria Pikoula <maria.pikoula_at_eng.ox.ac.uk> wrote:
>>>>
>>>>> Dear all,
>>>>>
>>>>> I have been attempting to use simultaneously coordinate and velocity information by processing two trajectories (one with coordinates and one with velocities) but with the same topology.
>>>>>
>>>>> I have tried this in the spirit of this thread: http://www.ks.uiuc.edu/Research/vmd/mailing_list/vmd-l/19291.html
>>>>>
>>>>> When I try to write out all velocities for each selected atom in each frame, the numbers are always 0. Is this something to do with the way numbers are stored in VMD? It seems like a rounding errors may be to blame. I appreciate any feedback.
>>>>>
>>>>> ##################################
>>>>> Here are the TCL commands:
>>>>>
>>>>> set sel_vel [atomselect 1 "water and name O"] #selects coordinates
>>>>>
>>>>> set sel_coor [atomselect 0 "water and name O"] #selects corresponding velocities
>>>>>
>>>>> set n [molinfo 1 get numframes]
>>>>>
>>>>> # here I assign the velocity information to a variable in the coordinate selection
>>>>>
>>>>> for {set i 0} {$i < $n} {incr i} {
>>>>> $sel_coor frame $i
>>>>> $sel_vel frame $i
>>>>> $sel_coor set {vx vy vz} [$sel_vel get {x y z}]
>>>>> }
>>>>>
>>>>> #commands to write out the velocity information for vx
>>>>>
>>>>> set file [open xO_avg_velx_all.txt w]
>>>>> puts $file "all vx"
>>>>> for { set i 0 } { $i < $n } { incr i } {
>>>>> set sum 0
>>>>> $sel_coor frame $i
>>>>> $sel_coor update
>>>>> foreach xcoord [$sel_coor get {vx}] {
>>>>> set sum1 [expr $xcoord + $sum]}
>>>>> puts $file "$sum [$sel_coor num]"
>>>>> }
>>>>>
>>>>> ####################################
>>>>>
>>>>> Many thanks,
>>>>>
>>>>> Maria
>>>>>
>>>>>
>>>>> Maria Pikoula
>>>>> Doctoral Candidate in Centre for Doctoral Training in Healthcare Innovation
>>>>> Institute of Biomedical Engineering
>>>>> Department of Engineering Science
>>>>> University of Oxford
>>>>> maria.pikoula_at_eng.ox.ac.uk
>>>>>
>>>>
>>>
>>> Maria Pikoula
>>> Doctoral Candidate in Centre for Doctoral Training in Healthcare Innovation
>>> Institute of Biomedical Engineering
>>> Department of Engineering Science
>>> University of Oxford
>>> maria.pikoula_at_eng.ox.ac.uk
>>
>
> Maria Pikoula
> Doctoral Candidate in Centre for Doctoral Training in Healthcare Innovation
> Institute of Biomedical Engineering
> Department of Engineering Science
> University of Oxford
> maria.pikoula_at_eng.ox.ac.uk
>