Esempio n. 1
0
 def test_read_file_to_list(self):
     shx = Shelxfile()
     shx.read_file('tests/resources/p21c.res')
     self.assertEqual(['TITL p21c in P2(1)/c',
                       '    created by SHELXL-2018/3 at 16:18:25 on 03-May-2018',
                       'CELL 0.71073 10.5086 20.9035 20.5072 90 94.13 90',
                       'ZERR 4 0.0003 0.0005 0.0005 0 0.001 0',
                       'LATT 1'],
                      [str(x) for x in shx._reslist[:5]])
Esempio n. 2
0
class TestShelxfileGoodModel(TestCase):

    def setUp(self) -> None:
        self.shx = Shelxfile()
        self.shx.read_file('tests/resources/model_finished/p21c.res')

    def test_atom_representation(self):
        a = self.shx._reslist[39]
        self.assertEqual(
            'C1     1   -0.187504    0.282782    0.527531    11.00000    0.01807    0.02353      0.01797    0.00008   -0.00179    0.00036',
            str(a))

    def test_atom_object(self):
        a = self.shx._reslist[39]
        self.assertEqual(
            'C1     1   -0.187504    0.282782    0.527531    11.00000    0.01807    0.02353      0.01797    0.00008   -0.00179    0.00036',
            a)
Esempio n. 3
0
    def test_SDM_rustversion(self):
        from shelxfile.shelx.sdm_rust import SDMR
        shx = Shelxfile()
        shx.read_file('tests/resources/p-31c.res')
        sdm = SDMR(shx)
        needsymm = sdm.calc_sdm()
        packed_atoms = sdm.packer(sdm, needsymm)

        for at in packed_atoms:
            if at.qpeak:
                print(at)
                continue
            self.head += wrap_line(str(at)) + '\n'
        self.head += self.tail
        p = Path('tests/resources/test-sdm1.res')
        print('Zeit für sdm:', round(sdm.sdmtime, 3), 's')
        self.assertEqual(p.read_text(), self.head)
Esempio n. 4
0
class TestShelxfileElementToSfac(TestCase):
    """
    SFAC C H O F Al Ga
    """

    def setUp(self) -> None:
        self.shx = Shelxfile()
        self.shx.read_file('tests/resources/p21c.res')

    def test_elem2sfac_oxygen(self):
        self.assertEqual(3, self.shx.elem2sfac('O'))

    def test_elem2sfac_carbon(self):
        self.assertEqual(1, self.shx.elem2sfac('c'))

    def test_elem2sfac_Argon(self):
        self.assertEqual(None, self.shx.elem2sfac('Ar'))
Esempio n. 5
0
class TestRefineFinishedmodel(TestCase):
    def setUp(self) -> None:
        if not find_shelxl_exe():
            self.skipTest('SHELXL not found')
        os.chdir(Path(__file__).parent.parent)
        res = Path('tests/resources/model_finished/p21c.res')
        hkl = Path('tests/resources/model_finished/p21c.hkl')
        shutil.copy(res, '.')
        shutil.copy(hkl, '.')
        self.shx = Shelxfile()
        self.shx.read_file('./p21c.res')

    def tearDown(self) -> None:
        os.chdir(Path(__file__).parent.parent)
        clean_refine_files('p21c')

    def test_refine_with_cycle_number_set_to_4_in_LScycles(self):
        self.assertTrue('L.S. 10' in Path('p21c.res').read_text())
        self.shx.cycles.set_refine_cycles(4)
        self.shx.refine(backup_before=False)
        txt = Path('p21c.res').read_text()
        self.assertTrue('L.S. 4' in txt)

    def test_refine_with_cycle_number_set_to_4_in_refine(self):
        self.assertTrue('L.S. 10' in Path('p21c.res').read_text())
        self.shx.refine(4, backup_before=False)
        txt = Path('p21c.res').read_text()
        self.assertTrue('L.S. 4' in txt)

    def test_refine_with_ANIS_inserted_and_cycle_number_set_to_4_in_refine(
            self):
        self.assertFalse('ANIS' in Path('p21c.res').read_text())
        self.shx.insert_anis()
        self.shx.refine(3, backup_before=False)
        self.assertTrue('ANIS' in Path('p21c.ins').read_text())
        self.assertFalse('ANIS' in Path('p21c.res').read_text())

    def test_refine_with_cycle_number_set_to_0_in_refine(self):
        self.assertTrue('L.S. 10' in Path('p21c.res').read_text())
        self.refine = self.shx.refine(0, backup_before=False)
        txt = Path('p21c.res').read_text()
        self.assertTrue('L.S. 0' in txt)
Esempio n. 6
0
    def test_SDM(self):
        shx = Shelxfile()
        shx.read_file('tests/resources/p-31c.res')
        sdm = SDM(shx)
        needsymm = sdm.calc_sdm()
        packed_atoms = sdm.packer(sdm, needsymm)
        # print(needsymm)
        # [[8, 5, 5, 5, 1], [16, 5, 5, 5, 1], [7, 4, 5, 5, 3]]
        # print(len(shx.atoms))
        # print(len(packed_atoms))

        for at in packed_atoms:
            if at.qpeak:
                continue
            # print(wrap_line(str(at)))
            self.head += wrap_line(str(at)) + '\n'
        self.head += self.tail
        p = Path('tests/resources/test-sdm1.res')
        print('Zeit für sdm:', round(sdm.sdmtime, 3), 's')
        self.assertEqual(p.read_text(), self.head)
Esempio n. 7
0
class TestShelxfile(TestCase):

    def setUp(self) -> None:
        self.shx = Shelxfile()
        self.shx.read_file('tests/resources/p21c.res')

    def test_sfac2elem_C(self):
        self.assertEqual('C', self.shx.sfac2elem(1))

    def test_sfac2elem_H(self):
        self.assertEqual('H', self.shx.sfac2elem(2))

    def test_sfac2elem_O(self):
        self.assertEqual('O', self.shx.sfac2elem(3))

    def test_sfac2elem_Al(self):
        self.assertEqual('Al', self.shx.sfac2elem(5))

    def test_sfac2elem_not_existent(self):
        self.assertEqual('', self.shx.sfac2elem(8))

    def test_sfac2elem_zero(self):
        self.assertEqual('', self.shx.sfac2elem(0))

    def test_sum_formula(self):
        self.assertEqual('C0.25 H0.5 O0.75 F1 AL1.25 GA1.5', self.shx.sum_formula)

    def test_read_file_to_list(self):
        shx = Shelxfile()
        shx.read_file('tests/resources/p21c.res')
        self.assertEqual(['TITL p21c in P2(1)/c',
                          '    created by SHELXL-2018/3 at 16:18:25 on 03-May-2018',
                          'CELL 0.71073 10.5086 20.9035 20.5072 90 94.13 90',
                          'ZERR 4 0.0003 0.0005 0.0005 0 0.001 0',
                          'LATT 1'],
                         [str(x) for x in shx._reslist[:5]])

    def test_read_file(self):
        shx = Shelxfile()
        with self.assertRaises(FileNotFoundError):
            shx.read_file('tests/resources/foobar.res')
Esempio n. 8
0
class TestRefine(TestCase):
    def setUp(self) -> None:
        if not find_shelxl_exe():
            self.skipTest('SHELXL not found')
        os.chdir(Path(__file__).parent.parent)
        res = Path('tests/resources/complete_run/p21c.res')
        shutil.copy(res, '.')
        self.shx = Shelxfile()
        self.shx.read_file('./p21c.res')

    def tearDown(self) -> None:
        os.chdir(Path(__file__).parent.parent)
        clean_refine_files('p21c')

    def test_get_xl_version_string_with_no_path(self):
        self.assertEqual('', get_xl_version_string(''))

    def test_get_xl_version_string_with_real_path(self):
        shx = which('shelxl') if which('shelxl') else which('xl')
        self.assertEqual('2019/2', get_xl_version_string(shx))

    def test_check_cycle_numbers(self):
        self.assertEqual('L.S. 10', str(self.shx.cycles))

    def test_set_cycle_numbers_directly(self):
        self.shx.cycles.number = 3
        self.assertEqual('L.S. 3', str(self.shx.cycles))

    def test_set_cycle_numbers_by_set_function(self):
        self.shx.cycles.set_refine_cycles(4)
        self.assertEqual('L.S. 4', str(self.shx.cycles))
        self.assertEqual('L.S. 4',
                         self.shx._reslist[self.shx.cycles.index].__repr__())

    def test_set_cycle_numbers_negative(self):
        self.shx.cycles.set_refine_cycles(-1)
        self.assertEqual('L.S. -1', str(self.shx.cycles))

    def test_set_cycle_numbers_directly2(self):
        self.shx.cycles.cycles = 3
        self.assertEqual('L.S. 10', str(self.shx.cycles))
Esempio n. 9
0
 def test_read_file(self):
     shx = Shelxfile()
     with self.assertRaises(FileNotFoundError):
         shx.read_file('tests/resources/foobar.res')
Esempio n. 10
0
            self.append([])
            for _ in range(self.height):
                self[i].append(" ")

    def set(self, index, val):
        x = index[0]
        y = index[1]
        self[x][y] = val

    def show(self):
        for row in self:
            print("".join(row))


if __name__ == "__main__":
    shx = Shelxfile()
    shx.read_file('./tests/resources/p21c.res')
    try:
        width = sys.argv[2]
        height = sys.argv[3]
        dims = (int(width), int(height) - 1)
    except IndexError:
        dims = None
    angle = 0
    angle_incr = (2 * pi) * (1 / 40)  # 40th of a circle
    while True:
        Molecule(shx.atoms).draw(plane=[Coordinate(0, 1, 0), Coordinate(sin(angle), 0, cos(angle))], dimensions=dims)
        angle = angle + angle_incr
        time.sleep(0.5)
        print("\33[H")
Esempio n. 11
0
 def test_parse_hklf_after_uncloded_resi(self):
     shx = Shelxfile()
     shx.read_file(r'tests/resources/unclosed_resi.res')
     self.assertEqual('HKLF 4 1  1 0 0 0 1 0 0 0 1  1 0',
                      shx.hklf.__repr__())  # add assertion here