Record xyz coordinates of one particle quickly?

The functionality of OpenMM will (eventually) include everything that one would need to run modern molecular simulation.
POST REPLY
User avatar
George Pantelopulos
Posts: 64
Joined: Mon Jun 01, 2015 2:15 pm

Record xyz coordinates of one particle quickly?

Post by George Pantelopulos » Tue Oct 09, 2018 11:32 pm

Hi all,

I'm doing umbrella sampling using a large system (~420,000 particles).

I'd like to record the position of one particle representing the umbrella as efficiently and as frequently as possible.

DCDReporter is quite slow for frequent writing, and I am not interested in frequently writing the position of all atoms in the system.

DCDReporter does "self._dcd.writeModel(state.getPositions(), periodicBoxVectors=state.getPeriodicBoxVectors())" to get the positions to pass to DCDfile.

However, might there be a way to write the position of one (or a subset) of particles in the system without accessing state? Or would it be about as fast as possible to just modify this line in DCDReporter to only access the atom index or indices of interest?

User avatar
Peter Eastman
Posts: 2593
Joined: Thu Aug 09, 2007 1:25 pm

Re: Record xyz coordinates of one particle quickly?

Post by Peter Eastman » Wed Oct 10, 2018 10:02 am

There's two parts to this: getting the positions from the context, and saving them. There's no other way to get positions than calling getState() (short of writing a plugin, anyway), and it always retrieves every particle. But the cost of writing them to disk of course scales with the number you're writing, so writing just one position will be faster than writing all of them.

The one other optimization I'd suggest is calling state.getPositions(asNumpy=True). Getting the positions as a Numpy array is faster than getting them as a list of Vec3s.

User avatar
George Pantelopulos
Posts: 64
Joined: Mon Jun 01, 2015 2:15 pm

Re: Record xyz coordinates of one particle quickly?

Post by George Pantelopulos » Wed Oct 10, 2018 4:27 pm

Hi Peter,

Doing this with state.getPositions(asNumpy=True) is quite fast! I don't notice any loss in speed.

Thank you once again.

POST REPLY