-
Notifications
You must be signed in to change notification settings - Fork 0
/
angle_hist.py
79 lines (71 loc) · 3.15 KB
/
angle_hist.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
72
73
74
75
76
77
78
79
# coding: utf-8
import scipy as sp
from scipy import stats
import numpy as np
import matplotlib.pyplot as plt
import mdtraj as md
import sys
from sys import argv
import math
script, parmfile, trajfile = argv
top = md.load_prmtop(parmfile)
traj = md.load(trajfile, top=top)
print(traj)
psi_list = md.compute_psi(traj)
#phi_list = md.compute_phi(traj)
#chi1_list = md.compute_chi1(traj)
#chi2_list = md.compute_chi2(traj)
for i in xrange(psi_list[1].shape[1]):
dihedral_traj = psi_list[1][:,i]
dihedral_traj_deg = (dihedral_traj * 180) / math.pi
index = np.linspace(1,len(dihedral_traj), len(dihedral_traj)).astype('int')
(n, bins, patches) = plt.hist(dihedral_traj_deg, bins = 300, range = (-180.00, 180.00), normed=True)
# data = np.vstack((index,dihedral_traj_deg)).T
# np.savetxt('dihedrals/psi_%d.xvg' %i, data, fmt=['%d', '%.4f'])
# Add a uniform prior to whole distribution to allow calculation of KL
n += ((np.mean(n))/100)
#print n
n = n / (sum(n))
#print n
# Find centre of each bin.
bincentre = 0.5*(bins[1:]+bins[:-1])
#print bincentre
# Create an array the length of the number of bins
index = np.linspace(1, len(bincentre), num = len(bincentre), dtype = int)
#print ind
# Arrange index and frequency of each bin in array
data = np.vstack((index, n)).T
np.savetxt('files/psi_hist_%d.dat' % i, data, fmt=['%d', '%.10f'])
#for i in xrange(phi_list[1].shape[1]):
# dihedral_traj = phi_list[1][:,i]
# dihedral_traj_deg = (dihedral_traj * 180) / math.pi
# index = np.linspace(1,len(dihedral_traj), len(dihedral_traj)).astype('int')
# (n, bins, patches) = plt.hist(dihedral_traj_deg, bins = 300, range = (-180.00, 180.00), normed=True)
# n += ((np.mean(n))/100)
# n = n / (sum(n))
# bincentre = 0.5*(bins[1:]+bins[:-1])
# index = np.linspace(1, len(bincentre), num = len(bincentre), dtype = int)
# data = np.vstack((index, n)).T
# np.savetxt('new/phi_hist_%d.dat' % i, data, fmt=['%d', '%.10f'])
#for i in xrange(chi1_list[1].shape[1]):
# dihedral_traj = chi1_list[1][:,i]
# dihedral_traj_deg = (dihedral_traj * 180) / math.pi
# index = np.linspace(1,len(dihedral_traj), len(dihedral_traj)).astype('int')
# (n, bins, patches) = plt.hist(dihedral_traj_deg, bins = 300, range = (-180.00, 180.00), normed=True)
# n += ((np.mean(n))/100)
# n = n / (sum(n))
# bincentre = 0.5*(bins[1:]+bins[:-1])
# index = np.linspace(1, len(bincentre), num = len(bincentre), dtype = int)
# data = np.vstack((index, n)).T
# np.savetxt('new/chi1_hist_%d.dat' % i, data, fmt=['%d', '%.10f'])
#for i in xrange(chi2_list[1].shape[1]):
# dihedral_traj = chi2_list[1][:,i]
# dihedral_traj_deg = (dihedral_traj * 180) / math.pi
# index = np.linspace(1,len(dihedral_traj), len(dihedral_traj)).astype('int')
# (n, bins, patches) = plt.hist(dihedral_traj_deg, bins = 300, range = (-180.00, 180.00), normed=True)
# n += ((np.mean(n))/100)
# n = n / (sum(n))
# bincentre = 0.5*(bins[1:]+bins[:-1])
# index = np.linspace(1, len(bincentre), num = len(bincentre), dtype = int)
# data = np.vstack((index, n)).T
# np.savetxt('new/chi2_hist_%d.dat' % i, data, fmt=['%d', '%.10f'])