In [2]:
import os
import sys
import random
import time
from random import seed, randint
import argparse
import platform
from datetime import datetime
import imp
import numpy as np
import fileinput
from itertools import product
import pandas as pd
from scipy.interpolate import griddata
from scipy.interpolate import interp2d
import seaborn as sns
from os import listdir
import matplotlib.pyplot as plt
import seaborn as sns
from scipy.interpolate import griddata
import matplotlib as mpl
# sys.path.insert(0,'..')
# from notebookFunctions import *
# from .. import notebookFunctions
from Bio.PDB.Polypeptide import one_to_three
from Bio.PDB.Polypeptide import three_to_one
from Bio.PDB.PDBParser import PDBParser
from pyCodeLib import *
from small_script.myFunctions import *
from collections import defaultdict
%matplotlib inline
# plt.rcParams['figure.figsize'] = (10,6.180) #golden ratio
# %matplotlib notebook
%load_ext autoreload
%autoreload 2
In [3]:
plt.rcParams['figure.figsize'] = 0.5 * np.array([16.18033, 10]) #golden ratio
plt.rcParams['figure.facecolor'] = 'w'
plt.rcParams['figure.dpi'] = 100
plt.rcParams.update({'font.size': 22})
In [4]:
import pickle
In [ ]:
ca_list = [0, 6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 83, 89, 95, 101, 107, 113, 119, 125, 131, 137, 143, 148, 154, 160, 166, 172, 178, 184, 190, 196, 202, 208, 214, 219, 225, 231, 237, 242, 248, 254, 260, 265, 271, 277, 283, 289, 295, 301, 307, 312, 318, 324, 330, 336, 342, 348, 354, 360, 365]
In [106]:
aa = np.load(pre + f"velocity")
aa = [np.array(aa[i]) for i in range(len(aa))]
In [107]:
len(aa)
Out[107]:
In [179]:
aa[0].shape
Out[179]:
In [103]:
back_info = info
In [112]:
info = []
In [116]:
data = pd.DataFrame(info, columns=["Step", "Run", "D"])
In [117]:
data.to_csv("/Users/weilu/Research/data/openMM/diffusion.csv")
In [120]:
data.plot.scatter("Step", "D")
Out[120]:
In [113]:
for step in [1, 10, 100]:
for i in range(10):
print(step, i)
pre = f"/Users/weilu/Research/server/dec_2019/diffusion_timescale/run1/step{step}/{i}/"
ss = compute_and_plot_ca(pre, d_length=1500)
D = (1/3)*np.sum(ss)*(1e3)*step
info.append([step, i, D])
plt.figure()
In [102]:
step = 1
for i in range(10):
pre = f"/Users/weilu/Research/server/dec_2019/diffusion_timescale/run1/step{step}/{i}/"
ss = compute_and_plot_ca(pre, d_length=1000)
D = (1/3)*np.sum(ss)*(1e3)
info.append([step, i, D])
In [ ]:
step = 10
for i in range(10):
pre = f"/Users/weilu/Research/server/dec_2019/diffusion_timescale/run1/step{step}/{i}/"
ss = compute_and_plot_ca(pre, d_length=200)
D = (1/3)*np.sum(ss)*(1e3)*step
info.append([step, i, D])
In [92]:
def compute_and_plot_ca(pre, ca_list=ca_list, d_length=100):
aa = np.load(pre + f"velocity")
aa = [np.array(aa[i]) for i in range(len(aa))]
ss = []
dd = list(range(0, d_length))
n = len(aa)
for d in dd:
s = 0
for i in range(n-d):
s += np.sum(aa[i][ca_list] * aa[i+d][ca_list])/len(ca_list)
ss.append(s/(n-d))
plt.plot(dd, ss)
D = (1/3)*np.sum(ss)*(1e3)
print("D: ", D)
return ss
In [47]:
def compute_and_plot(pre, d_length=100):
aa = np.load(pre + f"velocity")
aa = [np.array(aa[i]) for i in range(len(aa))]
ss = []
dd = list(range(0, d_length))
n = len(aa)
for d in dd:
s = 0
for i in range(n-d):
s += np.sum(aa[i][0] * aa[i+d][0])
ss.append(s/(n-d))
plt.plot(dd, ss)
D = (1/3)*np.sum(ss)*(1e3)
print("D: ", D)
return ss
def compute_and_plot_all_atoms(pre, d_length=400):
aa = np.load(pre + f"velocity")
aa = [np.array(aa[i]) for i in range(len(aa))]
ss = []
dd = list(range(0, d_length))
n = len(aa)
for d in dd:
s = 0
for i in range(n-d):
s += np.sum(aa[i] * aa[i+d])/len(aa[i])
ss.append(s/(n-d))
# ss.append(s)
plt.plot(dd, ss)
D = (1/3)*np.sum(ss)*(1e3)
print("D: ", D)
return ss
In [51]:
aa = np.load(pre + f"velocity")
# aa = [np.array(aa[i]) for i in range(len(aa))]
In [98]:
pre = "/Users/weilu/Research/server/dec_2019/diffusion_timescale/run2/step1/0/"
ss = compute_and_plot_ca(pre, d_length=200)
In [97]:
pre = "/Users/weilu/Research/server/dec_2019/diffusion_timescale/run2/step1/0/"
ss = compute_and_plot_ca(pre, d_length=100)
In [94]:
pre = "/Users/weilu/Research/server/dec_2019/diffusion_timescale/run2/step1/0/"
ss = compute_and_plot_ca(pre, d_length=400)
In [69]:
pre = "/Users/weilu/Research/server/dec_2019/diffusion_timescale/run2/step1/0/"
ss = compute_and_plot(pre, d_length=100)
In [66]:
pre = "/Users/weilu/Research/server/dec_2019/diffusion_timescale/run2/step1/0/"
ss_all_atoms = compute_and_plot_all_atoms(pre, d_length=100)
In [95]:
pre = "/Users/weilu/Research/server/dec_2019/diffusion_timescale/run2/step1/0/"
ss_all_atoms = compute_and_plot_all_atoms(pre, d_length=400)
In [67]:
pre = "/Users/weilu/Research/server/dec_2019/diffusion_timescale/run2/step1/0/"
ss_all_atoms = compute_and_plot_all_atoms(pre, d_length=400)
In [27]:
pre = "/Users/weilu/Research/server/dec_2019/diffusion_timescale/native/step1000/2_long/"
ss_all_atoms = compute_and_plot_all_atoms(pre)
In [30]:
pre = "/Users/weilu/Research/server/dec_2019/diffusion_timescale/native/step1000/2_long/"
ss_all_atoms = compute_and_plot_all_atoms(pre, d_length=10000)
In [ ]:
In [20]:
pre = "/Users/weilu/Research/server/dec_2019/diffusion_timescale/run1/step100/0/"
ss = compute_and_plot_all_atoms(pre)
In [8]:
pre = "/Users/weilu/Research/server/dec_2019/diffusion_timescale/native/step1000/1/"
ss = compute_and_plot_all_atoms(pre)
In [12]:
pre = "/Users/weilu/Research/server/dec_2019/diffusion_timescale/native/step1000/0/"
ss = compute_and_plot_all_atoms(pre)
In [5]:
movieFile = "/Users/weilu/Research/server/dec_2019/diffusion_timescale/native/step1000/0/movie.pdb"
parser = PDBParser()
s = parser.get_structure("X", movieFile)
# I want to have all the coordinates of all CA.
info = []
for i, model in enumerate(s.get_models()):
for j, res in enumerate(model.get_residues()):
ca_coord = res["CA"].get_coord()
info.append([i, j] + list(ca_coord))
data = pd.DataFrame(info, columns=["model", "res", "x", "y", "z"])
rsquare_list = []
model_list = []
for model, d in data.groupby("model"):
if model == 0:
a_0 = d.iloc[:, 2:5].values
a = d.iloc[:, 2:5].values - a_0
rsquare = np.sum(a**2)/len(a)
# print(rsquare, model)
model_list.append(model)
rsquare_list.append(rsquare)
plt.plot(model_list, rsquare_list)
Out[5]:
In [230]:
plt.plot(model_list, rsquare_list)
Out[230]:
In [ ]:
with open(movieFile, "r") as f:
a = f.readlines()
a = a[1:-1]
n = len(a)
length = int(n/10)
i = 0
b = a[i*length:(i+1)*length]
In [71]:
movieFile = "/Users/weilu/Research/server/dec_2019/diffusion_timescale/native/300/movie.pdb"
parser = PDBParser()
s = parser.get_structure("X", movieFile)
# I want to have all the coordinates of all CA.
info = []
for i, model in enumerate(s.get_models()):
for j, res in enumerate(model.get_residues()):
ca_coord = res["CA"].get_coord()
info.append([i, j] + list(ca_coord))
data = pd.DataFrame(info, columns=["model", "res", "x", "y", "z"])
a = data.iloc[:, 2:5].values
rsqure = np.sum(a**2)/len(a)
for model, d in data.groupby("model"):
a = d.iloc[:, 2:5].values
rsqure = np.sum(a**2)/len(a)
print(rsqure, model)
In [73]:
a = res["CA"]
In [74]:
a.id
Out[74]:
In [75]:
a.full_id
Out[75]:
In [79]:
model = list(s.get_models())[0]
In [80]:
model.get_atoms()
Out[80]:
In [85]:
ca_list = []
for i, atom in enumerate(model.get_atoms()):
if atom.id == "CA":
# print(i)
ca_list.append(i)
In [ ]: