markovmodel / PyEMMA

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

Issue on the dtrajs_concatenated #1499

Closed andresilvapimentel closed 3 years ago

andresilvapimentel commented 3 years ago

I concatenated the cluster.dtrajs array by using the following code:

cluster = pyemma.coordinates.cluster_kmeans( tica_output, k=75, max_iter=50, stride=10, fixed_seed=1) dtrajs_concatenated = np.concatenate(cluster.dtrajs)

By analyzing the stationary distribution and the free energy computed over the first two TICA coordinates, the stationary distribution, π, was stored in msm.pi or msm.stationary_distribution. I tried to compute the free energy landscape by re-weighting the trajectory frames with stationary probabilities from the MSM (returned by msm.trajectory_weights()) by using the code:

fig, axes = plt.subplots(1, 2, figsize=(10, 4), sharex=True, sharey=True) pyemma.plots.plot_contour( tica_concatenated[:, :2].T, msm.pi[dtrajs_concatenated], ax=axes[0], mask=True, cbar_label='stationary distribution') pyemma.plots.plot_free_energy( tica_concatenated[:, :2].T, weights=np.concatenate(msm.trajectory_weights()), ax=axes[1], legacy=False) for ax in axes.flat: ax.set_xlabel('IC 1') axes[0].set_ylabel('IC 2') axes[0].set_title('Stationary distribution', fontweight='bold') axes[1].set_title('Reweighted free energy surface', fontweight='bold') fig.tight_layout()

However, I got the following error:

IndexError Traceback (most recent call last)

in () 2 pyemma.plots.plot_contour( 3 *tica_concatenated[:, :2].T, ----> 4 msm.pi[dtrajs_concatenated], 5 ax=axes[0], 6 mask=True, IndexError: index 49 is out of bounds for axis 0 with size 47 How can I solve this issue?
clonker commented 3 years ago

The error occurs likely because two of your states were not connected. You can use msm.pi[np.concatenate(msm.dtrajs_active)] instead.