-
Notifications
You must be signed in to change notification settings - Fork 2
/
cntmotion14.py
73 lines (52 loc) · 2.09 KB
/
cntmotion14.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# CNTmotion14
# Martin Voegele, 2016-08-03
# Import necessary modulies
import sys
import argparse
import numpy as np
import scipy as sp
import MDAnalysis as mda
import MDAnalysis.analysis.helanal
import geometry
def motion_from_file(prmfile,trjfile,selection,skip):
# Create universe from files
u = mda.Universe(prmfile,trjfile)
sim_time = []
tube_com = []
tilt_cos = []
for ts in u.trajectory[::skip]:
sim_time.append(ts.time)
cnt = u.select_atoms(selection)
com = cnt.center_of_mass()
tube_com.append( com )
princ_ax = cnt.principal_axes()[0]
tilt_cos.append( np.abs(princ_ax[2]) )
return sim_time, tube_com, tilt_cos
## MAIN ##
# Parse arguments
parser = argparse.ArgumentParser()
parser.add_argument( '-p', dest='prmfile', default='system.prmtop', help="topology file (prmtop)" )
parser.add_argument( '-t', dest='trjfile', default='trajectory.nc', help="trajectory file", nargs='+' )
parser.add_argument( '-ocom', dest='outfcom', default='com.dat', help="output file for COM" )
parser.add_argument( '-otil', dest='outftil', default='tilt.dat', help="output file for tilting cos" )
parser.add_argument( '-sel', dest='selection', default='resname CNT', help="selection command" )
parser.add_argument( '-skip', dest='skip', default=1, type=int, help="use every nth frame" )
args = parser.parse_args()
# Initialize the time, the COM, and the tilting cosine
tot_time = []
tot_tilt = []
tot_com = []
# Go through all parts of the trajectory
for trjf in args.trjfile:
print trjf
time, com, tilt = motion_from_file(args.prmfile,trjf,args.selection,args.skip)
tot_com += com
tot_tilt += tilt
tot_time += time
tot_com = np.array(tot_com)
tot_tilt = np.array(tot_tilt)
tot_time = np.array(tot_time)
output = np.transpose([tot_time, tot_com[:,0], tot_com[:,1], tot_com[:,2]])
np.savetxt(args.outfcom,output,fmt='%.18e %.18e %.18e %.18e')
output = np.transpose([tot_time, tot_tilt])
np.savetxt(args.outftil,output,fmt='%.18e %.18e')