使用Python进行轨迹文件分析

问题描述

首先,我是python的新手。 我有一个包含多个时间步长的轨迹文件(50000),我想做的是编写一个python代码来计算水氧(O)原子的均方位移。

我的计划是先逐帧选择氧原子,然后使用MSD代码进行。在我的轨迹文件的单个框架中,前2行分别包含该垂直框架的原子总数(5058)和原子描述,之后的606行包含表面原子,其余的4450行包含水原子一种有序的方式(O,H,H,O,H,H,O,H,H等),我开始这样,但是我觉得自己无路可走。

  import numpy as np 
  import math
  
  #parameters
 
 
 m_o     = 16 #gmol-1                                                  
 m_h     = 1 #gmol-1
 leave   = 608 #including the two title lines first 606 atoms are surface atms.so they should be just read
 waters  = 4450 #after the first 606 atoms the rest are water atoms
 N       = 5060 #number of lines in a frame
 
 
 with open("traj.xyz","r") as f:
    count = len(f.readlines(  )) #counts the total number of lines
 #print(count)
 nof = count/N
 '''nof is number of frames'''
 print(int(nof))
 
 def frames():
    for i in nof:
        count = 0
        xcoord = []
        ycoord = []
        zcoord = []
        for i in range(leave):
            title = f.readline()
            for line in f:
                cnt+=1
                if (cnt % 3 == 1):
                    atmid,x,y,z = line.split()
                    xcoord.append(x)
                    ycoord.append(y)
                    zcoord.append(z)
                    print(atmid,z)

 if (cnt == waters):
    exit()                                                                
 frames()

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)