def calc_e_up(self, phi=0., omega=0., chi=0.): """ phi, omega, chi = angles of detector in radians. They are zeros by defaults. """ orientation_ij = (self.u_11, self.u_12, self.u_13, self.u_21, self.u_22, self.u_23, self.u_31, self.u_32, self.u_33) phi_ij = (numpy.cos(phi), numpy.sin(phi), 0.*phi, -numpy.sin(phi), numpy.cos(phi), 0.*phi, 0.*phi, 0.*phi, 0.*phi+1.) omega_ij = (numpy.cos(omega), numpy.sin(omega), 0.*omega, -numpy.sin(omega), numpy.cos(omega), 0.*omega, 0.*omega, 0.*omega, 0.*omega+1.) chi_ij = (numpy.cos(chi), 0.*chi, numpy.sin(chi), 0.*chi, 0.*chi+1., 0.*chi, -numpy.sin(chi), 0.*chi, numpy.cos(chi)) u_11, u_12, u_13, u_21, u_22, u_23, u_31, u_32, u_33 = \ calc_product_matrices(omega_ij, chi_ij, phi_ij, orientation_ij) ut_ij = (u_11, u_21, u_31, u_12, u_22, u_32, u_13, u_23, u_33) e_up_1, e_up_2, e_up_3 = calc_product_matrix_vector( ut_ij, (0., 0., 1.)) return e_up_1, e_up_2, e_up_3
def calc_moment_2d_by_susceptibility(r_ij, susc_i, m_norm_ij, h_loc): """Recalculate chi_i given according to symmetry elements for each point. chi_i is given in reciprocal unit cell. After susceptibility is multiplied in magnetic field defined r_ij:= r_11, r_12, r_13, r_21, r_22, r_23, r_31, r_32, r_33 susc_i:= chi_11, chi_22, chi_33, chi_12, chi_13, chi_23 Matrix m_norm used to recalculate coordinates from direct space (a1/|a1|, a2/|a2|, a3/|a3|) to Cartesian one (x||a*, z||c). x_cart = m_norm * x_direct m_norm = [[(1 - cos**2 alpha1 - cos**2 alpha2 - cos**2 alpha3 + \ 2 cos alpha1 cos alpha2 cos alpha3)**0.5/sin(alpha1), 0, 0], [(cos alpha3 - cos alpha1 cos alpha2) / sin alpha1, sin alpha1, 0], [cos alpha2, cos alpha1, 1]] Matrix m_norm should be given as m_norm_ij = (_11, _12, _13, _21, _22, _23, _31, _32, _33) Output ------ moment_2d: [points, symmetry] """ n_a = numpy.newaxis r_11, r_12, r_13, r_21, r_22, r_23, r_31, r_32, r_33 = r_ij chi_11, chi_22, chi_33, chi_12, chi_13, chi_23 = susc_i # [ind, symm] chi_2d_ij = calc_mRmCmRT( (r_11[n_a, :], r_12[n_a, :], r_13[n_a, :], r_21[n_a, :], r_22[n_a, :], r_23[n_a, :], r_31[n_a, :], r_32[n_a, :], r_33[n_a, :]), (chi_11[:, n_a], chi_12[:, n_a], chi_13[:, n_a], chi_12[:, n_a], chi_22[:, n_a], chi_23[:, n_a], chi_13[:, n_a], chi_23[:, n_a], chi_33[:, n_a])) chi_orto_ij = ortogonalize_matrix(chi_2d_ij, m_norm_ij) moment_2d = calc_product_matrix_vector(chi_orto_ij, h_loc) return moment_2d
def calc_phase_3d(hkl, r_ij, b_i, fract_xyz): """ Calculation of phases over 3 dimensions (hkl, points, symmetry): fract_xyz.shape = (pointxs, 3) r_ij, b_i are elements of symmetry phase = exp(2\pi i (h*Rs*x + h*bs)) phase_3d: [hkl, points, symmetry] """ h, k, l = hkl[0], hkl[1], hkl[2] x, y, z = fract_xyz[:, 0], fract_xyz[:, 1], fract_xyz[:, 2] r_11, r_12, r_13, r_21, r_22, r_23, r_31, r_32, r_33 = r_ij b_1, b_2, b_3 = b_i # [ind, symm] mr_2d_1, mr_2d_2, mr_2d_3 = calc_product_matrix_vector( (r_11[numpy.newaxis, :], r_12[numpy.newaxis, :], r_13[numpy.newaxis, :], r_21[numpy.newaxis, :], r_22[numpy.newaxis, :], r_23[numpy.newaxis, :], r_31[numpy.newaxis, :], r_32[numpy.newaxis, :], r_33[numpy.newaxis, :]), (x[:, numpy.newaxis], y[:, numpy.newaxis], z[:, numpy.newaxis])) # [hkl, ind, symm] hrr_3d = scalar_product( (h[:, numpy.newaxis, numpy.newaxis], k[:, numpy.newaxis, numpy.newaxis], l[:, numpy.newaxis, numpy.newaxis]), (mr_2d_1[numpy.newaxis, :, :], mr_2d_2[numpy.newaxis, :, :], mr_2d_3[numpy.newaxis, :, :])) # [hkl, symm] hb_2d = scalar_product( (h[:, numpy.newaxis], k[:, numpy.newaxis], l[:, numpy.newaxis]), (b_1[numpy.newaxis, :], b_2[numpy.newaxis, :], b_3[numpy.newaxis, :])) phase_3d = numpy.exp(2. * numpy.pi * 1j * (hrr_3d + hb_2d[:, numpy.newaxis, :])) return phase_3d
def calc_moments(fract_x, fract_y, fract_z, field_loc, density_point: DensityPointL, crystal: Crystal, mem_parameters: MEMParameters): """Calculate magnetic moments in points fract_x, fract_y, fract_z.""" points_a = mem_parameters.points_a points_b = mem_parameters.points_b points_c = mem_parameters.points_c cell = crystal.cell atom_site = crystal.atom_site np_ind_xyz = numpy.transpose( numpy.array( [fract_x * points_a, fract_y * points_b, fract_z * points_c], dtype=float)) # np_ind_xyz = (fract_x*points_a, fract_y*points_b, fract_z*points_c) chi_3d_11, chi_3d_22, chi_3d_33, chi_3d_12, chi_3d_13, chi_3d_23, \ chi_3d_iso = calc_densities_3d_for_mem( density_point, crystal, mem_parameters=mem_parameters) c_11 = tri_linear_interpolation(np_ind_xyz, chi_3d_11) c_22 = tri_linear_interpolation(np_ind_xyz, chi_3d_22) c_33 = tri_linear_interpolation(np_ind_xyz, chi_3d_33) c_12 = tri_linear_interpolation(np_ind_xyz, chi_3d_12) c_13 = tri_linear_interpolation(np_ind_xyz, chi_3d_13) c_23 = tri_linear_interpolation(np_ind_xyz, chi_3d_23) c_iso = tri_linear_interpolation(np_ind_xyz, chi_3d_iso) c_orto = cell.ortogonalize_matrix( (c_11, c_12, c_13, c_12, c_22, c_23, c_13, c_23, c_33)) m_x, m_y, m_z = calc_product_matrix_vector(c_orto, field_loc) m_b_x, m_b_y, m_b_z = c_iso*field_loc[0], c_iso*field_loc[1], \ c_iso*field_loc[2] moment_x, moment_y, moment_z = m_x + m_b_x, m_y + m_b_y, m_z + m_b_z return moment_x, moment_y, moment_z
def calc_asymmetric_unit_cell_indexes(n_x: int, n_y: int, n_z: int, r_ij, b_i)\ -> NoReturn: """ Calculate indexes of asymmetric unit cell. Input parameters: - symmetry elements; - points number. Multiplication of points number on corresponding symmetry element should give integer number. """ r_11, r_12, r_13, r_21, r_22, r_23, r_31, r_32, r_33 = r_ij b_1, b_2, b_3 = b_i ind_x = numpy.array(range(n_x), dtype=int) ind_y = numpy.array(range(n_y), dtype=int) ind_z = numpy.array(range(n_z), dtype=int) ind_2d_x, ind_2d_y, ind_2d_z = numpy.meshgrid(ind_x, ind_y, ind_z, indexing="ij") ind_x, ind_y = ind_2d_x.flatten(), ind_2d_y.flatten() ind_z = ind_2d_z.flatten() r_ij_2d = (r_11[numpy.newaxis, :], r_12[numpy.newaxis, :], r_13[numpy.newaxis, :], r_21[numpy.newaxis, :], r_22[numpy.newaxis, :], r_23[numpy.newaxis, :], r_31[numpy.newaxis, :], r_32[numpy.newaxis, :], r_33[numpy.newaxis, :]) nb_i_2d = (numpy.around(n_x * b_1, 0).astype(int)[numpy.newaxis, :], numpy.around(n_y * b_2, 0).astype(int)[numpy.newaxis, :], numpy.around(n_z * b_3, 0).astype(int)[numpy.newaxis, :]) ind_xyz = (ind_x[:, numpy.newaxis], ind_y[:, numpy.newaxis], ind_z[:, numpy.newaxis]) ind_2d_a, ind_2d_b, ind_2d_c = calc_product_matrix_vector(r_ij_2d, ind_xyz) ind_2d_a += nb_i_2d[0] ind_2d_b += nb_i_2d[1] ind_2d_c += nb_i_2d[2] ind_2d_a = numpy.mod(ind_2d_a.astype(int), n_x) ind_2d_b = numpy.mod(ind_2d_b.astype(int), n_y) ind_2d_c = numpy.mod(ind_2d_c.astype(int), n_z) ind_2d_abc = n_z * n_y * ind_2d_a + n_z * ind_2d_b + ind_2d_c ind_2d_abc_sorted = numpy.sort(ind_2d_abc, axis=1) a, ind_a_u_c, counts_a_u_c = numpy.unique(ind_2d_abc_sorted[:, 0], return_index=True, return_counts=True) ind_x_a_u_c = ind_x[ind_a_u_c] ind_y_a_u_c = ind_y[ind_a_u_c] ind_z_a_u_c = ind_z[ind_a_u_c] return ind_x_a_u_c, ind_y_a_u_c, ind_z_a_u_c, counts_a_u_c