Protein folding process analysis with MSM#

In this tutorial, we demonstrate how to use the HTMD code for analysing a protein folding process, in this case, of the protein Villin.

To analyze, one needs MD trajectories first, which can be generated with HTMD. Here, we already provide the trajectories (data) to analyze. You can download the data from here (Warning: 3GB filesize)

Alternatively, you can download the dataset using wget.

import os
assert os.system('wget -rcN -np -nH -q --cut-dirs=2 -R index.html* http://pub.htmd.org/tutorials/protein-folding-analysis/datasets/') == 0

Getting started#

First we import the modules we are going to need for the tutorial

from htmd.ui import *
config(viewer='webgl')
2022-09-23 09:03:30,833 - numexpr.utils - INFO - Note: NumExpr detected 12 cores but "NUMEXPR_MAX_THREADS" not set, so enforcing safe limit of 8.
2022-09-23 09:03:30,834 - numexpr.utils - INFO - NumExpr defaulting to 8 threads.
Please cite HTMD: Doerr et al.(2016)JCTC,12,1845. https://dx.doi.org/10.1021/acs.jctc.6b00049

HTMD Documentation at: https://www.htmd.org/docs/latest/

You are on the latest HTMD version (unpackaged : /home/sdoerr/Work/htmd/htmd).

Creating a simulation list#

For the purposes of an analysis, full atom information is required by HTMD. Therefore each simulation trajectory has to be associated with a corresponding PDB file. Additionally, if you plan to run adaptive, each trajectory needs to be associated with an input directory which contains the files used to run the simulations. The simList function allows us to make these associations

sims = simlist(glob('data/*/'), glob('input/*/'), glob('input/*/'))

Filtering trajectories#

Typically waters are removed from the trajectories as they are not used in the analysis and it helps speed up further calculations. These filtered trajectories are written into a new directory. The advantage of filtering is that if your input structures only differ in the number of water molecules, you can produce a single unique pdb file for all simulations once you remove the waters, which will speed up calculations. This step is not necessary for the analysis and you can skip it if you don’t mind the slowdown in calculations. In that case replace in the following commands the fsims variable with sims.

fsims = simfilter(sims, './filtered/', filtersel='not water')

In this tutorial, in order for the trajectories to be downloaded in a timely manner, we provide only the filtered trajectories which are stored in three separate dataset folders. Therefore we will skip the above two commands and construct the simulation list directly from the filtered trajectories.

sets = glob('datasets/*/')
sims = []
for s in sets:
    fsims = simlist(glob(s + '/filtered/*/'), 'datasets/1/filtered/')
    sims = simmerge(sims, fsims)
Creating simlist: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 708/708 [00:19<00:00, 36.13it/s]
Creating simlist: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 710/710 [00:19<00:00, 35.93it/s]
Creating simlist: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 719/719 [00:19<00:00, 36.23it/s]

Calculating metrics#

To build a Markov state model we need to project the atom coordinates onto a lower dimensional space which can be used for clustering the conformations into a set of states. Here we have selected to use the carbon alpha atoms of the protein. This will calculate contacts between all carbon alpha atoms.

metr = Metric(sims)
metr.set(MetricSelfDistance('protein and name CA', metric='contacts', periodic='chains'))
data = metr.project()
Projecting trajectories: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████| 2137/2137 [02:04<00:00, 17.15it/s]
2022-09-23 09:06:39,662 - htmd.projections.metric - INFO - Frame step 0.1ns was read from the trajectories. If it looks wrong, redefine it by manually setting the MetricData.fstep property.

Here we provide the frame-step in nanoseconds i.e. the time that passes between two consecutive frames in a trajectory. This is automatically read from the trajectories, however not all trajectories contain the correct fstep so it can be useful to manually define it like here.

data.fstep = 0.1

Removing trajectories#

Sometimes the set of trajectories can contain trajectories of incorrect length. These are typically corrupted trajectories and are removed.

The plotTrajSizes method plots all trajectory lengths sorted

data.plotTrajSizes()
../../_images/protein-folding-analysis_19_0.png

dropTraj has multiple options for removing simulations from the dataset. Here we use it to remove all trajectories whose length is not equal to the mode length.

data.dropTraj()
2022-09-23 09:06:40,637 - htmd.metricdata - INFO - Dropped 7 trajectories from 2137 resulting in 2130
array([ 168,  472,  709, 1507, 1601, 2100, 2111])

TICA#

TICA is a method that can be used to improve the clustering of the conformations. This is done by projecting the data onto a lower-dimensional space which separates well the metastable minima and places clusters on the transition regions.

tica = TICA(data, 2, units='ns')
dataTica = tica.project(3)

Bootstrapping#

If we want to bootstrap our calculations we can at this point drop a random 20% of the trajectories and do the rest of the analysis multiple times to see if the results are consistent. Alternatively we can keep on using dataTica in the following commands.

dataBoot = dataTica.bootstrap(0.8)

Clustering conformations#

Once we have cleaned the dataset we proceed to cluster the conformations.

Here we use the mini-batch kmeans clustering algorithm to produce 1000 clusters.

dataBoot.cluster(MiniBatchKMeans(n_clusters=1000))

Building the Markov model#

After clustering it is time to build the Markov model.

model = Model(dataBoot)

Before constructing the Markov model we need to choose the lag-time at which it will be built. The lag-time is typically chosen by looking at the implied timescale (ITS) plot and selecting a lag-time at which the top timescales start converging. By constructing Markov models at various lag times HTMD creates a plot which shows the slowest implied timescales of each Markov model at various lag times. If a model is Markovian at a specific lag time, the implied timescales should stay unchanged for any higher lag times. Therefore, given an implied timescales plot, the user can monitor the convergence and choose the lag time at which to construct his Markov model, typically the Markov time which is the shortest lag time at which the timescales converge. Too large lag times can reduce the temporal resolution of the Markov model and can create more statistical uncertainty due to fewer transition counts and thus instability in the implied timescales.

model.plotTimescales()
Estimating Timescales: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████| 26/26 [05:29<00:00, 12.69s/it]
/home/sdoerr/miniconda3/envs/htmd3.10/lib/python3.10/site-packages/deeptime/markov/tools/analysis/_api.py:256: UserWarning: truncated eigendecomposition to contain 7 components
  warnings.warn('truncated eigendecomposition to contain %s components' % new_k, category=UserWarning)
../../_images/protein-folding-analysis_35_1.png

After seeing the ITS plot we decide on a lag-time of 25ns. A jump at the end of the timescales simply indicates that at such high lag times the statistics are unreliable and we can ignore the jump by picking the earliest lagtime where the ITS converge. Additionally the ITS plot showed us that there is a separation between 3 slow timescales and the rest of the timescales which are fast. Therefore we choose to lump our microstates together into 4 macrostates.

model.markovModel(25, 4, units='ns')
2022-09-23 09:13:27,665 - htmd.model - INFO - 100.0% of the data was used
2022-09-23 09:13:27,800 - htmd.model - INFO - Number of trajectories that visited each macrostate:
2022-09-23 09:13:27,801 - htmd.model - INFO - [  95  534  113 1653]

We can also visualize the equilibrium populations of each macrostate using the following command

model.eqDistribution()
../../_images/protein-folding-analysis_39_0.png
array([0.00237803, 0.10927565, 0.22690892, 0.66143739])

Once we have a Markov model we can plot the free energy surface by projecting it on any of our projected coordinates. For example to plot it on the first two TICA coordinates we call it like this.

model.plotFES(0, 1, temperature=360)
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1000/1000 [00:09<00:00, 102.38it/s]
../../_images/protein-folding-analysis_41_1.png

We can also plot the micro and macrostates on top of the FES by setting states=True

model.plotFES(0, 1, temperature=360, states=True)
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1000/1000 [00:09<00:00, 102.87it/s]
../../_images/protein-folding-analysis_43_1.png

Visualizing the states#

To see what the states look like we can use the viewStates method. We load the macrostates and add a protein representation.

model.viewStates(protein=True)
Getting state Molecules: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████| 4/4 [00:04<00:00,  1.17s/it]
HBox(children=(Checkbox(value=True, description='macro 0'), Checkbox(value=True, description='macro 1'), Check…
NGLWidget()

Calculating the kinetics#

One of the major advantages of Markov state models is that they can provide quantitative results about the kinetics between states.

Provide the Kinetics constructor with the system temperature. It automatically then calculates the source and sink states.

kin = Kinetics(model, temperature=360)
2022-09-23 09:13:59,915 - htmd.kinetics - INFO - Detecting source state...
2022-09-23 09:14:01,520 - htmd.kinetics - INFO - Guessing the source state as the state with minimum contacts.
2022-09-23 09:14:01,522 - htmd.kinetics - INFO - Source macro = 3
2022-09-23 09:14:01,522 - htmd.kinetics - INFO - Detecting sink state...
2022-09-23 09:14:01,525 - htmd.kinetics - INFO - Sink macro = 2

To see the rates between the source and sink states we use the getRates method.

r = kin.getRates()
print(r)
2022-09-23 09:14:01,562 - htmd.kinetics - INFO - Calculating rates between source: [3] and sink: [2] states.
mfpton = 1.42E+03 (ns)
mfptoff = 2.38E+02 (ns)
kon = 7.06E+05 (1/M 1/s)
koff = 4.19E+06 (1/s)
koff/kon = 5.94E+00 (M)
kdeq = 2.91E+00 (M)
g0eq = 0.77 (kcal/M)

To plot the free energies and mean first passage times of all state use the plotRates() method.

kin.plotRates()
../../_images/protein-folding-analysis_53_0.png ../../_images/protein-folding-analysis_53_1.png ../../_images/protein-folding-analysis_53_2.png

To visualize the kinetic flux pathways between the source and sink states, use the plotFluxPathways method:

kin.plotFluxPathways()
../../_images/protein-folding-analysis_55_0.png
Path flux           %path   %of total       path
0.01819041899193386 100.0%  100.0%          [3 2]

And this concludes the protein folding tutorial.