• data2molecule
  • data2POSCAR
  • DFT_deform

    data2molecule

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    import pandas as pd
    import numpy as np
    import os
    import time
    modelname="HemiCG"
    csvname=modelname+".csv"
    f = pd.read_csv(modelname+".data", header=None)
    str = [' atoms', ' bonds', ' angles', ' dihedrals', ' impropers', ' atom types', ' bond types', ' angle types',
    ' dihedral types', ' improper types', 'xlo xhi', 'ylo yhi', 'zlo zhi', 'Masses', 'Atoms', 'Bonds', 'Angles',
    'Dihedrals', 'Impropers']
    N = len(str)
    p = ' Impropers'
    row_id = np.zeros(N)

    for i in range(N):
    q = f[f[0].str.contains(str[i])].index.tolist()
    if len(q) == 1:
    row_id[i] = q[0]
    ## 筛选特定行 并 提取信息
    id_bo = int(row_id[15])
    id_an = int(row_id[16])
    id_di = int(row_id[17])
    id_im = int(row_id[18])
    ## 定义特定拓扑结构字符串并新建mol文件
    inistr = ["\t", "Coords", "\t", "Types", "\t", "Charges", "\t", "Bonds", "\t", "Angles", "\t", "Dihedrals", "\t",
    "Impropers", "\t"]
    strinsert = pd.DataFrame(inistr)
    mol = open('8_201.csv', 'w')
    info = ["#molecule file generated by python --JiahaoLi " + time.strftime('%Y:%m:%d %H:%M:%S',
    time.localtime(int(time.time()))), "\t"];
    pd.DataFrame([info]).to_csv(csvname, mode='a', index=None, header=False)
    for i in range(4):
    f.iloc[int(row_id[i])].to_csv(csvname, mode='a', index=None, header=False)
    xyz = f.iloc[int(row_id[14]) + 1:id_bo]
    p = xyz[0].str.split(' ', expand=True)
    strinsert[0:3].to_csv(csvname, mode='a', index=None, header=False)

    tp = pd.merge(p.iloc[:, 0], p.iloc[:, 4:7], left_index=True, right_index=True)
    tp.to_csv(csvname, mode='a', index=None, header=False, sep=' ')
    strinsert[2:5].to_csv(csvname, mode='a', index=None, header=False)
    tp = pd.merge(p.iloc[:, 0], p.iloc[:, 2], left_index=True, right_index=True)
    tp.to_csv(csvname, mode='a', index=None, header=False, sep=' ')
    strinsert[4:7].to_csv(csvname, mode='a', index=None, header=False)
    tp = pd.merge(p.iloc[:, 0], p.iloc[:, 3], left_index=True, right_index=True)
    tp.to_csv(csvname, mode='a', index=None, header=False, sep=' ')
    ## 输出拓扑信息数目
    # mol.close()
    if id_bo == 0:
    mol.close()
    elif (id_bo != 0) & (id_an != 0) & (id_di != 0) & (id_im != 0):
    strinsert[6:9].to_csv(csvname, mode='a', header=False, index=None)
    p = f.iloc[id_bo + 1:id_an]
    p.to_csv(csvname, mode='a', index=None, header=False)
    strinsert[8:11].to_csv(csvname, mode='a', header=False, index=None)
    f.iloc[id_an + 1:id_di].to_csv(csvname, mode='a', index=None, header=False)
    strinsert[10:13].to_csv(csvname, mode='a', header=False, index=None)
    f.iloc[id_di + 1:id_im].to_csv(csvname, mode='a', index=None, header=False)
    strinsert[12::].to_csv(csvname, mode='a', header=False, index=None)
    f.iloc[id_im + 1::].to_csv(csvname, mode='a', index=None, header=False)

    elif (id_bo != 0) & (id_an != 0) & (id_di != 0) & (id_im == 0):
    strinsert[6:9].to_csv(csvname, mode='a', header=False, index=None)
    f.iloc[id_bo + 1:id_an].to_csv(csvname, mode='a', index=None, header=False)
    strinsert[8:11].to_csv(csvname, mode='a', header=False, index=None)
    f.iloc[id_an + 1:id_di].to_csv(csvname, mode='a', index=None, header=False)
    strinsert[10:13].to_csv(csvname, mode='a', header=False, index=None)
    f.iloc[id_di + 1::].to_csv(csvname, mode='a', index=None, header=False)

    elif (id_bo != 0) & (id_an != 0) & (id_di == 0) & (id_im != 0):
    strinsert[6:9].to_csv(csvname, mode='a', header=False, index=None)
    f.iloc[id_bo + 1:id_an].to_csv(csvname, mode='a', index=None, header=False)
    strinsert[8:11].to_csv(csvname, mode='a', header=False, index=None)
    f.iloc[id_an + 1:id_im].to_csv(csvname, mode='a', index=None, header=False)
    strinsert[12::].to_csv(csvname, mode='a', header=False, index=None)
    f.iloc[id_im + 1::].to_csv(csvname, mode='a', index=None, header=False)


    elif (id_bo != 0) & (id_an != 0) & (id_di == 0) & (id_im == 0):
    strinsert[6:9].to_csv(csvname, mode='a', header=False, index=None)
    f.iloc[id_bo + 1:id_an].to_csv(csvname, mode='a', index=None, header=False)
    strinsert[8:11].to_csv(csvname, mode='a', header=False, index=None)
    f.iloc[id_an + 1::].to_csv(csvname, mode='a', index=None, header=False)


    elif (id_bo != 0) & (id_an == 0) & (id_di != 0) & (id_im != 0):
    strinsert[6:9].to_csv(csvname, mode='a', header=False, index=None)
    f.iloc[id_bo + 1:id_di].to_csv(csvname, mode='a', index=None, header=False)
    strinsert[10:13].to_csv(csvname, mode='a', header=False, index=None)
    f.iloc[id_di + 1:id_im].to_csv(csvname, mode='a', index=None, header=False)
    strinsert[12::].to_csv(csvname, mode='a', header=False, index=None)
    f.iloc[id_im + 1::].to_csv(csvname, mode='a', index=None, header=False)

    elif (id_bo != 0) & (id_an == 0) & (id_di != 0) & (id_im == 0):
    strinsert[6:9].to_csv(csvname, mode='a', header=False, index=None)
    f.iloc[id_bo + 1:id_di].to_csv(csvname, mode='a', header=False, index=None)
    strinsert[10:13].to_csv(csvname, mode='a', header=False, index=None)
    f.iloc[id_di + 1::].to_csv(csvname, mode='a', index=None, header=False)

    elif (id_bo != 0) & (id_an == 0) & (id_di == 0) & (id_im != 0):
    strinsert[6:9].to_csv(csvname, mode='a', header=False, index=None)
    f.iloc[id_bo + 1:id_im].to_csv(csvname, mode='a', index=None, header=False)
    strinsert[12::].to_csv(csvname, mode='a', header=False, index=None)
    f.iloc[id_im + 1::].to_csv(csvname, mode='a', index=None, header=False)

    elif (id_bo != 0) & (id_an == 0) & (id_di == 0) & (id_im == 0):
    strinsert[6:9].to_csv(csvname, mode='a', header=False, index=None)
    f.iloc[id_bo + 1::].to_csv(csvname, mode='a', index=None, header=False)
    mol.close()
    os.rename(modelname+".csv", modelname+".mol")
    # m=f.iloc[id_bo:id_an]

    DFT计算材料变形

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/bin/sh
rm -r POSCAR
cp CONTCAR CONTCAR.$@
cp OSZICAR OSZICAR.$@
mv CONTCAR POSCAR.$@
awk 'BEGIN{my_a = 0.01; my_b = 0}{
if ((NR<=33&&NR>=10)||( NR<=102&&NR>=66 )||(NR<=110&&NR>=106)||(NR<=126&&NR>=112))
{
my_b = $2 + my_a;
if (my_b > 1)
my_b = my_b - 1;
printf("%.7f %.7f %.7f %s %s %s\n",$1, my_b,$3,$4,$5,$6);
}
else print $0;
}' POSCAR.$@>POSCAR

本文采用CC-BY-SA-3.0协议,转载请注明出处
作者: 得意喵~