From: Josh Vermaas (vermaas2_at_illinois.edu)
Date: Wed May 13 2015 - 20:51:23 CDT

Ahh. Don't do it with alchemy. Tag the user field instead, as that is
stored per frame. Then you can easily pick out different atoms based on
their "user" value.

set a [atomselect top "index < 1338 and name Si and y>9 and within 5 of
atom O]
set t [atomselect top all]

for { set i 0 } { $i < [molinfo top get numframes] } { incr i } {
$t frame $i
$t set user 0
  $a frame $i ; #changes the frame the selection will be based on
$a update ; #Rechecks that its selecting the right stuff
$a set user 1
}

I think then you can output your trajectory into a fileformat that
stores the user field. Which is currently none of them, but for movie
making this will totally work.

-Josh

On 05/13/2015 08:35 PM, JeJoon Yeon wrote:
> Thanks Josh,
>
> I checked with the smaller size file, and it seems the each frames
> converted in right manner. Thanks. But I need a single xyz file of all
> converted frames, not the 100,000 number of converted single frame xyz
> files. It will cost heavy hard disk drive and long time to merge them
> to single xyz file. Are there anyway to print out the result as single
> xyz file?
>
> It is just for post processing and visualization. I want to "mask"
> some specific atoms with different colors and size (=different atoms)
> based on my criteria of interest, which make them easily recognized
> from animation or picture. In addition, I need to analyze those
> 'different type of Si atoms', such as RDF and angular distribution or
> others. So, this 'masking using alchemy' is a really good skill to
> analyze the result xyz. (Sometimes I even masked O atoms using 10
> different atoms, based on their 10 different criteria = positions and
> vicinity to other specific atoms)
>
> I can do this work with fortran or python. However, sometimes I feel
> really convenient to use some options of VMD-tcl's 'atomselect'
> command, to target and differentiate the atoms of interest. Because it
> is easy to understand and straightforward to classify and convert the
> target atom with "atomselect". I don't need to write subroutines or
> more code lines. That is why I try to do this in VMD-tcl. If you could
> recommend me the other good and easy 'masking alchemy' tool for
> visualization, RDF and other analysis, I will happily accept your
> suggestion.
>
> Thank you
>
>
> 2015-05-13 20:00 GMT-04:00 Josh Vermaas <vermaas2_at_illinois.edu
> <mailto:vermaas2_at_illinois.edu>>:
>
> My understanding of how VMD works says that it cannot be done in a
> single xyz file. Name, type, etc, are not allowed to vary per
> frame (which works for 99.99% of all use cases). You want to let
> the identity of the atoms vary, which is weird, and needs a weird
> workaround by outputing each frame into a separate file.
>
> set a [atomselect top "index < 1338 and name Si and y>9 and within
> 5 of atom O]
> set t [atomselect top all]
>
> for { set i 0 } { $i < [molinfo top get numframes] } { incr i } {
> $a frame $i ; #changes the frame the selection will be based on
> $a update ; #Rechecks that its selecting the right stuff
> $a set name C
> $a set type C
> $a set element C
> $t frame $i
> $t writexyz frame$i.xyz ; #You will get a ton of individual frames
> where the Si atoms will be renamed.
> #Reset everything to Si for the next frame
> $a set name Si
> $a set type Si
> $a set element Si
> }
>
> This will work, but I really wanna know why on earth this is a
> reasonable thing to do. Silicon doesn't magically become carbon,
> which is why VMD assumes that atom identities are static.
>
> -Josh Vermaas
>
>
> On 05/13/2015 06:48 PM, JeJoon Yeon wrote:
>> Yes, I want to do that "alchemy" using VMD. Swapping Si atoms to
>> C atom, under specific conditions I want. I can do that job
>> without any problem for a single frame. But what I really want to
>> do is, do that "alchemy" for all frames of xyz file. (There are
>> 100000 frame inside my file) Unfortunately, using my attempts,
>> atoms didn't swapped, or incorrectly swapped.
>>
>> I think your mention "$a points always last frame in
>> atomselection" is the key. Because, all my attempts finished with
>> the weird results: all frame's target Si atoms were not properly
>> swapped to C. Instead, the swapped Si atoms during all frames,
>> are the target Si atoms of the last frame. As a result, my codes
>> only properly swapped the last frame's target Si atoms. To me, it
>> looks like "VMD swapped last frame's target Si atoms to C atom,
>> then track those atom all the way to first frame"
>>
>> I put
>>
>> set a [atomselect top "index < 1338 and name Si and y>9 and
>> within 5 of atom O]
>> set all [atomselect top all]
>>
>> these two lines out of the for-loop, but the results are the
>> same. Only the last frame's target Si atoms were swapped
>> properly. Others are just traceback of the last frame. For
>> example, in the first frame of result file, 'some Si atoms'
>> finished "alchemy", but they are not the target Si, instead they
>> are trace back of last frame's target Si atom. I think this is
>> because $a selected as the last frame, so VMD swapped all frame,
>> but it is only based on the position of last frame's information.
>> How can I escape from this situation?
>>
>>
>> 2015-05-13 17:29 GMT-04:00 Josh Vermaas <vermaas2_at_illinois.edu
>> <mailto:vermaas2_at_illinois.edu>>:
>>
>> That isn't a complete for loop (should have a closing
>> brace.). Beyond that, atomselections should happen outside
>> the loop if at all possible. Atomselections within a loop
>> need to be deleted to free up VMD internal memory, as they
>> aren't *just* tcl objects, but also create datastructures
>> within VMD that are not automatically deleted when the tcl
>> atomselection object goes out of scope. What exactly are you
>> trying to do? The way I've interpreted the code, you have a
>> bunch of Silicon atoms, but if they are close enough to an
>> oxygen, you want them to be a carbon instead (alchemy! VMD
>> doesn't like alchemy), and only for that frame. Is that
>> correct? Now you've muddled it a bit, since your $all
>> variable is never called outside of changing its frame, which
>> does nothing, and $a points to an atomselection that is
>> always at the last frame, so I can't read your intent. Could
>> you perhaps elaborate on what problem you are trying to solve?
>>
>>
>> On 05/13/2015 04:22 PM, JeJoon Yeon wrote:
>>> There was mistake in previous email. My for-loop looks like
>>>
>>> for { set i 0 } { $i <= $nf } { incr i } {
>>> set a [atomselect top "index < 1338 and name Si and y>9 and
>>> within 5 of atom O]
>>> set all [atomselect top all]
>>> $all frame $i
>>> $a set name C
>>> $a set type C
>>> $a set element C
>>>
>>> But I still think my way of writing is wrong...
>>>
>>> 2015-05-13 14:44 GMT-04:00 Josh Vermaas
>>> <vermaas2_at_illinois.edu <mailto:vermaas2_at_illinois.edu>>:
>>>
>>> Also, you need to make sure your for loop is doing this
>>> sanely. Here is how I'd approach it:
>>>
>>> set a [atomselect top "index < 1338 and name Si and y>9
>>> and within 5 of atom O]
>>> set t [atomselect top all]
>>>
>>> for { set i 0 } { $i < [molinfo top get numframes] } {
>>> incr i } {
>>>
>>> $a frame $i ; #changes the frame the selection will be
>>> based on
>>> $a update ; #Rechecks that its selecting the right stuff
>>> $a set name C
>>> $a set type C
>>> $a set element C
>>>
>>> }
>>>
>>> However name, type, and element are not per-frame
>>> fields, so you do know that you'll be changing it for
>>> all of them, right?
>>> -Josh
>>>
>>>
>>> On 05/13/2015 01:07 PM, Maxim Belkin wrote:
>>>
>>> Hi,
>>>
>>> Have you tried the following?
>>>
>>> animate write xyz output.xyz beg 0 end -1 waitfor all
>>>
>>> Maxim
>>>
>>>
>>> On May 13, 2015, at 12:53 PM, JeJoon Yeon
>>> <sonicturbulent_at_gmail.com
>>> <mailto:sonicturbulent_at_gmail.com>> wrote:
>>>
>>> Hello all
>>>
>>> I can swap specific atoms for a single frame xyz
>>> only. Like
>>>
>>> mol new test.xyz type xyz waitfor all
>>> set a [atomselect top "index < 1338 and name Si
>>> and y>9 and within 5 of atom O]
>>> $a set name C
>>> $a set type C
>>> $a set element C
>>> set t [atomselect top all]
>>> $t writexyz swapped.xyz
>>>
>>>
>>> But how can I do this with multiple frame? I
>>> tried to use for loop but
>>> 1) Sometimes it causes error
>>> 2) Sometimes it swaps the specific atoms for all
>>> frames, but the criteria is based on only last
>>> frame's xyz position.
>>>
>>> So I don't know what to do anymore. Can anyone
>>> help or modify that single frame code to work
>>> for multiple frames? Is this coming from read /
>>> write problem?
>>>
>>> Thanks
>>>
>>> Best,
>>>
>>>
>>>
>>>
>>
>>
>
>