In [1]:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import datetime
import os
# from small_script.myFunctions import *



%matplotlib inline
%load_ext autoreload
%autoreload 2

In [2]:
plt.rcParams['figure.facecolor'] = 'w'
plt.rcParams['figure.figsize'] = [16.18033, 10]
plt.rcParams['figure.dpi'] = 200

In [3]:
# plt.rcParams['figure.figsize'] = [16.18033, 10]

dataset = {"old":"1R69, 1UTG, 3ICB, 256BA, 4CPV, 1CCR, 2MHR, 1MBA, 2FHA".split(", "),
            "new":"1FC2C, 1ENH, 2GB1, 2CRO, 1CTF, 4ICB".split(", "),
            "test":["t089", "t120", "t251", "top7", "1ubq", "t0766", "t0778", "t0782", "t0792", "t0803", "t0815", "t0833", "t0842", "t0844"]}
dataset["combined"] = dataset["old"] + dataset["new"]

# pdb_list, steps = dataset["old"]

def get_data(pre, pdb_list, simType="all_simulations", n_rum=30, rerun=1, formatName=True):
    # to get last 20 frame of each run
    _all = []
    for p in pdb_list:
        if formatName:
            name = p.lower()[:4]
        else:
            name = p
        for i in range(n_rum):
            for ii in range(rerun):
                location = pre + f"{simType}/{name}/simulation/{i}/{ii}/wham.dat"
                try:
                    tmp = pd.read_csv(location).tail(50).reset_index()
                    tmp.columns = tmp.columns.str.strip()
                    _all.append(tmp.assign(Run=i, Name=name, Rerun=ii))
                except Exception as e: 
                    print(e)
    data = pd.concat(_all)
    data["Run"] = "Run" + data["Run"].astype(str)
    return data

# pre = "/Users/weilu/Research/server/feb_2019/optimization_iter1/database/2gb1/"
# fileName = "movie.pdb"
def splitPDB(pre, fileName):
    location = f"{pre}/{fileName}"
    with open(location, "r") as f:
        a = f.readlines()
    i = 0
    tmp = ""
    for line in a:
        tmp += line
    #     os.system(f"echo '{line}' >> {pre}frame{i}")
        if line == "END\n":
            with open(f"{pre}frame{i}.pdb", "w") as out:
                out.write(tmp)
            i += 1
            tmp = ""


import subprocess
def getFromTerminal(CMD):
    return subprocess.Popen(CMD,stdout=subprocess.PIPE,shell=True).communicate()[0].decode()
def getSize(p):
    protein = p.lower()[:4]
    pre = f"/Users/weilu/Research/server/feb_2019/iterative_optimization_test_set/all_simulations/{protein}/{protein}/ssweight"
    a = getFromTerminal(f"wc {pre}")
#     print(a)
    n = int(a.split()[0])
    return n

single memory make the problem too simple.


In [6]:
pre = "/Users/weilu/Research/server/single_memory_optimization/"
folder = "iterative_optimization_combined_train_set_singleMemory"
pre = pre + folder + "/"
simulationType = "original"
today = datetime.datetime.today().strftime('%m-%d')
# pdb_list, steps = dataset["test"]
pdb_list = dataset["combined"]
# pdb_list = "1FC2C, 1ENH, 2GB1, 2CRO, 1CTF, 4ICB".split(", ")
data = get_data(pre, pdb_list, simType=simulationType, n_rum=30, rerun=1, formatName=True)
data.reset_index(drop=True).to_csv(f"/Users/weilu/Research/data/optimization/{simulationType}_{folder}_{today}.csv")
# data.reset_index(drop=True).to_csv(f"/Users/weilu/Research/data/optimization/withoutContact_{today}.csv")
sns.boxplot("Name", "Qw", data=data)


Out[6]:
<matplotlib.axes._subplots.AxesSubplot at 0x1a1c55ce80>

In [170]:
data_origin = pd.read_csv("/Users/weilu/Research/data/optimization/original_iterative_optimization_combined_train_set_with_frag_04-06.csv", index_col=0)

data = pd.read_csv("/Users/weilu/Research/data/optimization/iter0_iterative_optimization_combined_train_set_with_frag_04-08.csv", index_col=0)
data2 = pd.read_csv("/Users/weilu/Research/data/optimization/without_contact_iterative_optimization_combined_train_set_with_frag_04-09.csv", index_col=0)
data3 = pd.read_csv("/Users/weilu/Research/data/optimization/original_with_rg_iterative_optimization_combined_train_set_with_frag_04-09.csv", index_col=0)
# data4 = pd.read_csv("/Users/weilu/Research/data/optimization/iter7_normalized_90_iterative_optimization_combined_train_set_with_frag_04-08.csv", index_col=0)


d = pd.concat([
                data_origin.query("Rerun == 1").assign(Scheme="original"), 
    data3.assign(Scheme="original with rg"),
                data.assign(Scheme="iter0"),         
                 data2.assign(Scheme="without contact"), 
                 
#                 data4.query("Rerun == 1").assign(Scheme="iter7_90"), 
#                 data5.query("Rerun == 1").assign(Scheme="iter3_90"), 
#     data6.query("Rerun == 1").assign(Scheme="iter4"), 
#     data7.query("Rerun == 1").assign(Scheme="iter5"), 
              ])
sns.boxplot("Name", "Qw", hue="Scheme", data=d)
# sns.boxplot("Qw", "Name", hue="Scheme", data=d)


Out[170]:
<matplotlib.axes._subplots.AxesSubplot at 0x1a2e453b70>

In [ ]:


In [3]:
pre = "/Users/weilu/Research/server/april_2019/"
folder = "iterative_optimization_combined_train_set_with_frag"
pre = pre + folder + "/"
simulationType = "iter6_with_rg"
today = datetime.datetime.today().strftime('%m-%d')
# pdb_list, steps = dataset["test"]
pdb_list = dataset["combined"]
# pdb_list = "1FC2C, 1ENH, 2GB1, 2CRO, 1CTF, 4ICB".split(", ")
data = get_data(pre, pdb_list, simType=simulationType, n_rum=30, rerun=1, formatName=True)
data.reset_index(drop=True).to_csv(f"/Users/weilu/Research/data/optimization/{simulationType}_{folder}_{today}.csv")
# data.reset_index(drop=True).to_csv(f"/Users/weilu/Research/data/optimization/withoutContact_{today}.csv")
sns.boxplot("Name", "Qw", data=data)


Out[3]:
<matplotlib.axes._subplots.AxesSubplot at 0x1a14de9240>

In [165]:
pre = "/Users/weilu/Research/server/april_2019/"
folder = "iterative_optimization_combined_train_set_with_frag"
pre = pre + folder + "/"
simulationType = "without_contact"
today = datetime.datetime.today().strftime('%m-%d')
# pdb_list, steps = dataset["test"]
pdb_list = dataset["combined"]
# pdb_list = "1FC2C, 1ENH, 2GB1, 2CRO, 1CTF, 4ICB".split(", ")
data = get_data(pre, pdb_list, simType=simulationType, n_rum=30, rerun=1, formatName=True)
data.reset_index(drop=True).to_csv(f"/Users/weilu/Research/data/optimization/{simulationType}_{folder}_{today}.csv")
# data.reset_index(drop=True).to_csv(f"/Users/weilu/Research/data/optimization/withoutContact_{today}.csv")
sns.boxplot("Name", "Qw", data=data)


Out[165]:
<matplotlib.axes._subplots.AxesSubplot at 0x1a2fc57978>

In [164]:
pre = "/Users/weilu/Research/server/april_2019/"
folder = "iterative_optimization_combined_train_set_with_frag"
pre = pre + folder + "/"
simulationType = "original_with_rg"
today = datetime.datetime.today().strftime('%m-%d')
# pdb_list, steps = dataset["test"]
pdb_list = dataset["combined"]
# pdb_list = "1FC2C, 1ENH, 2GB1, 2CRO, 1CTF, 4ICB".split(", ")
data = get_data(pre, pdb_list, simType=simulationType, n_rum=30, rerun=1, formatName=True)
data.reset_index(drop=True).to_csv(f"/Users/weilu/Research/data/optimization/{simulationType}_{folder}_{today}.csv")
# data.reset_index(drop=True).to_csv(f"/Users/weilu/Research/data/optimization/withoutContact_{today}.csv")
sns.boxplot("Name", "Qw", data=data)


Out[164]:
<matplotlib.axes._subplots.AxesSubplot at 0x1a2df184a8>

In [163]:
pre = "/Users/weilu/Research/server/april_2019/"
folder = "iterative_optimization_combined_train_set_with_frag"
pre = pre + folder + "/"
simulationType = "iter0"
today = datetime.datetime.today().strftime('%m-%d')
# pdb_list, steps = dataset["test"]
pdb_list = dataset["combined"]
# pdb_list = "1FC2C, 1ENH, 2GB1, 2CRO, 1CTF, 4ICB".split(", ")
data = get_data(pre, pdb_list, simType=simulationType, n_rum=30, rerun=1, formatName=True)
data.reset_index(drop=True).to_csv(f"/Users/weilu/Research/data/optimization/{simulationType}_{folder}_{today}.csv")
# data.reset_index(drop=True).to_csv(f"/Users/weilu/Research/data/optimization/withoutContact_{today}.csv")
sns.boxplot("Name", "Qw", data=data)


Out[163]:
<matplotlib.axes._subplots.AxesSubplot at 0x1a2e28fcf8>

In [159]:
pre = "/Users/weilu/Research/server/april_2019/"
folder = "iterative_optimization_combined_train_set_with_frag"
pre = pre + folder + "/"
simulationType = "iter7_normalized_90"
today = datetime.datetime.today().strftime('%m-%d')
# pdb_list, steps = dataset["test"]
pdb_list = dataset["combined"]
# pdb_list = "1FC2C, 1ENH, 2GB1, 2CRO, 1CTF, 4ICB".split(", ")
data = get_data(pre, pdb_list, simType=simulationType, n_rum=10, rerun=2, formatName=True)
data.reset_index(drop=True).to_csv(f"/Users/weilu/Research/data/optimization/{simulationType}_{folder}_{today}.csv")
# data.reset_index(drop=True).to_csv(f"/Users/weilu/Research/data/optimization/withoutContact_{today}.csv")
sns.boxplot("Name", "Qw", data=data.query("Rerun == 1"))


Out[159]:
<matplotlib.axes._subplots.AxesSubplot at 0x1a2ca6a4a8>

In [168]:
data_origin = pd.read_csv("/Users/weilu/Research/data/optimization/original_iterative_optimization_combined_train_set_with_frag_04-06.csv", index_col=0)

data = pd.read_csv("/Users/weilu/Research/data/optimization/iter5_normalized_noFrag_iterative_optimization_combined_train_set_with_frag_04-06.csv", index_col=0)
data2 = pd.read_csv("/Users/weilu/Research/data/optimization/iter6_normalized_noFrag_iterative_optimization_combined_train_set_with_frag_04-07.csv", index_col=0)

data3 = pd.read_csv("/Users/weilu/Research/data/optimization/iter7_normalized_iterative_optimization_combined_train_set_with_frag_04-08.csv", index_col=0)
data4 = pd.read_csv("/Users/weilu/Research/data/optimization/iter7_normalized_90_iterative_optimization_combined_train_set_with_frag_04-08.csv", index_col=0)


d = pd.concat([
                data_origin.query("Rerun == 1").assign(Scheme="original"), 
                data.query("Rerun == 1").assign(Scheme="iter5"),         
                 data2.query("Rerun == 1").assign(Scheme="iter6"), 
                data3.query("Rerun == 1").assign(Scheme="iter7"), 
#                 data4.query("Rerun == 1").assign(Scheme="iter7_90"), 
#                 data5.query("Rerun == 1").assign(Scheme="iter3_90"), 
#     data6.query("Rerun == 1").assign(Scheme="iter4"), 
#     data7.query("Rerun == 1").assign(Scheme="iter5"), 
              ])
sns.boxplot("Name", "Qw", hue="Scheme", data=d)
# sns.boxplot("Qw", "Name", hue="Scheme", data=d)


Out[168]:
<matplotlib.axes._subplots.AxesSubplot at 0x1a2f6d17f0>

In [169]:
pre = "/Users/weilu/Research/server/april_2019/"
folder = "iterative_optimization_combined_train_set_with_frag"
pre = pre + folder + "/"
simulationType = "iter7_normalized"
today = datetime.datetime.today().strftime('%m-%d')
# pdb_list, steps = dataset["test"]
pdb_list = dataset["combined"]
# pdb_list = "1FC2C, 1ENH, 2GB1, 2CRO, 1CTF, 4ICB".split(", ")
data = get_data(pre, pdb_list, simType=simulationType, n_rum=10, rerun=2, formatName=True)
data.reset_index(drop=True).to_csv(f"/Users/weilu/Research/data/optimization/{simulationType}_{folder}_{today}.csv")
# data.reset_index(drop=True).to_csv(f"/Users/weilu/Research/data/optimization/withoutContact_{today}.csv")
sns.boxplot("Name", "Qw", data=data.query("Rerun == 1"))


Out[169]:
<matplotlib.axes._subplots.AxesSubplot at 0x1a23ae3da0>

In [155]:
pre = "/Users/weilu/Research/server/april_2019/"
folder = "iterative_optimization_combined_train_set_with_frag"
pre = pre + folder + "/"
simulationType = "iter6_normalized_noFrag"
today = datetime.datetime.today().strftime('%m-%d')
# pdb_list, steps = dataset["test"]
pdb_list = dataset["combined"]
# pdb_list = "1FC2C, 1ENH, 2GB1, 2CRO, 1CTF, 4ICB".split(", ")
data = get_data(pre, pdb_list, simType=simulationType, n_rum=10, rerun=2, formatName=True)
data.reset_index(drop=True).to_csv(f"/Users/weilu/Research/data/optimization/{simulationType}_{folder}_{today}.csv")
# data.reset_index(drop=True).to_csv(f"/Users/weilu/Research/data/optimization/withoutContact_{today}.csv")
sns.boxplot("Name", "Qw", data=data.query("Rerun == 1"))


Out[155]:
<matplotlib.axes._subplots.AxesSubplot at 0x1a2861c5c0>

In [153]:
pre = "/Users/weilu/Research/server/april_2019/"
folder = "iterative_optimization_combined_train_set_with_frag"
pre = pre + folder + "/"
simulationType = "original"
today = datetime.datetime.today().strftime('%m-%d')
# pdb_list, steps = dataset["test"]
pdb_list = dataset["combined"]
# pdb_list = "1FC2C, 1ENH, 2GB1, 2CRO, 1CTF, 4ICB".split(", ")
data = get_data(pre, pdb_list, simType=simulationType, n_rum=10, rerun=2, formatName=True)
data.reset_index(drop=True).to_csv(f"/Users/weilu/Research/data/optimization/{simulationType}_{folder}_{today}.csv")
# data.reset_index(drop=True).to_csv(f"/Users/weilu/Research/data/optimization/withoutContact_{today}.csv")
sns.boxplot("Name", "Qw", data=data.query("Rerun == 1"))


[Errno 2] File b'/Users/weilu/Research/server/april_2019/iterative_optimization_combined_train_set_with_frag/original/2fha/simulation/0/1/wham.dat' does not exist: b'/Users/weilu/Research/server/april_2019/iterative_optimization_combined_train_set_with_frag/original/2fha/simulation/0/1/wham.dat'
[Errno 2] File b'/Users/weilu/Research/server/april_2019/iterative_optimization_combined_train_set_with_frag/original/2fha/simulation/2/1/wham.dat' does not exist: b'/Users/weilu/Research/server/april_2019/iterative_optimization_combined_train_set_with_frag/original/2fha/simulation/2/1/wham.dat'
[Errno 2] File b'/Users/weilu/Research/server/april_2019/iterative_optimization_combined_train_set_with_frag/original/2fha/simulation/3/1/wham.dat' does not exist: b'/Users/weilu/Research/server/april_2019/iterative_optimization_combined_train_set_with_frag/original/2fha/simulation/3/1/wham.dat'
[Errno 2] File b'/Users/weilu/Research/server/april_2019/iterative_optimization_combined_train_set_with_frag/original/2fha/simulation/4/1/wham.dat' does not exist: b'/Users/weilu/Research/server/april_2019/iterative_optimization_combined_train_set_with_frag/original/2fha/simulation/4/1/wham.dat'
[Errno 2] File b'/Users/weilu/Research/server/april_2019/iterative_optimization_combined_train_set_with_frag/original/2fha/simulation/5/1/wham.dat' does not exist: b'/Users/weilu/Research/server/april_2019/iterative_optimization_combined_train_set_with_frag/original/2fha/simulation/5/1/wham.dat'
[Errno 2] File b'/Users/weilu/Research/server/april_2019/iterative_optimization_combined_train_set_with_frag/original/2fha/simulation/7/1/wham.dat' does not exist: b'/Users/weilu/Research/server/april_2019/iterative_optimization_combined_train_set_with_frag/original/2fha/simulation/7/1/wham.dat'
[Errno 2] File b'/Users/weilu/Research/server/april_2019/iterative_optimization_combined_train_set_with_frag/original/2fha/simulation/8/1/wham.dat' does not exist: b'/Users/weilu/Research/server/april_2019/iterative_optimization_combined_train_set_with_frag/original/2fha/simulation/8/1/wham.dat'
[Errno 2] File b'/Users/weilu/Research/server/april_2019/iterative_optimization_combined_train_set_with_frag/original/2fha/simulation/9/1/wham.dat' does not exist: b'/Users/weilu/Research/server/april_2019/iterative_optimization_combined_train_set_with_frag/original/2fha/simulation/9/1/wham.dat'
Out[153]:
<matplotlib.axes._subplots.AxesSubplot at 0x1a26ad3b00>

In [152]:
pre = "/Users/weilu/Research/server/april_2019/"
folder = "iterative_optimization_combined_train_set_with_frag"
pre = pre + folder + "/"
simulationType = "iter5_normalized_noFrag"
today = datetime.datetime.today().strftime('%m-%d')
# pdb_list, steps = dataset["test"]
pdb_list = dataset["combined"]
# pdb_list = "1FC2C, 1ENH, 2GB1, 2CRO, 1CTF, 4ICB".split(", ")
data = get_data(pre, pdb_list, simType=simulationType, n_rum=10, rerun=2, formatName=True)
data.reset_index(drop=True).to_csv(f"/Users/weilu/Research/data/optimization/{simulationType}_{folder}_{today}.csv")
# data.reset_index(drop=True).to_csv(f"/Users/weilu/Research/data/optimization/withoutContact_{today}.csv")
sns.boxplot("Name", "Qw", data=data.query("Rerun == 1"))


Out[152]:
<matplotlib.axes._subplots.AxesSubplot at 0x1a283bd320>

In [14]:
%matplotlib inline
plt.rcParams['figure.facecolor'] = 'w'
plt.rcParams['figure.figsize'] = [16.18033, 10]
plt.rcParams['figure.dpi'] = 200

In [19]:
data_origin = pd.read_csv("/Users/weilu/Research/data/optimization/original_iterative_optimization_combined_train_set_04-01.csv", index_col=0)

data = pd.read_csv("/Users/weilu/Research/data/optimization/iter0_normalized_noFrag_iterative_optimization_combined_train_set_03-31.csv", index_col=0)
data2 = pd.read_csv("/Users/weilu/Research/data/optimization/iter1_normalized_noFrag_iterative_optimization_combined_train_set_03-31.csv", index_col=0)
data3 = pd.read_csv("/Users/weilu/Research/data/optimization/iter2_normalized_noFrag_iterative_optimization_combined_train_set_04-01.csv", index_col=0)
data4 = pd.read_csv("/Users/weilu/Research/data/optimization/iter3_normalized_noFrag_iterative_optimization_combined_train_set_04-03.csv", index_col=0)
data5 = pd.read_csv("/Users/weilu/Research/data/optimization/iter3_normalized_noFrag_90_iterative_optimization_combined_train_set_04-03.csv", index_col=0)
data6 = pd.read_csv("/Users/weilu/Research/data/optimization/iter4_normalized_noFrag_iterative_optimization_combined_train_set_04-03.csv", index_col=0)
data7 = pd.read_csv("/Users/weilu/Research/data/optimization/iter5_normalized_noFrag_iterative_optimization_combined_train_set_04-04.csv", index_col=0)


d = pd.concat([
                data_origin.query("Rerun == 1").assign(Scheme="original"), 
                data.query("Rerun == 1").assign(Scheme="iter0"),         
                 data2.query("Rerun == 1").assign(Scheme="iter1"), 
                data3.query("Rerun == 1").assign(Scheme="iter2"), 
                data4.query("Rerun == 1").assign(Scheme="iter3"), 
#                 data5.query("Rerun == 1").assign(Scheme="iter3_90"), 
    data6.query("Rerun == 1").assign(Scheme="iter4"), 
    data7.query("Rerun == 1").assign(Scheme="iter5"), 
              ])
sns.boxplot("Name", "Qw", hue="Scheme", data=d)
# sns.boxplot("Qw", "Name", hue="Scheme", data=d)


Out[19]:
<matplotlib.axes._subplots.AxesSubplot at 0x1a28dddb00>

In [77]:
pre = "/Users/weilu/Research/server/april_2019/"
folder = "iterative_optimization_combined_train_set"
pre = pre + folder + "/"
simulationType = "iter5_normalized_noFrag"
today = datetime.datetime.today().strftime('%m-%d')
# pdb_list, steps = dataset["test"]
pdb_list = dataset["combined"]
# pdb_list = "1FC2C, 1ENH, 2GB1, 2CRO, 1CTF, 4ICB".split(", ")
data = get_data(pre, pdb_list, simType=simulationType, n_rum=10, rerun=2, formatName=True)
data.reset_index(drop=True).to_csv(f"/Users/weilu/Research/data/optimization/{simulationType}_{folder}_{today}.csv")
# data.reset_index(drop=True).to_csv(f"/Users/weilu/Research/data/optimization/withoutContact_{today}.csv")
sns.boxplot("Name", "Qw", data=data.query("Rerun == 1"))


Out[77]:
<matplotlib.axes._subplots.AxesSubplot at 0x1a2030fb70>

In [75]:
pre = "/Users/weilu/Research/server/april_2019/"
folder = "iterative_optimization_combined_train_set"
pre = pre + folder + "/"
simulationType = "iter4_normalized_noFrag"
today = datetime.datetime.today().strftime('%m-%d')
# pdb_list, steps = dataset["test"]
pdb_list = dataset["combined"]
# pdb_list = "1FC2C, 1ENH, 2GB1, 2CRO, 1CTF, 4ICB".split(", ")
data = get_data(pre, pdb_list, simType=simulationType, n_rum=10, rerun=2, formatName=True)
data.reset_index(drop=True).to_csv(f"/Users/weilu/Research/data/optimization/{simulationType}_{folder}_{today}.csv")
# data.reset_index(drop=True).to_csv(f"/Users/weilu/Research/data/optimization/withoutContact_{today}.csv")
sns.boxplot("Name", "Qw", data=data.query("Rerun == 1"))


Out[75]:
<matplotlib.axes._subplots.AxesSubplot at 0x1a221b6908>

In [70]:
pre = "/Users/weilu/Research/server/april_2019/"
folder = "iterative_optimization_combined_train_set"
pre = pre + folder + "/"
simulationType = "iter3_normalized_noFrag_90"
today = datetime.datetime.today().strftime('%m-%d')
# pdb_list, steps = dataset["test"]
pdb_list = dataset["combined"]
# pdb_list = "1FC2C, 1ENH, 2GB1, 2CRO, 1CTF, 4ICB".split(", ")
data = get_data(pre, pdb_list, simType=simulationType, n_rum=10, rerun=2, formatName=True)
data.reset_index(drop=True).to_csv(f"/Users/weilu/Research/data/optimization/{simulationType}_{folder}_{today}.csv")
# data.reset_index(drop=True).to_csv(f"/Users/weilu/Research/data/optimization/withoutContact_{today}.csv")
sns.boxplot("Name", "Qw", data=data.query("Rerun == 1"))


Out[70]:
<matplotlib.axes._subplots.AxesSubplot at 0x1a202d17b8>

In [16]:
pre = "/Users/weilu/Research/server/april_2019/"
folder = "iterative_optimization_combined_train_set"
pre = pre + folder + "/"
simulationType = "original"
today = datetime.datetime.today().strftime('%m-%d')
# pdb_list, steps = dataset["test"]
pdb_list = dataset["combined"]
# pdb_list = "1FC2C, 1ENH, 2GB1, 2CRO, 1CTF, 4ICB".split(", ")
data = get_data(pre, pdb_list, simType=simulationType, n_rum=10, rerun=2, formatName=True)
data.reset_index(drop=True).to_csv(f"/Users/weilu/Research/data/optimization/{simulationType}_{folder}_{today}.csv")
# data.reset_index(drop=True).to_csv(f"/Users/weilu/Research/data/optimization/withoutContact_{today}.csv")
sns.boxplot("Name", "Qw", data=data.query("Rerun == 1"))


Out[16]:
<matplotlib.axes._subplots.AxesSubplot at 0x1a19494a20>

In [71]:
pre = "/Users/weilu/Research/server/april_2019/"
folder = "iterative_optimization_combined_train_set"
pre = pre + folder + "/"
simulationType = "iter3_normalized_noFrag"
today = datetime.datetime.today().strftime('%m-%d')
# pdb_list, steps = dataset["test"]
pdb_list = dataset["combined"]
# pdb_list = "1FC2C, 1ENH, 2GB1, 2CRO, 1CTF, 4ICB".split(", ")
data = get_data(pre, pdb_list, simType=simulationType, n_rum=10, rerun=2, formatName=True)
data.reset_index(drop=True).to_csv(f"/Users/weilu/Research/data/optimization/{simulationType}_{folder}_{today}.csv")
# data.reset_index(drop=True).to_csv(f"/Users/weilu/Research/data/optimization/withoutContact_{today}.csv")
sns.boxplot("Name", "Qw", data=data.query("Rerun == 1"))


Out[71]:
<matplotlib.axes._subplots.AxesSubplot at 0x1a202b66a0>

In [57]:
pre = "/Users/weilu/Research/server/april_2019/"
folder = "iterative_optimization_combined_train_set"
pre = pre + folder + "/"
simulationType = "iter2_normalized_noFrag"
today = datetime.datetime.today().strftime('%m-%d')
# pdb_list, steps = dataset["test"]
pdb_list = dataset["combined"]
# pdb_list = "1FC2C, 1ENH, 2GB1, 2CRO, 1CTF, 4ICB".split(", ")
data = get_data(pre, pdb_list, simType=simulationType, n_rum=10, rerun=2, formatName=True)
data.reset_index(drop=True).to_csv(f"/Users/weilu/Research/data/optimization/{simulationType}_{folder}_{today}.csv")
# data.reset_index(drop=True).to_csv(f"/Users/weilu/Research/data/optimization/withoutContact_{today}.csv")
sns.boxplot("Name", "Qw", data=data.query("Rerun == 1"))


Out[57]:
<matplotlib.axes._subplots.AxesSubplot at 0x1a1bf63eb8>

In [13]:
pre = "/Users/weilu/Research/server/april_2019/"
folder = "iterative_optimization_combined_train_set"
pre = pre + folder + "/"
simulationType = "iter0_normalized_noFrag"
today = datetime.datetime.today().strftime('%m-%d')
# pdb_list, steps = dataset["test"]
pdb_list = dataset["combined"]
# pdb_list = "1FC2C, 1ENH, 2GB1, 2CRO, 1CTF, 4ICB".split(", ")
data = get_data(pre, pdb_list, simType=simulationType, n_rum=10, rerun=2, formatName=True)
data.reset_index(drop=True).to_csv(f"/Users/weilu/Research/data/optimization/{simulationType}_{folder}_{today}.csv")
# data.reset_index(drop=True).to_csv(f"/Users/weilu/Research/data/optimization/withoutContact_{today}.csv")
sns.boxplot("Name", "Qw", data=data.query("Rerun == 1"))


Out[13]:
<matplotlib.axes._subplots.AxesSubplot at 0x104a7f668>

In [14]:
pre = "/Users/weilu/Research/server/april_2019/"
folder = "iterative_optimization_combined_train_set"
pre = pre + folder + "/"
simulationType = "iter1_normalized_noFrag"
today = datetime.datetime.today().strftime('%m-%d')
# pdb_list, steps = dataset["test"]
pdb_list = dataset["combined"]
# pdb_list = "1FC2C, 1ENH, 2GB1, 2CRO, 1CTF, 4ICB".split(", ")
data = get_data(pre, pdb_list, simType=simulationType, n_rum=10, rerun=2, formatName=True)
data.reset_index(drop=True).to_csv(f"/Users/weilu/Research/data/optimization/{simulationType}_{folder}_{today}.csv")
# data.reset_index(drop=True).to_csv(f"/Users/weilu/Research/data/optimization/withoutContact_{today}.csv")
sns.boxplot("Name", "Qw", data=data.query("Rerun == 1"))


Out[14]:
<matplotlib.axes._subplots.AxesSubplot at 0x1a18c17b38>

In [10]:
data.head()


Out[10]:
index Steps Qw Rg Tc Energy Run Name Rerun
0 950 3804000 0.111828 22.666299 23 27.342100 Run0 1r69 0
1 951 3808000 0.087000 23.804092 17 11.928062 Run0 1r69 0
2 952 3812000 0.053962 24.655929 14 45.089979 Run0 1r69 0
3 953 3816000 0.088343 24.288471 21 63.482033 Run0 1r69 0
4 954 3820000 0.118645 24.264631 24 50.847944 Run0 1r69 0

In [11]:
data.tail()


Out[11]:
index Steps Qw Rg Tc Energy Run Name Rerun
45 1995 15984000 0.294303 12.372903 105 -230.151421 Run9 4icb 1
46 1996 15988000 0.290072 12.530187 100 -248.805133 Run9 4icb 1
47 1997 15992000 0.282667 13.151885 90 -237.669696 Run9 4icb 1
48 1998 15996000 0.279217 12.576629 95 -248.688889 Run9 4icb 1
49 1999 16000000 0.294767 12.072510 97 -250.027118 Run9 4icb 1

In [18]:
data = pd.read_csv("/Users/weilu/Research/data/optimization/single_iterative_optimization_old_set_with_frag_03-28.csv", index_col=0)
data2 = pd.read_csv("/Users/weilu/Research/data/optimization/iter7_2_iterative_optimization_old_set_with_frag_03-28.csv", index_col=0)

d = pd.concat([
                data.assign(Scheme="original"), 
                 data2.assign(Scheme="iter7"), 

              ])
sns.boxplot("Name", "Qw", hue="Scheme", data=d)


Out[18]:
<matplotlib.axes._subplots.AxesSubplot at 0x1a1b36dcf8>

In [66]:
data = pd.read_csv("/Users/weilu/Research/data/optimization/single_iterative_optimization_new_set_with_frag_04-02.csv", index_col=0)
data2 = pd.read_csv("/Users/weilu/Research/data/optimization/iter7_2_iterative_optimization_new_set_with_frag_04-01.csv", index_col=0)

d = pd.concat([
                data.assign(Scheme="original"), 
                 data2.assign(Scheme="iter7"), 

              ])
sns.boxplot("Name", "Qw", hue="Scheme", data=d)


Out[66]:
<matplotlib.axes._subplots.AxesSubplot at 0x1a1b3e59b0>

In [61]:
pre = "/Users/weilu/Research/server/april_2019/"
folder = "iterative_optimization_new_set_with_frag"
pre = pre + folder + "/"
simulationType = "iter7_2"
today = datetime.datetime.today().strftime('%m-%d')
# pdb_list, steps = dataset["test"]
pdb_list = dataset["new"]
# pdb_list = "1FC2C, 1ENH, 2GB1, 2CRO, 1CTF, 4ICB".split(", ")
data = get_data(pre, pdb_list, simType=simulationType, n_rum=10)
data.reset_index(drop=True).to_csv(f"/Users/weilu/Research/data/optimization/{simulationType}_{folder}_{today}.csv")
# data.reset_index(drop=True).to_csv(f"/Users/weilu/Research/data/optimization/withoutContact_{today}.csv")
sns.boxplot("Name", "Qw", data=data)


Out[61]:
<matplotlib.axes._subplots.AxesSubplot at 0x1a1be95320>

In [65]:
pre = "/Users/weilu/Research/server/april_2019/"
folder = "iterative_optimization_new_set_with_frag"
pre = pre + folder + "/"
simulationType = "single"
today = datetime.datetime.today().strftime('%m-%d')
# pdb_list, steps = dataset["test"]
pdb_list = dataset["new"]
# pdb_list = "1FC2C, 1ENH, 2GB1, 2CRO, 1CTF, 4ICB".split(", ")
data = get_data(pre, pdb_list, simType=simulationType, n_rum=10)
data.reset_index(drop=True).to_csv(f"/Users/weilu/Research/data/optimization/{simulationType}_{folder}_{today}.csv")
# data.reset_index(drop=True).to_csv(f"/Users/weilu/Research/data/optimization/withoutContact_{today}.csv")
sns.boxplot("Name", "Qw", data=data)


Out[65]:
<matplotlib.axes._subplots.AxesSubplot at 0x1a1bef4940>

In [53]:
location = "/Users/weilu/Research/server/april_2019/iterative_optimization_new_set_with_frag/all_simulations/1fc2/1fc2"
# def relocate(location):
#     fileLocation = location + "/frags.mem"
#     pre = location + "/../"
#     os.system(f"mkdir -p {pre}/fraglib")
#     with open(fileLocation) as f:
#         next(f)
#         next(f)
#         next(f)
#         next(f)
#         for line in f:
#             out = os.system(f"cp {line.split()[0]} {pre}/fraglib/")
#             if out != 0:
#                 print(f"!!Problem!!, {line.split()[0]}")

def relocate(location):
    fileLocation = location + "/frags.mem"
    pre = location + "/../"
    os.system(f"mkdir -p {pre}/fraglib")
    a = pd.read_csv(fileLocation, skiprows=4, sep=" ", names=["location", "i", "j", "sep", "w"])
    b = a["location"].unique()
    for l in b:
        out = os.system(f"cp {l} {pre}/fraglib/")
        if out != 0:
            print(f"!!Problem!!, {line.split()[0]}")

             
relocate(location)

In [64]:
a = ["a", "b"]
print(f"{a}")


['a', 'b']

In [80]:
fastaFile = "/Users/weilu/Research/server/april_2019/complete_2xov/P09391.fasta"
with open(fastaFile) as input_data:
    data = ""
    for line in input_data:
        if(line[0] == ">"):
            print(line)
        elif(line == "\n"):
            pass
        else:
            data += line.strip("\n")
print(len(data))
print(data)


>sp|P09391|GLPG_ECOLI Rhomboid protease GlpG OS=Escherichia coli (strain K12) OX=83333 GN=glpG PE=1 SV=5

276
MLMITSFANPRVAQAFVDYMATQGVILTIQQHNQSDVWLADESQAERVRAELARFLENPADPRYLAASWQAGHTGSGLHYRRYPFFAALRERAGPVTWVMMIACVVVFIAMQILGDQEVMLWLAWPFDPTLKFEFWRYFTHALMHFSLMHILFNLLWWWYLGGAVEKRLGSGKLIVITLISALLSGYVQQKFSGPWFGGLSGVVYALMGYVWLRGERDPQSGIYLQRGLIIFALIWIVAGWFDLFGMSMANGAHIAGLAVGLAMAFVDSLNARKRK

In [81]:
data


Out[81]:
'MLMITSFANPRVAQAFVDYMATQGVILTIQQHNQSDVWLADESQAERVRAELARFLENPADPRYLAASWQAGHTGSGLHYRRYPFFAALRERAGPVTWVMMIACVVVFIAMQILGDQEVMLWLAWPFDPTLKFEFWRYFTHALMHFSLMHILFNLLWWWYLGGAVEKRLGSGKLIVITLISALLSGYVQQKFSGPWFGGLSGVVYALMGYVWLRGERDPQSGIYLQRGLIIFALIWIVAGWFDLFGMSMANGAHIAGLAVGLAMAFVDSLNARKRK'

In [83]:
from Bio.PDB.Polypeptide import one_to_three

In [84]:
one_to_three("A")


Out[84]:
'ALA'

In [88]:
i = 27

In [98]:
t = 123
print(f"!{t: >4}!")


! 123!

In [108]:
from small_script.myFunctions import duplicate_pdb

In [112]:
duplicate_pdb("/Users/weilu/Research/server/april_2019/complete_2xov/2lep.pdb", 
              "/Users/weilu/Research/server/april_2019/complete_2xov/shifted.pdb", offset_z=-50, new_chain="A")

In [107]:
def generate_SEQRES(fastaFile):
    # fastaFile = "/Users/weilu/Research/server/april_2019/complete_2xov/P09391.fasta"
    with open(fastaFile) as input_data:
        data = ""
        for line in input_data:
            if(line[0] == ">"):
                print(line)
            elif(line == "\n"):
                pass
            else:
                data += line.strip("\n")
    i = 0
    template = ""
    length = len(data)
    while i < len(data):
        seq = data[i:i+13]
        a = [one_to_three(r) for r in seq]
        template += f"SEQRES   1 A {length: >4}  " + " ".join(a) + "\n"
        i += 13
    return template

In [121]:
i = 0
template = ""
c = 1
length = len(data)
while i < len(data):
    seq = data[i:i+13]
    a = [one_to_three(r) for r in seq]
    ss = " ".join(a)
    template += f"SEQRES {c: >3} A {length: >4}  {ss: <51}          \n"
    i += 13
    c += 1

In [122]:
print(template)


SEQRES   1 A  276  MET LEU MET ILE THR SER PHE ALA ASN PRO ARG VAL ALA          
SEQRES   2 A  276  GLN ALA PHE VAL ASP TYR MET ALA THR GLN GLY VAL ILE          
SEQRES   3 A  276  LEU THR ILE GLN GLN HIS ASN GLN SER ASP VAL TRP LEU          
SEQRES   4 A  276  ALA ASP GLU SER GLN ALA GLU ARG VAL ARG ALA GLU LEU          
SEQRES   5 A  276  ALA ARG PHE LEU GLU ASN PRO ALA ASP PRO ARG TYR LEU          
SEQRES   6 A  276  ALA ALA SER TRP GLN ALA GLY HIS THR GLY SER GLY LEU          
SEQRES   7 A  276  HIS TYR ARG ARG TYR PRO PHE PHE ALA ALA LEU ARG GLU          
SEQRES   8 A  276  ARG ALA GLY PRO VAL THR TRP VAL MET MET ILE ALA CYS          
SEQRES   9 A  276  VAL VAL VAL PHE ILE ALA MET GLN ILE LEU GLY ASP GLN          
SEQRES  10 A  276  GLU VAL MET LEU TRP LEU ALA TRP PRO PHE ASP PRO THR          
SEQRES  11 A  276  LEU LYS PHE GLU PHE TRP ARG TYR PHE THR HIS ALA LEU          
SEQRES  12 A  276  MET HIS PHE SER LEU MET HIS ILE LEU PHE ASN LEU LEU          
SEQRES  13 A  276  TRP TRP TRP TYR LEU GLY GLY ALA VAL GLU LYS ARG LEU          
SEQRES  14 A  276  GLY SER GLY LYS LEU ILE VAL ILE THR LEU ILE SER ALA          
SEQRES  15 A  276  LEU LEU SER GLY TYR VAL GLN GLN LYS PHE SER GLY PRO          
SEQRES  16 A  276  TRP PHE GLY GLY LEU SER GLY VAL VAL TYR ALA LEU MET          
SEQRES  17 A  276  GLY TYR VAL TRP LEU ARG GLY GLU ARG ASP PRO GLN SER          
SEQRES  18 A  276  GLY ILE TYR LEU GLN ARG GLY LEU ILE ILE PHE ALA LEU          
SEQRES  19 A  276  ILE TRP ILE VAL ALA GLY TRP PHE ASP LEU PHE GLY MET          
SEQRES  20 A  276  SER MET ALA ASN GLY ALA HIS ILE ALA GLY LEU ALA VAL          
SEQRES  21 A  276  GLY LEU ALA MET ALA PHE VAL ASP SER LEU ASN ALA ARG          
SEQRES  22 A  276  LYS ARG LYS                                                  


In [123]:
from Bio.PDB.PDBParser import PDBParser

In [124]:
from pdbfixer import PDBFixer

In [125]:
fromFile = "/Users/weilu/Research/server/april_2019/complete_2xov/original_pdbs/complete.pdb"

In [126]:
fixer = PDBFixer(filename=fromFile)

In [132]:
fixer.findMissingResidues()

In [134]:
chains = list(fixer.topology.chains())

In [135]:
chains


Out[135]:
[<Chain 0>]

In [133]:
fixer.missingResidues.keys()


Out[133]:
dict_keys([])

In [129]:
list(fixer.sequences)


Out[129]:
[<pdbfixer.pdbfixer.Sequence at 0x1a28836fd0>]

In [139]:
chains = [c for c in fixer.topology.chains() if len(list(c.residues())) > 0]
chainWithGaps = {}

# Find the sequence of each chain, with gaps for missing residues.

for chain in chains:
    minResidue = min(int(r.id) for r in chain.residues())
    maxResidue = max(int(r.id) for r in chain.residues())
    residues = [None]*(maxResidue-minResidue+1)
    for r in chain.residues():
        residues[int(r.id)-minResidue] = r.name
    chainWithGaps[chain] = residues

In [145]:
chainSequence = {}
chainOffset = {}
for sequence in fixer.sequences:
    for chain in chains:
        print(chain.id, sequence.chainId)
        if chain.id != sequence.chainId:
            continue
        if chain in chainSequence:
            continue
        print(chain.id, sequence.chainId)
        for offset in range(len(sequence.residues)-len(chainWithGaps[chain])+1):
            if all(a == b or b == None for a,b in zip(sequence.residues[offset:], chainWithGaps[chain])):
                chainSequence[chain] = sequence
                chainOffset[chain] = offset
                break
        if chain in chainSequence:
            break


A A
A A

In [146]:
len(sequence.residues)


Out[146]:
276

In [147]:
len(chainWithGaps[chain])


Out[147]:
271

In [142]:
chainOffset


Out[142]:
{}

In [143]:
chainSequence


Out[143]:
{}

In [138]:
for a in fixer.sequences:
    print(a.residues, len(a.residues), a.id)


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-138-5fff18515a59> in <module>
      1 for a in fixer.sequences:
----> 2     print(a.residues, len(a.residues), a.id)

AttributeError: 'Sequence' object has no attribute 'id'

In [116]:
print(template)


SEQRES   1 A  276  MET LEU MET ILE THR SER PHE ALA ASN PRO ARG VAL ALA         
SEQRES   2 A  276  GLN ALA PHE VAL ASP TYR MET ALA THR GLN GLY VAL ILE         
SEQRES   3 A  276  LEU THR ILE GLN GLN HIS ASN GLN SER ASP VAL TRP LEU         
SEQRES   4 A  276  ALA ASP GLU SER GLN ALA GLU ARG VAL ARG ALA GLU LEU         
SEQRES   5 A  276  ALA ARG PHE LEU GLU ASN PRO ALA ASP PRO ARG TYR LEU         
SEQRES   6 A  276  ALA ALA SER TRP GLN ALA GLY HIS THR GLY SER GLY LEU         
SEQRES   7 A  276  HIS TYR ARG ARG TYR PRO PHE PHE ALA ALA LEU ARG GLU         
SEQRES   8 A  276  ARG ALA GLY PRO VAL THR TRP VAL MET MET ILE ALA CYS         
SEQRES   9 A  276  VAL VAL VAL PHE ILE ALA MET GLN ILE LEU GLY ASP GLN         
SEQRES  10 A  276  GLU VAL MET LEU TRP LEU ALA TRP PRO PHE ASP PRO THR         
SEQRES  11 A  276  LEU LYS PHE GLU PHE TRP ARG TYR PHE THR HIS ALA LEU         
SEQRES  12 A  276  MET HIS PHE SER LEU MET HIS ILE LEU PHE ASN LEU LEU         
SEQRES  13 A  276  TRP TRP TRP TYR LEU GLY GLY ALA VAL GLU LYS ARG LEU         
SEQRES  14 A  276  GLY SER GLY LYS LEU ILE VAL ILE THR LEU ILE SER ALA         
SEQRES  15 A  276  LEU LEU SER GLY TYR VAL GLN GLN LYS PHE SER GLY PRO         
SEQRES  16 A  276  TRP PHE GLY GLY LEU SER GLY VAL VAL TYR ALA LEU MET         
SEQRES  17 A  276  GLY TYR VAL TRP LEU ARG GLY GLU ARG ASP PRO GLN SER         
SEQRES  18 A  276  GLY ILE TYR LEU GLN ARG GLY LEU ILE ILE PHE ALA LEU         
SEQRES  19 A  276  ILE TRP ILE VAL ALA GLY TRP PHE ASP LEU PHE GLY MET         
SEQRES  20 A  276  SER MET ALA ASN GLY ALA HIS ILE ALA GLY LEU ALA VAL         
SEQRES  21 A  276  GLY LEU ALA MET ALA PHE VAL ASP SER LEU ASN ALA ARG         
SEQRES  22 A  276  LYS ARG LYS         


In [ ]:
if i+13 < len(data):
    seq = data[i:i+13]
else:
    seq = data[i:]

In [106]:
"SEQRES   1 A  276  GLY LEU ALA MET ALA PHE VAL ASP SER LEU ASN ALA ARG"[20]


Out[106]:
'L'

In [ ]:
a = [one_to_three(r) for r in seq]
template += "SEQRES   1 A   69  " + " ".join(a[13]) + "\n"

"SEQRES   1 A   69  MET LEU MET ILE THR SER PHE ALA ASN PRO ARG VAL ALA"
"SEQRES   1 A   69  GLY LEU ALA MET ALA PHE VAL ASP SER LEU ASN ALA ARG"
"SEQRES   1 A  276  GLY LEU ALA MET ALA PHE VAL ASP SER LEU ASN ALA ARG"[20]
"SEQRES  21 A  276  GLY LEU ALA MET ALA PHE VAL ASP SER LEU ASN ALA ARG"
"SEQRES  21 A  276  GLY LEU ALA MET ALA PHE VAL ASP SER LEU ASN ALA ARG         "
"SEQRES  21 A  276  GLY LEU ALA MET ALA PHE VAL ASP SER LEU ASN ALA ARG          "