首页 > 解决方案 > 使用 Python 进行轨迹文件分析

问题描述

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

我的计划是首先逐帧选择氧原子,然后使用 MSD 代码执行。在我的轨迹文件的单帧中,前两行分别包含该特定帧的原子总数(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,x,y,z)

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

标签: pythonnumpyfileanalysisframes

解决方案


推荐阅读