Skip to main content

CI codecov Documentation Status

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. Install it from conda-forge with conda:

conda install -c conda-forge mastermsm

or from PyPI with pip:

pip install MasterMSM

Either installs the dependencies: numpy, scipy, matplotlib, networkx, mdtraj and scikit-learn.

To work on the code, install it from source instead:

git clone https://github.com/BioKT/MasterMSM
cd MasterMSM
pip install -e .

HDBSCAN clustering additionally needs the optional hdbscan package (conda install -c conda-forge hdbscan, or pip install "MasterMSM[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

The data go to $MASTERMSM_TEST_DATA if set. To run offline, set MASTERMSM_NO_DOWNLOAD=1: tests whose data are missing are skipped.

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"
}

If you use HDBSCAN discretization (Discretizer.hdbscan), please also cite:

@article{mitxelena2021markov,
author = "Ion Mitxelena and Xabier L{\'o}pez and David De Sancho",
title = "{Markov state models from hierarchical density-based assignment}",
year = "2021",
journal = "J. Chem. Phys.",
volume = "155",
number = "5",
pages = "054102",
url = "https://doi.org/10.1063/5.0056748",
doi = "10.1063/5.0056748"
}

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.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for MasterMSM 2.1.0
File Size Uploaded Provenance Actions
mastermsm-2.1.0.tar.gz 71.0 kB With provenance Details for mastermsm-2.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for MasterMSM 2.1.0
File Interpreter ABI Platform Actions
mastermsm-2.1.0-py3-none-any.whl Python 3 none any Details for mastermsm-2.1.0-py3-none-any.whl

Total release size: 144.3 kB

Release files / mastermsm-2.1.0.tar.gz

Download URL mastermsm-2.1.0.tar.gz
Size 71.0 kB
Tags Source
SHA-256 checksum
How to use checksums
cb53d8317041c8abd433ed0080cd6609e8d8a534ec093fd5a8a30a739983d490
BLAKE2b-256 checksum
How to use checksums
91cf7c84cf58e21905e02cb1a54bcc77d85277178d1b90da380493c356d55824
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 18, 2026.

Transparency log

Release files / mastermsm-2.1.0-py3-none-any.whl

Download URL mastermsm-2.1.0-py3-none-any.whl
Size 73.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a4eb768af8a93699ea5783b2324b43ad8d06270da8721c41f18e771467c126b7
BLAKE2b-256 checksum
How to use checksums
83cf270a90c7a6105b09e7ccd693a4f0c27fb49b8fd1e398d4ab5bbd77e6c04a
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 18, 2026.

Transparency log

Security for MasterMSM 2.1.0

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.

Select from 2 files

Attestation for mastermsm-2.1.0.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 18, 2026.

Transparency log

A 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.

Release history Release notifications | RSS feed

This release

2.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page