markovmodel / PyEMMA

🚂 Python API for Emma's Markov Model Algorithms 🚂
http://pyemma.org
GNU Lesser General Public License v3.0
307 stars 118 forks source link

IndexError: Index out of bound #1521

Closed rubinanoor9 closed 2 years ago

rubinanoor9 commented 2 years ago

Dear PyEMMA users!

I am following the tutorial " http://www.emma-project.org/latest/legacy-notebooks/applications/pentapeptide_msm/pentapeptide_msm.html" in my own project and following the same strategy as mentioned in it but during analysis I got the error mentioned here: "Traceback (most recent call last): File "", line 1, in File "", line 1, in File "", line 1, in IndexError: index 192 is out of bounds for axis 0 with size 173" by using this "proj_ev_all = [np.hstack([M.eigenvectors_right()[:,i][dtraj] for dtraj in M.discrete_trajectories_full]) for i in range(1, 10)]" command line. I am looking forward to here from you. Thanking You, Regards Rubina

clonker commented 2 years ago

Hi Rubina, it would be good if you could give us a bit more information. How many discrete trajectories do you have? How many Markov states do you use? Another thing to look out for (and I think the source of your issue) is the active_set. You probably don't have a full active set, so you'll have to exclude the frames in dtraj that are not contained before using them with the eigenvectors. Best Moritz

rubinanoor9 commented 2 years ago

Thank you so much for your reply. I have applied different number of clusters (50, 75, 100, 250, 300) but I got similar index error but with different index number, With the 100 number of cluster, I got error; IndexError: index 99 is out of bounds for axis 0 with size 98" and when I am using cluster number=50, I got; IndexError: index 49 is out of bounds for axis 0 with size 48" I am attaching an input script. Thanks in advance. Regards Rubina input-script.odt

clonker commented 2 years ago

This is indeed an issue with the discrete trajectories. You have to map them to the active set before applying them to the eigenvector components. so instead of taking M.discrete_trajectories_full, you take

dtrajs_active = M.discrete_trajectories_active
dtrajs_active_reduced = [dtraj[dtraj != -1] for dtraj in dtrajs_active]
proj_ev_all = [np.hstack([M.eigenvectors_right()[:,i][dtraj] for dtraj in dtrajs_active_reduced]) for i in range(1, min(10, M.eigenvectors_right().shape[1]))]
rubinanoor9 commented 2 years ago

Thank you so much for the help. I have applied this command line as you mentioned, now it did not get error but when I have tried to plot them by using the following command line: fig, axes = plt.subplots(1, 3, figsize=(16,4)) for i, ax in enumerate(axes): plot_sampled_function(xall, yall, proj_ev_all[i], ax=ax, cbar=False, cmap=plt.cm.Blues) plot_labels(ax)

I got error, which is:

IndexError Traceback (most recent call last) /tmp/ipykernel_29983/3979245165.py in 1 fig, axes = plt.subplots(1, 3, figsize=(16,4)) 2 for i, ax in enumerate(axes): ----> 3 plot_sampled_function(xall, yall, proj_ev_all[i], ax=ax, cbar=False, cmap=plt.cm.Blues) 4 plot_labels(ax)

/tmp/ipykernel_29983/3546841851.py in plot_sampled_function(xall, yall, zall, ax, nbins, nlevels, cmap, cbar, cbar_label) 18 # average over bins 19 for t in range(len(xall)): ---> 20 z[xI[t], yI[t]] += zall[t] 21 N[xI[t], yI[t]] += 1.0 22 with warnings.catch_warnings() as cm:

IndexError: index 164687 is out of bounds for axis 0 with size 164687

I am also new user of python, so not be able to solve this issue. Thanks in advance.

thempel commented 2 years ago

I believe that you are trying to plot the reduced projected eigenvectors (which are reduced to the active set states) as a function of the un-reduced x and y coordinates xall and yall. That means that your x and y-coordinates have more points than the z-coordinate. Therefore, you got to reduce the x-y coordinates in the same way, e.g. by

xall_reduced = xall[np.concatenate(dtrajs_active) != -1]
yall_reduced = yall[np.concatenate(dtrajs_active) != -1]

Then, call the plot function plot_sampled_function by replacing xall -> xall_reduced and yall -> yall_reduced. (Disclaimer: I did not test this code.)

A note of attention: These reduced trajectories should be used for plotting only. The dynamics is perturbed by removing inactive states, so one should not use them for estimating MSMs or the like.

rubinanoor9 commented 2 years ago

Thank you so much. Now the problem has been resolved based on your suggestion. Thanks again.

clonker commented 2 years ago

You're welcome! Closing this now.