-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #108 from jeiros/add-trace2d-plot
[WIP] Add trace2d plot
- Loading branch information
Showing
4 changed files
with
140 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
""" | ||
Two dimensional trace plot | ||
=============== | ||
""" | ||
from msmbuilder.example_datasets import FsPeptide | ||
from msmbuilder.featurizer import DihedralFeaturizer | ||
from msmbuilder.decomposition import tICA | ||
from msmbuilder.cluster import MiniBatchKMeans | ||
from msmbuilder.msm import MarkovStateModel | ||
from matplotlib import pyplot as pp | ||
import numpy as np | ||
|
||
import msmexplorer as msme | ||
|
||
rs = np.random.RandomState(42) | ||
|
||
# Load Fs Peptide Data | ||
trajs = FsPeptide().get().trajectories | ||
|
||
# Extract Backbone Dihedrals | ||
featurizer = DihedralFeaturizer(types=['phi', 'psi']) | ||
diheds = featurizer.fit_transform(trajs) | ||
|
||
# Perform Dimensionality Reduction | ||
tica_model = tICA(lag_time=2, n_components=2) | ||
tica_trajs = tica_model.fit_transform(diheds) | ||
|
||
# Plot free 2D free energy (optional) | ||
txx = np.concatenate(tica_trajs, axis=0) | ||
ax = msme.plot_free_energy( | ||
txx, obs=(0, 1), n_samples=100000, | ||
random_state=rs, | ||
shade=True, | ||
clabel=True, | ||
clabel_kwargs={'fmt': '%.1f'}, | ||
cbar=True, | ||
cbar_kwargs={'format': '%.1f', 'label': 'Free energy (kcal/mol)'} | ||
) | ||
# Now plot the first trajectory on top of it to inspect it's movement | ||
msme.plot_trace2d( | ||
data=tica_trajs[0], ts=0.2, ax=ax, | ||
scatter_kwargs={'s': 2}, | ||
cbar_kwargs={'format': '%d', 'label': 'Time (ns)', | ||
'orientation': 'horizontal'}, | ||
xlabel='tIC 1', ylabel='tIC 2' | ||
) | ||
# Finally, let's plot every trajectory to see the individual sampled regions | ||
f, ax = pp.subplots() | ||
msme.plot_trace2d(tica_trajs, ax=ax, xlabel='tIC 1', ylabel='tIC 2') | ||
pp.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters