分子动力学开源分析软件MDAnalysis安装介绍及使用


MD Analysis (以下简称mda) 是一款分子动力学后处理代码,具有优秀的后处理函数库,高效的处理速度,可并行的计算功能。通过mda可以读取LAMMPS的单个data、连续dump轨迹文件,做一些基本结构计算不是问题。但其对dump文件的读取仅限于id, type, x, y, z这几类。对于dump的不足,本人改动了一下源文件,支持读取dump的其他列的数据信息,需要的同学可以留言或邮件(yunai2384@163.com)。In addition, for beginner of molecular dynamics, ASE is more suggested.

一、MD Analysis 安装

MD Analysis相关网站见:
官方网站
官方文档

普通安装

(1) 从pip:

pip install --upgrade MDAnalysis
# pip install --upgrade MDAnalysisTests   # 安装测试数据

(2) 从Conda:

conda install -c conda-forge mdanalysis
# conda update mdanalysis # 升级
# conda install -c conda-forge MDAnalysisTests  # 安装测试数据

从源码安装:

# git clone https://github.com/MDAnalysis/mdanalysis.git  # 下载mda
git clone https://gitee.com/yunai9/mdanalysis.git # 我已备份至gitee,速度更快
cd mdanalysis/package/
pip install -r requirements.txt  --upgrade
python setup.py install

二、MD Analysis使用

mda支持二十多种文件格式,包括LAMMPS (dump, data格式),xyz格式,CHARMM,Gromacs (xtc, trr格式),AMBER相关格式,DL_Poly,MOL2,NAMD相关格式。而就我所知,支持的LAMMPS的dump格式中,对除了id type x y z 之外的列并不读取。之所以还要选择mda,主要是能够直接接触底层数据,并直接进行相关处理,包括近邻相关计算,结构分析等。
LAMMPS read and write info
基本使用方法:

读取文件

import MDAnalysis as mda
from MDAnalysis.lib import NeighborSearch
u = mda.Universe('lammps.data', atom_style='id type charge x y z imx imy imz')
# 选择原子种类
Type1 = u.select_atoms("type  1")
# Type1原子总数
nType1 = Type1.atoms.n_atoms
# 所搜Type1每个原子在截断半径2 A中的其他原子
for i in range(nType1):
    neAtom = ns.search(Type1.atoms[i], 2.0)
    # do something else
# 读取lammps dump轨迹文件
u = mda.Universe('lammps.data', format='LAMMPSDUMP')
# 对dump文件的每一帧进行处理
for ts in u.trajectory:
	# ts 中的选项和u中的选项有所区别,请注意
	# do something else
MDAnalysis 分析分子动力学轨迹 MDAnalysis-0.7.2.tar.gz MDAnalysis is an object-oriented python toolkit to analyze molecular dynamics trajectories generated by CHARMM, Gromacs, NAMD, LAMMPS, or Amber. It allows one to read molecular dynamics trajectories and access the atomic coordinates through numpy arrays. This provides an extremely flexible and relatively fast framework for complex analysis tasks. In addition, CHARMM-style atom selection commands are implemented. Trajectories can also be manipulated (for instance, fit to a reference structure) and written out. A typical usage pattern is to iterate through a trajectory and analyze coordinates for every frame. In the following example the end-to-end distance of a protein and the radius of gyration of the backbone atoms are calculated: import MDAnalysis from MDAnalysis.tests.datafiles import PSF,DCD # test trajectory import numpy.linalg u = MDAnalysis.Universe(PSF,DCD) # always start with a Universe nterm = u.s4AKE.N[0] # can access structure via segid (s4AKE) and atom name cterm = u.s4AKE.C[-1] # ... takes the last atom named 'C' bb = u.selectAtoms('protein and backbone') # a selection (a AtomGroup) for ts in u.trajectory: # iterate through all frames r = cterm.pos - nterm.pos # end-to-end vector from atom positions d = numpy.linalg.norm(r) # end-to-end distance rgyr = bb.radiusOfGyration() # method of a AtomGroup; updates with each frame print "frame = %d: d = %f Angstroem, Rgyr = %f Angstroem" % (ts.frame, d, rgyr)
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值