def init_pos(natom): from qharv.inspect import crystal from ase import Atoms from ase.build import make_supercell rho = 2.2e22 * 1e6 / 1e30 # atoms/A^3 lbox = (natom / rho)**(1. / 3) nxf = (natom / 4.)**(1. / 3) nx = int(round(nxf)) if not np.isclose(nx, nxf): raise RuntimeError('natom=%d nxf=%3.2f!=%d' % (natom, nxf, nx)) # create FCC crystal alat = lbox / nx axes0 = alat / 2 * (np.ones(3) - np.eye(3)) tmat = nx * (np.ones(3) - 2 * np.eye(3)) s0 = Atoms('H', cell=axes0, positions=[[0, 0, 0]], pbc=[1, 1, 1]) s1 = make_supercell(s0, tmat) pos = s1.get_positions() axes = s1.get_cell() # check density rho1 = natom / axes_pos.volume(axes) if not np.isclose(rho, rho1): raise RuntimeError('supercell density is wrong') # save/view crystal fig, ax = volumetric.figax3d() crystal.draw_cell(ax, axes) crystal.draw_atoms(ax, pos) plt.show() return pos
def show_moR(moR): import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D # enable 3D projection from qharv.inspect import volumetric,crystal fig = plt.figure() iplot = 0 for iorb in mo_to_plot: iplot += 1 val = moR[:,iorb].reshape(2*dgs+1) fval= volumetric.spline_volumetric(val) grid= volumetric.axes_func_on_grid3d(axes,fval,grid_shape) myup = default_up mydn = default_dn if iorb in up_dn_map.keys(): myup = up_dn_map[iorb]['up'] mydn = up_dn_map[iorb]['dn'] # end if ax = fig.add_subplot(2,2,iplot,projection='3d') crystal.draw_cell(ax,axes*grid_shape/alat0,pos*grid_shape/alat0,'y') ax.set_title('orb %d' % iorb) if myup >0: meshm = volumetric.isosurf(ax,grid,level_frac=myup) meshm.set_facecolor('#3498db') meshm.set_edgecolor('#34495e') if mydn >0: meshp = volumetric.isosurf(ax,grid,level_frac=mydn) meshp.set_facecolor('#fb9a99') meshp.set_edgecolor('#e11a1c') # end for plt.show()
def make_mhcpc(s1, rb=0.74, iax=2, check=False): # copied from f16b1/prim.py axes = s1.get_cell() pos = s1.get_positions() box = np.diag(axes) # make sure cell is diagonal assert np.allclose(np.diag(box), axes) posl = [] for center in pos: p1 = center.copy() p1[iax] += rb/2. posl.append(p1.copy()) p1[iax] -= rb posl.append(p1) pos1 = np.array(posl) if check: # check pos1 from qharv.inspect import box_pos from qharv.inspect import crystal, volumetric pos1 = box_pos.pos_in_box(pos1, box) fig, ax = volumetric.figax3d() crystal.draw_cell(ax, axes) crystal.draw_atoms(ax, pos, c='k', ms=2) crystal.draw_atoms(ax, pos1) plt.show() s2 = make_atoms(axes, pos1) s2.wrap() return s2
val_arr = df.loc[:, ['x']].values.flatten() k1, v1 = unfold(pos, val_arr) pos = k1 val_arr = v1 vmin, vmax = val_arr.min(), val_arr.max() fig = plt.figure() from mpl_toolkits.mplot3d import Axes3D ax = fig.add_subplot(1, 1, 1, projection="3d") ax.set_xlabel("k1") ax.set_ylabel("k2") ax.set_zlabel("k3") from qharv.inspect import crystal crystal.draw_cell(ax, axes) uValpts = [] cmap = plt.get_cmap('rainbow') for ipos in range(len(pos)): val = val_arr[ipos] if abs(val) < 2e-5: continue uval = (val - vmin) / (vmax - vmin) rgb = cmap(uval) cs = crystal.draw_atoms(ax, np.array([pos[ipos]]), c=rgb) #,ms=5,alpha=0.5) uValpts.append(uval) # end for fig1 = plt.figure() ax1 = fig1.gca()
else: from pyscf.pbc.gto.cell import gen_uniform_grids from pyscf.pbc.dft.numint import eval_ao coords = gen_uniform_grids(cell,gs=dgs) aoR = eval_ao(cell,coords) dm = mf.make_rdm1(mf.mo_coeff, mf.mo_occ) rho = np.dot(aoR, np.diag(dm) ) np.savetxt(rho_fname,rho) # end if import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D # enable 3D projection from qharv.inspect import volumetric,crystal fig = plt.figure() fval= volumetric.spline_volumetric(rho.reshape(2*dgs+1) ) grid= volumetric.axes_func_on_grid3d(axes,fval,grid_shape) ax = fig.add_subplot(1,1,1,projection='3d') crystal.draw_cell(ax,axes*grid_shape/alat0,pos*grid_shape/alat0,'y') meshm = volumetric.isosurf(ax,grid,level_frac=0.3) meshm.set_facecolor('#3498db') meshm.set_edgecolor('#34495e') meshp = volumetric.isosurf(ax,grid,level_frac=0.75) meshp.set_facecolor('#fb9a99') meshp.set_edgecolor('#e11a1c') plt.show() # end __main__