def MU(einsumString, Z, factors): Zhat = hat(self._A, self._H, self._C) return ( einsum( einsumString, self.data * (Zhat ** (self.beta - 2)), *factors) / einsum( einsumString, Zhat ** (self.beta - 1), *factors ) )
def hat(A, H, C, eps=None): """Builds common fate model tensor from factors makes use of numpys einstein summation Parameters ---------- A : tuple The shape H : tuple The shape C : tuple The shape Returns ------- np.ndarray, shape=(P.shape + H.shape + C.shape) tensor with same shape as common fate transform """ if eps is None: eps = np.finfo(float).eps return eps + einsum('abfj,tj,cj->abftc', A, H, C)
def find_x_bonds(initial_atoms, final_atoms, simulation_params): slip_system = simulation_params[0] motif = slip_system['motif'] if motif.ndim == 1: motif_length = 1 else: motif_length = len(motif) size = simulation_params[2] initial_positions = initial_atoms[:,:3] final_positions = final_atoms[:,:3] x_bonds = np.zeros_like(initial_positions, dtype=myfloat) b = slip_system['latt_params'][0] rolled_initial = np.roll(initial_positions, -motif_length, axis=0) rolled_final = np.roll(final_positions, -motif_length, axis=0) mask = ((rolled_initial - initial_positions) - np.array([b, 0, 0])) mask = einsum('ni,ni->n', mask, mask) mask = mask < 1e-16 # number of bonds expected to be left hanging # at the positive x extreme: if slip_system['motif'].shape == (4,): motif_length = 1 else: motif_length = len(slip_system['motif']) if size[2] == 0: no_of_missing_bonds = 2 * size[1] * motif_length else: no_of_missing_bonds = (2 * size[1] * 2 * size[2] * motif_length) if np.count_nonzero(mask) == (len(mask) - no_of_missing_bonds): x_bonds[mask] = rolled_final[mask] - final_positions[mask] else: # A slow backup if we don't find any # bonds assume we've messed up, # should work for an arbitrary ordered array for i in range(initial_atoms.shape[0]): rolled_initial = np.roll(initial_positions, -(i+1), axis=0) rolled_final = np.roll(final_positions, -(i+1), axis=0) mask = ((rolled_initial - initial_positions) - np.array([b, 0, 0])) mask = einsum('ni,ni->n', mask, mask) mask = mask < 1e-16 x_bonds[mask] = (rolled_final[mask] - final_positions[mask]) return x_bonds
def hat(P, At, Ac, eps=None): if eps is None: eps = np.finfo(float).eps return eps + einsum('abfj,tj,cj->abftc', P, At, Ac)