Esempio n. 1
0
def test_structurefactor():
    asyunit = cr.Atomset({
        cr.Atom("Ca1", "Ca", fs("p 0     0     0")),
        cr.Atom("Mn1", "Mn", fs("p 1/2   0     0")),
        cr.Atom("Mn2", "Mn", fs("p 1/2   0     0")),
        cr.Atom("Mn3", "Mn", fs("p 0     0     1/2")),
        cr.Atom("O1", "O", fs("p 0.223 0.274 0.081")),
        cr.Atom("O2", "O", fs("p 0.342 0.522 0.341"))
    })
    sg = tables.spacegroup(148)
    cell = sg**asyunit
    cellparameters = geo.Cellparameters(10.46, 10.46, 6.35, 90, 90, 120)
    metric = cellparameters.to_Metric()
    q = fs("q 3 0 0")
    wavelength = 0.71073
    F = cr.structurefactor(cell, metric, q, wavelength)
    #    assert test_numbers_Mixed.approx(-6.540191224, F.real)
    #    assert test_numbers_Mixed.approx(0.0, F.imag)

    cell = cr.Atomset({
        cr.Atom("Au1", "Au", fs("p 0   0   0  ")),
        cr.Atom("Cu1", "Cu", fs("p 0   1/2 1/2")),
        cr.Atom("Cu2", "Cu", fs("p 1/2 0   1/2")),
        cr.Atom("Cu3", "Cu", fs("p 1/2 1/2 0  "))
    })
    cellparameters = geo.Cellparameters(3.71, 3.71, 3.71, 90, 90, 90)
    metric = cellparameters.to_Metric()
    q = fs("q 1 0 0")
    sintl = 0.5 * metric.length(q)
Esempio n. 2
0
def test_Face():
    f = cr.Face("F", [fs("p 0 0 0"), fs("p 1.0 0 0"), fs("p 0 1.0 0")])
    f_ = cr.Face("F", [fs("p 0 1.0 0"), fs("p 0 0 0"), fs("p 1.0 0 0")])
    f__ = cr.Face("F", [fs("p 0 1.0 0"), fs("p 1.0 0 0"), fs("p 0 0 0")])
    assert f == f_
    assert hash(f) == hash(f_)
    assert f == f__
    assert hash(f) == hash(f__)
    f = cr.Face("F", [fs("p 0 0 0"), fs("p 1 0 0"), fs("p 0 1 0")])
    f_ = cr.Face("F", [fs("p 0 1 0"), fs("p 0 0 0"), fs("p 1 0 0")])
    assert isinstance(f, cr.Face)
    f.set_color((0, 0, 1))
    f.set_color((fs("0.3"), 0.1, 1))
    f.set_opacity(0.5)
    d = fs("d 0 0 1/2")
    f1 = cr.Face("Fblabla", [fs("p 0 0 0"), fs("p 1 0 0"), fs("p 0 1 0")])
    f2 = cr.Face("F", [fs("p 0 0 0"), fs("p 0.7 0 0"), fs("p 0 1 0")])
    f3 = cr.Face("F", [fs("p 0 0 0"), fs("p 1 0 0"), fs("p 0 2 0")])
    assert f == f1
    assert f == f_
    assert hash(f) == hash(f_)
    assert (f == f2) == False
    assert (f == f3) == False
    assert f + d == cr.Face("F", [fs("p 0 0 1/2"), fs("p 1 0 1/2"), fs("p 0 1 1/2")])
    assert fs("x+1/2,y,z") ** f == cr.Face("F", [fs("p 1/2 0 0"), fs("p 3/2 0 0"), fs("p 1/2 1 0")])
    assert fs("{x+3/2,y,z}") ** f == cr.Face("F", [fs("p 1/2 0 0"), fs("p 1/2 0 0"), fs("p 1/2 0 0")])
    f = cr.Face("F", [fs("p 0 0 0"), fs("p 1 0 0"), fs("p 0 1 0")])
    assert (f + "test").name == "Ftest"

    three = fs("{-y,x-y,z}")
    sg = geo.Spacegroup(
        geo.canonical,
        [fs("{x,y,z}"), three, three*three]
    )
    p1 = fs("p 0.1740 0.8260 0.5871")
    p2 = fs("-y,x-y,z")**p1
    p3 = fs("-y,x-y,z")**p2
    a1 = cr.Atom("Fe1", "Fe", p1)
    a2 = cr.Atom("Fe2", "Fe", p2)
    a3 = cr.Atom("Fe3", "Fe", p3)
    atomset = cr.Atomset({a1, a2, a3})
    atomset = sg**atomset
    print(atomset)
    assert len(atomset.menge) == 3
    f = cr.Face("F", [p1, p2, p3])
    atomset = cr.Atomset({f})
    assert len(atomset.menge) == 1
    atomset = sg ** atomset
    assert len(atomset.menge) == 1
Esempio n. 3
0
def test_print_cif():
    atomset = \
        cr.Atomset({cr.Atom("Dy1", "Dy", fs("p 0.982(0)    0.082(0)  1/4        ")),
                cr.Atom("Mn1", "Mn", fs("p 1/2         0         0          ")),
                cr.Atom("O1", "O", fs("p 0.108(2)    0.471(2)  1/4        ")),
                cr.Atom("O2", "O", fs("p 0.707(1)    0.328(1)  0.052(1)   "))})

    sg = geo.Spacegroup(geo.canonical, [fs("{x,y,z}"), fs("{-x,-y,-z}")])
    liste = ["Dy1", "Mn1", "O1", "O2"]

    atomset_all = (sg**atomset) % geo.canonical

    assert cryspy_niceprint.print_cif_without_symmetries(
        liste, atomset_all) == "hallo"
Esempio n. 4
0
def test_print_atomtable():
    atomset = \
        cr.Atomset({cr.Atom("Dy1", "Dy", fs("p 0.982(0)    0.082(0)  1/4        ")),
                cr.Atom("Mn1", "Mn", fs("p 1/2         0         0          ")),
                cr.Atom("O1", "O", fs("p 0.108(2)    0.471(2)  1/4        ")),
                cr.Atom("O2", "O", fs("p 0.707(1)    0.328(1)  0.052(1)   "))})

    liste = ["Dy1", "Mn1", "O1", "O2"]
    assert cryspy.niceprint.atomtable(liste, atomset) == \
        "  name  type          x           y           z \n" \
        "  ----  ----         ---         ---         ---\n" \
        "   Dy1    Dy    0.982(0)    0.082(0)         1/4\n" \
        "   Mn1    Mn         1/2           0           0\n" \
        "    O1     O  0.1080(20)  0.4710(20)         1/4\n" \
        "    O2     O  0.7070(10)  0.3280(10)  0.0520(10)"
Esempio n. 5
0
def test_print_cif():
    atomset = \
        cr.Atomset({cr.Atom("Dy1", "Dy", fs("p 0.982(0)    0.082(0)  1/4        ")),
                cr.Atom("Mn1", "Mn", fs("p 1/2         0         0          ")),
                cr.Atom("O1", "O", fs("p 0.108(2)    0.471(2)  1/4        ")),
                cr.Atom("O2", "O", fs("p 0.707(1)    0.328(1)  0.052(1)   "))})

    sg = geo.Spacegroup(geo.canonical, [fs("{x,y,z}"), fs("{-x,-y,-z}")])
    liste = ["Dy1", "Dy1_1", "Mn1", "O1", "O1_1", "O2", "O2_1"]

    atomset_all = (sg**atomset) % geo.canonical
    metric = geo.Cellparameters(5.0, 5.0, 5.0, 90, 90, 90).to_Metric()
    print(
        cryspy.niceprint.print_cif_without_symmetries(liste, atomset_all,
                                                      metric))
    assert cryspy.niceprint.print_cif_without_symmetries(liste, atomset_all, metric) == \
    "data_global _chemical_name 'noname' \n" \
    "_cell_length_a 5.0\n" \
    "_cell_length_b 5.0\n" \
    "_cell_length_c 5.0\n" \
    "_cell_angle_alpha 90\n" \
    "_cell_angle_beta 90\n" \
    "_cell_angle_gamma 90\n" \
    "_symmetry_space_group_name_H-M 'P 1'\n" \
    "loop_ \n" \
    " _atom_site_label \n" \
    " _atom_site_type_symbol \n" \
    " _atom_site_fract_x \n" \
    " _atom_site_fract_y \n" \
    " _atom_site_fract_z \n" \
    "  Dy1_1 Dy 0.982000 0.082000 0.250000\n" \
    "  Dy1_1_1 Dy 0.018000 0.918000 0.750000\n" \
    "  Mn1_1 Mn 0.500000 0.000000 0.000000\n" \
    "  O1_1 O 0.108000 0.471000 0.250000\n" \
    "  O1_1_1 O 0.892000 0.529000 0.750000\n" \
    "  O2_1 O 0.707000 0.328000 0.052000\n" \
    "  O2_1_1 O 0.293000 0.672000 0.948000\n"
Esempio n. 6
0
def test_Atomset():
    atom1 = cr.Atom("Cs1", "Cs", fs("p 0 0 0"))
    atom2 = cr.Atom("Cs2", "Cs", fs("p 1/4 1/4 0"))
    momentum = cr.Momentum("M", fs("p 0 0 0"), fs("d 0 0 1"))
    bond = cr.Bond("B", fs("p 0 0 0"), fs("p 1/2 1/2 1/2"))
    face = cr.Face("F", [fs("p 0 0 0"), fs("p 1 0 0"), fs("p 0 1 0")])
    atomset = cr.Atomset({atom1, atom2, momentum, bond, face})
    print(atomset)
    assert atomset.__str__() == \
        "Atomset                          \n" \
        "-------                          \n" \
        "         Atom Cs1 Cs Pos /  0  \ \n" \
        "                        |   0   |\n" \
        "                         \  0  / \n" \
        "                                 \n" \
        "       Atom Cs2 Cs Pos /  1/4  \ \n" \
        "                      |   1/4   |\n" \
        "                       \    0  / \n" \
        "                                 \n" \
        "                         Momentum\n" \
        "                             Bond\n" \
        "                             Face"

    transformation = fs("O->(0,0,1/4) \n"
                        "then\n"
                        "a' = a+b \n"
                        "b' = b   \n"
                        "c' = c")
    atomset1 = transformation**atomset
    atomset2 = cr.Atomset({cr.Atom("Cs1", "Cs", fs("p 0 0 -1/4")), \
                           cr.Atom("Cs2", "Cs", fs("p 1/4 0 -1/4")), \
                           cr.Momentum("M", fs("p 0 0 -1/4"), fs("d 0 0 1")), \
                           cr.Bond("B", fs("p 0 0 -1/4"), fs("p 1/2 0 1/4")), \
                           cr.Face("F", [fs("p 0 0 -1/4"), fs("p 1 -1 -1/4"), fs("p 0 1 -1/4")])})
    assert (transformation**bond) == cr.Bond("B", fs("p 0 0 -1/4"),
                                             fs("p 1/2 0 1/4"))
    assert (transformation**face) == cr.Face(
        "F", [fs("p 0 0 -1/4"),
              fs("p 1 -1 -1/4"),
              fs("p 0 1 -1/4")])
    assert atomset1 == atomset2

    spacegroup = geo.Spacegroup(
        geo.canonical, [fs("{x, y, z}"), fs("{-x, -y, -z}")])

    atomset1 = spacegroup**atomset
    atomset2 = cr.Atomset({cr.Atom("Cs1", "Cs", fs("p 0 0 0")), \
                           cr.Atom("Cs2", "Cs", fs("p 1/4 1/4 0")), \
                           cr.Atom("Cs2_1", "Cs", fs("p 3/4 3/4 0")), \
                           momentum, \
                           bond, \
                           cr.Face("F", [fs("p 0 0 0"), fs("p 0 0 0"), fs("p 0 0 0")])})
    assert atomset1 == atomset2
    assert atomset1.atomnames == atomset2.atomnames

    atomset1 = spacegroup**(atomset + "_1")
    atomset2 = cr.Atomset({cr.Atom("Cs1_1", "Cs", fs("p 0 0 0")), \
                           cr.Atom("Cs2_1", "Cs", fs("p 1/4 1/4 0")), \
                           cr.Atom("Cs2_2", "Cs", fs("p 3/4 3/4 0")), \
                           momentum, \
                           bond, \
                           cr.Face("F", [fs("p 0 0 0"), fs("p 0 0 0"), fs("p 0 0 0")])})
    assert atomset1 == atomset2
    assert atomset1.atomnames == atomset2.atomnames

    atomset = cr.Atomset({
        cr.Atom("Cs1", "Cs", fs("p 0 0 -1/4")),
        cr.Atom("Cs2", "Cs", fs("p 1/4 0 -1/4"))
    })
    atomset1 = atomset % geo.canonical
    atomset2 = cr.Atomset({
        cr.Atom("Cs1", "Cs", fs("p 0 0 3/4")),
        cr.Atom("Cs2", "Cs", fs("p 1/4 0 3/4"))
    })

    assert atomset1 == atomset2

    atomset1 = cr.Atomset({cr.Atom("Cs1", "Cs", fs("p 0 0 0"))})
    atomset2 = cr.Atomset({cr.Atom("Cu1", "Cu", fs("p 1/2 1/2 1/2"))})
    atomset3 = atomset1 + atomset2
    atomset4 = cr.Atomset({
        cr.Atom("Cs1", "Cs", fs("p 0 0 0")),
        cr.Atom("Cu1", "Cu", fs("p 1/2 1/2 1/2"))
    })
    assert atomset3 == atomset4

    d = fs("d 1/2 0 0")
    atomset5 = cr.Atomset({cr.Atom("Cs1", "Cs", fs("p 1/2 0 0"))})
    atomset6 = atomset1 + d
    atomset7 = d + atomset1
    assert atomset5 == atomset6
    assert atomset5 == atomset7

    atomset = cr.Atomset({
        cr.Atom("Cs1", "Cs", fs("p 0 0 -1/4")),
        cr.Atom("Cs2", "Cs", fs("p 1/4 0 -1/4"))
    })
    assert atomset.nextname("Cs1") == "Cs1_1"
    assert atomset.nextname("Cs3") == "Cs3"

    atomset = cr.Atomset({
        cr.Atom("Cs_1", "Cs", fs("p 0 0 -1/4")),
        cr.Atom("Ar_1", "Cs", fs("p 1/4 0 -1/4")),
        cr.Atom("Ar_2", "Ar", fs("p 0 1/2 0"))
    })
    assert atomset.nextname("Cs_1") == "Cs_2"
    assert atomset.nextname("Ar_2") == "Ar_3"
    assert atomset.nextname("Ar_1") == "Ar_3"
Esempio n. 7
0
def test_Atomset():
    atom1 = cr.Atom("Cs1", "Cs", fs("p 0.0000 0 0"))
    atom1a = cr.Atom("Cs1", "Cs", fs("p 0.00000001 0 0"))
    atom2 = cr.Atom("Cs2", "Cs", fs("p 1/4 1/4 0"))
    momentum = cr.Momentum("M", fs("p 0 0 0"), fs("d 0 0 1"))
    bond = cr.Bond("B", fs("p 0 0 0"), fs("p 1/2 1/2 1/2"))
    face = cr.Face("F", [fs("p 0 0 0"), fs("p 1 0 0"), fs("p 0 1 0")])
    assert hash(atom1) == hash(atom1a)
    assert len({atom1, atom1a}) == 1
    atomset = cr.Atomset({atom1, atom1a, atom2, momentum, bond, face})
    assert atomset.__str__() == \
        "Atomset                            \n" \
        "-------                            \n" \
        "       Atom Cs1 Cs Pos /  1e-08  \ \n" \
        "                      |       0   |\n" \
        "                       \      0  / \n" \
        "                                   \n" \
        "         Atom Cs2 Cs Pos /  1/4  \ \n" \
        "                        |   1/4   |\n" \
        "                         \    0  / \n" \
        "                                   \n" \
        "                           Momentum\n" \
        "                               Bond\n" \
        "                               Face"

    transformation = fs("O->(0,0,1/4) \n"
                        "then\n"
                        "a' = a+b \n"
                        "b' = b   \n"
                        "c' = c")
    atomset1 = transformation**atomset
    print(atomset1)
    atomset2 = cr.Atomset({cr.Atom("Cs1", "Cs", fs("p 0.00000001 -0.00000001 -1/4")), \
                           cr.Atom("Cs2", "Cs", fs("p 1/4 0 -1/4")), \
                           cr.Momentum("M", fs("p 0 0 -1/4"), fs("d 0 0 1")), \
                           cr.Bond("B", fs("p 0 0 -1/4"), fs("p 1/2 0 1/4")), \
                           cr.Face("F", [fs("p 0 0 -1/4"), fs("p 1 -1 -1/4"), fs("p 0 1 -1/4")])})
    assert (transformation ** bond) == cr.Bond("B", fs("p 0 0 -1/4"), fs("p 1/2 0 1/4"))
    assert (transformation ** face) == cr.Face("F", [fs("p 0 0 -1/4"), fs("p 1 -1 -1/4"), fs("p 0 1 -1/4")])
    assert atomset1 == atomset2

    atom1 = cr.Atom("Cs1", "Cs", fs("p 0 0 0"))
    atom2 = cr.Atom("Cs2", "Cs", fs("p 1/4 1/4 0"))
    momentum = cr.Momentum("M", fs("p 0 0 0"), fs("d 0 0 1"))
    bond = cr.Bond("B", fs("p 0 0 0"), fs("p 1/2 1/2 1/2"))
    face = cr.Face("F", [fs("p 0 0 0"), fs("p 1 0 0"), fs("p 0 1 0")])
    atomset = cr.Atomset({atom1, atom2, momentum, bond, face})
 
    spacegroup = geo.Spacegroup(geo.canonical, [fs("{x, y, z}"),
                                                fs("{-x, -y, -z}")])

    atomset1 = spacegroup ** atomset
    atomset2 = cr.Atomset({cr.Atom("Cs1", "Cs", fs("p 0 0 0")), \
                           cr.Atom("Cs2", "Cs", fs("p 1/4 1/4 0")), \
                           cr.Atom("Cs2_1", "Cs", fs("p 3/4 3/4 0")), \
                           momentum, \
                           bond, \
                           cr.Face("F", [fs("p 0 0 0"), fs("p 0 0 0"), fs("p 0 0 0")])})
    assert atomset1 == atomset2
    assert atomset1.names == atomset2.names

    atomset1 = spacegroup ** (atomset + "_1")
    atomset2 = cr.Atomset({cr.Atom("Cs1_1", "Cs", fs("p 0 0 0")), \
                           cr.Atom("Cs2_1", "Cs", fs("p 1/4 1/4 0")), \
                           cr.Atom("Cs2_2", "Cs", fs("p 3/4 3/4 0")), \
                           momentum, \
                           bond, \
                           cr.Face("F", [fs("p 0 0 0"), fs("p 0 0 0"), fs("p 0 0 0")])})
    assert atomset1 == atomset2
    assert atomset1.names == atomset2.names


    atomset = cr.Atomset({cr.Atom("Cs1", "Cs", fs("p 0 0 -1/4")),
                          cr.Atom("Cs2", "Cs", fs("p 1/4 0 -1/4"))})
    atomset1 = atomset % geo.canonical
    atomset2 = cr.Atomset({cr.Atom("Cs1", "Cs", fs("p 0 0 3/4")),
                          cr.Atom("Cs2", "Cs", fs("p 1/4 0 3/4"))})

    assert atomset1 == atomset2

    atomset1 = cr.Atomset({cr.Atom("Cs1", "Cs", fs("p 0 0 0"))})
    atomset2 = cr.Atomset({cr.Atom("Cu1", "Cu", fs("p 1/2 1/2 1/2"))})
    atomset3 = atomset1 + atomset2
    atomset4 = cr.Atomset({cr.Atom("Cs1", "Cs", fs("p 0 0 0")),
                           cr.Atom("Cu1", "Cu", fs("p 1/2 1/2 1/2"))})
    assert atomset3 == atomset4

    d = fs("d 1/2 0 0")
    atomset5 = cr.Atomset({cr.Atom("Cs1", "Cs", fs("p 1/2 0 0"))})
    atomset6 = atomset1 + d
    atomset7 = d + atomset1
    assert atomset5 == atomset6
    assert atomset5 == atomset7

    atomset = cr.Atomset({cr.Atom("Cs1", "Cs", fs("p 0 0 -1/4")),
                          cr.Atom("Cs2", "Cs", fs("p 1/4 0 -1/4"))})
    assert atomset.nextname("Cs1") == "Cs1_1"
    assert atomset.nextname("Cs3") == "Cs3"

    atomset = cr.Atomset({cr.Atom("Cs_1", "Cs", fs("p 0 0 -1/4")),
                          cr.Atom("Ar_1", "Cs", fs("p 1/4 0 -1/4")),
                          cr.Atom("Ar_2", "Ar", fs("p 0 1/2 0"))})
    assert atomset.nextname("Cs_1") == "Cs_2"
    assert atomset.nextname("Ar_2") == "Ar_3"
    assert atomset.nextname("Ar_1") == "Ar_3"

    atomset = cr.Atomset({cr.Subset("S_1", fs("p 0 0 0"), {
                                        cr.Atom("Fe1", "Fe", fs("p -0.1 0 0")),
                                        cr.Atom("Fe2", "Fe", fs("p  0.1 0 0"))
                                    }
                          )
    })
    sg = geo.Spacegroup(geo.canonical, [fs("{x, y, z}"), fs("{x, -y+1/2, z}")])
    assert sg.is_really_a_spacegroup()
    atomset1 = cr.Atomset({cr.Subset("S_1", fs("p 0 0 0"), {
                                        cr.Atom("Fe1", "Fe", fs("p -0.1 0 0")),
                                        cr.Atom("Fe2", "Fe", fs("p  0.1 0 0"))
                                    }
                          ),
                           cr.Subset("S_2", fs("p 0 1/2 0"), {
                                        cr.Atom("Fe1", "Fe", fs("p -0.1 1/2 0")),
                                        cr.Atom("Fe2", "Fe", fs("p  0.1 1/2 0"))
                                    }
                          )

    })
    
    assert sg ** atomset == atomset1
    
    atomset_unpacked = cr.Atomset({
        cr.Atom("S_1:Fe1", "Fe", fs("p -0.1  0  0")),
        cr.Atom("S_1:Fe2", "Fe", fs("p  0.1  0  0")),
        cr.Atom("S_2:Fe1", "Fe", fs("p -0.1 1/2 0")),
        cr.Atom("S_2:Fe2", "Fe", fs("p  0.1 1/2 0"))
    })
    for subset in (sg ** atomset).menge:
        print(subset.name)
    assert (sg ** atomset).unpack_subsets() == atomset_unpacked
    assert (sg ** atomset).names \
        == atomset1.names
    assert ((sg ** atomset).unpack_subsets()).names \
        == atomset_unpacked.names