def test_clone(self): store = Storage(filename=self.filename, template=self.template_snapshot, mode='w') assert(os.path.isfile(self.filename)) copy = self.template_snapshot.copy() store.save(copy) store.save(self.traj) store.clone(filename=self.filename_clone, subset = self.solute_indices) # clone the storage and reduce the number of atoms to only solute store2 = Storage(filename=self.filename_clone, mode='a') # do some tests, if this is still the same data compare_snapshot( store2.snapshots.load(0), store.snapshots.load(0).subset(self.solute_indices) ) compare_snapshot( store2.snapshots.load(1), store.snapshots.load(1).subset(self.solute_indices) ) store.close() store2.close() pass
def test_clone_empty(self): store = Storage(filename=self.filename, template=self.template_snapshot, mode='w') assert(os.path.isfile(self.filename)) copy = self.template_snapshot.copy() store.save(copy) store.save(self.traj) store.clone_empty(filename=self.filename_clone) # clone the storage and reduce the number of atoms to only solute store2 = Storage(filename=self.filename_clone, mode='a') # do some tests, if this is still the same data compare_snapshot( store2.snapshots.load(0), store.snapshots.load(0) ) # check if the reversed copy also works compare_snapshot( store2.snapshots.load(1), store.snapshots.load(1) ) assert_equal(len(store2.snapshots), 2) assert_equal(len(store2.trajectories), 0) store.close() store2.close() pass
def test_stored_template(self): store = Storage(filename=self.filename, template=self.template_snapshot, mode='w') assert(os.path.isfile(self.filename)) store.close() store = Storage(filename=self.filename, mode='a') loaded_template = store.template compare_snapshot(loaded_template, self.template_snapshot) store.close()
def test_stored_topology(self): raise SkipTest store = Storage(filename=self.filename, mode='w') assert (os.path.isfile(self.filename)) store.close() store = Storage(filename=self.filename, mode='a') loaded_topology = store.template.topology # check if poth topologies have the same JSON string # this also tests the simplifier for topologies assert_equal(self.simplifier.to_json(self.template_snapshot.topology), self.simplifier.to_json(loaded_topology)) store.close()
def setup_package(): # this should generate the trajectory.nc file which we'll use for # everything else mdtrajectory = md.load(data_filename("ala_small_traj.pdb")) snapshot = peng.snapshot_from_pdb(data_filename("ala_small_traj.pdb")) storage = Storage(filename=data_filename("ala_small_traj.nc"), template=snapshot, mode='w') mytraj = peng.trajectory_from_mdtraj(mdtrajectory, simple_topology=True) storage.trajectories.save(mytraj) storage.close()
def test_stored_topology(self): store = Storage(filename=self.filename, template=self.template_snapshot, mode='w') assert(os.path.isfile(self.filename)) store.close() store = Storage(filename=self.filename, mode='a') loaded_topology = store.template.topology # check if poth topologies have the same JSON string (this also tests the simplifier for topologies assert_equal( self.simplifier.to_json(self.template_snapshot.topology), self.simplifier.to_json(loaded_topology) ) store.close()
def test_reverse_bug(self): store = Storage(filename=self.filename, mode='w') assert (os.path.isfile(self.filename)) store.snapshots.save(self.template_snapshot) rev = self.template_snapshot.reversed # save the reversed one store.snapshots.save(rev) # check that the reversed one has index 1 and not 3! assert (store.idx(rev) == 1) # and we have exactly one snapshot assert (len(store.snapshots) == 2) assert (len(store.dimensions['snapshots']) == 1) store.close()
def setup_package(): # this should generate the trajectory.nc file which we'll use for # everything else mdtrajectory = md.load(data_filename("ala_small_traj.pdb")) snapshot = peng.snapshot_from_pdb(data_filename("ala_small_traj.pdb")) storage = Storage( filename=data_filename("ala_small_traj.nc"), template=snapshot, mode='w' ) mytraj = peng.trajectory_from_mdtraj(mdtrajectory, simple_topology=True) storage.trajectories.save(mytraj) storage.close()
def test_load_save_uuid(self): store = Storage(filename=self.filename, mode='w') assert (os.path.isfile(self.filename)) store.save(self.template_snapshot) store.close() store = Storage(filename=self.filename, mode='a') loaded_template = store.snapshots[self.template_snapshot.__uuid__] loaded_r = store.snapshots[self.template_snapshot.reversed.__uuid__] compare_snapshot(loaded_template, self.template_snapshot, True) compare_snapshot(loaded_template.reversed, self.template_snapshot.reversed, True) compare_snapshot(loaded_r, self.template_snapshot.reversed) store.close()
def test_load_save_uuid(self): store = Storage(filename=self.filename, mode='w') assert(os.path.isfile(self.filename)) store.save(self.template_snapshot) store.close() store = Storage(filename=self.filename, mode='a') loaded_template = store.snapshots[self.template_snapshot.__uuid__] loaded_r = store.snapshots[self.template_snapshot.reversed.__uuid__] compare_snapshot(loaded_template, self.template_snapshot, True) compare_snapshot( loaded_template.reversed, self.template_snapshot.reversed, True) compare_snapshot(loaded_r, self.template_snapshot.reversed) store.close()
def test_load_save(self): store = Storage(filename=self.filename, template=self.template_snapshot, mode='w') assert(os.path.isfile(self.filename)) copy = self.template_snapshot.copy() store.save(copy) store.close() store = Storage(filename=self.filename, mode='a') loaded_template = store.template compare_snapshot(loaded_template, self.template_snapshot) loaded_copy = store.load(Snapshot, 1) compare_snapshot(loaded_template, loaded_copy) store.close()
def test_reverse_bug(self): store = Storage(filename=self.filename, mode='w', use_uuid=False) assert(os.path.isfile(self.filename)) store.snapshots.save(self.template_snapshot) rev = self.template_snapshot.reversed # save the reversed one store.snapshots.save(rev) # check that the reversed one has index 1 and not 3! assert(store.idx(rev) == 1) # and we have exactly one snapshot assert(len(store.snapshots) == 2) assert(len(store.dimensions['snapshots']) == 1) store.close()
def test_load_save_toy(self): store = Storage(filename=self.filename, mode='w') assert (os.path.isfile(self.filename)) store.save(self.toy_template) store.close() store = Storage(filename=self.filename, mode='a') loaded_template = store.snapshots[0] loaded_r = store.snapshots[1] compare_snapshot(loaded_template, self.toy_template, True) compare_snapshot(loaded_template.reversed, self.toy_template.reversed, True) compare_snapshot(loaded_r, self.toy_template.reversed) store.close()
def setup_package(): if not md: return # this should generate the ala_small_traj.nc file which we'll use for # everything else # NOTE: tests using this must be skipped if there's no mdtraj! mdtrajectory = md.load(data_filename("ala_small_traj.pdb")) snapshot = peng.snapshot_from_pdb(data_filename("ala_small_traj.pdb")) storage = Storage(filename=data_filename("ala_small_traj.nc"), template=snapshot, mode='w') mytraj = peng.trajectory_from_mdtraj(mdtrajectory, simple_topology=True) storage.trajectories.save(mytraj) storage.close()
def test_proxy(self): for use_uuid in [True, False]: store = Storage(filename=self.filename, mode='w', use_uuid=use_uuid) assert (os.path.isfile(self.filename)) tm = self.template_snapshot store.save(tm) px = store.snapshots.proxy(0) # make sure that the proxy and assert (hash(px) == hash(tm)) assert (px == tm) store.snapshots.cache.clear() s0 = store.snapshots[0] assert (hash(px) == hash(s0)) assert (px == s0) compare_snapshot(px, tm) compare_snapshot(s0, tm) px = store.snapshots.proxy(0) # make sure that after reloading it still works assert (hash(px) == hash(tm)) assert (px == tm) store.close() store = Storage(filename=self.filename, mode='a') s1 = store.snapshots[0] store.close() # when loading only for uuid based storages you get the same id assert ((hash(px) == hash(s1)) is use_uuid) assert ((px == s1) is use_uuid)
def setup_package(): # this should generate the trajectory.nc file which we'll use for # everything else mdtrajectory = md.load(data_filename("ala_small_traj.pdb")) snapshot = paths.snapshot_from_pdb(data_filename("ala_small_traj.pdb")) # once we have a template configuration (coordinates to not really matter) # we can create a storage. We might move this logic out of the dynamics engine # and keep sotrage and engine generation completely separate! storage = Storage(filename=data_filename("ala_small_traj.nc"), template=snapshot, mode='w') mytraj = paths.tools.trajectory_from_mdtraj(mdtrajectory) storage.trajectories.save(mytraj) storage.close()
def test_load_save(self): for use_uuid in [True, False]: store = Storage(filename=self.filename, mode='w', use_uuid=use_uuid) assert(os.path.isfile(self.filename)) store.save(self.template_snapshot) store.close() store = Storage(filename=self.filename, mode='a') loaded_template = store.snapshots[0] loaded_r = store.snapshots[1] compare_snapshot(loaded_template, self.template_snapshot, True) compare_snapshot( loaded_template.reversed, self.template_snapshot.reversed, True) compare_snapshot(loaded_r, self.template_snapshot.reversed) store.close()
def test_load_save_toy(self): store = Storage(filename=self.filename, mode='w', use_uuid=False) assert(os.path.isfile(self.filename)) store.save(self.toy_template) store.close() store = Storage(filename=self.filename, mode='a') loaded_template = store.snapshots[0] loaded_r = store.snapshots[1] compare_snapshot(loaded_template, self.toy_template, True) compare_snapshot( loaded_template.reversed, self.toy_template.reversed, True) compare_snapshot(loaded_r, self.toy_template.reversed) store.close()
def test_load_save(self): for use_uuid in [True, False]: store = Storage(filename=self.filename, mode='w', use_uuid=use_uuid) assert (os.path.isfile(self.filename)) store.save(self.template_snapshot) store.close() store = Storage(filename=self.filename, mode='a') loaded_template = store.snapshots[0] loaded_r = store.snapshots[1] compare_snapshot(loaded_template, self.template_snapshot, True) compare_snapshot(loaded_template.reversed, self.template_snapshot.reversed, True) compare_snapshot(loaded_r, self.template_snapshot.reversed) store.close()
def test_proxy(self): for use_uuid in [True, False]: store = Storage(filename=self.filename, mode='w', use_uuid=use_uuid) assert(os.path.isfile(self.filename)) tm = self.template_snapshot store.save(tm) px = store.snapshots.proxy(0) # make sure that the proxy and assert(hash(px) == hash(tm)) assert(px == tm) store.snapshots.cache.clear() s0 = store.snapshots[0] assert(hash(px) == hash(s0)) assert(px == s0) compare_snapshot(px, tm) compare_snapshot(s0, tm) px = store.snapshots.proxy(0) # make sure that after reloading it still works assert(hash(px) == hash(tm)) assert(px == tm) store.close() store = Storage(filename=self.filename, mode='a') s1 = store.snapshots[0] store.close() # when loading only for uuid based storages you get the same id assert((hash(px) == hash(s1)) is use_uuid) assert((px == s1) is use_uuid)
def setup_package(): # this should generate the trajectory.nc file which we'll use for # everything else mdtrajectory = md.load(data_filename("ala_small_traj.pdb")) snapshot = paths.snapshot_from_pdb(data_filename("ala_small_traj.pdb")) # once we have a template configuration (coordinates to not really matter) # we can create a storage. We might move this logic out of the dynamics engine # and keep sotrage and engine generation completely separate! storage = Storage( filename=data_filename("ala_small_traj.nc"), template=snapshot, mode='w' ) mytraj = paths.Trajectory.from_mdtraj(mdtrajectory) storage.trajectories.save(mytraj) storage.close()
def test_create_template(self): store = Storage(filename=self.filename, template=self.template_snapshot, mode='w') assert(os.path.isfile(data_filename("storage_test.nc"))) store.close()
def test_create_storage(self): store = Storage(filename=self.filename, mode='w') assert (os.path.isfile(data_filename("storage_test.nc"))) store.close()
""" This is an example file of how to remove water from a netCDF file. @author: Jan-Hendrik Prinz """ from openpathsampling.storage import Storage if __name__=="__main__": storage = Storage( filename="trajectory.nc", mode='a' ) solute = range(22) storage.clone('test_solute.nc', subset=None) storage.close() storage2 = Storage('test_solute.nc') storage2.clone('test_solute2.nc', subset=solute)