File: test_smallmol.py

package info (click to toggle)
gemmi 0.7.4%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,644 kB
  • sloc: cpp: 64,445; python: 5,425; ansic: 4,545; sh: 374; makefile: 112; javascript: 86; f90: 42
file content (43 lines) | stat: -rwxr-xr-x 1,535 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python

import os
import unittest
import gemmi

def full_path(filename):
    return os.path.join(os.path.dirname(__file__), filename)

# tests for gemmi/smcif.hpp
class TestRealCif(unittest.TestCase):
    def test_cod_sic(self):
        path = full_path('1011031.cif')
        sic = gemmi.read_small_structure(path)
        self.assertEqual(sic.name, '1011031')
        self.assertEqual(sic.cell.a, 4.358)
        self.assertEqual(sic.cell.alpha, 90.0)
        self.assertEqual(len(sic.sites), 2)
        self.assertEqual(len(sic.get_all_unit_cell_sites()), 8)
        self.assertEqual(4 * sic.sites[1].orth(sic.cell).x, sic.cell.a)

    def test_fen4(self):
        path = full_path('2242624.cif')
        small = gemmi.read_small_structure(path)
        types = small.atom_types
        self.assertEqual(len(types), 2)
        self.assertEqual(types[0].symbol, 'Fe')
        self.assertEqual(types[1].element, gemmi.Element('N'))

    def test_perovskite(self):
        small = gemmi.read_small_structure(full_path('4003024.cif'))
        self.assertEqual(small.spacegroup_hm, 'P m -3 m')
        disorder_groups = [site.disorder_group for site in small.sites]
        self.assertEqual(disorder_groups, [0, 1, 0, 2])

    def test_mgi2(self):
        small = gemmi.read_small_structure(full_path('2013551.cif'))
        for site in small.sites:
            u_eq = small.cell.calculate_u_eq(site.aniso)
            self.assertAlmostEqual(u_eq, site.u_iso, delta=0.00012)

if __name__ == '__main__':
    unittest.main()