MasterMSM
MasterMSM is a Python package for building Markov state models (MSMs) from molecular dynamics trajectories, using a formulation based on the chemical master equation. Besides the usual transition matrix, it estimates the rate matrix of the model, which gives direct access to rate coefficients, committors and reactive fluxes.
Full documentation is at mastermsm.readthedocs.io.
Features
- Trajectory handling: read MD trajectories through MDTraj or discrete state trajectories from file.
- Featurization and dimensionality reduction: backbone torsions and contacts; PCA and TICA.
- Discretization: assignment to Ramachandran basins with transition-based assignment (suited to small peptides), k-means and HDBSCAN clustering. Different protocols can be run on the same data and compared.
- Model estimation: count and transition matrices at any lag time; rate matrices from a Taylor expansion or from the maximum likelihood propagator-based (MLPB) method; bootstrap errors for relaxation times and equilibrium populations.
- Validation: convergence of relaxation times with lag time, Chapman-Kolmogorov test, autocorrelation functions of the eigenmodes.
- Kinetics: committors, reactive fluxes and rates between sets of states; sensitivity analysis of the network.
- Coarse-graining: few-state models from the eigenvectors of the MSM.
Installation
MasterMSM requires Python >= 3.10 and is installed from
PyPI with pip:
pip install MasterMSM
To work on the code, install it from source instead:
git clone https://github.com/BioKT/MasterMSM
cd MasterMSM
pip install -e .
The dependencies are installed automatically by pip: numpy, scipy,
matplotlib, networkx, mdtraj and scikit-learn.
If you use conda, you may prefer to install them from conda-forge
first:
conda install -c conda-forge numpy scipy matplotlib \
networkx mdtraj scikit-learn
HDBSCAN clustering additionally needs the optional
hdbscan package
(pip install "MasterMSM[hdbscan]", or pip install hdbscan).
Quick start
The script below builds an MSM for the alanine dipeptide from a short MD trajectory (downloaded from OSF on first use).
from mastermsm.trajectory import traj
from mastermsm.msm import msm
from mastermsm.fewsm import fewsm
from mastermsm.test import download_data as dd
if __name__ == "__main__":
# 1. Load the trajectory and assign frames to Ramachandran states
dd.download_osf_alaTB()
tr = traj.TimeSeries(top=dd._DATA_DIR + "/alaTB.gro",
xtc=dd._DATA_DIR + "/alaTB.xtc")
tr.discretize(states=["A", "E", "L"])
tr.find_keys()
# 2. Build the MSM at a lag time of 10 ps (units of the trajectory)
smsm = msm.SuperMSM([tr])
lagt = 10
smsm.do_msm(lagt)
model = smsm.msms[lagt]
model.do_trans() # transition matrix and its eigenvalues
model.boots() # bootstrap errors
print(model.keep_keys) # states in the model: ['A', 'E', 'L']
print(model.tauT) # relaxation times, ~794 and ~55 ps
print(model.tau_std)
print(model.peqT) # equilibrium populations
# 3. Rate matrix, committors and flux between E and A
model.do_rate() # method='Taylor' (default) or 'MLPB'
print(model.rate)
model.do_pfold(FF=["A"], UU=["E"])
print(model.pfold, model.kf)
# 4. Coarse-grain into a two-state model
two_state = fewsm.FEWSM(parent=model, N=2)
print(two_state.macros)
# 5. Validate: relaxation times as a function of lag time
smsm.convergence_test(time=[5, 10, 20, 50, 100], error=True)
for lt in sorted(smsm.msms):
print(lt, smsm.msms[lt].tauT)
MasterMSM uses multiprocessing, so scripts need the
if __name__ == "__main__": guard shown above. This is not required
in a Jupyter notebook.
Examples
The examples folder contains Jupyter notebooks:
| Folder | Content |
|---|---|
| alanine_dipeptide | Complete workflow on the simplest peptide model: discretization, MSM, validation, rate matrix (Taylor and MLPB) |
| alanine_pentapeptide | Featurization, TICA and comparison of discretization protocols |
| bistable_potential | Brownian dynamics on one and two dimensional two-state potentials |
| schutte_potential | Brownian dynamics on the one dimensional Schütte potential |
Most of the data are hosted at OSF; each notebook says where its data come from. The Brownian dynamics data for the bistable and Schütte potentials can be fetched with
python examples/download_data.py
Testing
The tests use pytest and download a small amount of MD data on the
first run:
pip install pytest
pytest --pyargs mastermsm
Contributing
Development takes place on the develop branch; master holds the
releases. Bug reports and pull requests (against develop) are welcome
on GitHub.
Citation
If you use MasterMSM in your work, please cite:
@article{mastermsm,
author = "David De Sancho and Anne Aguirre",
title = "{MasterMSM: A Package for Constructing Master Equation Models of Molecular Dynamics}",
year = "2019",
month = "6",
journal = "J. Chem. Inf. Model.",
url = "https://doi.org/10.1021/acs.jcim.9b00468",
doi = "10.1021/acs.jcim.9b00468"
}
Contributors
- David De Sancho
- Anne Aguirre
- Ion Mitxelena
License
MasterMSM is distributed under the GNU General Public License, version 2. See LICENSE.
Metadata
Release files for MasterMSM 2.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mastermsm-2.0.1.tar.gz | 66.3 kB | With provenance | Details for mastermsm-2.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mastermsm-2.0.1-py3-none-any.whl | Python 3 | none | any | Details for mastermsm-2.0.1-py3-none-any.whl |
Total release size: 135.1 kB
Release files / mastermsm-2.0.1.tar.gz
| Download URL | mastermsm-2.0.1.tar.gz |
|---|---|
| Size | 66.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d09f65e57401d25d590d1e6e9f30525efa81c3a63c1930ca6b963644b9aa64a3
|
|
BLAKE2b-256 checksum How to use checksums |
09c29985aed889e476db4d6d142641ef76e0ddc37e9b0f76ef9ef2c02760f807
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.
Transparency logRelease files / mastermsm-2.0.1-py3-none-any.whl
| Download URL | mastermsm-2.0.1-py3-none-any.whl |
|---|---|
| Size | 68.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f04310ef2e4787f42f7bdef4f70a07c63ec8853c886941ce3cb5acadc3a486dd
|
|
BLAKE2b-256 checksum How to use checksums |
ae6f6d6ba34843db963792b5c4b9a8c9ae6b86346009007afe26b09a4ab42832
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.
Transparency logSecurity for MasterMSM 2.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for mastermsm-2.0.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.