What is the fastest way to get the distance between two particles?

The functionality of OpenMM will (eventually) include everything that one would need to run modern molecular simulation.
POST REPLY
User avatar
Yan Zhang
Posts: 38
Joined: Mon Dec 19, 2016 2:39 pm

What is the fastest way to get the distance between two particles?

Post by Yan Zhang » Mon Sep 11, 2017 7:17 am

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

User avatar
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?

Post by Peter Eastman » Mon Sep 11, 2017 10:02 am

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

User avatar
Yan Zhang
Posts: 38
Joined: Mon Dec 19, 2016 2:39 pm

Re: What is the fastest way to get the distance between two particles?

Post by Yan Zhang » Mon Sep 11, 2017 2:22 pm

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.

User avatar
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?

Post by Peter Eastman » Mon Sep 11, 2017 2:31 pm

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

User avatar
Yan Zhang
Posts: 38
Joined: Mon Dec 19, 2016 2:39 pm

Re: What is the fastest way to get the distance between two particles?

Post by Yan Zhang » Mon Sep 11, 2017 6:41 pm

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?

User avatar
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?

Post by Peter Eastman » Tue Sep 12, 2017 9:59 am

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

User avatar
Yan Zhang
Posts: 38
Joined: Mon Dec 19, 2016 2:39 pm

Re: What is the fastest way to get the distance between two particles?

Post by Yan Zhang » Tue Sep 12, 2017 11:09 am

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!

POST REPLY