Пример #1
0
def GetPrimLattice(latt, pos, num, dictp):
    is_prim = None
    rot = np.identity(3)
    tr = SymTrans(rot, dictp, num, pos, latt)
    #print('tr:\n', tr)
    if tr is not None:
        if len(tr) == 1:
            print('Input cell is primitive!')
            is_prim = 1  # // primitive cell flag
            #print('primitive lattice:\n', latt)  # // delaunay of primitive lattice vec
            #print('primitive numbers:\n', num)
            #print('primitive cell positions:\n', pos)  # atom postion
            #return latt, num, pos
            #// delaunay change part
            flag, reduc_b, delauP = delaunay.Delaunay(latt, -1)
            if flag:
                new_pos = delaunay.ChangeOfBasis(pos, np.linalg.inv(delauP))
                print('primitive lattice (delaunay):\n',
                      reduc_b)  # // delaunay of primitive lattice vec
                print('primitive cell positions:\n',
                      [list(i) for i in new_pos])  # atom postion
                return reduc_b, num, new_pos, is_prim
        else:
            print('Input cell is not primitive! Changing...')
            is_prim = 0  # // convetional cell flag
            ori_tr = [
                np.array([1.000000000, 0.0000000000, 0.0000000000]),
                np.array([0.000000000, 1.0000000000, 0.0000000000]),
                np.array([0.000000000, 0.0000000000, 1.0000000000])
            ]
            #print('original:\n', ori_tr)
            prim_vec = tr[1:] + ori_tr  # delete the first vec in tr (ori-ori)
            print('all primitive translations:\n', prim_vec)
            #min_prim_latt = np.zeros((3, 3))
            flag3, min_prim_latt = check_volume1(
                prim_vec, latt)  # // delaunay of primitive lattice vec
            if flag3 == 'Found':
                #print('final primitive lattice\n', min_prim_latt)
                #prim_latt, new_num, new_pos = AtomPosConv2Prim(min_prim_latt, latt, pos, num)
                #return prim_latt, new_num, new_pos
                #print('new numbers:\n', new_num)
                #print('new positions:\n', new_pos)
                # // delaunay change part
                flag, reduc_b, delaup = delaunay.Delaunay(min_prim_latt, -1)
                if flag:
                    print('primitive lattice (delaunay):\n', reduc_b)
                    reduc_latt, new_num, new_pos = AtomPosConv2Prim(
                        reduc_b, latt, pos, num)
                    print('primitive cell positions:\n',
                          [list(i) for i in new_pos])  # atom postion
                    return reduc_latt, new_num, new_pos, is_prim
Пример #2
0
    def test_delaunay_init_D_eq_dimP(self):
        N = 5
        D = 2
        P = list(self.generate_points(N, D))

        # if provided D should be same order as P, if not throw exception
        self.assertRaises(Exception, delaunay.Delaunay, P, D + 1)
        _delaunay = delaunay.Delaunay(P, D)
Пример #3
0
    def test_delaunay_init_infer_D(self):
        N = 5
        D = 2
        P = list(self.generate_points(N, D))
        _delaunay = delaunay.Delaunay(P)

        # infer D from P if no D arg
        self.assertEquals(_delaunay.D, D, msg="infer D from P if no D arg")
Пример #4
0
def SymRotation(prim_latt):
    """
        Get point group, G before rotation  
    """
    # min_latt, num, pos = primitive.GetPrimLattice()
    # min_latt should be the delaunay lattice, that is "delaunay.Delaunay(prim_latt)"
    flag, min_latt, delauP = delaunay.Delaunay(prim_latt, -1)

    # min_latt = prim_latt.copy()
    metric = GetMetricMat(min_latt)

    # G after rotation
    rotations = AllRotOperation()
    latt_oper = []
    new_rot = []
    count = 0
    for i in rotations:

        rot_latt = np.dot(np.transpose(i), min_latt)
        metric_rot = GetMetricMat(rot_latt)
        if MetricCondition(metric, metric_rot):
            if count < 48:
                latt_oper.append(i)
                count += 1
                # print('check here count: ', count)

            elif count == 48:
                print('Too many symmetric operations! Stop...')
                break
    # print('count', count)

    if count < 49:
        new_rot = GetRotOfLowerSymm(prim_latt, min_latt, latt_oper)

    # print(len(latt_oper), len(new_rot))
    # print(len(new_rot))
    # All symmetry rotation parts
    return new_rot
Пример #5
0
def GetSpaceGroup(prim_latt, symmetry, pgt_type, axis):
    """
        Get space group
        input  :  primitive lattice, symmetry operations, point group type, axis
        return :  space group number, hall number, origin, 
                  new lattice, new transformation matrix, center
    """

    laue = pgt_type[5]
    trans_matP = (np.transpose(axis)).copy()  # P : vertical vec
    # print(axis, trans_matP)
    if pgt_type[0] == 0:
        print('Error! No symmetry!')
        return None, None, None, None, None, None

    #conv_latt = np.zeros((3, 3))
    conv_latt = np.dot(axis, prim_latt)  # axis = np.transpose(trans_matP)

    if laue == 'LAUE1':  # TRICLINIC

        # get new transformation matrix
        # change conventional one to minimum by Niggli Transformation
        # then find trans_mat of primitive to minimum
        nigg = niggli.Niggli(conv_latt)
        min_latt = np.zeros((3, 3))
        if not (nigg == np.zeros((3, 3))).all():
            for i in range(3):
                for j in range(3):
                    min_latt[i, j] = nigg[i, j]

        if np.linalg.det(min_latt) < 0:
            min_latt = -min_latt

        inv_latt = np.linalg.inv(np.transpose(prim_latt))
        trans_matP = np.dot(inv_latt,
                            np.transpose(min_latt))  # P : vertical vec
        for i in range(3):
            for j in range(3):
                if trans_matP[i, j] < 0.0:
                    trans_matP[i, j] = int(trans_matP[i, j] - 0.5)
                else:
                    trans_matP[i, j] = int(trans_matP[i, j] + 0.5)
        # return trans_matP

    if laue == 'LAUE2M':  # MONOCLINIC

        # get new transformation matrix
        # change conv to min using delaunay, then find trans_nat of prim to min
        flag, min_latt, delauP = delaunay.Delaunay(conv_latt,
                                                   1)  # delauP : vertical
        if flag:
            inv_latt = np.linalg.inv(prim_latt)
            trans_matP = np.transpose(np.dot(min_latt, inv_latt))
            for i in range(3):
                for j in range(3):
                    if trans_matP[i, j] < 0.0:
                        trans_matP[i, j] = int(trans_matP[i, j] - 0.5)
                    else:
                        trans_matP[i, j] = int(trans_matP[i, j] + 0.5)
        # return trans_matP

    center = None
    center, correct_mat = GetCenter(trans_matP, laue)

    # print(trans_matP)
    print('correct matrix: \n', correct_mat)
    print('center: \n', center)

    new_trans_mat = trans_matP.copy()
    if center is not None:

        # trans_P, correct_mat and new_trans_mat are vertical vecs
        new_trans_mat = np.dot(trans_matP, correct_mat)

        # conv_latt : horizontal vectors
        conv_latt = np.dot(np.transpose(new_trans_mat), prim_latt)

    # print('conven latt1:\n', conv_latt)
    print('new trans mat: \n', new_trans_mat)
    if center == 'R_CENTER':
        conv_symm = GetConvSymm('PRIMITIVE', new_trans_mat, symmetry)
    else:
        conv_symm = GetConvSymm(center, new_trans_mat, symmetry)

    # print('check numsym:', len(conv_symm))
    spgnum = None
    hallnum = None
    origin = np.zeros(3)
    new_latt = np.zeros((3, 3))

    if conv_symm != []:
        for i in range(231):
            flag, new_latt, origin, spgnum = GetHallNumber(
                conv_latt, i, pgt_type, conv_symm, center)
            if flag:
                print('Congratulations! Find space group!')
                hallnum = spg_to_hall_num[spgnum]
                return spgnum + 1, hallnum, origin, new_latt, new_trans_mat, center
                # break

        print('Error! Cannot match any space group data!')
        return None, None, None, None, None, None
    '''
Пример #6
0
          " : ",
          scoreOpti / bestScore,
          ", best : ",
          bestScore,
          file=f)
    f.close()

    print("shortest path on clear weather ")
    bestState = nx.shortest_path(graph, start, end, "weight")
    print(bestState)
    print("best score : ", CTPgameOptimist.evaluate(bestState))


for i in range(0, 100):

    delau = delaunay.Delaunay(20)
    g = delau.graph

    f = open("log3.txt", "w+")

    print("Graph : ", file=f)
    print(g.nodes(), file=f)
    print(g.edges(), file=f)

    print("Info : ", file=f)
    for (u, v) in g.edges():
        print(u, v, " : ", g[u][v], file=f)

    f.close()
    playCTP(g, "1", "20", iterationMax=10000)
    print("#################################", i + 1, "OUT OF 100",
Пример #7
0
def test_niggli():
    latt, pos, numb, dictp = delaunay.StructRead()
    flag, reduc_b, delauP = delaunay.Delaunay(latt, -1)
    print('red', reduc_b)
    A = Niggli(reduc_b)
    print(A)
Пример #8
0
def GetSpaceGroup(prim_latt, symmetry, pgt_type, axis):
    # // search hall number
    # // standardize
    #o_latt, o_pos, o_num, dictp = delaunay.StructRead()
    #prim_latt, num, pos = primitive.GetPrimLattice(o_latt, o_pos, o_num, dictp)
    #symmetry, pgt_type, axis = pointgp.GetPointGroup(prim_latt, num, pos, dictp)  # // pgt_type = [pgnum, pgtable, symbol, schoenf, holo, Laue]

    laue = pgt_type[5]
    trans_matP = (np.transpose(axis)).copy()  # // P : vertical vectors
    # print(axis, trans_matP)
    if pgt_type[0] == 0:
        print('Error! No symmetry!')
        return None, None, None, None, None, None  # // return 0

    #conv_latt = np.zeros((3, 3))
    conv_latt = np.dot(axis, prim_latt)  # // axis = np.transpose(trans_matP)

    if laue == 'LAUE1':  # // TRICLINIC

        #   // get new transformation matrix
        #   // change conv to min using niggli, then find trans_nat of prim to min
        nigg = niggli.Niggli(conv_latt)
        min_latt = np.zeros((3, 3))
        if not (nigg == np.zeros((3, 3))).all():
            for i in range(3):
                for j in range(3):
                    min_latt[i, j] = nigg[i, j]

        if np.linalg.det(min_latt) < 0:
            min_latt = -min_latt

        inv_latt = np.linalg.inv(np.transpose(prim_latt))
        trans_matP = np.dot(
            inv_latt, np.transpose(min_latt))  # // here, P is vertical vec
        for i in range(3):
            for j in range(3):
                if trans_matP[i, j] < 0.0:
                    trans_matP[i, j] = int(trans_matP[i, j] - 0.5)
                else:
                    trans_matP[i, j] = int(trans_matP[i, j] + 0.5)
        # // return trans_matP

    if laue == 'LAUE2M':  # // MONOCLINIC

        #   // get new transformation matrix
        #   // change conv to min using delaunay, then find trans_nat of prim to min
        flag, min_latt, delauP = delaunay.Delaunay(conv_latt,
                                                   1)  # // delauP is vertical
        if flag:
            inv_latt = np.linalg.inv(prim_latt)
            trans_matP = np.transpose(np.dot(min_latt, inv_latt))
            for i in range(3):
                for j in range(3):
                    if trans_matP[i, j] < 0.0:
                        trans_matP[i, j] = int(trans_matP[i, j] - 0.5)
                    else:
                        trans_matP[i, j] = int(trans_matP[i, j] + 0.5)
        # // return trans_matP

    center = None
    center, correct_mat = GetCenter(trans_matP, laue)

    #print(trans_matP)
    print('correct matrix: \n', correct_mat)
    print('center: \n', center)

    new_trans_mat = trans_matP.copy()
    if center is not None:
        new_trans_mat = np.dot(
            trans_matP, correct_mat
        )  # // trans_P, correct_mat and new_trans_mat are vertical vecs
        conv_latt = np.dot(np.transpose(new_trans_mat),
                           prim_latt)  # // conv_latt : horizontal vectors

    #print('conven latt1:\n', conv_latt)
    print('new trans mat: \n', new_trans_mat)
    if center == 'R_CENTER':
        conv_symm = GetConvSymm('PRIMITIVE', new_trans_mat, symmetry)
    else:
        conv_symm = GetConvSymm(center, new_trans_mat, symmetry)

    #print('check numsym:', len(conv_symm))
    spgnum = None
    hallnum = None
    origin = np.zeros(3)
    new_latt = np.zeros((3, 3))

    if conv_symm != []:
        for i in range(231):
            flag, new_latt, origin, spgnum = GetHallNumber(
                conv_latt, i, pgt_type, conv_symm, center)
            if flag:
                print('Congratulations! Find space group!')
                hallnum = spg_to_hall_num[spgnum]
                return spgnum + 1, hallnum, origin, new_latt, new_trans_mat, center
                #break

        print('Error! Cannot match any space group data!')
        return None, None, None, None, None, None
    '''
Пример #9
0
import random as r
from vectangle import Vectorizer

p1 = geo.Point(100, 100)
p2 = geo.Point(150, 150)
p3 = geo.Point(100, 150)
p4 = geo.Point(150, 150)
p5 = geo.Point(125, 130)
p6 = geo.Point(130, 125)
p7 = geo.Point(120, 125)
p8 = geo.Point(125, 120)

colors = [
    '#FFFFFF', '#C0C0C0', '#808080', '#000000', '#FF0000', '#800000',
    '#FFFF00', '#808000', '#00FF00', '#008000', '#00FFFF', '#008080',
    '#0000FF', '#000080', '#FF00FF', '#800080'
]

d = delaunay.Delaunay(200, 200)

d.add_points([p5, p6, p7, p8])

for tri in d.tris:
    print(tri)

vec = Vectorizer('15cm', '15cm')
for tri in d.tris:
    vec.add_tri(tri, colors[r.randint(0, 15)])

vec.save('testvec')