{"id":13869989,"url":"https://github.com/torchmd/mdgrad","last_synced_at":"2025-12-25T15:30:33.352Z","repository":{"id":78367013,"uuid":"287831662","full_name":"torchmd/mdgrad","owner":"torchmd","description":"Pytorch differentiable molecular dynamics ","archived":false,"fork":false,"pushed_at":"2022-09-05T05:23:21.000Z","size":225049,"stargazers_count":172,"open_issues_count":2,"forks_count":17,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-01-20T23:48:57.106Z","etag":null,"topics":["chemistry","differentiable-simulations","force-field-optimization","graph-neural-networks","molecular-dynamics","physics-simulation","polymer","quantum-dynamics","quantum-isomerization","statistical-mechanics"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/torchmd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2020-08-15T22:03:52.000Z","updated_at":"2025-01-16T16:32:16.000Z","dependencies_parsed_at":"2023-03-05T23:00:23.767Z","dependency_job_id":null,"html_url":"https://github.com/torchmd/mdgrad","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/torchmd%2Fmdgrad","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/torchmd%2Fmdgrad/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/torchmd%2Fmdgrad/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/torchmd%2Fmdgrad/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/torchmd","download_url":"https://codeload.github.com/torchmd/mdgrad/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235527725,"owners_count":19004371,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chemistry","differentiable-simulations","force-field-optimization","graph-neural-networks","molecular-dynamics","physics-simulation","polymer","quantum-dynamics","quantum-isomerization","statistical-mechanics"],"created_at":"2024-08-05T20:01:24.475Z","updated_at":"2025-10-06T13:31:46.825Z","avatar_url":"https://github.com/torchmd.png","language":"Python","readme":"# torchmd\n\u003cp align=\"left\"\u003e\n  \u003cimg src=\"assets/logo.jpg\" width=\"150\"\u003e\n\u003c/p\u003e \n\n\u003cp align=\"left\"\u003e\n  \u003cimg src=\"assets/fold.gif\" width=\"200\"\u003e\n\u003c/p\u003e\n\nThis is not just a regular simulator but a DIFFERENTIABLE simulator!\n\nPyTorch code for End-to-end differetiable molecular simulations. More docs and tutorials are comings.\nThis repo is under heavy development, your contribution is very much welcomed.  \n\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"assets/rdf_inv.png\" width=\"350\"\u003e\n\u003c/p\u003e\n\n\n### Install packages \n\nI highly recommend creating a dedicated conda environment via: \n```\nconda create -n mdgrad python=3.8\n```\n\nDownload and install \n```\ngit clone https://github.com/torchmd/mdgrad.git\ncd mdgrad\nconda activate mdgrad\npip install -r requirements.txt # I have tested this, it should work \npip install -e . # -e is useful if you want to edit the source code\n```\n\n\n## Highlights\n\n- Reverse-mode automatic differentiation through ODE Solver (O(1) backprop)\n- solvers supported: 4th order Runge-Kutta and Velocity Verlet \n- Include a Graph Neural Network Module (our own SchNet implementation)\n- GPU-accelerated Neighborlist algorithm\n- End-to-End Differentiable Observable implemented - RDF, VACF\n- Good for single molecule and condensed phase( liquids and solids )\n- Compatible with ASE for system initialization \n- Users can write interface to their favorite Force Field architecture (SchNet, DimeNet, SE3NN, LAMMPS etc.)\n\nWang, W., Axelrod, S., \u0026 Gómez-Bombarelli, R. (2020). Differentiable Molecular Simulations for Control and Learning. https://arxiv.org/abs/2003.00868\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"assets/schematic.jpg\" width=\"400\"\u003e\n\u003c/p\u003e\n\nThis repo features the following [demos](https://github.com/wwang2/torchmd/tree/master/demo):\n\n1. Differentiable folding of a polymer \n\n2. Learning interactions from observables (pair correlation function, velocity auto-correlations)\n\n3. Quantum isomerization of a minimal retinal model \n\n```\n# Define a box of particles \nL = 1.6 \natoms = FaceCenteredCubic(symbol='H', size=(3, 3, 3), latticeconstant=L, pbc=True)\n\n# use System to wrap ase.atoms\nfrom torchmd.system import System \ndevice = 'cuda:0'\nsystem = System(atoms, device=device)\nsystem.set_temperature(1.0)\n\n# Define interactions \nfrom torchmd.potentials import ExcludedVolume\npair = PairPotentials(system, ExcludedVolume, **{'epsilon': 1.0,  'sigma': 1.0,\"power\": 12}, cutoff=2.5).to(device)\n\n# Define simulation\nfrom torchmd.md import NoseHooverChain\nintegrator = NoseHooverChain(model, \n            system,\n            Q=50.0, \n            T=1.0,\n            num_chains=5, \n            adjoint=True).to(device)\n\nsim = Simulations(system, integrator)\n\n# Simulate \nv_t, q_t, pv_t = sim.simulate(steps=50, frequency=50, dt=0.01) #v_t: velocity  q_t: position  pv_t bath: variables\n\n# Compute observable \nobs = rdf(system, nbins=100, r_range=(0.75, 2.5))\n_, _, g = obs(q_t)\n\ng.sum().backward()\n# You will find out g can be backpropagated for gradient cumulation, give it a try!\n```\n\n### DEMOs\n\n#### End-to-End Fitting for Macroscopic/Coarse-Grained Observable \nBackpropagating through the trajectory to train a GNN that reproduces a target pair distribution function.\nWe demonstrated the fitting of water rdf (Oxygen-Oxygen) at 298k with differentiable simulations\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"assets/water_gnn_rdf_298k.gif\" width=\"300\"\u003e\n\u003c/p\u003e\n\n\n#### Controllable Fold for polymer chain \nFolding a polymer with Graph Neural Networks \n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"assets/fold.gif\" width=\"300\"\u003e\n\u003c/p\u003e\n\n\n#### Quantum Isomerization \n\nWe fit electric field to optimize efficiency of a quantum isomerization process for retinal molecule\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"assets/quantumyield.gif\" width=\"300\"\u003e\n\u003c/p\u003e\n\n### TODO \n\n- Imeplement Forward Sensitivity solver\n- More thermostats (Parrinello-Rahman dynamics, etc.) \n- Interface to LAMMPS so that this tool can be used as a plug-in for LAMMPS simulations \n- Write interface to SE3NN, DimeNET, etc.\n- Better loggers for observables\n","funding_links":[],"categories":["Python"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftorchmd%2Fmdgrad","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftorchmd%2Fmdgrad","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftorchmd%2Fmdgrad/lists"}