def velcal(lc, posa, potim, num=None, bound=0.1): #????????????????,?????????(??????2~n-1??) import numpy as np import vasp if num == None: timestep = 2 * potim vela = [0] * (len(posa) - 2) check = False for i in range(len(vela)): vela[i] = np.mat(np.zeros((len(posa[1]), 3))) for i in range(len(posa) - 2): # print(i) #?? for j in range(len(posa[1])): for k in range(3): # if abs(posa[i+2][j,k]) < 0.05 or abs(posa[i+2][j,k]-1) < 0.05 or abs(posa[i+2][j,k]) or abs(posa[i][j,k])> 1: #???? if abs(posa[i + 2][j, k]) < bound or abs(posa[i + 2][j, k] - 1) < bound: #???? check = True break if check: posa[i + 2][j, :] = vasp.nearby(lc, posa[i][j, :], posa[i + 2][j, :]) check = False vela[i][j, :] = (posa[i + 2][j, :] - posa[i][j, :]) * lc / timestep return vela else: num -= 1 timestep = 2 * potim vela = [0] * (len(posa) - 2) check = False for i in range(len(vela)): vela[i] = np.mat(np.zeros((1, 3))) for i in range(len(vela)): # print(i) #?? for k in range(3): # if abs(posa[i+2][num,k]) < 0.05 or abs(posa[i+2][num,k]-1) < 0.05 or abs(posa[i+2][num,k]) > 1 or abs(posa[i][num,k]) > 1: #???? if abs(posa[i + 2][num, k]) < bound or abs(posa[i + 2][num, k] - 1) < bound: #???? check = True break if check: posa[i + 2][num, :] = vasp.nearby(lc, posa[i][num, :], posa[i + 2][num, :]) check = False vela[i][:] = (posa[i + 2][num, :] - posa[i][num, :]) * lc / timestep return vela
def bond_angle(ap, lc, arg1, arg2, arg3): #???????? import numpy as np import vasp import math arg1 -= 1 arg2 -= 1 arg3 -= 1 ap[arg1, :] = vasp.nearby(lc, ap[arg2, :], ap[arg1, :]) ap[arg3, :] = vasp.nearby(lc, ap[arg2, :], ap[arg3, :]) dp1 = ap[arg1, :] * lc dp2 = ap[arg2, :] * lc dp3 = ap[arg3, :] * lc ll1 = dp2 - dp1 ll2 = dp2 - dp3 cita = math.acos(ll1 * np.transpose(ll2) / math.sqrt( (ll1 * np.transpose(ll1)) * (ll2 * np.transpose(ll2)))) * 180 / math.pi return cita
def checkaway(lc, posa, vela, num, oneatom=True, dis_lim=5, v_d_lim=0.10): #???? #??????????? import numpy as np import math import vasp num -= 1 nstep = len(posa) check = False if oneatom: for n in range(7): step = int((n + 1) * nstep / 8) posa[step][num, :] = vasp.nearby(lc, posa[0][num, :], posa[step][num, :]) dp = (posa[step][num, :] - posa[0][num, :]) * lc dis = math.sqrt(dp * np.transpose(dp)) disv = dp * np.transpose(vela[step]) if dis > dis_lim: check = True break elif disv > v_d_lim: check = True break return check else: for n in range(7): step = int((n + 1) * nstep / 8) posa[step][num, :] = vasp.nearby(lc, posa[0][num, :], posa[step][num, :]) dp = (posa[step][num, :] - posa[0][num, :]) * lc dis = math.sqrt(dp * np.transpose(dp)) disv = dp * np.transpose(vela[step][num, :]) if dis > dis_lim: check = True break elif disv > v_d_lim: check = True break return check
def bond_length(ap, lc, arg1, arg2): #???????? import numpy as np import vasp import math arg1 -= 1 arg2 -= 1 ap[arg2, :] = vasp.nearby(lc, ap[arg1, :], ap[arg2, :]) dp1 = ap[arg1, :] * lc dp2 = ap[arg2, :] * lc dis = (dp1 - dp2) * np.transpose(dp1 - dp2) dis = math.sqrt(dis) return dis