python - 使用 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()
解决方案
推荐阅读
- java - mapstruct 将方法应用于列表中的所有对象
- javascript - 使用 CSP 从 analytics.js 迁移到 gtag.js
- wordpress - 在 WooCommerce 购物车中设置全球最低金额,但类别餐饮 + 子类别除外
- javascript - 如何使用jQuery比较每个数组编号?如果小于输入范围数 div 标签将隐藏
- julia - 可以用对字段维度的持久要求来定义 julia 结构吗?
- spring-boot - 依赖 spring-boot-starter-webflux 时发生 reactor.netty 错误
- r - 如何使用具有三个水平的 x 变量和比例不相关的二分 y 变量创建条形图
- r - 从日期开始的月、日、小时、分钟、秒的子集
- sqlite - 如何根据人数动态配置时段
- mongoose - 在 Mongoose 中使用变量来定位对象路径