Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Tutorial for Analyzing MD Trajectories Using Deeptime #294

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 130 additions & 0 deletions examples/md_trajectory_tutorial.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Tutorial: Analyzing MD Trajectories with Deeptime\n",
"\n",
"This tutorial demonstrates how to analyze Molecular Dynamics (MD) trajectories using Deeptime. We will perform Time-lagged Independent Component Analysis (TICA) on an example trajectory using MDAnalysis and Deeptime.\n",
"\n",
"### Prerequisites\n",
"- Install Deeptime: `pip install deeptime`\n",
"- Install MDAnalysis: `pip install MDAnalysis`\n",
"\n",
"### Steps\n",
"1. Load MD trajectory using MDAnalysis.\n",
"2. Perform TICA using Deeptime.\n",
"3. Visualize the results.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Requirement already satisfied: pip in c:\\users\\aster\\appdata\\local\\programs\\python\\python37\\lib\\site-packages (24.0)\n",
"Requirement already satisfied: setuptools in c:\\users\\aster\\appdata\\local\\programs\\python\\python37\\lib\\site-packages (68.0.0)\n",
"Collecting Cython\n",
" Downloading Cython-3.0.10-cp37-cp37m-win_amd64.whl.metadata (3.2 kB)\n",
"Downloading Cython-3.0.10-cp37-cp37m-win_amd64.whl (2.7 MB)\n",
" ---------------------------------------- 2.7/2.7 MB 828.5 kB/s eta 0:00:00\n",
"Installing collected packages: Cython\n",
"Successfully installed Cython-3.0.10\n"
]
}
],
"source": [
"\n",
"\n",
"# Upgrade pip and setuptools\n",
"!pip install --upgrade pip setuptools\n",
"\n",
"# Install Cython\n",
"!pip install Cython\n",
"\n",
"# Install MDAnalysis\n",
"!pip install MDAnalysis\n",
"\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Load an example trajectory using MDAnalysis\n",
"u = mda.Universe('topology_file.pdb', 'trajectory_file.xtc')\n",
"\n",
"# Select atoms or residues to analyze (e.g., protein)\n",
"atoms = u.select_atoms('protein')\n",
"\n",
"# Create a matrix to store the data\n",
"data = []\n",
"\n",
"# Iterate through trajectory frames and store positions\n",
"for ts in u.trajectory:\n",
" data.append(atoms.positions)\n",
"\n",
"# Convert data to numpy array\n",
"data = np.array(data)\n",
"\n",
"# Perform TICA\n",
"tica = TICA(lag_time=10, dim=2)\n",
"tica_model = tica.fit(data).fetch_model()\n",
"\n",
"# Transform the data\n",
"transformed_data = tica_model.transform(data)\n",
"\n",
"# Plot the transformed data\n",
"plt.scatter(transformed_data[:, 0], transformed_data[:, 1])\n",
"plt.xlabel('TIC 1')\n",
"plt.ylabel('TIC 2')\n",
"plt.title('TICA of MD Trajectory')\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading