计算化学公社

标题: 怎么修改脚本可以导出显示粒子运动轨迹及原分子为pdb文件 [打印本页]

作者
Author:
landian666    时间: 2023-6-13 23:03
标题: 怎么修改脚本可以导出显示粒子运动轨迹及原分子为pdb文件
显示粒子运动轨迹的VMD脚本
http://sobereva.com/65


在利用上面方法绘制出一个原子的轨迹后,如下图,怎么修改脚本可将图中红色轨迹以及原始的分子导出一个pdb文件?以便之后可以直接导入这个pdb观看整个原分子构型和红色轨迹。




作者
Author:
lyj714    时间: 2023-6-13 23:12
本帖最后由 lyj714 于 2023-6-13 23:15 编辑

我记得你之前sob老师不是回复过你吗。直接输出成xyz格式,顶多改一下原子数目。不要自己puts成pdb格式,因为pdb格式的每一列和列宽是有严格定义的,如果你不了解输出的pdb格式就不对。
作者
Author:
landian666    时间: 2023-6-14 10:03
lyj714 发表于 2023-6-13 23:12
我记得你之前sob老师不是回复过你吗。直接输出成xyz格式,顶多改一下原子数目。不要自己puts成pdb格式,因 ...

是呀,自己尝试写了一个没搞定,如下,还请不吝赐教。多谢!
proc showtrj {fps1 fps2 space selection output} {
    set selnow [atomselect top $selection frame $fps1]
    set selnext [atomselect top $selection frame $fps1]
    set num [$selnow num]
   
    set outfile [open $output w]
   
    for {set fps $fps1} {$fps < $fps2} {incr fps $space} {
        $selnow frame $fps
        $selnext frame [expr $fps + $space]
        $selnow update
        $selnext update
        
        puts $outfile "MODEL        $fps"
        for {set i 0} {$i < $num} {incr i 1} {
            set x [lindex [$selnext get x] $i]
            set y [lindex [$selnext get y] $i]
            set z [lindex [$selnext get z] $i]
            set atomname [lindex [$selnext get name] $i]
            set resid [lindex [$selnext get resid] $i]
            set segname [lindex [$selnext get segname] $i]
            draw line [lindex [$selnow get {x y z}] $i] [lindex [$selnext get {x y z}] $i]
            draw sphere [lindex [$selnext get {x y z}] $i] radius 0.12
            puts $outfile "ATOM  $i  $atomname  $segname  $resid  $x  $y  $z  1.00  0.00"
        }
        puts $outfile "ENDMDL"
        
        puts "Frame $fps done"
    }
   
    close $outfile
}
作者
Author:
lyj714    时间: 2023-6-14 10:38
本帖最后由 lyj714 于 2023-6-14 10:41 编辑
landian666 发表于 2023-6-14 10:03
是呀,自己尝试写了一个没搞定,如下,还请不吝赐教。多谢!
proc showtrj {fps1 fps2 space selection  ...
  1. puts $outfile "ATOM  $i  $atomname  $segname  $resid  $x  $y  $z  1.00  0.00"
复制代码

这就有问题啊,我前面都已经说了你不要出输出pdb,你这根本就是错误的pdb格式,根本没有按照标准的pdb格式输出,你为什么还要用。



作者
Author:
landian666    时间: 2023-6-14 13:13
lyj714 发表于 2023-6-14 10:38
这就有问题啊,我前面都已经说了你不要出输出pdb,你这根本就是错误的pdb格式,根本没有按照标准的pdb ...

proc showtrj {fps1 fps2 space selection output} {
set selnow [atomselect top $selection frame $fps1]
set selnext [atomselect top $selection frame $fps1]
set num [$selnow num]

set outfile [open $output w]

for {set fps $fps1} {$fps < $fps2} {incr fps $space} {
    $selnow frame $fps
    $selnext frame [expr $fps + $space]
    $selnow update
    $selnext update

    puts $outfile "$num"
    puts $outfile "Frame $fps"
    for {set i 0} {$i < $num} {incr i 1} {
        set x [lindex [$selnext get x] $i]
        set y [lindex [$selnext get y] $i]
        set z [lindex [$selnext get z] $i]
        set atomname [lindex [$selnext get name] $i]

        draw line [lindex [$selnow get {x y z}] $i] [lindex [$selnext get {x y z}] $i]
        draw sphere [lindex [$selnext get {x y z}] $i] radius 0.12

   
        puts $outfile "$atomname $x $y $z"
    }
    puts $outfile ""

    puts "Frame $fps done"
}

close $outfile

}

修改了一下如上,现在的问题是
1、没有把每一个红色的轨迹点都输出,只输出了一部分。
2、没有输出轨迹红点间的连线。
3、没有输出原始的分子构型。

想请教一下还需如何修改可以解决上述三个问题,感谢!!!

作者
Author:
landian666    时间: 2023-6-15 16:36
landian666 发表于 2023-6-14 13:13
proc showtrj {fps1 fps2 space selection output} {
set selnow [atomselect top $selection frame $fp ...

修改了一下脚本,可以成功导出每一个轨迹点的xyz格式的文件,方便作图和测量,供大家参考。

用法为:showtrj 0 1001 10 "resname LIG and name O1" "/path/1.xyz”
可以导出LIG上O1所有的轨迹点。

proc showtrj {fps1 fps2 space selection output} {
    set selnow [atomselect top $selection frame $fps1]
    set num [$selnow num]

    set outfile [open $output w]

    puts $outfile [expr {$num *(int(($fps2 - $fps1) / $space) + 1)}]
    puts $outfile "Merged Frame"

    for {set i 0} {$i < $num} {incr i 1} {
        set x [lindex [$selnow get x] $i]
        set y [lindex [$selnow get y] $i]
        set z [lindex [$selnow get z] $i]
        set atomname [lindex [$selnow get name] $i]
        puts $outfile "$atomname $x $y $z"
    }

    for {set fps [expr $fps1 + $space]} {$fps < $fps2} {incr fps $space} {
        $selnow frame $fps
        $selnow update

        for {set i 0} {$i < $num} {incr i 1} {
            set x [lindex [$selnow get x] $i]
            set y [lindex [$selnow get y] $i]
            set z [lindex [$selnow get z] $i]
            set atomname [lindex [$selnow get name] $i]
            puts $outfile "$atomname $x $y $z"
        }
    }

    close $outfile
    puts "Merged frame generated."
}




欢迎光临 计算化学公社 (http://bbs.keinsci.com/) Powered by Discuz! X3.3