def test_data_types(self): """Test that import works""" # Make sure that interface is 8-bit clean buf = b"test string \x82\x00\xb8 with 8-bit data and embedded null" RMF.set_log_level("trace") bh = RMF.BufferConstHandle(buf) name = RMF._get_temporary_file_path("buffer") print(name) self.assertEqual(bh.get_buffer(), buf) RMF.write_buffer(bh, name) bbh = RMF.read_buffer(name) self.assertEqual(bbh.get_buffer(), bh.get_buffer())
#!/usr/bin/env python from IMP.npctransport import * import IMP.rmf import RMF import sys f=open(sys.argv[1], "rb") o= Output() #config.SetTotalBytesLimit(50000000) o.ParseFromString(f.read()) bch= RMF.BufferConstHandle(o.rmf_conformation); RMF.write_buffer(bch, sys.argv[2] )
def test_init_from_rmf(self): """ Testing whether initialize_positions_from_rmf indeed restores the beads coordinates correctly """ IMP.set_log_level(IMP.SILENT) test_util.test_protobuf_installed(self) # First simulation with one seed: output_pb1 = self.get_tmp_file_name("output1.pb") output_rmf1 = IMP.create_temporary_file_name("output", ".rmf") print("Starting first simulation with RMF file " + output_rmf1) sd = self._make_and_run_simulation(output_pb1, output_rmf1, seed=1) e1 = sd.get_bd().get_scoring_function().evaluate(False) print("*** After first simulation") print("Energy %.2f" % e1) coordsI = self._get_beads_coords(sd) sd = None # Second simulation with another seed: output_pb2 = self.get_tmp_file_name("output2.pb") output_rmf2 = IMP.create_temporary_file_name("output2", ".rmf") print("*** Starting second simulation with RMF file " + output_rmf2) print("YYY") sd = self._make_and_run_simulation(output_pb2, output_rmf2, seed=2) print("XXX") e2 = sd.get_bd().get_scoring_function().evaluate(False) print("*** After second simulation") print("Energy %.2f" % e2) coordsII = self._get_beads_coords(sd) # Restoration from first simulation through rmf file: print("*** Initializing positions from RMF file " + output_rmf1) fl = RMF.open_rmf_file_read_only(output_rmf1) sd.initialize_positions_from_rmf(fl) e3 = sd.get_bd().get_scoring_function().evaluate(False) print("*** After initializing positions from RMF file " + output_rmf1) print("Energy %.2f" % e3) self.assertAlmostEqual(e1, e3, delta=0.0001) self.assertNotAlmostEqual(e1, e2, delta=0.0001) coordsIII = self._get_beads_coords(sd) # make sure that all coordinates were restored and as sanity # check control, also that the second simulation is different than # the first one: for i in range(len(coordsI)): for j in range(3): self.assertAlmostEqual(coordsI[i][j], coordsIII[i][j], delta=0.00001) self.assertNotAlmostEqual(coordsI[i][j], coordsII[i][j], delta=0.00001) # Simulate more to scramble stuff sd.get_bd().optimize(1000) e4 = sd.get_bd().get_scoring_function().evaluate(False) print("Energy %.2f" % e4) coordsIV = self._get_beads_coords(sd) # Restoration from first simulation through output protobuf file: print("*** Initializing positions from ProtoBuf file " + output_pb1) f = open(output_pb1, "rb") config = IMP.npctransport.Output() config.ParseFromString(f.read()) bch = RMF.BufferConstHandle(config.rmf_conformation) fch = RMF.open_rmf_buffer_read_only(bch) sd.initialize_positions_from_rmf(fch) e5 = sd.get_bd().get_scoring_function().evaluate(False) print("*** After initializing positions from RMF file " + output_rmf1) print("Energy %.2f" % e5) self.assertAlmostEqual(e1, e5, delta=0.00001) self.assertNotAlmostEqual(e1, e4, delta=0.00001) coordsV = self._get_beads_coords(sd) for i in range(len(coordsI)): for j in range(3): self.assertAlmostEqual(coordsI[i][j], coordsV[i][j], delta=0.00001) self.assertNotAlmostEqual(coordsI[i][j], coordsIV[i][j], delta=0.00001)