- 
                Notifications
    You must be signed in to change notification settings 
- Fork 42
          Add UserGuide documentation for IMDReader 
          #430
        
          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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -9,3 +9,4 @@ Other | |
| :maxdepth: 1 | ||
|  | ||
| parmed_sim | ||
| streaming_imd | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,325 @@ | ||||||
| { | ||||||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is IMD-coords essential for GROMACS? Will the stream fail out without it? Or do you just mean its essential for this example? 
 Maybe it's worth specifying exactly what's necessary for this example: you need to have coordinates turned on regardless of simulation engine, you need to have freq set to 1, and you need to turn off coordinate unwrapping (so that there are consistent configs across engines) 
 Also, should this link the docs for each of the simulation engines? Reply via ReviewNB There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Link to 
 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line #42. # simple_imd_analysis() 
 Why is this commented out? Will github run it automatically as a part of docstring tests if it's uncommented? Reply via ReviewNB There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The notebook needs to be primarily a readable document, don't expect people to edit it. Thus, it should show _working code_, so avoid "un-commenting something so that it works". 
 If there are issues with it being run, comment on the PR and then let's look for a solution. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line #41. potential_energy = -1000 + np.random.normal(0, 50) Not all simulation engines implement energy packet, so maybe remove this? Reply via ReviewNB There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's true but for the ones that do, we should show how one can get the information. 
 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line #51. ax1.clear() Just double checking, did you test this method of live updating plot locally? Looks a bit different than what we did in workshop 
 https://github.com/MDAnalysis/imd-workshop-2024/blob/main/activity/graph_utils.py Reply via ReviewNB There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Include links to the authoritative docs — imdclient and IMDReader in the main docs. 
 The imdclient package should be installed as a dependency of MDAnalysis (in 2.10.0...IIRC( Reply via ReviewNB There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For all codes: 
 1) Do we want to send IMD data every integrator step in the example? It's ok to do so but write some text above that says explicitly that we are doing it in the example but in production simulations this may be every 5 or every 10 steps. 
 For GROMACS: 
 2) Let's model best practice and encourage everyone to send time and box information so that this is always available in MDAnalysis: IMD-time = Yes ; Send time information ... IMD-box = Yes ; Send box dimensions (recommended) Reply via ReviewNB There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This section appears to be a duplicate of what's in the imd.rst. Can you just omit all of it and just link? It's basically impossible to keep documentation in sync so the best you can do is to only have it in a single place and link — DRY, don't repeat yourself. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Explain what analysis you're performing. Link to https://docs.mdanalysis.org/stable/documentation_pages/core/groups.html#MDAnalysis.core.groups.AtomGroup.radius_of_gyration (or somewhere in the User Guide) for background. 
 Also explain that **as an example** you only process the first 10 frames but normally you'd read all frames. 
 You should also discuss 
 Reply via ReviewNB There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't like the structure of the code in that the contents of the  
 (Additionally, I don't like catching all exceptions and then just printing an error — this is bad practice because errors can slip through.) Reply via ReviewNB There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line #21. frame_count = 0 In the text, explain that one of the limitations is that one cannot use  
 By the way, couldn't you use  Reply via ReviewNB There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line #15. try: Same comment as above: kind of ugly to have so much code inside try/except. 
 I'd rewrite the code block inside the try block as a function and then keep the existing try/except structure to demonstrate the overall control structure. Reply via ReviewNB There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line #41. potential_energy = -1000 + np.random.normal(0, 50) Why do we fake it? Instead we should get it from the energies packet. You just need to say above that one needs to enable sending of energies and then pull the correct data out of the  Reply via ReviewNB There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. | ||||||
| "cells": [ | ||||||
| { | ||||||
| "cell_type": "markdown", | ||||||
| "id": "d090b35a", | ||||||
| "metadata": {}, | ||||||
| "source": [ | ||||||
| "# Real-time Streaming Analysis with IMDv3\n", | ||||||
| "\n", | ||||||
| "This tutorial demonstrates how to use MDAnalysis for real-time streaming analysis of molecular dynamics simulations using the Interactive Molecular Dynamics (IMD) v3 protocol. You'll learn how to connect to running simulations and perform live analysis as the simulation progresses.\n", | ||||||
| "\n", | ||||||
| "**Streaming** involves processing data in real-time as it is generated, rather than storing it for later analysis. In molecular dynamics, this means sending simulation data to a client on-the-fly while the simulation is running, without writing large trajectory files to disk.\n", | ||||||
| "\n", | ||||||
| "This is achieved through a TCP/IP socket connection between the simulation engine and receiving client, transmitting coordinates, velocities, forces, energies, and timing information using the IMDv3 protocol.\n", | ||||||
| "\n", | ||||||
| "## What it covers\n", | ||||||
| "\n", | ||||||
| "- How to set up streaming connections to MD engines\n", | ||||||
| "- Real-time monitoring\n", | ||||||
| "- Live analysis workflows\n", | ||||||
| "\n", | ||||||
| "## Prerequisites\n", | ||||||
| "\n", | ||||||
| "Before starting, you'll need:\n", | ||||||
| "- MDAnalysis with IMD support\n", | ||||||
| "- The `imdclient` package (≥ 0.2.2)\n", | ||||||
| "- A running MD simulation with IMD enabled (examples are engine agnostic for the most part)" | ||||||
| ] | ||||||
| }, | ||||||
| { | ||||||
| "cell_type": "markdown", | ||||||
| "id": "e2168297", | ||||||
| "metadata": {}, | ||||||
| "source": [ | ||||||
| "## Installation and Setup\n", | ||||||
| "\n", | ||||||
| "The IMDReader requires the `imdclient` package. Let's check if everything is properly installed:" | ||||||
| ] | ||||||
| }, | ||||||
| { | ||||||
| "cell_type": "code", | ||||||
| "execution_count": null, | ||||||
| "id": "6024bb10", | ||||||
| "metadata": {}, | ||||||
| "outputs": [], | ||||||
| "source": [ | ||||||
| "# Install required packages (uncomment if needed)\n", | ||||||
| "# !pip install imdclient>=0.2.2\n", | ||||||
| "\n", | ||||||
| "import warnings\n", | ||||||
| "warnings.filterwarnings('ignore')\n", | ||||||
| "\n", | ||||||
| "import MDAnalysis as mda\n", | ||||||
| "import numpy as np\n", | ||||||
| "import matplotlib.pyplot as plt\n", | ||||||
| "from datetime import datetime\n", | ||||||
| "import time\n", | ||||||
| "\n", | ||||||
| "# Check if IMD support is available\n", | ||||||
| "try:\n", | ||||||
| " from MDAnalysis.coordinates.IMD import IMDReader, HAS_IMDCLIENT\n", | ||||||
| " print(f\"IMD support available: {HAS_IMDCLIENT}\")\n", | ||||||
| " if HAS_IMDCLIENT:\n", | ||||||
| " import imdclient\n", | ||||||
| " print(f\"imdclient version: {imdclient.__version__}\")\n", | ||||||
| " print(\"✅ Ready for streaming analysis!\")\n", | ||||||
| " else:\n", | ||||||
| " print(\"❌ IMD support not available\")\n", | ||||||
| "except ImportError as e:\n", | ||||||
| " print(f\"❌ IMD support not available: {e}\")\n", | ||||||
| " print(\"Please install imdclient: pip install imdclient>=0.2.2\")" | ||||||
| ] | ||||||
| }, | ||||||
| { | ||||||
| "cell_type": "markdown", | ||||||
| "id": "e698ca2d", | ||||||
| "metadata": {}, | ||||||
| "source": [ | ||||||
| "## Setting Up a Simulation with IMD\n", | ||||||
| "\n", | ||||||
| "Before we can demonstrate streaming analysis, we need a simulation running with IMD enabled. Here are configuration examples for different MD engines:\n", | ||||||
| "\n", | ||||||
| "### GROMACS Setup\n", | ||||||
| "\n", | ||||||
| "Add these comprehensive IMD settings to your `.mdp` file:\n", | ||||||
| "```code\n", | ||||||
| 
     | ||||||
| "; IMD settings for v3 protocol\n", | ||||||
| "IMD-group = System ; Group to stream (typically System)\n", | ||||||
| "IMD-version = 3 ; Use IMDv3 protocol (required for MDAnalysis)\n", | ||||||
| "IMD-nst = 1 ; Frequency of data transmission (every step)\n", | ||||||
| "IMD-time = No ; Send time information\n", | ||||||
| "IMD-coords = Yes ; Send atomic coordinates (essential)\n", | ||||||
| "IMD-vels = No ; Send velocities (optional)\n", | ||||||
| "IMD-forces = No ; Send forces (optional)\n", | ||||||
| "IMD-box = No ; Send box dimensions (optional)\n", | ||||||
| "IMD-unwrap = No ; Unwrap coordinates across PBC\n", | ||||||
| "IMD-energies = No ; Send energy information (optional)\n", | ||||||
| "```\n", | ||||||
| "\n", | ||||||
| "Run the simulation:\n", | ||||||
| "```bash\n", | ||||||
| "gmx mdrun -v -nt 4 -imdwait -imdport 8889\n", | ||||||
| "```\n", | ||||||
| "\n", | ||||||
| "### LAMMPS Setup\n", | ||||||
| "\n", | ||||||
| "Use the comprehensive IMD fix in your input script:\n", | ||||||
| "```code\n", | ||||||
| 
     | ||||||
| "```code\n", | |
| "```lammps\n", | 
    
      
    
      Copilot
AI
    
    
    
      Oct 10, 2025 
    
  
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code block language identifier should be a valid language (e.g., 'bash', 'text', or 'tcl') instead of 'code' for proper syntax highlighting in the documentation.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we want people to install with Conda for consistency?
Also, will people be running this notebook, or reading it as a guide? I think this cell can potentially be removed, seems like a bit of overkill
Reply via ReviewNB
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need package installation here. imdclient will always be installed when MDA is installed.imdclient will need to be installed separately. However, I'd mention this fact and then link to installation instructions instead of repeating instructions that may change over time.In general, always link to authoritative instructions; you're the expert on the matter so you should know what the authoritative sources are.