Exemplo n.º 1
0
def test_fill():
    atomset = cryspy.crystal.Atomset({cryspy.crystal.Atom("Fe1", "Fe", fs("p 1/2 1/2 1/2"))})
    atomset = cryspy.utils.fill(atomset, [0.6, 0.6, 0.6])
    assert len(atomset.menge) == 27
    
    atomset = cryspy.crystal.Atomset({cryspy.crystal.Atom("Fe1", "Fe", fs("p 0 0 0"))})
    atomset = cryspy.utils.fill(atomset, [0.1, 0.1, 0.1])
    assert len(atomset.menge) == 8
Exemplo n.º 2
0
def read_atomset_from_cif(infilepathname):
    # So far only for cif-files generated by JANA2006, and even this
    # without any warranty, and maybe not all parameters.
    infile = open(infilepathname, "r")
    status = "waiting_for_loop"
    loop_header = []
    menge = set([])
    for line in infile:
        words = line.split()
        if len(words) >= 1:
            if status == "reading_loop_header":
                if words[0][0] == "_":
                    loop_header += [words[0]]
                else:
                    print(loop_header)
                    status = "reading_loop_data"
            if status == "reading_loop_data":
                if len(words) == len(loop_header):
                    atom_name = None
                    atom_type = None
                    x = None
                    y = None
                    z = None
                    for i in range(len(loop_header)):
                        if loop_header[i] == "_atom_site_label":
                            atom_name = words[i]
                        if loop_header[i] == "_atom_site_type_symbol":
                            atom_type = words[i]
                        if loop_header[i] == "_atom_site_fract_x":
                            x = fs(words[i])
                        if loop_header[i] == "_atom_site_fract_y":
                            y = fs(words[i])
                        if loop_header[i] == "_atom_site_fract_z":
                            z = fs(words[i])
                    if      isinstance(atom_name, str) \
                        and isinstance(atom_type, str) \
                        and isinstance(x, cryspy.numbers.Mixed) \
                        and isinstance(y, cryspy.numbers.Mixed) \
                        and isinstance(z, cryspy.numbers.Mixed):
                        print(atom_name, atom_type, x, y, z)
                        menge.add(
                            cryspy.crystal.Atom(
                                atom_name, atom_type,
                                cryspy.geo.Pos(
                                    cryspy.numbers.Matrix([[x], [y], [z], [1]])
                                )
                            )
                        )

            if words[0] == "loop_":
                loop_header = []
                status = "reading_loop_header"
        if len(words) == 0:
            if status == "reading_loop_data":
                status = "waiting_for_loop"
    infile.close()
    return cryspy.crystal.Atomset(menge)
Exemplo n.º 3
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)"
Exemplo 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)"
Exemplo n.º 5
0
def test_Karussell():
    metric = cryspy.geo.Cellparameters(1, 1, 1, 90, 90, 90).to_Metric()
    k = cryspy.utils.Karussell(metric, fs("d 1 0 0"), fs("d 0 1 0"))
    d1 = k.direction(0)
    assert float(metric.length(d1 - fs("d 1.0 0.0 0"))) < 1e-9
    d2 = k.direction(np.pi / 2)
    assert float(metric.length(d2 - fs("d 0 1 0"))) < 1e-9

    metric = cryspy.geo.Cellparameters(1, 1, 1, 90, 90, 45).to_Metric()
    k = cryspy.utils.Karussell(metric, fs("d 1 0 0"), fs("d 0 1 0"))
    d1 = k.direction(0)
    assert float(metric.length(d1 - fs("d 1.0 0.0 0"))) < 1e-9
    d2 = k.direction(np.pi / 4)
    assert float(metric.length(d2 - fs("d 0 1 0"))) < 1e-9
Exemplo n.º 6
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"
Exemplo n.º 7
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"
Exemplo n.º 8
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"
Exemplo n.º 9
0
def read_metric_from_cif(infilepathname):
    # So far only for cif-files generated by JANA2006, and even this
    # without any warranty, and maybe not all parameters.

    infile = open(infilepathname, "r")
    for line in infile:
        words = line.split()
        if len(words) >= 2:
            if words[0] == "_cell_length_a":
                a = fs(words[1])
            if words[0] == "_cell_length_b":
                b = fs(words[1])
            if words[0] == "_cell_length_c":
                c = fs(words[1])
            if words[0] == "_cell_angle_alpha":
                alpha = fs(words[1])
            if words[0] == "_cell_angle_beta" :
                beta  = fs(words[1])
            if words[0] == "_cell_angle_gamma":
                gamma = fs(words[1])
    infile.close()
    return cryspy.geo.Cellparameters(
        a, b, c, alpha, beta, gamma
    ).to_Metric()
Exemplo n.º 10
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
Exemplo n.º 11
0
import sys
sys.path.append('../../src/')
import cryspy
from cryspy.fromstr import fromstr as fs

metric = cryspy.geo.Cellparameters(10.4416, 10.4416, 6.3432, 90, 90, 120).to_Metric()

atomset = cryspy.crystal.Atomset( { \
    cryspy.crystal.Atom("Ca1", "Ca", fs("p 0       0      0      ")), \
    cryspy.crystal.Atom("Mn1", "Mn", fs("p 1/2     0      0      ")), \
    cryspy.crystal.Atom("Mn2", "Mn", fs("p 1/2     0      1/2    ")), \
    cryspy.crystal.Atom("Mn3", "Mn", fs("p 0       0      1/2    ")), \
    cryspy.crystal.Atom("O1",  "O",  fs("p 0.2226  0.2731 0.0814 ")), \
    cryspy.crystal.Atom("O2",  "O",  fs("p 0.34219 0.5221 0.3410 "))
    } )

Rm3 = cryspy.tables.spacegroup(148)

atomset = Rm3 ** atomset
atomset1 = fs("x,   y,   z+1") ** atomset
atomset2 = fs("x,   y+1, z  ") ** atomset
atomset3 = fs("x,   y+1, z+1") ** atomset
atomset4 = fs("x+1, y,   z  ") ** atomset
atomset5 = fs("x+1, y,   z+1") ** atomset
atomset6 = fs("x+1, y+1, z  ") ** atomset
atomset7 = fs("x+1, y+1, z+1") ** atomset

menge = set([])
    
for atom in atomset.menge:
    menge = menge.union({atom})
Exemplo n.º 12
0
def test_formfactor():
    assert 72.633286681565636 == tb.formfactor('Au', fs('0.13445'))
Exemplo n.º 13
0
def test_Subset():
    a1 = cr.Atom("Fe1", "Fe", fs("p 0 0 0"))
    a2 = cr.Atom("Fe2", "Fe", fs("p 0 0 1/4"))
    subset = cr.Subset("Sub", fs("p 0 0 1/8"), {a1, a2})
    subset1 = cr.Subset("Sub1", fs("p 0 0 1/8"), {a1, a2})
    subset2 = cr.Subset("Sub", fs("p 0 0 0"), {a1, a2})
    subset3 = cr.Subset("Sub", fs("p 0 0 1/8"), {a1})
    assert subset == subset1
    assert (subset == subset2) == False
    assert (subset == subset3) == False
    assert str(subset) == "Subset"
    subset4 = cr.Subset("Sub", fs("p 7/8 0 1/8"),
                        {cr.Atom("Fe1", "Fe", fs("p 7/8 0 0")), 
                         cr.Atom("Fe2", "Fe", fs("p 7/8 0 1/4"))})
    assert fs("x+7/8, y, z") ** subset == subset4
    assert fs("{x-1/8, y, z}") ** subset == subset4
    subset5 = cr.Subset("Sub", fs("p 1/2 0 1/8"),
                        {cr.Atom("Fe1", "Fe", fs("p 1/2 0 0")), 
                         cr.Atom("Fe2", "Fe", fs("p 1/2 0 1/4"))})
    assert subset + fs("d 1/2 0 0") == subset5
Exemplo n.º 14
0
def test_fromstr():
    string = "1/2"
    assert isinstance(fs(string), nb.Mixed)
    assert fs(string) == nb.Mixed(fr.Fraction(1, 2))
    string = "1.2+/-0.1"
    assert fs(string).value.n == nb.Mixed(uc.ufloat(1.2, 0.1)).value.n
    assert fs(string).value.s == nb.Mixed(uc.ufloat(1.2, 0.1)).value.s
    string = "1.2(1)"
    assert fs(string).value.n == nb.Mixed(uc.ufloat(1.2, 0.1)).value.n
    assert fs(string).value.s == nb.Mixed(uc.ufloat(1.2, 0.1)).value.s
    string = "4"
    assert fs(string) == nb.Mixed(fr.Fraction(4, 1))
    string = "4.5"
    assert fs(string) == nb.Mixed(4.5)

    string = "1 2 3"
    assert fromstr.typefromstr(string) == nb.Matrix
    assert fs(string) == nb.Matrix([[1, 2, 3]])

    string = "/ 1 2 \ \n \ 3 4 /"
    assert fs(string) == \
        nb.Matrix([nb.Row([nb.Mixed(1), nb.Mixed(2)]),
                   nb.Row([nb.Mixed(3), nb.Mixed(4)])])
    string = "1 2 \n 3 4"
    assert fs(string) == \
        nb.Matrix([nb.Row([nb.Mixed(1), nb.Mixed(2)]),
                   nb.Row([nb.Mixed(3), nb.Mixed(4)])])
    string = "x+y,y - x +1/3,2z"
    g = fs(string)
    assert g == geo.Symmetry(
        fs("/ 1 1 0 0 \n"
           " -1 1 0 1/3 \n"
           "  0 0 2 0 \n"
           "  0 0 0 1"))
    string = "O->(0,0,0)\n" \
             "then\n" \
             "a' = a-b \n" \
             "b' = b+a \n" \
             "c' = 2c"
    g = fs(string)
    assert g == geo.Transformation(
        fs(" 1 1 0 0 \n"
           "-1 1 0 0 \n"
           " 0 0 2 0 \n"
           " 0 0 0 1").inv())

    string = "O->(0,0,0) \n" \
             "then\n" \
             "a' = c \n" \
             "b' = a \n" \
             "c' = b"
    g = fs(string)
    assert g == geo.Transformation(
        fs("0 1 0 0 \n"
           "0 0 1 0 \n"
           "1 0 0 0 \n"
           "0 0 0 1").inv())
    string = "O -> (1/2, 0, 0) \n" \
             "then\n" \
             "a' = a \n" \
             "b' = b \n" \
             "c' = c"
    g = fs(string)
    assert g == geo.Transformation(
        fs("1 0 0 -1/2 \n"
           "0 1 0    0 \n"
           "0 0 1    0 \n"
           "0 0 0    1"))

    string1 = "O -> (1/2, 0, 0) \n" \
              "then\n" \
              "a' = a \n" \
              "b' = b \n" \
              "c' = c"

    string2 = "O -> (0,0,0) \n" \
              "then\n" \
              "a' = b\n" \
              "b' = a\n" \
              "c' = c"
    string = "O -> (1/2, 0, 0) \n" \
             "then\n"\
             "a' = b\n"\
             "b' = a\n"\
             "c' = c"

    g1 = fs(string1)
    g2 = fs(string2)
    g = fs(string)
    assert g == g2 * g1

    string = "O -> (1/2, 0, 0) \n" \
             "then\n" \
             "a' = a + b\n" \
             "b' = b\n" \
             "c' = c"
    print("--------")
    g = fs(string)
    print(g.value)
    assert g**fs("p 1/2 0 0") == fs("p 0 0 0")
    assert g**fs("p 1/2 1/3 0") == fs("p 0 1/3 0")
    assert g**fs("p 0 0 0") == fs("p -1/2 1/2 0")

    assert g * g.inv() == geo.Transformation(nb.Matrix.onematrix(4))

    string = "p0 0 0"
    p = fs(string)
    assert p == geo.Pos(fs("0 \n 0 \n 0 \n 1"))
    string = "P0 0 0"
    p = fs(string)
    assert p == geo.Pos(fs("0 \n 0 \n 0 \n 1"))
    string = "r0 0 0"
    p = fs(string)
    assert p == geo.Pos(fs("0 \n 0 \n 0 \n 1"))
    string = "R0 0 0"
    p = fs(string)
    assert p == geo.Pos(fs("0 \n 0 \n 0 \n 1"))
    string = p.__str__()
    assert string == "Pos /  0  \ \n" \
                     "   |   0   |\n" \
                     "    \  0  / "
    p1 = fs(string)
    assert p == p1
    string = "R1/2 1/2 1/2"
    p = fs(string)
    assert p == geo.Pos(fs("1/2 \n 1/2 \n 1/2 \n 1"))

    q = fs("k1 2 3")
    assert q == geo.Rec(fs("1 2 3 0"))
    q = fs("K 1 2 3")
    assert q == geo.Rec(fs("1 2 3 0"))
    q = fs("q 1/2 1/2 0")
    assert q == geo.Rec(fs("1/2 1/2 0 0"))
    q = fs("Q0 0 0")
    assert q == geo.Rec(fs("0 0 0 0"))
    q = fs("Rec <  1  2  3  > ")
    assert q == geo.Rec(fs("1 2 3 0"))
Exemplo n.º 15
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)
Exemplo n.º 16
0
def fill(atomset, extraextensions):
    assert isinstance(atomset, cryspy.crystal.Atomset), \
        "First argument of cryspy.utils.fill(...) must be of " \
        "type cryspy.crystal.Atomset."
    assert isinstance(extraextensions, list), \
        "Second argument of cryspy.utils.fill(...) must be of " \
        "type list."
    assert len(extraextensions) == 3, \
        "Second argument of cryspy.utils.fill(...) must be a " \
        "list of three numbers."
    for item in extraextensions:
        assert isinstance(item, cryspy.numbers.Mixed) \
            or isinstance(item, float) or isinstance(item, int), \
            "Scond argument of cryspy.utils.fill(...) must be a " \
            "list of three numbers."

    atomset_new =  \
                 ((atomset + "lbd") + fs("d -1 -1 -1")) \
               + ((atomset + "lb") + fs("d -1 -1  0")) \
               + ((atomset + "lbu") + fs("d -1 -1 +1")) \
               + ((atomset + "ld") + fs("d -1  0 -1")) \
               + ((atomset + "l") + fs("d -1  0  0")) \
               + ((atomset + "lu") + fs("d -1  0 +1")) \
               + ((atomset + "lfd") + fs("d -1 +1 -1")) \
               + ((atomset + "lf") + fs("d -1 +1  0")) \
               + ((atomset + "lfu") + fs("d -1 +1 +1")) \
               + ((atomset + "bd") + fs("d  0 -1 -1")) \
               + ((atomset + "b") + fs("d  0 -1  0")) \
               + ((atomset + "bu") + fs("d  0 -1 +1")) \
               + ((atomset + "d") + fs("d  0  0 -1")) \
               + ((atomset + "") + fs("d  0  0  0")) \
               + ((atomset + "u") + fs("d  0  0 +1")) \
               + ((atomset + "fd") + fs("d  0 +1 -1")) \
               + ((atomset + "f") + fs("d  0 +1  0")) \
               + ((atomset + "fu") + fs("d  0 +1 +1")) \
               + ((atomset + "rbd") + fs("d +1 -1 -1")) \
               + ((atomset + "rb") + fs("d +1 -1  0")) \
               + ((atomset + "rbu") + fs("d +1 -1 +1")) \
               + ((atomset + "rd") + fs("d +1  0 -1")) \
               + ((atomset + "r") + fs("d +1  0  0")) \
               + ((atomset + "ru") + fs("d +1  0 +1")) \
               + ((atomset + "rfd") + fs("d +1 +1 -1")) \
               + ((atomset + "rf") + fs("d +1 +1  0")) \
               + ((atomset + "rfu") + fs("d +1 +1 +1")) \

    menge = atomset_new.menge
    menge_new = set([])
    extra_x = extraextensions[0]
    extra_y = extraextensions[1]
    extra_z = extraextensions[2]
    for atom in menge:
        if (0 - extra_x <= float(atom.pos.x()) <= 1 + extra_x) \
            and (0 - extra_y <= float(atom.pos.y()) <= 1 + extra_y) \
            and (0 - extra_z <= float(atom.pos.z()) <= 1 + extra_z):
            menge_new.add(atom)
    return cryspy.crystal.Atomset(menge_new)
Exemplo n.º 17
0
import sys
sys.path.append('../../src/')
import cryspy
from cryspy.fromstr import fromstr as fs

metric = cryspy.geo.Cellparameters(10.4416, 10.4416, 6.3432, 90, 90, 120).to_Metric()

atomset = cryspy.crystal.Atomset( { \
    cryspy.crystal.Atom("Ca1", "Ca", fs("p 0       0      0      ")), \
    cryspy.crystal.Atom("Mn1", "Mn", fs("p 1/2     0      0      ")), \
    cryspy.crystal.Atom("Mn2", "Mn", fs("p 1/2     0      1/2    ")), \
    cryspy.crystal.Atom("Mn3", "Mn", fs("p 0       0      1/2    ")), \
    cryspy.crystal.Atom("O1",  "O",  fs("p 0.2226  0.2731 0.0814 ")), \
    cryspy.crystal.Atom("O2",  "O",  fs("p 0.34219 0.5221 0.3410 "))
    } )

Rm3 = cryspy.tables.spacegroup(148)

atomset = Rm3 ** atomset
atomset1 = fs("x,   y,   z+1") ** atomset
atomset2 = fs("x,   y+1, z  ") ** atomset
atomset3 = fs("x,   y+1, z+1") ** atomset
atomset4 = fs("x+1, y,   z  ") ** atomset
atomset5 = fs("x+1, y,   z+1") ** atomset
atomset6 = fs("x+1, y+1, z  ") ** atomset
atomset7 = fs("x+1, y+1, z+1") ** atomset

menge = set([])
    
for atom in atomset.menge:
    menge = menge.union({atom})
Exemplo n.º 18
0
def make_blender_script(atomset, metric, structurename, outfilename):
    assert isinstance(atomset, crystal.Atomset), \
        "atomset must be of type crystal.Atomset."
    assert isinstance(metric, geo.Metric), \
        "metric must be of type geo.Metric."
    assert isinstance(outfilename, str), \
        "outfilename must be of type str."

    outstr = "import bpy\n" \
             "import bmesh\n" \
             "\n"

    # Delete the old structure, if exists:
    outstr += "for ob in bpy.data.objects:\n"
    outstr += "    if ob.name.startswith('%s'):\n" % (structurename)
    outstr += "        ob.select = True\n"
    outstr += "bpy.ops.object.delete()\n"

    outstr += "for me in bpy.data.meshes:\n"
    outstr += "    if me.name.startswith('%s'):\n" % (structurename)
    outstr += "        bpy.data.meshes.remove(me)\n"

    outstr += "for mat in bpy.data.materials:\n"
    outstr += "    if mat.name.startswith('%s'):\n" % (structurename)
    outstr += "        bpy.data.materials.remove(mat)\n"

    # Delete all existing lamps:
    outstr += "bpy.ops.object.select_all(action='DESELECT')\n"
    outstr += "for object in bpy.data.objects:\n"
    outstr += "    if object.type == 'LAMP':\n"
    outstr += "        object.select = True\n"
    outstr += "bpy.ops.object.delete()\n"

    # Set background color:
    outstr += "bpy.data.worlds['World'].horizon_color = %s\n" \
        % (str(const.blender__background_color))

    # Place some cool lamps:
    outstr += "bpy.ops.object.lamp_add(type='POINT')\n"
    outstr += "l = bpy.context.object\n"
    outstr += "l.name = '%s.Lamp1'\n" % (structurename)
    outstr += "l.location = %s\n" % (str(const.blender__location_of_lamp1))
    outstr += "bpy.ops.object.lamp_add(type='HEMI')\n"
    outstr += "l = bpy.context.object\n"
    outstr += "l.name = '%s.LampHemi'\n" % (structurename)
    outstr += "l.location = (-10, -10, 10)\n"
    outstr += "l.data.energy = %10.4f\n" % (const.blender__diffuse_light)

    # Plot the axes:
    t = metric.schmidttransformation

    pos = fs("p 1 0 0")
    x = float((t**pos).x())
    y = float((t**pos).y())
    z = float((t**pos).z())
    outstr += add_axis(structurename, 'XAxis', x, y, z)

    pos = fs("p 0 1 0")
    x = float((t**pos).x())
    y = float((t**pos).y())
    z = float((t**pos).z())
    outstr += add_axis(structurename, 'YAxis', x, y, z)

    pos = fs("p 0 0 1")
    x = float((t**pos).x())
    y = float((t**pos).y())
    z = float((t**pos).z())
    outstr += add_axis(structurename, 'ZAxis', x, y, z)

    # Create empty mesh for the positions of the atoms
    outstr += "bpy.ops.mesh.primitive_cube_add(location=(0,0,0))\n"
    outstr += "bpy.ops.object.mode_set(mode='EDIT')\n"
    outstr += "bpy.ops.mesh.delete(type='VERT')\n"
    outstr += "bpy.ops.object.mode_set(mode='OBJECT')\n"
    outstr += "posobject = bpy.context.object\n"
    outstr += "posobject.name = '%s.Positions'\n" % (structurename)

    # Inspect atomset for different kinds of object and sort them into different lists
    typs = []
    atomlist = []
    momentumlist = []
    bondlist = []
    facelist = []
    for item in atomset.menge:
        if isinstance(item, crystal.Atom):
            atomlist.append(item)
        elif isinstance(item, crystal.Momentum):
            momentumlist.append(item)
        elif isinstance(item, crystal.Bond):
            bondlist.append(item)
        elif isinstance(item, crystal.Face):
            facelist.append(item)

    # Create a mesh for each atom-type, respectively
    for atom in atomlist:
        if atom.typ not in typs:
            typs.append(atom.typ)

    for typ in typs:
        (spheresize, color) = tables.colorscheme_jmol(typ)
        outstr += "bpy.ops.mesh.primitive_ico_sphere_add(location=(0,0,0), size=%f, subdivisions=%i)\n" \
            % (spheresize, const.blender__atom_icosphere_subdivisions)
        outstr += "ob = bpy.context.object\n"
        outstr += "me = ob.data\n"
        outstr += "me.name = '%s.mesh.%s'\n" % (structurename, typ)
        outstr += "bpy.ops.object.delete()\n"
        outstr += "mat = bpy.data.materials.new('%s.material.%s')\n" \
            % (structurename, typ)
        outstr += "mat.diffuse_color = %s\n" % (color.__str__())
        outstr += "me.materials.append(mat)\n"

    # Create spheres for the atoms and add a vertex
    # to the position-mesh, respectively
    materialnumber = 0
    atomnumber = 0
    for atom in atomlist:
        atomnumber += 1
        materialnumber += 1
        x = float((t**atom.pos).x())
        y = float((t**atom.pos).y())
        z = float((t**atom.pos).z())
        outstr += "posobject.data.vertices.add(1)\n"
        outstr += "posobject.data.vertices[-1].co = (%f, %f, %f)\n" % (x, y, z)
        outstr += "ob = bpy.data.objects.new( \
            '%s.Atom%03i(%s)', bpy.data.meshes['%s.mesh.%s'])\n" \
            % (structurename, atomnumber, atom.name, structurename, atom.typ)
        outstr += "ob.location = (%f, %f, %f)\n" % (x, y, z)
        outstr += "bpy.ops.object.shade_smooth()\n"
        outstr += "bpy.context.scene.objects.link(ob)\n"

    # Create arrows for the momentums:
    momentumindex = 0
    for momentum in momentumlist:
        momentumindex += 1
        momentumname = "Momentum%03i" % (momentumindex)
        if momentum.has_plotlength:
            plotlength = momentum.plotlength
        else:
            plotlength = const.blender__std_momentum_plotlength
        if momentum.has_color:
            color = momentum.color
        else:
            color = const.blender__std_momentum_color

        x0 = float((t**momentum.pos).x())
        y0 = float((t**momentum.pos).y())
        z0 = float((t**momentum.pos).z())
        dx = float((t**momentum.direction).x())
        dy = float((t**momentum.direction).y())
        dz = float((t**momentum.direction).z())

        length = np.sqrt(dx * dx + dy * dy + dz * dz)
        x1 = x0 - dx * plotlength / length
        y1 = y0 - dy * plotlength / length
        z1 = z0 - dz * plotlength / length
        x2 = x0 + dx * plotlength / length
        y2 = y0 + dy * plotlength / length
        z2 = z0 + dz * plotlength / length

        outstr += add_momentum(structurename, momentumname, x1, y1, z1, x2, y2,
                               z2, color)

    # Create Cylinders for the Bonds:
    bondindex = 0
    for bond in bondlist:
        bondindex += 1
        bondname = "Bond%03i" % (bondindex)
        if bond.has_color:
            color = bond.color
        else:
            color = const.blender__std_bond_color
        if bond.has_thickness:
            thickness = bond.thickness
        else:
            thickness = const.blender__std_bond_thickness
        x1 = float((t**bond.start).x())
        y1 = float((t**bond.start).y())
        z1 = float((t**bond.start).z())
        x2 = float((t**bond.target).x())
        y2 = float((t**bond.target).y())
        z2 = float((t**bond.target).z())

        outstr += add_cylinder(structurename, bondname, x1, y1, z1, x2, y2, z2,
                               thickness,
                               const.blender__num_of_segments_of_bond)

        outstr += "mat = bpy.data.materials.new('%s.material.%s')\n"\
            % (structurename, bondname)
        outstr += "mat.diffuse_color = %s\n"\
            % (str(color))
        outstr += "mat.specular_color = (0, 0, 0)\n"
        outstr += "ob1.data.materials.append(mat)\n"

    # Create Faces:
    faceindex = 0
    for face in facelist:
        faceindex += 1
        facename = "Face%03i" % (faceindex)
        if face.has_color:
            color = face.color
        else:
            color = const.blender__std_face_color
        verts = []
        for corner in face.corners:
            cartesian_corner = t**corner
            x = float(cartesian_corner.x())
            y = float(cartesian_corner.y())
            z = float(cartesian_corner.z())
            verts.append((x, y, z))
        outstr += add_face(structurename, facename, verts)
        outstr += "mat = bpy.data.materials.new('%s.material.%s')\n" \
            %(structurename, facename)
        if face.has_opacity:
            opacity = face.opacity
        else:
            opacity = const.blender__std_face_opacity
        if opacity < 1:
            outstr += "mat.use_transparency = True\n"
            outstr += "mat.alpha = %10.4f\n" % (opacity)
        outstr += "mat.diffuse_color = %s\n" % (str(color))
        outstr += "mat.specular_color = (0, 0, 0)\n"
        outstr += "ob1.data.materials.append(mat)\n"

    # Make all atoms looking smooth:
    outstr += "for ob in bpy.data.objects:\n"
    outstr += "    if ob.name.startswith('%s.Atom'):\n" % (structurename)
    outstr += "        ob.select = True\n"
    outstr += "    else:\n"
    outstr += "        ob.select = False\n"
    outstr += "bpy.ops.object.shade_smooth()\n"

    outfile = open(outfilename, "w")
    outfile.write(outstr)
    outfile.close()
Exemplo n.º 19
0
def test_Momentum():
    m = cr.Momentum("M", fs("p 0 0 0"), fs("d 0 0 1"))
    assert isinstance(m, cr.Momentum)
    m.set_color((0, 0, 1))
    m.set_color((fs("0.3"), 0.1, 1))
    m.set_plotlength(1)
    m.set_plotlength(0.5)
    m.set_plotlength(fs("1/2"))
    d = fs("d 0 0 1/2")
    m1 = cr.Momentum("M", fs("p 0 0 0"), fs("d 0 0 1"))
    m2 = cr.Momentum("M", fs("p 1 2 3"), fs("d 0 0 1"))
    m3 = cr.Momentum("M", fs("p 0 0 0"), fs("d 1 2 3"))
    assert m == m1
    assert hash(m) == hash(m1)
    assert (m == m2) == False
    assert (m == m3) == False
    assert m + d == cr.Momentum("M", fs("p 0 0 1/2"), fs("d 0 0 1"))
    assert fs("x+1/2,y,z") ** m == cr.Momentum("M", fs("p 1/2 0 0"), fs("d 0 0 1"))
    assert fs("{x+3/2,y,z}") ** m == cr.Momentum("M", fs("p 1/2 0 0"), fs("d 0 0 1"))
    m1 = cr.Momentum("M", fs("p 0 0 1/2"), fs("d 0 0 1"))
    assert (m1 + "test").name == "Mtest"
Exemplo n.º 20
0
def test_Bond():
    b = cr.Bond("B", fs("p 0 0 0"), fs("p 0 0 1/2"))
    assert isinstance(b, cr.Bond)
    b.set_color((0, 0, 1))
    b.set_color((fs("0.3"), 0.1, 1))
    b.set_thickness(1)
    assert b.thickness == 1
    b.set_thickness(0.5)
    assert b.thickness == 0.5
    b.set_thickness(fs("1/2"))
    assert b.thickness == fs("1/2")
    d = fs("d 0 0 1/2")
    b1 = cr.Bond("Bblabla", fs("p 0 0 0"), fs("p 0 0 1/2"))
    b2 = cr.Bond("B", fs("p 1 2 3"), fs("p 0 0 1/2"))
    b3 = cr.Bond("B", fs("p 0 0 0"), fs("p 1 2 3"))
    b4 = cr.Bond("B", fs("p 0 0 1/2"), fs("p 0 0 0"))
    assert hash(b) == hash(b4)
    assert (b == b4) == False
    assert b == b1
    assert (b == b2) == False
    assert (hash(b) == hash(b3)) == False
    assert (b == b3) == False
    assert b + d == cr.Bond("B", fs("p 0 0 1/2"), fs("p 0 0 1"))
    assert fs("x+1/2,y,z") ** b == cr.Bond("B", fs("p 1/2 0 0"), fs("p 1/2 0 1/2"))
    assert fs("{x+3/2,y,z}") ** b == cr.Bond("B", fs("p 1/2 0 0"), fs("p 1/2 0 1/2"))
    b = cr.Bond("B", fs("p 0 0 0"), fs("p 0 0 1/2"))
    assert (b + "test").name == "Btest"
Exemplo n.º 21
0
def test_Face():
    f = cr.Face("F", [fs("p 0 0 0"), fs("p 1 0 0"), fs("p 0 1 0")])
    assert isinstance(f, cr.Face)
    f.set_color((0, 0, 1))
    f.set_color((fs("0.3"), 0.1, 1))
    d = fs("d 0 0 1/2")
    f1 = cr.Face("F", [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 == 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"
Exemplo n.º 22
0
def make_blender_script(atomset, metric, structurename, outfilename):
    assert isinstance(atomset, crystal.Atomset), \
        "atomset must be of type crystal.Atomset."
    assert isinstance(metric, geo.Metric), \
        "metric must be of type geo.Metric."
    assert isinstance(outfilename, str), \
        "outfilename must be of type str."

    outstr = "import bpy\n" \
             "import bmesh\n" \
             "\n"

    atomset = atomset.unpack_subsets()

    # Delete the old structure, if exists:
    outstr += "for ob in bpy.data.objects:\n"
    outstr += "    if ob.name.startswith('%s'):\n" % (structurename)
    outstr += "        ob.select = True\n"
    outstr += "bpy.ops.object.delete()\n"

    outstr += "for me in bpy.data.meshes:\n"
    outstr += "    if me.name.startswith('%s'):\n" % (structurename)
    outstr += "        bpy.data.meshes.remove(me)\n"

    outstr += "for mat in bpy.data.materials:\n"
    outstr += "    if mat.name.startswith('%s'):\n" % (structurename)
    outstr += "        bpy.data.materials.remove(mat)\n"

    # Delete all existing lamps:
    outstr += "bpy.ops.object.select_all(action='DESELECT')\n"
    outstr += "for object in bpy.data.objects:\n"
    outstr += "    if object.type == 'LAMP':\n"
    outstr += "        object.select = True\n"
    outstr += "bpy.ops.object.delete()\n"

    # Set background color:
    outstr += "bpy.data.worlds['World'].horizon_color = %s\n" \
        % (str(const.blender__background_color))

    # Place some cool lamps:
    outstr += "bpy.ops.object.lamp_add(type='POINT')\n"
    outstr += "l = bpy.context.object\n"
    outstr += "l.name = '%s.Lamp1'\n" % (structurename)
    outstr += "l.location = %s\n" % (str(const.blender__location_of_lamp1))
    outstr += "bpy.ops.object.lamp_add(type='HEMI')\n"
    outstr += "l = bpy.context.object\n"
    outstr += "l.name = '%s.LampHemi'\n" % (structurename)
    outstr += "l.location = (-10, -10, 10)\n"
    outstr += "l.data.energy = %10.4f\n" % (const.blender__diffuse_light)

    # Plot the axes:
    t = metric.schmidttransformation

    pos = fs("p 1 0 0")
    x = float((t ** pos).x())
    y = float((t ** pos).y())
    z = float((t ** pos).z())
    outstr += add_axis(structurename, 'XAxis', x, y, z)

    pos = fs("p 0 1 0")
    x = float((t ** pos).x())
    y = float((t ** pos).y())
    z = float((t ** pos).z())
    outstr += add_axis(structurename, 'YAxis', x, y, z)

    pos = fs("p 0 0 1")
    x = float((t ** pos).x())
    y = float((t ** pos).y())
    z = float((t ** pos).z())
    outstr += add_axis(structurename, 'ZAxis', x, y, z)

    # Create empty mesh for the positions of the atoms
    outstr += "bpy.ops.mesh.primitive_cube_add(location=(0,0,0))\n"
    outstr += "bpy.ops.object.mode_set(mode='EDIT')\n"
    outstr += "bpy.ops.mesh.delete(type='VERT')\n"
    outstr += "bpy.ops.object.mode_set(mode='OBJECT')\n"
    outstr += "posobject = bpy.context.object\n"
    outstr += "posobject.name = '%s.Positions'\n" % (structurename)

    # Inspect atomset for different kinds of object and sort them into different lists
    typs = []
    atomlist = []
    momentumlist = []
    bondlist = []
    facelist = []
    for item in atomset.menge:
        if isinstance(item, crystal.Atom):
            atomlist.append(item)
        elif isinstance(item, crystal.Momentum):
            momentumlist.append(item)
        elif isinstance(item, crystal.Bond):
            bondlist.append(item)
        elif isinstance(item, crystal.Face):
            facelist.append(item)

    # Create a mesh for each atom-type, respectively
    for atom in atomlist:
        if atom.typ not in typs:
            typs.append(atom.typ)

    for typ in typs:
        (spheresize, color) = tables.colorscheme_jmol(typ)
        outstr += "bpy.ops.mesh.primitive_ico_sphere_add(location=(0,0,0), size=%f, subdivisions=%i)\n" \
            % (spheresize, const.blender__atom_icosphere_subdivisions)
        outstr += "ob = bpy.context.object\n"
        outstr += "me = ob.data\n"
        outstr += "me.name = '%s.mesh.%s'\n" % (structurename, typ)
        outstr += "bpy.ops.object.delete()\n"
        outstr += "mat = bpy.data.materials.new('%s.material.%s')\n" \
            % (structurename, typ)
        outstr += "mat.diffuse_color = %s\n" % (color.__str__())
        outstr += "me.materials.append(mat)\n"

    # Create spheres for the atoms and add a vertex
    # to the position-mesh, respectively
    materialnumber = 0
    atomnumber = 0
    for atom in atomlist:
        atomnumber += 1
        materialnumber += 1
        x = float((t ** atom.pos).x())
        y = float((t ** atom.pos).y())
        z = float((t ** atom.pos).z())
        outstr += "posobject.data.vertices.add(1)\n"
        outstr += "posobject.data.vertices[-1].co = (%f, %f, %f)\n" % (x, y, z)
        outstr += "ob = bpy.data.objects.new( \
            '%s.Atom%03i(%s)', bpy.data.meshes['%s.mesh.%s'])\n" \
            % (structurename, atomnumber, atom.name, structurename, atom.typ)
        outstr += "ob.location = (%f, %f, %f)\n" % (x, y, z)
        outstr += "bpy.ops.object.shade_smooth()\n"
        outstr += "bpy.context.scene.objects.link(ob)\n"

    # Create arrows for the momentums:
    momentumindex = 0
    for momentum in momentumlist:
        momentumindex += 1
        momentumname = "Momentum%03i" % (momentumindex)
        if momentum.has_plotlength:
            plotlength = momentum.plotlength
        else:
            plotlength = const.blender__std_momentum_plotlength
        if momentum.has_color:
            color = momentum.color
        else:
            color = const.blender__std_momentum_color

        x0 = float((t ** momentum.pos).x())
        y0 = float((t ** momentum.pos).y())
        z0 = float((t ** momentum.pos).z())
        dx = float((t ** momentum.direction).x())
        dy = float((t ** momentum.direction).y())
        dz = float((t ** momentum.direction).z())

        length = np.sqrt(dx * dx + dy * dy + dz * dz)
        x1 = x0 - dx * plotlength / length
        y1 = y0 - dy * plotlength / length
        z1 = z0 - dz * plotlength / length
        x2 = x0 + dx * plotlength / length
        y2 = y0 + dy * plotlength / length
        z2 = z0 + dz * plotlength / length

        outstr += add_momentum(structurename, momentumname,
                               x1, y1, z1, x2, y2, z2, color)

    # Create Cylinders for the Bonds:
    bondindex = 0
    for bond in bondlist:
        bondindex += 1
        bondname = "Bond%03i" % (bondindex)
        if bond.has_color:
            color = bond.color
        else:
            color = const.blender__std_bond_color
        if bond.has_thickness:
            thickness = bond.thickness
        else:
            thickness = const.blender__std_bond_thickness
        x1 = float((t ** bond.start).x())
        y1 = float((t ** bond.start).y())
        z1 = float((t ** bond.start).z())
        x2 = float((t ** bond.target).x())
        y2 = float((t ** bond.target).y())
        z2 = float((t ** bond.target).z())

        outstr += add_cylinder(structurename, bondname, 
            x1, y1, z1, x2, y2, z2, 
            thickness, const.blender__num_of_segments_of_bond)

        outstr += "mat = bpy.data.materials.new('%s.material.%s')\n"\
            % (structurename, bondname)
        outstr += "mat.diffuse_color = %s\n"\
            % (str(color))
        outstr += "mat.specular_color = (0, 0, 0)\n"
        outstr += "ob1.data.materials.append(mat)\n"
        
    # Create Faces:
    faceindex = 0
    for face in facelist:
        faceindex += 1
        facename = "Face%03i" % (faceindex)
        if face.has_color:
            color = face.color
        else:
            color = const.blender__std_face_color
        verts = []
        for corner in face.corners:
            cartesian_corner = t**corner
            x = float(cartesian_corner.x())
            y = float(cartesian_corner.y())
            z = float(cartesian_corner.z())
            verts.append((x, y, z))
        outstr += add_face(structurename, facename, verts)
        outstr += "mat = bpy.data.materials.new('%s.material.%s')\n" \
            %(structurename, facename)
        if face.has_opacity:
            opacity = face.opacity
        else:
            opacity = const.blender__std_face_opacity
        if opacity < 1:
            outstr += "mat.use_transparency = True\n"
            outstr += "mat.alpha = %10.4f\n"%(opacity)
        outstr += "mat.diffuse_color = %s\n" % (str(color))
        outstr += "mat.specular_color = (0, 0, 0)\n"
        outstr += "ob1.data.materials.append(mat)\n"



    # Make all atoms looking smooth:
    outstr += "for ob in bpy.data.objects:\n"
    outstr += "    if ob.name.startswith('%s.Atom'):\n" % (structurename)
    outstr += "        ob.select = True\n"
    outstr += "    else:\n"
    outstr += "        ob.select = False\n"
    outstr += "bpy.ops.object.shade_smooth()\n"

    outfile = open(outfilename, "w")
    outfile.write(outstr)
    outfile.close()
Exemplo n.º 23
0
def test_Metric():
    M = nb.Matrix([[1, 0, 0, 0],
                   [0, 1, 0, 0],
                   [0, 0, 1, 0],
                   [0, 0, 0, 1]])
    metric = geo.Metric(M)
    t = metric.schmidttransformation

    assert t ** geo.canonical_e0 == geo.Dif(nb.Matrix([[1], [0], [0], [0]]))
    assert t ** geo.canonical_e1 == geo.Dif(nb.Matrix([[0], [1], [0], [0]]))
    assert t ** geo.canonical_e2 == geo.Dif(nb.Matrix([[0], [0], [1], [0]]))

    metric = geo.Cellparameters(1, 1, 1, 90, 90, 45).to_Metric()
    t = metric.schmidttransformation
    assert t ** geo.canonical_e0 == geo.Dif(nb.Matrix([[1], [0], [0], [0]]))
    e1 = t ** geo.canonical_e1
    assert abs(e1.x() - 0.70710678).value < 0.000001
    assert abs(e1.y() - 0.70710678).value < 0.000001
    assert abs(e1.z() - 0).value < 0.000001
    e2 = t ** geo.canonical_e2
    assert abs(e2.x() - 0).value < 0.000001
    assert abs(e2.y() - 0).value < 0.000001
    assert abs(e2.z() - 1).value < 0.000001

    t = metric.schmidttransformation.inv()

    M = nb.Matrix([[9, 0, 0, 0],
                   [0, 4, 0, 0],
                   [0, 0, 1, 0],
                   [0, 0, 0, 1]])
    metric = geo.Metric(M)
    assert metric.__str__() == "Metric /  9  0  0  0  \ \n" \
                               "      |   0  4  0  0   |\n" \
                               "      |   0  0  1  0   |\n" \
                               "       \  0  0  0  1  / "
    o = geo.Pos(nb.Matrix([[0], [0], [0], [1]]))
    p1 = geo.Pos(nb.Matrix([[1], [0], [0], [1]]))
    p2 = geo.Pos(nb.Matrix([[0], [1], [0], [1]]))
    q1 = geo.Rec(nb.Matrix([[1, 0, 0, 0]]))
    q2 = geo.Rec(nb.Matrix([[0, 1, 0, 0]]))
    q3 = geo.Rec(nb.Matrix([[1, 1, 0, 0]]))
    assert metric.dot(p1 - o, p1 - o).__str__() == "9"
    assert metric.dot(p1 - o, p2 - o).__str__() == "0"
    assert metric.dot(q1, q1).__str__() == "1/9"
    assert metric.dot(q2, q2).__str__() == "1/4"
    assert metric.dot(q3, q3).__str__() == "13/36"
    assert metric.length(p1 - o) == 3
    assert np.abs(float(metric.angle(p1 - o, p2 - o)) - 1.5707963) < 0.0001
    assert metric.dangle(p1 - o, p2 - o) == 90
    assert metric.length(q1).__str__() == "1/3"
    assert np.abs(float(metric.angle(q1, q2)) - 1.5707963) < 0.0001
    assert metric.dangle(q1, q2) == 90
    assert metric.angle(p1 - o, p1 - o).__str__() == "0.0"
    assert metric.dangle(p1 - o, p1 - o).__str__() == "0"
    assert metric.angle(q1, q1).__str__() == "0.0"
    assert metric.dangle(q1, q1).__str__() == "0"

    metric = geo.Cellparameters(4.15, 4.15, 28.64, 90, 90, 120).to_Metric()

    M = nb.Matrix([[9, 0, 0, 0],
                   [0, 4, 0, 0],
                   [0, 0, 1, 0],
                   [0, 0, 0, 1]])
    metric = geo.Metric(M)

    cell = metric.to_Cellparameters()
    assert cell.__str__() == \
        geo.Cellparameters(3, 2, 1, 90, 90, 90).__str__()

    t = geo.Transformation(nb.Matrix([[0, 1, 0, 0],
                                      [1, 0, 0, 0],
                                      [0, 0, 1, 0.5],
                                      [0, 0, 0, 1]]))

    assert t ** metric == geo.Metric(nb.Matrix([[4, 0, 0, 0],
                                                [0, 9, 0, 0],
                                                [0, 0, 1, 0],
                                                [0, 0, 0, 1]]))

    metric = geo.Cellparameters(fs("8.534(5)"), fs("8.556(5)"), fs("7.015(5)"),
                                fs("101.53(8)"), fs("114.97(8)"), 
                                fs("103.38(8)")).to_Metric()
    assert np.abs(metric.cellvolume().value.n - 425.24239) < 0.0001

    metric = geo.Cellparameters(fs("1.0(1)"), 1, 1, 90, 90, 90).to_Metric()
    print(metric.cellvolume())
    assert np.abs(metric.cellvolume().value.n - 1) < 0.00000001
    assert np.abs(metric.cellvolume().value.s - 0.1) < 0.00000001

    a = fs("1.0(1)")
    metric = geo.Cellparameters(a, a, a, 90, 90, 90).to_Metric()
    m00 = metric.value.liste[0].liste[0]
    m11 = metric.value.liste[1].liste[1]
    assert (m00 - m11).value.n == 0.0
    assert (m00 - m11).value.s == 0.0
Exemplo n.º 24
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
Exemplo n.º 25
0
def test_Atom():
    atom1 = cr.Atom("Cs1", "Cs", fs("p 0 0 0"))
    assert atom1.has_color == False
    assert atom1.__str__() == \
        "Atom Cs1 Cs Pos /  0  \ \n" \
        "               |   0   |\n" \
        "                \  0  / "
    assert (atom1 + "hallo").name == atom1.name + "hallo"
    atom2 = cr.Atom("Cs2", "Cs", fs("p 0 0 0"))
    assert atom2 == atom1
    assert {atom2} == {atom1}
    atom3 = cr.Atom("Cs3", "Cs", fs("p0.1 0 0"))
    assert atom3 != atom1
    atom4 = cr.Atom("Cs1", "Fe", fs("p 0 0 0"))
    assert atom4 != atom1

    atom = cr.Atom("Cl1", "Cl", fs("p 1/2 1/2 1/2"))
    transformation = fs("O->(0,0,0) \n"
                        "then\n"
                        "a' = a \n"
                        "b' = 2b \n"
                        "c' = c")
    atom_trans = cr.Atom("Cl1", "Cl", fs("p 1/2 1/4 1/2"))
    assert (transformation**atom).__str__() == atom_trans.__str__()

    sym = fs("-x+1/2,-y+1/2, z")
    atom_sym = cr.Atom("Cl1", "Cl", fs("p0 0 1/2"))
    assert (sym**atom).__str__() == atom_sym.__str__()

    coset = fs("{x, -y, z+1}")
    atom = cr.Atom("Cl1", "Cl", fs("p 1/2 1/4 1/2"))
    atom1 = coset**atom
    atom2 = cr.Atom("Cl1", "Cl", fs("p 1/2 3/4 1/2"))
    assert atom1.__str__() == atom2.__str__()

    transgen = geo.Transgen(fs("d 1 0 0"), fs("d 0 1 0"), fs("d 0 0 2"))
    atom = cr.Atom("Cl1", "Cl", fs("p 1/2 5/4 -1/2"))
    atom1 = atom % transgen
    atom2 = cr.Atom("Cl1", "Cl", fs("p 1/2 1/4 3/2"))
    assert atom1 == atom2

    d = fs("d 1/2 0 0")
    atom1 = cr.Atom("Cl1", "Cl", fs("p 0 0 0"))
    atom2 = cr.Atom("Cl1", "Cl", fs("p 1/2 0 0"))
    atom3 = atom1 + d
    assert atom2 == atom3
Exemplo n.º 26
0
import cryspy
from cryspy.fromstr import fromstr as fs


# Nach [Alonso2000a table 2]
metric = cryspy.geo.Cellparameters(fs("5.29314(5)"), fs("5.8384(1)"), fs("7.4025(1)"), 90, 90, 90).to_Metric()

atomset = cryspy.crystal.Atomset({
    cryspy.crystal.Atom("Tb1", "Tb", fs("p 0.9831(4) 0.0824(3) 1/4      ")),
    cryspy.crystal.Atom("Mn1", "Mn", fs("p 1/2       0         0        ")),
    cryspy.crystal.Atom("O1",  "O",  fs("p 0.1038(5) 0.4667(4) 1/4      ")),
    cryspy.crystal.Atom("O2",  "O",  fs("p 0.7039(4) 0.3262(3) 0.0510(2)"))
})

# Raumgruppe Pbnm (durch Transformation aus Pnma):
sg = fs("a' = c\n"
        "b' = a\n"
        "c' = b") \
        ** \
        cryspy.tables.spacegroup(62)


atomset = sg ** atomset

atomset = cryspy.utils.fill(atomset, [0.5, 0.05, 0.05])        

"""
face1 = cryspy.crystal.Face("Face1", [atomset.get_atom("O2_6").pos, atomset.get_atom("O2_3").pos, atomset.get_atom("O1_2").pos])
face2 = cryspy.crystal.Face("Face2", [atomset.get_atom("O2_2r").pos, atomset.get_atom("O2_3").pos, atomset.get_atom("O1_2").pos])
face3 = cryspy.crystal.Face("Face3", [atomset.get_atom("O2_2r").pos, atomset.get_atom("O2_7r").pos, atomset.get_atom("O1_2").pos])
face4 = cryspy.crystal.Face("Face4", [atomset.get_atom("O2_6").pos, atomset.get_atom("O2_7r").pos, atomset.get_atom("O1_2").pos])
Exemplo n.º 27
0
def fill(atomset, extraextensions):
    assert isinstance(atomset, cryspy.crystal.Atomset), \
        "First argument of cryspy.utils.fill(...) must be of " \
        "type cryspy.crystal.Atomset."
    assert isinstance(extraextensions, list), \
        "Second argument of cryspy.utils.fill(...) must be of " \
        "type list."
    assert len(extraextensions) == 3, \
        "Second argument of cryspy.utils.fill(...) must be a " \
        "list of three numbers."
    for item in extraextensions:
        assert isinstance(item, cryspy.numbers.Mixed) \
            or isinstance(item, float) or isinstance(item, int), \
            "Scond argument of cryspy.utils.fill(...) must be a " \
            "list of three numbers."

    atomset_new =  \
                 ((atomset + "lbd") + fs("d -1 -1 -1")) \
               + ((atomset + "lb") + fs("d -1 -1  0")) \
               + ((atomset + "lbu") + fs("d -1 -1 +1")) \
               + ((atomset + "ld") + fs("d -1  0 -1")) \
               + ((atomset + "l") + fs("d -1  0  0")) \
               + ((atomset + "lu") + fs("d -1  0 +1")) \
               + ((atomset + "lfd") + fs("d -1 +1 -1")) \
               + ((atomset + "lf") + fs("d -1 +1  0")) \
               + ((atomset + "lfu") + fs("d -1 +1 +1")) \
               + ((atomset + "bd") + fs("d  0 -1 -1")) \
               + ((atomset + "b") + fs("d  0 -1  0")) \
               + ((atomset + "bu") + fs("d  0 -1 +1")) \
               + ((atomset + "d") + fs("d  0  0 -1")) \
               + ((atomset + "") + fs("d  0  0  0")) \
               + ((atomset + "u") + fs("d  0  0 +1")) \
               + ((atomset + "fd") + fs("d  0 +1 -1")) \
               + ((atomset + "f") + fs("d  0 +1  0")) \
               + ((atomset + "fu") + fs("d  0 +1 +1")) \
               + ((atomset + "rbd") + fs("d +1 -1 -1")) \
               + ((atomset + "rb") + fs("d +1 -1  0")) \
               + ((atomset + "rbu") + fs("d +1 -1 +1")) \
               + ((atomset + "rd") + fs("d +1  0 -1")) \
               + ((atomset + "r") + fs("d +1  0  0")) \
               + ((atomset + "ru") + fs("d +1  0 +1")) \
               + ((atomset + "rfd") + fs("d +1 +1 -1")) \
               + ((atomset + "rf") + fs("d +1 +1  0")) \
               + ((atomset + "rfu") + fs("d +1 +1 +1")) \

    menge = atomset_new.menge
    menge_new = set([])
    extra_x = extraextensions[0]
    extra_y = extraextensions[1]
    extra_z = extraextensions[2]
    for atom in menge:
        if (0 - extra_x <= float(atom.pos.x()) <= 1 + extra_x) \
            and (0 - extra_y <= float(atom.pos.y()) <= 1 + extra_y) \
            and (0 - extra_z <= float(atom.pos.z()) <= 1 + extra_z):
            menge_new.add(atom)
    return cryspy.crystal.Atomset(menge_new)
Exemplo n.º 28
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"
Exemplo n.º 29
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)
Exemplo n.º 30
0
def test_Momentum():
    m = cr.Momentum("M", fs("p 0 0 0"), fs("d 0 0 1"))
    assert isinstance(m, cr.Momentum)
    m.set_color((0, 0, 1))
    m.set_color((fs("0.3"), 0.1, 1))
    m.set_plotlength(1)
    m.set_plotlength(0.5)
    m.set_plotlength(fs("1/2"))
    d = fs("d 0 0 1/2")
    m1 = cr.Momentum("M", fs("p 0 0 0"), fs("d 0 0 1"))
    m2 = cr.Momentum("M", fs("p 1 2 3"), fs("d 0 0 1"))
    m3 = cr.Momentum("M", fs("p 0 0 0"), fs("d 1 2 3"))
    assert m == m1
    assert (m == m2) == False
    assert (m == m3) == False
    assert m + d == cr.Momentum("M", fs("p 0 0 1/2"), fs("d 0 0 1"))
    assert fs("x+1/2,y,z")**m == cr.Momentum("M", fs("p 1/2 0 0"),
                                             fs("d 0 0 1"))
    assert fs("{x+3/2,y,z}")**m == cr.Momentum("M", fs("p 1/2 0 0"),
                                               fs("d 0 0 1"))
    m1 = cr.Momentum("M", fs("p 0 0 1/2"), fs("d 0 0 1"))
    assert (m1 + "test").name == "Mtest"
Exemplo n.º 31
0
def test_formfactor():
    assert 72.633286681565636 == tb.formfactor('Au', fs('0.13445'))
Exemplo n.º 32
0
def test_Bond():
    b = cr.Bond("B", fs("p 0 0 0"), fs("p 0 0 1/2"))
    assert isinstance(b, cr.Bond)
    b.set_color((0, 0, 1))
    b.set_color((fs("0.3"), 0.1, 1))
    b.set_thickness(1)
    b.set_thickness(0.5)
    b.set_thickness(fs("1/2"))
    d = fs("d 0 0 1/2")
    b1 = cr.Bond("B", fs("p 0 0 0"), fs("p 0 0 1/2"))
    b2 = cr.Bond("B", fs("p 1 2 3"), fs("p 0 0 1/2"))
    b3 = cr.Bond("B", fs("p 0 0 0"), fs("p 1 2 3"))
    assert b == b1
    assert (b == b2) == False
    assert (b == b3) == False
    assert b + d == cr.Bond("B", fs("p 0 0 1/2"), fs("p 0 0 1"))
    assert fs("x+1/2,y,z")**b == cr.Bond("B", fs("p 1/2 0 0"),
                                         fs("p 1/2 0 1/2"))
    assert fs("{x+3/2,y,z}")**b == cr.Bond("B", fs("p 1/2 0 0"),
                                           fs("p 1/2 0 1/2"))
    b = cr.Bond("B", fs("p 0 0 0"), fs("p 0 0 1/2"))
    assert (b + "test").name == "Btest"
Exemplo n.º 33
0
def spacegroup(number):
    if number == 10:
        return geo.Spacegroup(
            geo.canonical,
            [fs("{x,y,z}"),
             fs("{-x,y,-z}"),
             fs("{-x,-y,-z}"),
             fs("{x,-y,z}")])

    if number == 13:
        return geo.Spacegroup(geo.canonical, [
            fs("{x,y,z}"),
            fs("{-x,y,-z+1/2}"),
            fs("{-x,-y,-z}"),
            fs("{x,-y,z+1/2}")
        ])

    if number == 15:
        return geo.Spacegroup(geo.canonical, [
            fs("{x,y,z}"),
            fs("{-x,y,-z+1/2}"),
            fs("{-x,-y,-z}"),
            fs("{x,-y,z+1/2}"),
            fs("{x+1/2,y+1/2,z}"),
            fs("{-x+1/2,y+1/2,-z+1/2}"),
            fs("{-x+1/2,-y+1/2,-z}"),
            fs("{x+1/2,-y+1/2,z+1/2}")
        ])

    if number == 33:
        return geo.Spacegroup(geo.canonical, [
            fs("{x,y,z}"),
            fs("{-x,-y,z+1/2}"),
            fs("{x+1/2,-y+1/2,z}"),
            fs("{-x+1/2,y+1/2,z+1/2}")
        ])

    if number == 46:
        return geo.Spacegroup(geo.canonical, [
            fs("{x,y,z}"),
            fs("{-x,-y,z}"),
            fs("{x+1/2,-y,z}"),
            fs("{-x+1/2,y,z}"),
            fs("{x+1/2,y+1/2,z+1/2}"),
            fs("{-x+1/2,-y+1/2,z+1/2}"),
            fs("{x,-y+1/2,z+1/2}"),
            fs("{-x,y+1/2,z+1/2}")
        ])

    if number == 62:
        return geo.Spacegroup(geo.canonical, [
            fs("{x,y,z}"),
            fs("{-x+1/2,-y,z+1/2}"),
            fs("{-x,y+1/2,-z}"),
            fs("{x+1/2,-y+1/2,-z+1/2}"),
            fs("{-x,-y,-z}"),
            fs("{x+1/2,y,-z+1/2}"),
            fs("{x,-y+1/2,z}"),
            fs("{-x+1/2,y+1/2,z+1/2}")
        ])

    if number == 63:
        return geo.Spacegroup(geo.canonical, [
            fs("{x,y,z}"),
            fs("{-x,-y,z+1/2}"),
            fs("{-x,y,-z+1/2}"),
            fs("{x,-y,-z}"),
            fs("{-x,-y,-z}"),
            fs("{x,y,-z+1/2}"),
            fs("{x,-y,z+1/2}"),
            fs("{-x,y,z}"),
            fs("{x+1/2,y+1/2,z}"),
            fs("{-x+1/2,-y+1/2,z+1/2}"),
            fs("{-x+1/2,y+1/2,-z+1/2}"),
            fs("{x+1/2,-y+1/2,-z}"),
            fs("{-x+1/2,-y+1/2,-z}"),
            fs("{x+1/2,y+1/2,-z+1/2}"),
            fs("{x+1/2,-y+1/2,z+1/2}"),
            fs("{-x+1/2,y+1/2,z}")
        ])

    if number == 64:
        return geo.Spacegroup(geo.canonical, [
            fs("{x,y,z}"),
            fs("{-x,-y+1/2,z+1/2}"),
            fs("{-x,y+1/2,-z+1/2}"),
            fs("{x,-y,-z}"),
            fs("{-x,-y,-z}"),
            fs("{x,y+1/2,-z+1/2}"),
            fs("{x,-y+1/2,z+1/2}"),
            fs("{-x,y,z}"),
            fs("{x+1/2,y+1/2,z}"),
            fs("{-x+1/2,-y,z+1/2}"),
            fs("{-x+1/2,y,-z+1/2}"),
            fs("{x+1/2,-y+1/2,-z}"),
            fs("{-x+1/2,-y+1/2,-z}"),
            fs("{x+1/2,y,-z+1/2}"),
            fs("{x+1/2,-y,z+1/2}"),
            fs("{-x+1/2,y+1/2,z}")
        ])

    if number == 73:
        return geo.Spacegroup(geo.canonical, [
            fs("{x,y,z}"),
            fs("{-x+1/2,-y,z+1/2}"),
            fs("{-x,y+1/2,-z+1/2}"),
            fs("{x+1/2,-y+1/2,-z}"),
            fs("{-x,-y,-z}"),
            fs("{x+1/2,y,-z+1/2}"),
            fs("{x,-y+1/2,z+1/2}"),
            fs("{-x+1/2,y+1/2,z}"),
            fs("{x+1/2,y+1/2,z+1/2}"),
            fs("{-x,-y+1/2,z}"),
            fs("{-x+1/2,y,-z}"),
            fs("{x,-y,-z+1/2}"),
            fs("{-x+1/2,-y+1/2,-z+1/2}"),
            fs("{x,y+1/2,-z}"),
            fs("{x+1/2,-y,z}"),
            fs("{-x,y,z+1/2}")
        ])

    if number == 142:
        return geo.Spacegroup(geo.canonical, [
            fs("{x,y,z}"),
            fs("{-x+1/2,-y+1/2,z+1/2}"),
            fs("{-y,x+1/2,z+1/4}"),
            fs("{y+1/2,-x,z+3/4}"),
            fs("{-x+1/2,y,-z+1/4}"),
            fs("{x,-y+1/2,-z+3/4}"),
            fs("{y+1/2,x+1/2,-z}"),
            fs("{-y,-x,-z+1/2}"),
            fs("{-x,-y+1/2,-z+1/4}"),
            fs("{x+1/2,y,-z+3/4}"),
            fs("{y,-x,-z}"),
            fs("{-y+1/2,x+1/2,-z+1/2}"),
            fs("{x+1/2,-y+1/2,z}"),
            fs("{-x,y,z+1/2}"),
            fs("{-y+1/2,-x,z+1/4}"),
            fs("{y,x+1/2,z+3/4}"),
            fs("{x+1/2,y+1/2,z+1/2}"),
            fs("{-x,-y,z}"),
            fs("{-y+1/2,x,z+3/4}"),
            fs("{y,-x+1/2,z+1/4}"),
            fs("{-x,y+1/2,-z+3/4}"),
            fs("{x+1/2,-y,-z+1/4}"),
            fs("{y,x,-z+1/2}"),
            fs("{-y+1/2,-x+1/2,-z}"),
            fs("{-x+1/2,-y,-z+3/4}"),
            fs("{x,y+1/2,-z+1/4}"),
            fs("{y+1/2,-x+1/2,-z+1/2}"),
            fs("{-y,x,-z}"),
            fs("{x,-y,z+1/2}"),
            fs("{-x+1/2,y+1/2,z}"),
            fs("{-y,-x+1/2,z+3/4}"),
            fs("{y+1/2,x,z+1/4}")
        ])

    if number == 148:
        return geo.Spacegroup(geo.canonical, [
            fs("{x,y,z}"),
            fs("{-y,x-y,z}"),
            fs("{-x+y,-x,z}"),
            fs("{-x,-y,-z}"),
            fs("{y,-x+y,-z}"),
            fs("{x-y,x,-z}"),
            fs("{x+2/3,y+1/3,z+1/3}"),
            fs("{-y+2/3,x-y+1/3,z+1/3}"),
            fs("{-x+y+2/3,-x+1/3,z+1/3}"),
            fs("{-x+2/3,-y+1/3,-z+1/3}"),
            fs("{y+2/3,-x+y+1/3,-z+1/3}"),
            fs("{x-y+2/3,x+1/3,-z+1/3}"),
            fs("{x+1/3,y+2/3,z+2/3}"),
            fs("{-y+1/3,x-y+2/3,z+2/3}"),
            fs("{-x+y+1/3,-x+2/3,z+2/3}"),
            fs("{-x+1/3,-y+2/3,-z+2/3}"),
            fs("{y+1/3,-x+y+2/3,-z+2/3}"),
            fs("{x-y+1/3,x+2/3,-z+2/3}")
        ])

    if number == 166:
        return geo.Spacegroup(geo.canonical, [
            fs("{x ,y ,z }"),
            fs("{-y  , x-y, z}"),
            fs("{-x+y,-x  ,z }"),
            fs("{y ,x ,-z}"),
            fs("{x-y ,-y  ,-z}"),
            fs("{-x  ,-x+y,-z}"),
            fs("{-x,-y,-z}"),
            fs("{y   ,-x+y,-z}"),
            fs("{x-y ,x   ,-z}"),
            fs("{-y,-x,z }"),
            fs("{-x+y,y   ,z }"),
            fs("{x   ,x-y ,z }"),
            fs("{x  +2/3,y  +1/3,z  +1/3}"),
            fs("{-y   +2/3, x-y +1/3, z +1/3}"),
            fs("{-x+y +2/3,-x   +1/3,z  +1/3}"),
            fs("{y  +2/3,x  +1/3,-z +1/3}"),
            fs("{x-y  +2/3,-y   +1/3,-z +1/3}"),
            fs("{-x   +2/3,-x+y +1/3,-z +1/3}"),
            fs("{-x +2/3,-y +1/3,-z +1/3}"),
            fs("{y    +2/3,-x+y +1/3,-z +1/3}"),
            fs("{x-y  +2/3,x    +1/3,-z +1/3}"),
            fs("{-y +2/3,-x +1/3,z  +1/3}"),
            fs("{-x+y +2/3,y    +1/3,z  +1/3}"),
            fs("{x    +2/3,x-y  +1/3,z  +1/3}"),
            fs("{x  +1/3,y  +2/3,z  +2/3}"),
            fs("{-y   +1/3, x-y +2/3, z +2/3}"),
            fs("{-x+y +1/3,-x   +2/3,z  +2/3}"),
            fs("{y  +1/3,x  +2/3,-z +2/3}"),
            fs("{x-y  +1/3,-y   +2/3,-z +2/3}"),
            fs("{-x   +1/3,-x+y +2/3,-z +2/3}"),
            fs("{-x +1/3,-y +2/3,-z +2/3}"),
            fs("{y    +1/3,-x+y +2/3,-z +2/3}"),
            fs("{x-y  +1/3,x    +2/3,-z +2/3}"),
            fs("{-y +1/3,-x +2/3,z  +2/3}"),
            fs("{-x+y +1/3,y    +2/3,z  +2/3}"),
            fs("{x    +1/3,x-y  +2/3,z  +2/3}")
        ])

    if number == 186:
        return geo.Spacegroup(geo.canonical, [
            fs("{x,y,z}"),
            fs("{-y,x-y,z}"),
            fs("{-x+y,-x,z}"),
            fs("{-x,-y,z+1/2}"),
            fs("{y,-x+y,z+1/2}"),
            fs("{x-y,x,z+1/2}"),
            fs("{-y,-x,z}"),
            fs("{-x+y,y,z}"),
            fs("{x,x-y,z}"),
            fs("{y,x,z+1/2}"),
            fs("{x-y,-y,z+1/2}"),
            fs("{-x,-x+y,z+1/2}")
        ])

    if number == 194:
        return geo.Spacegroup(geo.canonical, [
            fs("{x,y,z}"),
            fs("{-y,x-y,z}"),
            fs("{-x+y,-x,z}"),
            fs("{-x,-y,z+1/2}"),
            fs("{y,-x+y,z+1/2}"),
            fs("{x-y,x,z+1/2}"),
            fs("{y,x,-z}"),
            fs("{x-y,-y,-z}"),
            fs("{-x,-x+y,-z}"),
            fs("{-y,-x,-z+1/2}"),
            fs("{-x+y,y,-z+1/2}"),
            fs("{x,x-y,-z+1/2}"),
            fs("{-x,-y,-z}"),
            fs("{y,-x+y,-z}"),
            fs("{x-y,x,-z}"),
            fs("{x,y,-z+1/2}"),
            fs("{-y,x-y,-z+1/2}"),
            fs("{-x+y,-x,-z+1/2}"),
            fs("{-y,-x,z}"),
            fs("{-x+y,y,z}"),
            fs("{x,x-y,z}"),
            fs("{y,x,z+1/2}"),
            fs("{x-y,-y,z+1/2}"),
            fs("{-x,-x+y,z+1/2}")
        ])

    if number == 198:
        return geo.Spacegroup(geo.canonical, [
            fs("{x,y,z}"),
            fs("{-x+1/2,-y,z+1/2}"),
            fs("{-x,y+1/2,-z+1/2}"),
            fs("{x+1/2,-y+1/2,-z}"),
            fs("{z,x,y}"),
            fs("{z+1/2,-x+1/2,-y}"),
            fs("{-z+1/2,-x,y+1/2}"),
            fs("{-z,x+1/2,-y+1/2}"),
            fs("{y,z,x}"),
            fs("{-y,z+1/2,-x+1/2}"),
            fs("{y+1/2,-z+1/2,-x}"),
            fs("{-y+1/2,-z,x+1/2}")
        ])

    if number == 212:
        return geo.Spacegroup(geo.canonical, [
            fs("{x,y,z}"),
            fs("{-x+1/2,-y,z+1/2}"),
            fs("{-x,y+1/2,-z+1/2}"),
            fs("{x+1/2,-y+1/2,-z}"),
            fs("{z,x,y}"),
            fs("{z+1/2,-x+1/2,-y}"),
            fs("{-z+1/2,-x,y+1/2}"),
            fs("{-z,x+1/2,-y+1/2}"),
            fs("{y,z,x}"),
            fs("{-y,z+1/2,-x+1/2}"),
            fs("{y+1/2,-z+1/2,-x}"),
            fs("{-y+1/2,-z,x+1/2}"),
            fs("{y+1/4,x+3/4,-z+3/4}"),
            fs("{-y+1/4,-x+1/4,-z+1/4}"),
            fs("{ y+3/4,-x+3/4, z+1/4}"),
            fs("{-y+3/4, x+1/4, z+3/4}"),
            fs("{x+1/4,z+3/4,-y+3/4}"),
            fs("{-x+3/4, z+1/4, y+3/4}"),
            fs("{-x+1/4,-z+1/4,-y+1/4}"),
            fs("{ x+3/4,-z+3/4, y+1/4}"),
            fs("{z+1/4,y+3/4,-x+3/4}"),
            fs("{ z+3/4,-y+3/4, x+1/4}"),
            fs("{-z+3/4, y+1/4, x+3/4}"),
            fs("{-z+1/4,-y+1/4,-x+1/4}")
        ])

    if number == 227:
        sg = geo.Spacegroup(geo.canonical, [
            fs("{ x,     y,     z    }"),
            fs("{    -x,    -y+1/2, z+1/2}"),
            fs("{-x+1/2, y+1/2,-z    }"),
            fs("{ x+1/2,-y,    -z+1/2}"),
            fs("{ z,     x,     y    }"),
            fs("{     z+1/2,-x,    -y+1/2}"),
            fs("{-z,    -x+1/2, y+1/2}"),
            fs("{-z+1/2, x+1/2,-y    }"),
            fs("{ y,     z,     x    }"),
            fs("{    -y+1/2, z+1/2,-x    }"),
            fs("{ y+1/2,-z,    -x+1/2}"),
            fs("{-y,    -z+1/2, x+1/2}"),
            fs("{ y+3/4, x+1/4,-z+3/4}"),
            fs("{-y+1/4,    -x+1/4,-z+1/4}"),
            fs("{ y+1/4,-x+3/4, z+3/4}"),
            fs("{-y+3/4, x+3/4, z+1/4}"),
            fs("{ x+3/4, z+1/4,-y+3/4}"),
            fs("{-x+3/4,     z+3/4, y+1/4}"),
            fs("{-x+1/4,-z+1/4,-y+1/4}"),
            fs("{ x+1/4,-z+3/4, y+3/4}"),
            fs("{ z+3/4, y+1/4,-x+3/4}"),
            fs("{ z+1/4,    -y+3/4, x+3/4}"),
            fs("{-z+3/4, y+3/4, x+1/4}"),
            fs("{-z+1/4,-y+1/4,-x+1/4}"),
            fs("{-x+1/4,-y+1/4,-z+1/4}"),
            fs("{ x+1/4,     y+3/4,-z+3/4}"),
            fs("{ x+3/4,-y+3/4, z+1/4}"),
            fs("{-x+3/4, y+1/4, z+3/4}"),
            fs("{-z+1/4,-x+1/4,-y+1/4}"),
            fs("{-z+3/4,     x+1/4, y+3/4}"),
            fs("{ z+1/4, x+3/4,-y+3/4}"),
            fs("{ z+3/4,-x+3/4, y+1/4}"),
            fs("{-y+1/4,-z+1/4,-x+1/4}"),
            fs("{ y+3/4,    -z+3/4, x+1/4}"),
            fs("{-y+3/4, z+1/4, x+3/4}"),
            fs("{ y+1/4, z+3/4,-x+3/4}"),
            fs("{-y+1/2,-x,     z+1/2}"),
            fs("{ y,         x,     z    }"),
            fs("{-y,     x+1/2,-z+1/2}"),
            fs("{ y+1/2,-x+1/2,-z    }"),
            fs("{-x+1/2,-z,     y+1/2}"),
            fs("{ x+1/2,    -z+1/2,-y    }"),
            fs("{ x,     z,     y    }"),
            fs("{-x,     z+1/2,-y+1/2}"),
            fs("{-z+1/2,-y,     x+1/2}"),
            fs("{-z,         y+1/2,-x+1/2}"),
            fs("{ z+1/2,-y+1/2,-x    }"),
            fs("{ z,     y,     x    }")
        ])
        sg = geo.Spacegroup(
            geo.canonical, sg.liste_cosets +
            [fs("{x,y+1/2,z+1/2}") * coset for coset in sg.liste_cosets] +
            [fs("{x+1/2,y,z+1/2}") * coset for coset in sg.liste_cosets] +
            [fs("{x+1/2,y+1/2,z}") * coset for coset in sg.liste_cosets])
        return sg
Exemplo n.º 34
0
def test_Atom():
    atom1 = cr.Atom("Cs1", "Cs", fs("p 0 0 0"))
    assert atom1.has_color == False
    assert atom1.__str__() == \
        "Atom Cs1 Cs Pos /  0  \ \n" \
        "               |   0   |\n" \
        "                \  0  / "
    assert (atom1 + "hallo").name == atom1.name + "hallo"
    atom2 = cr.Atom("Cs2", "Cs", fs("p 0 0 0"))
    assert atom2 == atom1
    assert hash(atom2) == hash(atom1)
    assert {atom2} == {atom1}
    atom3 = cr.Atom("Cs3", "Cs", fs("p0.1 0 0"))
    assert atom3 != atom1
    atom4 = cr.Atom("Cs1", "Fe", fs("p 0 0 0"))
    assert atom4 != atom1

    atom5 = cr.Atom("Cs1", "Cs", fs("p 0.1234 0 0"))
    atom6 = cr.Atom("Cs2", "Cs", fs("p 0.1234000000001 0 0"))
    assert hash(atom5) == hash(atom6)
    assert atom5 == atom6

    atom = cr.Atom("Cl1", "Cl", fs("p 1/2 1/2 1/2"))
    transformation = fs("O->(0,0,0) \n"
                        "then\n"
                        "a' = a \n"
                        "b' = 2b \n"
                        "c' = c")
    atom_trans = cr.Atom("Cl1", "Cl", fs("p 1/2 1/4 1/2"))
    assert (transformation ** atom).__str__() == atom_trans.__str__()

    sym = fs("-x+1/2,-y+1/2, z")
    atom_sym = cr.Atom("Cl1", "Cl", fs("p0 0 1/2"))
    assert (sym ** atom).__str__() == atom_sym.__str__()

    coset = fs("{x, -y, z+1}")
    atom = cr.Atom("Cl1", "Cl", fs("p 1/2 1/4 1/2"))
    atom1 = coset ** atom
    atom2 = cr.Atom("Cl1", "Cl", fs("p 1/2 3/4 1/2"))
    assert atom1.__str__() == atom2.__str__()

    transgen = geo.Transgen(fs("d 1 0 0"),
                            fs("d 0 1 0"),
                            fs("d 0 0 2"))
    atom = cr.Atom("Cl1", "Cl", fs("p 1/2 5/4 -1/2"))
    atom1 = atom % transgen
    atom2 = cr.Atom("Cl1", "Cl", fs("p 1/2 1/4 3/2"))
    assert atom1 == atom2

    d = fs("d 1/2 0 0")
    atom1 = cr.Atom("Cl1", "Cl", fs("p 0 0 0"))
    atom2 = cr.Atom("Cl1", "Cl", fs("p 1/2 0 0"))
    atom3 = atom1 + d
    assert atom2 == atom3