openmm / openmmforcefields

CHARMM and AMBER forcefields for OpenMM (with small molecule support)
http://openmm.org
Other
254 stars 80 forks source link

Getting coordinates out of MCMCSampler or Multi-state Sampler #114

Closed aclyde11 closed 4 years ago

aclyde11 commented 4 years ago

Hello,

I have a naive question...

I want to be able to pull a PDB File out every few steps or so (for some clustering/checking forces on ligand/etc).

For instance, when using a standard OpenMM simulation:

coords =  self.simulation.context.getState(getPositions=True,enforcePeriodicBox=True).getPositions(asNumpy=True)
app.PDBFile.writeFile(self.topology, coords, file=f)

but when I try it with MCMCSampler I can't get the periodic boundary conditions enforced in the positions (the PDB is correctly writing out the crystal header, but protein/ligand go over the edge).

I know I can get the coordinates out by

sampler = MCMCSampler(...)
sampler.run(10)
coords =  sampler.sampler_state.positions
# or 
coords = cache.global_context_cache.get_context(self.thermodynamic_state[0].getState(getPositions=True, enforcePeriodicBox=True).getPositions()

but in either case it doesn't work... except after minimization the second method works, but not the first. Once run/step is called, it doesn't seem to work anymore. I've checked all the objects, everyone knows about the box vector and states it periodic...

I would guess I'm just doing something I shouldn't be or not grabbing the context correctly.

Thanks!

jchodera commented 4 years ago

Could you post this in https://github.com/choderalab/openmmtools/issues, since that repo has the MCMCSampler?

I get confused myself since everything has open in the name!

aclyde11 commented 4 years ago

@jchodera ah yes my bad, indeed very confusing sometimes!