コード例 #1
0
def test_cif_parse():
    tools.skip_if_pkg_missing('CifFile')
    for filename in ['files/cif_struct.cif', 'files/cif_cart_struct.cif']:
        p1 = CifFile(filename).get_struct()
        assert p1.cell is not None
        assert p1.cryst_const is not None
        assert p1.symbols is not None
        assert p1.coords is not None
        assert p1.coords_frac is not None

        # test writing
        filename = os.path.join(testdir, 'test_write_cif.cif')
        io.write_cif(filename, p1)
        p2 = CifFile(filename).get_struct()
        np.testing.assert_array_almost_equal(p1.coords_frac, p2.coords_frac)
        np.testing.assert_array_almost_equal(p1.coords, p2.coords)
        np.testing.assert_array_almost_equal(p1.cryst_const, p2.cryst_const)
        np.testing.assert_array_almost_equal(p1.cell, p2.cell)
        assert p1.symbols == p2.symbols
コード例 #2
0
def test_symmetry():
    tools.skip_if_pkg_missing('pyspglib')
    st_prim = crys.Structure(coords_frac=np.array([[0] * 3, [.5] * 3]),
                             cryst_const=np.array([3.5] * 3 + [60] * 3),
                             symbols=['Al', 'N'])
    st_sc = crys.scell(st_prim, (2, 3, 4))
    st_prim2 = symmetry.spglib_get_primitive(st_sc, symprec=1e-2)
    # irreducible structs
    assert symmetry.spglib_get_primitive(st_prim, symprec=1e-2) is None
    assert symmetry.spglib_get_primitive(st_prim2, symprec=1e-2) is None
    for st in [st_prim, st_sc, st_prim2]:
        assert symmetry.spglib_get_spacegroup(st_prim,
                                              symprec=1e-2) == (225, 'Fm-3m')
    # this is redundant since we have is_same_struct(), but keep it anyway
    tools.assert_dict_with_all_types_almost_equal(
        st_prim.__dict__,
        st_prim2.__dict__,
        keys=['natoms', 'symbols', 'volume', 'cryst_const'])
    assert symmetry.is_same_struct(st_prim, st_prim2)
コード例 #3
0
ファイル: test_angle.py プロジェクト: zari277/pwtools
def test_angle():
    # CaCl struct, the supercell will have 0 and 180 degrees -> check corner
    # cases
    tools.skip_if_pkg_missing('CifFile')
    st = io.read_cif('files/angle/rs.cif')
    st = crys.scell(st, (2, 1, 1))
    nang = st.natoms * (st.natoms - 1) * (st.natoms - 2)
    mask_val = 999.0
    for deg in [True, False]:
        for pbc in [True, False]:
            agf = crys.angles(st, pbc=pbc, mask_val=mask_val)
            agpy, aipy = angles(st, pbc=pbc, mask_val=mask_val)
            eps = np.finfo(float).eps * 5
            assert np.allclose(agf, agpy)
            assert aipy.shape[0] == nang
            assert len((agf != mask_val).nonzero()[0]) == nang
            angleidx = np.array(list(zip(*(agf != mask_val).nonzero())))
            assert (angleidx == aipy).all()
            assert not np.isnan(agpy).any(), "python angle nan"
            assert not np.isnan(agf).any(), "fortran angle nan"
            # do we have 0 and 180 degrees?
            assert (agf < eps).any(), "no zero degree cases"
            assert (agf - 180.0 < eps).any(), "no 180 degree cases"
            assert (agf >= 0.0).all(), "negative angles"
コード例 #4
0
def test_cif2sgroup():
    tools.skip_if_pkg_missing('CifFile')
    exe = os.path.join(os.path.dirname(__file__), '../../bin/cif2sgroup.py')
    cmd = '{e} files/cif_struct.cif > cif2sgroup.log'.format(e=exe)
    sp.run(cmd, check=True, shell=True)
コード例 #5
0
 def __init__(self):
     tools.skip_if_pkg_missing('pyspglib')