Page 1 of 1
What is the fastest way to get the distance between two particles?
Posted: Mon Sep 11, 2017 7:17 am
by yaz62
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
Re: What is the fastest way to get the distance between two particles?
Posted: Mon Sep 11, 2017 10:02 am
by peastman
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
Re: What is the fastest way to get the distance between two particles?
Posted: Mon Sep 11, 2017 2:22 pm
by yaz62
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
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.
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.
Re: What is the fastest way to get the distance between two particles?
Posted: Mon Sep 11, 2017 2:31 pm
by peastman
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
Re: What is the fastest way to get the distance between two particles?
Posted: Mon Sep 11, 2017 6:41 pm
by yaz62
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
Yes exactly. Is there a tutorial on how to use MDTraj with OpenMM?
Re: What is the fastest way to get the distance between two particles?
Posted: Tue Sep 12, 2017 9:59 am
by peastman
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:
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)
(I just wrote that in the browser, so it might have a few mistakes, but it should be pretty close.)
Peter
Re: What is the fastest way to get the distance between two particles?
Posted: Tue Sep 12, 2017 11:09 am
by yaz62
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:
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)
(I just wrote that in the browser, so it might have a few mistakes, but it should be pretty close.)
Peter
This is really useful. I'll look into it. Many thanks!