def test_read_lgt_not_defined(self): pdb = readwrite.Files('test.pdb') with self.assertRaises(ValueError) as context: pdb.read_lgt() self.assertTrue( "No lgtfile has been defined" in str(context.exception)) return
def test_read_pdb_flip(self): self.path = os.path.dirname(os.path.abspath(__file__)) pdb = readwrite.Files(os.path.join(self.path, 'test.pdb'), flip=True) pdb.read_pdb() assert_equal(pdb.number_of_timesteps, 6) assert_equal(pdb.times, [0., 10000., 20000., 30000., 40000., 50000.]) assert_equal(len(pdb.atoms), 6) for i in range(0, len(pdb.atoms)): assert_equal(len(pdb.atoms[i]), 3) assert_equal(pdb.atoms[i][0].atom, 'C1') assert_equal(pdb.atoms[i][1].atom, 'C2') assert_equal(pdb.atoms[i][2].atom, 'C3') for i in range(0, 2): assert_equal(pdb.atoms[i * 3][0].zpos, 02.500) assert_equal(pdb.atoms[i * 3][1].zpos, 01.500) assert_equal(pdb.atoms[i * 3][2].zpos, 00.500) assert_equal(pdb.atoms[i * 3 + 1][0].zpos, 00.500) assert_equal(pdb.atoms[i * 3 + 1][1].zpos, 02.500) assert_equal(pdb.atoms[i * 3 + 1][2].zpos, 01.500) assert_equal(pdb.atoms[i * 3 + 2][0].zpos, 01.500) assert_equal(pdb.atoms[i * 3 + 2][1].zpos, 00.500) assert_equal(pdb.atoms[i * 3 + 2][2].zpos, 02.500) assert_equal(pdb.cell, [[1.000, 1.000, 4.000], [2.000, 1.000, 4.000], [3.000, 1.000, 4.000], [4.000, 1.000, 4.000], [5.000, 1.000, 4.000], [6.000, 1.000, 4.000]]) return
def test_average_sld_profile(self): self.path = os.path.dirname(os.path.abspath(__file__)) a = readwrite.Files(os.path.join(self.path, 'test.pdb'), lgtfile=os.path.join(self.path, 'test.lgt'), datfile=os.path.join(self.path, 'test3.dat')) a.read_pdb() a.read_lgt() a.read_dat() b = job.Job(a, 1., 0.) b.set_times(times=[0., 20000., 10000.]) b.set_lgts() c = sld.SLD(b) c.get_sld_profile() c.average_sld_profile() assert_equal(len(c.av_sld_profile), 4) assert_almost_equal(c.av_sld_profile[0].real, 0.) assert_almost_equal(c.av_sld_profile[0].imag, 0.) assert_almost_equal(c.av_sld_profile[1].real, (1e-5 + (2e-5 / 2.) + (3e-5 / 3.)) / 3.) assert_almost_equal(c.av_sld_profile[1].imag, (0 + (1e-5 / 2.) + (2e-5 / 3.)) / 3.) assert_almost_equal(c.av_sld_profile[2].real, (2e-5 + (3e-5 / 2.) + (1e-5 / 3.)) / 3.) assert_almost_equal(c.av_sld_profile[2].imag, ((1e-5) + (2e-5 / 2.) + (0 / 3.)) / 3.) assert_almost_equal(c.av_sld_profile[3].real, (3e-5 + (1e-5 / 2.) + (2e-5 / 3.)) / 3.) assert_almost_equal(c.av_sld_profile[3].imag, ((2e-5) + (0 / 2.) + (1e-5 / 3.)) / 3.) return
def test_set_lgts(self): self.path = os.path.dirname(os.path.abspath(__file__)) a = readwrite.Files(os.path.join(self.path, 'test.pdb'), lgtfile=os.path.join(self.path, 'test.lgt')) a.read_pdb() a.read_lgt() b = job.Job(a, 1., 5.) b.set_lgts() assert_equal(b.new_file, False)
def test_files_standard(self): pdb = readwrite.Files('test.pdb') assert_equal(pdb.pdbfile, 'test.pdb') assert_equal(pdb.lgtfile, None) assert_equal(pdb.datfile, None) assert_equal(pdb.resolution, 5.) assert_equal(pdb.ierror, 5.) assert_equal(pdb.flip, False) return
def test_set_times(self): self.path = os.path.dirname(os.path.abspath(__file__)) a = readwrite.Files(os.path.join(self.path, 'test.pdb'), lgtfile=os.path.join(self.path, 'test.lgt')) a.read_pdb() a.read_lgt() b = job.Job(a, 1., 5.) b.set_times([0., 20000., 10000.]) assert_equal(len(b.times), 3) assert_equal(b.times, [0., 10000., 20000.])
def test_set_run(self): self.path = os.path.dirname(os.path.abspath(__file__)) a = readwrite.Files(os.path.join(self.path, 'test.pdb'), lgtfile=os.path.join(self.path, 'test.lgt'), datfile=os.path.join(self.path, 'test3.dat')) a.read_pdb() a.read_lgt() a.read_dat() b = job.Job(a, 1., 5.) self.path = os.path.dirname(os.path.abspath(__file__)) a2 = readwrite.Files(os.path.join(self.path, 'test2.pdb'), lgtfile=os.path.join(self.path, 'test.lgt'), datfile=os.path.join(self.path, 'test3.dat')) a2.read_pdb() a2.read_lgt() a2.read_dat() b.set_run(files=a2, layer_thickness=2., cut_off_size=3.) assert_equal(b.layer_thickness, 2.) assert_equal(b.cut_off_size, 3.) assert_equal(b.times, [0., 10000., 20000., 30000., 40000.])
def test_get_sld_profile(self): self.path = os.path.dirname(os.path.abspath(__file__)) a = readwrite.Files(os.path.join(self.path, 'test.pdb'), lgtfile=os.path.join(self.path, 'test.lgt'), datfile=os.path.join(self.path, 'test3.dat')) a.read_pdb() a.read_lgt() a.read_dat() b = job.Job(a, 1., 0.) b.set_times(times=[0., 20000., 10000.]) b.set_lgts() c = sld.SLD(b) c.get_sld_profile() assert_equal(len(c.sld_profile), 3) for i in range(0, len(c.sld_profile)): assert_equal(len(c.sld_profile[i]), 4) assert_almost_equal(c.sld_profile[0][0].thick, 1.) assert_almost_equal(c.sld_profile[0][0].real, 0.) assert_almost_equal(c.sld_profile[0][0].imag, 0.) assert_almost_equal(c.sld_profile[0][1].thick, 1.) assert_almost_equal(c.sld_profile[0][1].real, 1e-5) assert_almost_equal(c.sld_profile[0][1].imag, 0.) assert_almost_equal(c.sld_profile[0][2].thick, 1.) assert_almost_equal(c.sld_profile[0][2].real, 2e-5) assert_almost_equal(c.sld_profile[0][2].imag, 1e-5) assert_almost_equal(c.sld_profile[0][3].thick, 1.) assert_almost_equal(c.sld_profile[0][3].real, 3e-5) assert_almost_equal(c.sld_profile[0][3].imag, 2e-5) assert_almost_equal(c.sld_profile[1][0].thick, 1.) assert_almost_equal(c.sld_profile[1][0].real, 0. / 2.) assert_almost_equal(c.sld_profile[1][0].imag, 0. / 2.) assert_almost_equal(c.sld_profile[1][1].thick, 1.) assert_almost_equal(c.sld_profile[1][1].real, 2e-5 / 2.) assert_almost_equal(c.sld_profile[1][1].imag, 1e-5 / 2.) assert_almost_equal(c.sld_profile[1][2].thick, 1.) assert_almost_equal(c.sld_profile[1][2].real, 3e-5 / 2.) assert_almost_equal(c.sld_profile[1][2].imag, 2e-5 / 2.) assert_almost_equal(c.sld_profile[1][3].thick, 1.) assert_almost_equal(c.sld_profile[1][3].real, 1e-5 / 2.) assert_almost_equal(c.sld_profile[1][3].imag, 0 / 2.) assert_almost_equal(c.sld_profile[2][0].thick, 1.) assert_almost_equal(c.sld_profile[2][0].real, 0. / 3.) assert_almost_equal(c.sld_profile[2][0].imag, 0. / 3.) assert_almost_equal(c.sld_profile[2][1].thick, 1.) assert_almost_equal(c.sld_profile[2][1].real, 3e-5 / 3.) assert_almost_equal(c.sld_profile[2][1].imag, 2e-5 / 3.) assert_almost_equal(c.sld_profile[2][2].thick, 1.) assert_almost_equal(c.sld_profile[2][2].real, 1e-5 / 3.) assert_almost_equal(c.sld_profile[2][2].imag, 0 / 3.) assert_almost_equal(c.sld_profile[2][3].thick, 1.) assert_almost_equal(c.sld_profile[2][3].real, 2e-5 / 3.) assert_almost_equal(c.sld_profile[2][3].imag, 1e-5 / 3.) return
def test_get_qs(self): pdb = readwrite.Files('test.pdb') pdb.get_qs(0.0005, 0.0020, 4) assert_equal(len(pdb.expdata), 4) assert_equal(pdb.expdata[0].q, 0.0005) assert_almost_equal(pdb.expdata[0].dq, 0.0005 * 0.05) assert_equal(pdb.expdata[1].q, 0.0010) assert_almost_equal(pdb.expdata[1].dq, 0.0010 * 0.05) assert_equal(pdb.expdata[2].q, 0.0015) assert_almost_equal(pdb.expdata[2].dq, 0.0015 * 0.05) assert_equal(pdb.expdata[3].q, 0.0020) assert_almost_equal(pdb.expdata[3].dq, 0.0020 * 0.05) return
def test_read_dat_not_defined(self): pdb = readwrite.Files('test.pdb') assert_equal(pdb.expdata, []) captured_output = StringIO() sys.stdout = captured_output pdb.read_dat() sys.stdout = sys.__stdout__ assert_equal( captured_output.getvalue(), 'No DAT file has been given, therefore no comparison will be conducted, please use the get_qs ' 'function. Alternatively the DAT file can be added using the setFile function.\n' ) return
def test_files_variation(self): pdb = readwrite.Files('test1.pdb', lgtfile='test1.lgt', datfile='test1.dat', resolution=1., ierror=1., flip=True) assert_equal(pdb.pdbfile, 'test1.pdb') assert_equal(pdb.lgtfile, 'test1.lgt') assert_equal(pdb.datfile, 'test1.dat') assert_equal(pdb.resolution, 1.) assert_equal(pdb.ierror, 1.) assert_equal(pdb.flip, True) return
def test_read_lgt(self): self.path = os.path.dirname(os.path.abspath(__file__)) pdb = readwrite.Files('test.pdb', lgtfile=os.path.join(self.path, 'test.lgt')) pdb.read_lgt() assert_equal(pdb.scat_lens[0].atom, 'C1') assert_almost_equal(pdb.scat_lens[0].real, 1e-5) assert_almost_equal(pdb.scat_lens[0].imag, 0) assert_equal(pdb.scat_lens[1].atom, 'C2') assert_almost_equal(pdb.scat_lens[1].real, 2e-5) assert_almost_equal(pdb.scat_lens[1].imag, 1e-5) assert_equal(pdb.scat_lens[2].atom, 'C3') assert_almost_equal(pdb.scat_lens[2].real, 3e-5) assert_almost_equal(pdb.scat_lens[2].imag, 2e-5) return
def test_read_dat4(self): self.path = os.path.dirname(os.path.abspath(__file__)) pdb = readwrite.Files('test.pdb', datfile=os.path.join(self.path, 'test4.dat')) pdb.read_dat() assert_almost_equal(pdb.expdata[0].q, 0.051793) assert_almost_equal(pdb.expdata[0].i, 0.00034985) assert_almost_equal(pdb.expdata[0].di, 5.0354e-6) assert_almost_equal(pdb.expdata[0].dq, 0.0003) assert_almost_equal(pdb.expdata[1].q, 0.13742) assert_almost_equal(pdb.expdata[1].i, 1.4924e-5) assert_almost_equal(pdb.expdata[1].di, 3.7729e-7) assert_almost_equal(pdb.expdata[1].dq, 0.0007) assert_almost_equal(pdb.expdata[2].q, 0.38285) assert_almost_equal(pdb.expdata[2].i, 1.215e-6) assert_almost_equal(pdb.expdata[2].di, 3.478e-7) assert_almost_equal(pdb.expdata[2].dq, 0.0019) return
def test_read_dat2(self): self.path = os.path.dirname(os.path.abspath(__file__)) pdb = readwrite.Files('test.pdb', datfile=os.path.join(self.path, 'test2.dat')) pdb.read_dat() assert_almost_equal(pdb.expdata[0].q, 0.051793) assert_almost_equal(pdb.expdata[0].i, 0.00034985) assert_almost_equal(pdb.expdata[0].di, 0.00034985 * 0.05) assert_almost_equal(pdb.expdata[0].dq, 0.051793 * 0.05) assert_almost_equal(pdb.expdata[1].q, 0.13742) assert_almost_equal(pdb.expdata[1].i, 1.4924e-5) assert_almost_equal(pdb.expdata[1].di, 1.4924e-5 * 0.05) assert_almost_equal(pdb.expdata[1].dq, 0.13742 * 0.05) assert_almost_equal(pdb.expdata[2].q, 0.38285) assert_almost_equal(pdb.expdata[2].i, 1.215e-6) assert_almost_equal(pdb.expdata[2].di, 1.215e-6 * 0.05) assert_almost_equal(pdb.expdata[2].dq, 0.38285 * 0.05) return
def test_sld(self): self.path = os.path.dirname(os.path.abspath(__file__)) a = readwrite.Files(os.path.join(self.path, 'test.pdb'), lgtfile=os.path.join(self.path, 'test.lgt'), datfile=os.path.join(self.path, 'test3.dat')) a.read_pdb() a.read_lgt() a.read_dat() b = job.Job(a, 1., 5.) b.set_times(times=[0., 20000., 10000.]) b.set_lgts() c = sld.SLD(b) assert_equal(len(c.assigned_job.files.times), 6) assert_equal(c.assigned_job.files.times, [0, 10000., 20000., 30000., 40000., 50000.]) assert_equal(len(c.assigned_job.times), 3) assert_equal(c.assigned_job.times, [0, 10000., 20000.]) assert_equal(c.assigned_job.layer_thickness, 1.) assert_equal(c.assigned_job.cut_off_size, 5.) return
def test_set_pdbfile(self): pdb = readwrite.Files('test.pdb') assert_equal(pdb.pdbfile, 'test.pdb') pdb.set_file(pdbfile='test1.pdb') assert_equal(pdb.pdbfile, 'test1.pdb') return
def test_set_datfile(self): pdb = readwrite.Files('test.pdb') assert_equal(pdb.datfile, None) pdb.set_file(datfile='test1.dat') assert_equal(pdb.datfile, 'test1.dat') return