Beispiel #1
0
def ensure_connectivity_msm(msm):
    if msm.nstates_full == msm.nstates:
        return msm.stationary_distribution
    else:
        counts = msm.count_matrix_full
        counts += 1 / counts.shape[0]
        trans = utils.buildRevTransitionMatrix(counts)
        _, eic = getSortedEigen(trans)
        return getStationaryDistr(eic[:, 0])
Beispiel #2
0
import numpy as np
from scipy import linalg
from collections import Counter
import toy_matrices as mat
from AdaptivePELE.analysis import autoCorrelation as autoC
from AdaptivePELE.freeEnergies import runMarkovChainModel as run
from AdaptivePELE.freeEnergies import utils
import time
import matplotlib.pyplot as plt

plt.style.use("ggplot")

C = mat.pre_docking
n = C.shape[0]
# T = run.buildTransitionMatrix(C)
T = utils.buildRevTransitionMatrix(C.astype(np.float))
eigenvals, eigenvectors = linalg.eig(T, left=True, right=False)
sortedIndices = np.argsort(eigenvals)[::-1]
# stationary distribution
goldenStationary = run.getStationaryDistr(eigenvectors[:, sortedIndices[0]])

test_initial = False
run_simulation = True
# test generation of initial structures according to a distribution
numberOfSimulations = 127
possible_state = []
for l in range(n):
    possible_state.extend([
        l for _ in range(
            np.round(goldenStationary[l] * numberOfSimulations).astype(int))
    ])
Beispiel #3
0
def estimateTransitionMatrix(trajectories, n, tau, symm=True):
    C = estimateCountMatrix(trajectories, n, tau) + 1. / n
    if symm:
        return utils.buildRevTransitionMatrix(C)
    return buildTransitionMatrix(C)
def reestimate_transition_matrix(count_matrix):
    count_matrix += 1 / float(count_matrix.shape[0])
    return utils.buildRevTransitionMatrix(count_matrix)
Beispiel #5
0
def main(path, native, resname, nEigen, path_sasa):
    # Z = np.array([[4380, 153, 15, 2, 0, 0], [211, 4788, 1, 0, 0, 0], [169, 1, 4604, 226, 0, 0],
    #               [3, 13, 158, 4823, 3, 0], [0, 0, 0, 4, 4978, 18], [7, 5, 0, 0, 62, 4926]])
    MSM = utilities.readClusteringObject(os.path.join(path, "MSM_object_0.pkl"))
    Z = MSM.count_matrix_full
    np.set_printoptions(precision=4)
    m = 100
    k = Z.shape[0]
    alpha = 1/float(k)
    U_counts = Z + alpha
    w = U_counts.sum(axis=1)
    P_rev = utils.buildRevTransitionMatrix(U_counts)
    P = U_counts / w[:, np.newaxis]
    P = P_rev
    eigvalues, _ = np.linalg.eig(P)
    eigvalues.sort()
    eigvalues = eigvalues[::-1]
    eigvalues_rev, _ = np.linalg.eig(P_rev)
    eigvalues_rev.sort()
    eigvalues_rev = eigvalues_rev[::-1]
    ek = np.zeros(k)
    ek[k-1] = 1.0
    variance = []
    contribution = []
    nEigs = 10
    for index in range(1, nEigs):
        A = P - eigvalues[index]*np.eye(k)
        q = calculate_q(A, P, k, ek)
        score = (q/(w+1))-(q/(w+1+m))
        norm_q = q/q.sum()
        contribution.append(score/score.sum())
        variance.append(norm_q)
    sasa = getSASAvalues(os.path.join(path, "representative_structures", "representative_structures_0.dat"), 4, path_sasa)
    pdb_native = atomset.PDB()
    pdb_native.initialise(u"%s" % native, resname=resname)
    minim = pdb_native.getCOM()
    clusters = np.loadtxt(os.path.join(path, "clusterCenters_0.dat"))
    distance = np.linalg.norm(clusters-minim, axis=1)

    variance = np.array(variance[:nEigen])
    variance = variance.sum(axis=0)
    variance /= variance.sum()
    print(variance)
    # states = variance.argsort()[-1:-10:-1]
    # print(" ".join(["structures/cluster_%d.pdb" % st for st in states]))
    f, axarr = plt.subplots(1, 2)
    axarr[0].scatter(distance, variance)
    axarr[0].set_xlabel("Distance to minimum")
    axarr[0].set_ylabel("Variance")
    axarr[1].scatter(sasa, variance)
    axarr[1].set_xlabel("SASA")
    axarr[0].set_ylabel("Variance")
    f.suptitle("Variance for eigenvalues 2-%d" % (nEigen+1))
    # for ind, var in enumerate(variance[:5]):
    #     f, axarr = plt.subplots(1, 2)
    #     axarr[0].scatter(distance, var)
    #     axarr[0].set_xlabel("Distance to minimum")
    #     axarr[0].set_ylabel("Variance")
    #     axarr[1].scatter(sasa, var)
    #     axarr[1].set_xlabel("SASA")
    #     axarr[0].set_ylabel("Variance")
    #     f.suptitle("Variance for eigenvalue %d" % (ind+2))
    plt.show()