grid_pot, electrons = md.density_2_grid(vasp_pot,NGX,NGY,NGZ) ## Get the gradiens (Field), if required. ## Comment out if not required, due to compuational expense. print("Calculating gradients (Electic field, E=-Grad.V )...") grad_x,grad_y,grad_z = np.gradient(grid_pot[:,:,:],resolution_x,resolution_y,resolution_z) #------------------------------------------------------------------ ##------------------------------------------------------------------ ## Get the equation for the plane ## This is the section for plotting on a user defined plane; ## uncomment commands if this is the option that you want. ##------------------------------------------------------------------ ## Convert the fractional points to grid points on the density surface a = md.numbers_2_grid(a_point,NGX,NGY,NGZ) b = md.numbers_2_grid(b_point,NGX,NGY,NGZ) c = md.numbers_2_grid(c_point,NGX,NGY,NGZ) plane_coeff = md.points_2_plane(a,b,c) ## Calculate magnitude of gradient. # Should be able to use numpy.linalg.norm for this, but the Python array indices are causing me grief X2 = np.multiply(grad_x,grad_x) Y2 = np.multiply(grad_y,grad_y) Z2 = np.multiply(grad_z,grad_z) grad_mag = np.sqrt(np.add(X2,Y2,Z2)) # This was my, non working, attempt to use the built in function. #grad_mag=np.linalg.norm( [grad_y,grad_y,grad_z], axis=3)
resolution_z = vector_c / NGZ grid_pot, electrons = md.density_2_grid(vasp_pot, NGX, NGY, NGZ) ## Get the gradiens (Field), if required. ## Comment out if not required, due to compuational expense. grad_x, grad_y, grad_z = np.gradient(grid_pot[:, :, :], resolution_x, resolution_y, resolution_z) #------------------------------------------------------------------ ##------------------------------------------------------------------ ## Get the equation for the plane ## This is the section for plotting on a user defined plane; ## uncomment commands if this is the option that you want. ##------------------------------------------------------------------ ## Convert the fractional points to grid points on the density surface a = md.numbers_2_grid(a_point, NGX, NGY, NGZ) b = md.numbers_2_grid(b_point, NGX, NGY, NGZ) c = md.numbers_2_grid(c_point, NGX, NGY, NGZ) plane_coeff = md.points_2_plane(a, b, c) ## Get the gradients XY = np.multiply(grad_x, grad_y) grad_mag = np.multiply(XY, grad_z) ## Create the plane xx, yy, grd = md.create_plotting_mesh(NGX, NGY, NGZ, plane_coeff, grad_x) ## Plot the surface plt.contour(xx, yy, grd, 1) plt.show() ##------------------------------------------------------------------ ##------------------------------------------------------------------
def test_numbers_2_grid(self): '''Tests the numbers_2_grid function''' a = md.numbers_2_grid([0.5, 0.5, 0.5], 10, 10, 10) b = [5, 5, 5] self.assertSequenceEqual(a.tolist(), b)