During the simulation I want to check the distance between each pair of particles. I know that I could use state.getPositions to get the positions and then calculate the distance myself, but since openmm must've calculated the distances itself for forcefield, so I'm wondering if I could somehow get the access to that to save some computational resources?
Thanks,
Yan
What is the fastest way to get the distance between two particles?
- Peter Eastman
- Posts: 2593
- Joined: Thu Aug 09, 2007 1:25 pm
Re: What is the fastest way to get the distance between two particles?
For what purpose do you want to check the distances? Is it for every pair of particles, or just a subset? How often do you want to do it?
There are lots of possible approaches, so I need to know a bit more about what you want to accomplish.
Peter
There are lots of possible approaches, so I need to know a bit more about what you want to accomplish.
Peter
Re: What is the fastest way to get the distance between two particles?
This is related to another question of mine viewtopicPhpbb.php?f=161&t=8191&p=0&sta ... 4fc443e529 and viewtopicPhpbb.php?f=161&t=7951&p=0&sta ... 4fc443e529.peastman wrote:For what purpose do you want to check the distances? Is it for every pair of particles, or just a subset? How often do you want to do it?
There are lots of possible approaches, so I need to know a bit more about what you want to accomplish.
Peter
Basically when two particles are in proximity, I'll change some parameters for their force fields. I'll need to check the distances of almost all pairs, and "almost" because it is a circular chain of particles so I'll skip checking the neighbors of a particle. The chain is long enough to consider it as checking the distances of every pair though.
- Peter Eastman
- Posts: 2593
- Joined: Thu Aug 09, 2007 1:25 pm
Re: What is the fastest way to get the distance between two particles?
So really what you want to do is build a list of every pair of particles that are within a cutoff distance of each other? That can be done much faster than actually computing all pairwise distances. MDTraj has a `compute_neighborlist()` function that does it pretty quickly. I'd give that a try.
Peter
Peter
Re: What is the fastest way to get the distance between two particles?
Yes exactly. Is there a tutorial on how to use MDTraj with OpenMM?peastman wrote:So really what you want to do is build a list of every pair of particles that are within a cutoff distance of each other? That can be done much faster than actually computing all pairwise distances. MDTraj has a `compute_neighborlist()` function that does it pretty quickly. I'd give that a try.
Peter
- Peter Eastman
- Posts: 2593
- Joined: Thu Aug 09, 2007 1:25 pm
Re: What is the fastest way to get the distance between two particles?
This tutorial demonstrates creating an MDTraj trajectory from OpenMM data:
https://github.com/choderalab/openmm-tu ... enMM.ipynb
Search for "mdtraj", since it's a ways down. The code for what you want to do will look something like this:
(I just wrote that in the browser, so it might have a few mistakes, but it should be pretty close.)
Peter
https://github.com/choderalab/openmm-tu ... enMM.ipynb
Search for "mdtraj", since it's a ways down. The code for what you want to do will look something like this:
Code: Select all
mdtraj_topology = mdtraj.Topology.from_openmm(topology)
traj = mdtraj.Trajectory(state.getPositions().value_in_unit(nanometers), mdtraj_topology)
traj.unitcell_vectors = state.getPeriodicBoxVectors()
neighbors = mdtraj.geometry.compute_neighborlist(traj, cutoff)
Peter
Re: What is the fastest way to get the distance between two particles?
This is really useful. I'll look into it. Many thanks!peastman wrote:This tutorial demonstrates creating an MDTraj trajectory from OpenMM data:
https://github.com/choderalab/openmm-tu ... enMM.ipynb
Search for "mdtraj", since it's a ways down. The code for what you want to do will look something like this:
(I just wrote that in the browser, so it might have a few mistakes, but it should be pretty close.)Code: Select all
mdtraj_topology = mdtraj.Topology.from_openmm(topology) traj = mdtraj.Trajectory(state.getPositions().value_in_unit(nanometers), mdtraj_topology) traj.unitcell_vectors = state.getPeriodicBoxVectors() neighbors = mdtraj.geometry.compute_neighborlist(traj, cutoff)
Peter