Page 1 of 1

Record xyz coordinates of one particle quickly?

Posted: Tue Oct 09, 2018 11:32 pm
by gpantel
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?

Re: Record xyz coordinates of one particle quickly?

Posted: Wed Oct 10, 2018 10:02 am
by peastman
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.

Re: Record xyz coordinates of one particle quickly?

Posted: Wed Oct 10, 2018 4:27 pm
by gpantel
Hi Peter,

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

Thank you once again.