def empty_snapshot_from_openmm_topology(topology, simple_topology=False): """ Return an empty snapshot from an openmm.Topology object Velocities will be set to zero. Parameters ---------- topology : openmm.Topology the topology representing the structure and number of atoms simple_topology : bool if `True` only a simple topology with n_atoms will be created. This cannot be used with complex CVs but loads and stores very fast Returns ------- openpathsampling.engines.Snapshot the complete snapshot with zero coordinates and velocities """ n_atoms = topology.n_atoms if simple_topology: topology = Topology(n_atoms, 3) else: topology = MDTrajTopology(md.Topology.from_openmm(topology)) snapshot = Snapshot.construct( coordinates=u.Quantity(np.zeros((n_atoms, 3)), u.nanometers), box_vectors=u.Quantity(topology.setUnitCellDimensions(), u.nanometers), velocities=u.Quantity(np.zeros((n_atoms, 3)), u.nanometers / u.picoseconds), engine=TopologyEngine(topology)) return snapshot
def snapshot_from_pdb(pdb_file, simple_topology=False): """ Construct a Snapshot from the first frame in a pdb file without velocities Parameters ---------- pdb_file : str The filename of the .pdb file to be used simple_topology : bool if `True` only a simple topology with n_atoms will be created. This cannot be used with complex CVs but loads and stores very fast Returns ------- :class:`openpathsampling.engines.Snapshot` the constructed Snapshot """ pdb = md.load(pdb_file) velocities = np.zeros(pdb.xyz[0].shape) if simple_topology: topology = Topology(*pdb.xyz[0].shape) else: topology = MDTrajTopology(pdb.topology) snapshot = Snapshot.construct( coordinates=u.Quantity(pdb.xyz[0], u.nanometers), box_vectors=u.Quantity(pdb.unitcell_vectors[0], u.nanometers), velocities=u.Quantity(velocities, u.nanometers / u.picoseconds), engine=FileEngine(topology, pdb_file)) return snapshot
def snapshot_from_pdb(pdb_file, simple_topology=False): """ Construct a Snapshot from the first frame in a pdb file without velocities Parameters ---------- pdb_file : str The filename of the .pdb file to be used simple_topology : bool if `True` only a simple topology with n_atoms will be created. This cannot be used with complex CVs but loads and stores very fast Returns ------- :class:`openpathsampling.engines.Snapshot` the constructed Snapshot """ pdb = md.load(pdb_file) velocities = np.zeros(pdb.xyz[0].shape) if simple_topology: topology = Topology(*pdb.xyz[0].shape) else: topology = MDTrajTopology(pdb.topology) snapshot = Snapshot.construct( coordinates=u.Quantity(pdb.xyz[0], u.nanometers), box_vectors=u.Quantity(pdb.unitcell_vectors[0], u.nanometers), velocities=u.Quantity(velocities, u.nanometers / u.picoseconds), engine=FileEngine(topology, pdb_file) ) return snapshot
def _build_current_snapshot(self): # TODO: Add caching for this and mark if changed state = self.simulation.context.getState(getPositions=True, getVelocities=True, getEnergy=True) snapshot = Snapshot.construct( coordinates=state.getPositions(asNumpy=True), box_vectors=state.getPeriodicBoxVectors(asNumpy=True), velocities=state.getVelocities(asNumpy=True), engine=self ) return snapshot
def snapshot_from_testsystem(testsystem, simple_topology=False): """ Construct a Snapshot from openmm topology and state objects Parameters ---------- testsystem : openmmtools.Topology The filename of the .pdb file to be used simple_topology : bool if `True` only a simple topology with n_atoms will be created. This cannot be used with complex CVs but loads and stores very fast Returns ------- :class:`openpathsampling.engines.Snapshot` the constructed Snapshot """ velocities = u.Quantity( np.zeros(testsystem.positions.shape), u.nanometers / u.picoseconds) if simple_topology: topology = Topology(*testsystem.positions.shape) else: topology = MDTrajTopology(md.Topology.from_openmm(testsystem.topology)) box_vectors = \ np.array([ v / u.nanometers for v in testsystem.system.getDefaultPeriodicBoxVectors()]) * u.nanometers snapshot = Snapshot.construct( coordinates=testsystem.positions, box_vectors=box_vectors, velocities=velocities, engine=OpenMMToolsTestsystemEngine(topology, testsystem.name) ) return snapshot
def snapshot_from_testsystem(testsystem, simple_topology=False): """ Construct a Snapshot from openmm topology and state objects Parameters ---------- testsystem : openmmtools.Topology The filename of the .pdb file to be used simple_topology : bool if `True` only a simple topology with n_atoms will be created. This cannot be used with complex CVs but loads and stores very fast Returns ------- :class:`openpathsampling.engines.Snapshot` the constructed Snapshot """ velocities = u.Quantity(np.zeros(testsystem.positions.shape), u.nanometers / u.picoseconds) if simple_topology: topology = Topology(*testsystem.positions.shape) else: topology = MDTrajTopology(md.Topology.from_openmm(testsystem.topology)) box_vectors = \ np.array([ v / u.nanometers for v in testsystem.system.getDefaultPeriodicBoxVectors()]) * u.nanometers snapshot = Snapshot.construct(coordinates=testsystem.positions, box_vectors=box_vectors, velocities=velocities, engine=OpenMMToolsTestsystemEngine( topology, testsystem.name)) return snapshot
def empty_snapshot_from_openmm_topology(topology, simple_topology=False): """ Return an empty snapshot from an openmm.Topology object Velocities will be set to zero. Parameters ---------- topology : openmm.Topology the topology representing the structure and number of atoms simple_topology : bool if `True` only a simple topology with n_atoms will be created. This cannot be used with complex CVs but loads and stores very fast Returns ------- openpathsampling.engines.Snapshot the complete snapshot with zero coordinates and velocities """ n_atoms = topology.n_atoms if simple_topology: topology = Topology(n_atoms, 3) else: topology = MDTrajTopology(md.Topology.from_openmm(topology)) snapshot = Snapshot.construct( coordinates=u.Quantity(np.zeros((n_atoms, 3)), u.nanometers), box_vectors=u.Quantity(topology.setUnitCellDimensions(), u.nanometers), velocities=u.Quantity( np.zeros((n_atoms, 3)), u.nanometers / u.picoseconds), engine=TopologyEngine(topology) ) return snapshot