コード例 #1
0
 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')
コード例 #2
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]])
コード例 #3
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'))
コード例 #4
0
ファイル: test_sdm.py プロジェクト: dkratzert/ShelXFile
    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)
コード例 #5
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)
コード例 #6
0
ファイル: test_sdm.py プロジェクト: dkratzert/ShelXFile
    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)
コード例 #7
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))
コード例 #8
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')
コード例 #9
0
 def test_is_an_atom_short(self):
     is_atom = Shelxfile.is_atom('O1    3    0.120080   0.336659   0.494426')
     self.assertEqual(True, is_atom)
コード例 #10
0
 def test_is_no_atom_because_its_a_command2(self):
     is_atom = Shelxfile.is_atom("AFIX")
     self.assertEqual(False, is_atom)
コード例 #11
0
 def test_is_no_atom_because_coordinate_is_missing(self):
     is_an_atom = Shelxfile.is_atom(atomline='O1  4  0.120080    0.494426  11.00000   0.01445 ...')
     self.assertEqual(False, is_an_atom)
コード例 #12
0
ファイル: draw_molecule.py プロジェクト: dkratzert/ShelXFile
            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")
コード例 #13
0
ファイル: test_parse.py プロジェクト: dkratzert/ShelXFile
 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
コード例 #14
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)
コード例 #15
0
ファイル: test_sdm.py プロジェクト: dkratzert/ShelXFile
 def test_vector_length(self):
     shx = Shelxfile()
     shx.read_string(self.head + self.tail)
     sdm = SDM(shx)
     self.assertEqual(7.343581289102655, sdm.vector_length(-0.3665069999999999, 0.293439, -0.06597900000000001))
コード例 #16
0
 def test_is_atom_long_line_true(self):
     """
     """
     is_an_atom = Shelxfile.is_atom(atomline='O1    3    0.120080   0.336659   0.494426  11.00000   0.01445 ...')
     self.assertEqual(True, is_an_atom)
コード例 #17
0
    def test_hkl_checksum(self) -> bool:
        """
        A method to check whether the checksums in the cif file fit to the content.
        """
        cif_hkl_ckecksum = 0
        hkl_checksum_calcd = self.hkl_checksum_calcd
        if hkl_checksum_calcd > 0:
            cif_hkl_ckecksum = self['_shelx_hkl_checksum'] or -1
            try:
                cif_hkl_ckecksum = int(cif_hkl_ckecksum)
            except ValueError:
                cif_hkl_ckecksum = -1
        if cif_hkl_ckecksum > 0 and cif_hkl_ckecksum != hkl_checksum_calcd:
            return False
        else:
            return True


if __name__ == '__main__':
    c = CifContainer('test-data/p21c.cif')
    # print(c.hkl_file)
    # print(c.hkl_as_cif)
    # print(c.test_hkl_checksum())
    s = Shelxfile()
    # print(c.res_file_data)
    s.read_string(c.res_file_data)
    print(s.hklf.n)

# print(CifContainer('tests/examples/1979688.cif').hkl_as_cif[-250:])
コード例 #18
0
 def test_read_file(self):
     shx = Shelxfile()
     with self.assertRaises(FileNotFoundError):
         shx.read_file('tests/resources/foobar.res')
コード例 #19
0
 def hklf_number_from_shelxl_file(self) -> int:
     shx = Shelxfile()
     shx.read_string(self.res_file_data)
     return shx.hklf.n if shx.hklf.n != 0 else 4
コード例 #20
0
 def setUp(self) -> None:
     self.shx = Shelxfile()
     self.shx.read_file('tests/resources/model_finished/p21c.res')
コード例 #21
0
 def test_is_no_atoms_because_type_is_missing(self):
     is_an_atom = Shelxfile.is_atom(atomline='O1    0.120080   0.336659   0.494426  11.00000   0.01445 ...')
     self.assertEqual(False, is_an_atom)