def export_hessian_forshengbte_original(self, sc): from csld.util.tool import matrix2text na = self.prim.num_sites Nsc = sc.n_cell hmat = self.get_hessian(sc, True) hmat = hmat.reshape((na, Nsc, 3, na, Nsc, 3)) with open('FORCE_CONSTANTS_2ND', 'w') as f: f.write("%d \n" % (na * Nsc)) index = np.arange(na * Nsc).reshape( (na, *(np.diag(sc.sc_mat)[::-1]))) sort_idx = np.lexsort( [sc.ijk_ref[:, 0], sc.ijk_ref[:, 1], sc.ijk_ref[:, 2]]) sc.ijk_ref = sc.ijk_ref[sort_idx] for ia1 in range(na): for scindex in range(Nsc): scorder = sort_idx[scindex] for ia2 in range(na): for l, ls in zip(sort_idx, sc.ijk_ref): if scindex == 0 and ia1 == 0 and ia2 == 0: print("l = ", l, " ls =", ls) f.write("%d %d\n%s\n" % (index[ia1, 0, 0, 0] + 1 + scindex, index[ia2, ls[2], ls[1], ls[0]] + 1, matrix2text(hmat[ia1, scorder, :, ia2, l, :])))
def export_hessian_forshengbte_original(self, sc): from csld.util.tool import matrix2text na = self.prim.num_sites Nsc = sc.n_cell hmat = self.get_hessian(sc, True) hmat = hmat.reshape((na, Nsc, 3, na, Nsc, 3)) with open('FORCE_CONSTANTS_2ND', 'w') as f: f.write("%d \n" % (na * Nsc)) index = np.arange(na * Nsc).reshape( (na, *(np.diag(sc.sc_mat)[::-1]))) print(index) for scindex in range(Nsc): for ia1 in range(na): for ia2 in range(na): for l, ls in enumerate(sc.ijk_ref): f.write("%d %d\n%s\n" % (index[ia1, 0, 0, 0] + 1 + scindex, index[ia2, ls[2], ls[1], ls[0]] + 1, matrix2text(hmat[ia1, scindex, :, ia2, l, :])))
def export_hessian_forshengbte(self, sc): from csld.util.tool import matrix2text na = self.prim.num_sites Nsc = sc.n_cell hmat = self.get_hessian(sc, True) hmat = hmat.reshape((na, Nsc, 3, na, Nsc, 3)) #with open('FORCE_CONSTANTS_2short', 'w') as f: # for ia1 in range(na): # for ia2 in range(na): # for l,ls in enumerate(sc.ijk_ref): # f.write("%d %d %d %d %d %s\n"%(ia1+1,ls[0]+1,ls[1]+1,ls[2]+1,ia2+1,matrix2text(hmat[ia1,0,:,ia2,l,:].reshape(-1)))) # new compact format with open('FORCE_CONSTANTS_2ND', 'w') as f: f.write("%d %d\n" % (na, na * Nsc)) index = np.arange(na * Nsc).reshape( (na, *(np.diag(sc.sc_mat)[::-1]))) for ia1 in range(na): for ia2 in range(na): for l, ls in enumerate(sc.ijk_ref): f.write("%d %d\n%s\n" % (index[ia1, 0, 0, 0] + 1, index[ia2, ls[2], ls[1], ls[0]] + 1, matrix2text(hmat[ia1, 0, :, ia2, l, :])))