Frame与Time换算
经过Amber模拟后,再使用CPPTRAJ软件处理坐标轨迹和数据文件并作图后,得到的结果如下所示:
但我们为了更直观地展示数据,我们需要将横坐标轴从frame转换为time。
转换原理
第 i i i个 f r a m e frame frame的时间 t t t为: t = i × n t w x × d t = i × 10 ( p s ) = i × 0.01 ( n s ) t = i\times ntwx\times dt = i \times 10 (ps) = i \times 0.01 (ns) t=i×ntwx×dt=i×10(ps)=i×0.01(ns)
n t w x ntwx ntwx与 d t dt dt的值均在md.in中设置。
参数解释:
• dt=0.002
:积分步长为
2
p
s
2 ps
2ps
• ntwx=5000
:每5000步输出一次轨迹坐标,用于后续的轨迹分析。
原始数据rmsd.dat
#Frame ToFirst
1 0.0000
2 0.9008
3 0.9561
4 1.0030
5 1.0868
6 1.1593
7 1.1733
8 1.2441
9 1.1592
10 1.1371
转换后的数据rmsd_ns.dat
0.010000 0.0000
0.020000 0.9008
0.030000 0.9561
0.040000 1.0030
0.050000 1.0868
0.060000 1.1593
0.070000 1.1733
0.080000 1.2441
0.090000 1.1592
0.100000 1.1371
转换的python代码
# 读取输入文件并处理数据
with open('rmsd.dat', 'r') as input_file:
lines = input_file.readlines()
# 处理每一行并写入新文件
with open('rms_ns.dat', 'w') as output_file:
for line in lines:
# 跳过以'#'开头的标题行
if line.startswith('#'):
continue
# 分割每行的数据
columns = line.split()
# 将第一列转换为浮点数并乘以0.01
first_column = float(columns[0]) * 0.01
# 保留第二列数据
second_column = float(columns[1])
# 写入新文件
output_file.write(f"{first_column:.6f} {second_column}\n")