def _calc_g_zs_uniform(self, g_z, g_zs): if self.cex: self.cex._calc_g_zs_uniform(g_z, g_zs, LAMBDA_0, LAMBDA_1, *self.shape) else: segments = g_zs.shape[1] pg_zs = g_zs[:, 0] for r in range(1, segments): g_zs[:, r] = pg_zs = correlate(pg_zs, LAMBDA_ARRAY, 1) * g_z
def _calc_g_zs_uniform(self, g_z, g_zs): if self.cex: self.cex._calc_g_zs_uniform(g_z, g_zs, LAMBDA_0, LAMBDA_1, *self.shape) else: segments = g_zs.shape[1] pg_zs = g_zs[:, 0] for r in range(1, segments): g_zs[:, r] = pg_zs = correlate(pg_zs, LAMBDA_ARRAY, 1) * g_z
def _calc_g_zs(self, g_z, c_i, g_zs): if self.cex: self.cex._calc_g_zs(g_z, c_i, g_zs, LAMBDA_0, LAMBDA_1, *self.shape) else: pg_zs = g_zs[:, 0] segment_iterator = enumerate(c_i[::-1]) next(segment_iterator) for r, c in segment_iterator: g_zs[:, r] = pg_zs = (correlate(pg_zs, LAMBDA_ARRAY, 1) + c) * g_z
def _calc_g_zs(self, g_z, c_i, g_zs): if self.cex: self.cex._calc_g_zs(g_z, c_i, g_zs, LAMBDA_0, LAMBDA_1, *self.shape) else: pg_zs = g_zs[:, 0] segment_iterator = enumerate(c_i[::-1]) next(segment_iterator) for r, c in segment_iterator: g_zs[:, r] = pg_zs = (correlate(pg_zs, LAMBDA_ARRAY, 1) + c) * g_z
def SCFeqns(phi_z, chi, chi_s, sigma, n_avg, p_i, phi_b=0): """ System of SCF equation for terminally attached polymers. Formatted for input to a nonlinear minimizer or solver. The sign convention here on u is "backwards" and always has been. It saves a few sign flips, and looks more like Cosgrove's. """ # let the solver go negative if it wants phi_z = abs(phi_z) # penalize attempts that overfill the lattice toomuch = phi_z > .99999 penalty_flag = toomuch.any() if penalty_flag: penalty = np.where(toomuch, phi_z - .99999, 0) phi_z[toomuch] = .99999 # calculate new g_z (Boltzmann weighting factors) u_prime = log((1.0 - phi_z) / (1.0 - phi_b)) u_int = 2 * chi * (correlate(phi_z, LAMBDA_ARRAY, 1) - phi_b) u_int[0] += chi_s u_z = u_prime + u_int g_z = exp(u_z) # normalize g_z for numerical stability u_z_avg = np.mean(u_z) g_z_norm = g_z / exp(u_z_avg) phi_z_new = calc_phi_z(g_z_norm, n_avg, sigma, phi_b, u_z_avg, p_i) eps_z = phi_z - phi_z_new if penalty_flag: np.copysign(penalty, eps_z, penalty) eps_z += penalty return eps_z
def SCFeqns(phi_z, chi, chi_s, sigma, n_avg, p_i, phi_b=0): """ System of SCF equation for terminally attached polymers. Formatted for input to a nonlinear minimizer or solver. The sign convention here on u is "backwards" and always has been. It saves a few sign flips, and looks more like Cosgrove's. """ # let the solver go negative if it wants phi_z = abs(phi_z) # penalize attempts that overfill the lattice toomuch = phi_z > .99999 penalty_flag = toomuch.any() if penalty_flag: penalty = np.where(toomuch, phi_z - .99999, 0) phi_z[toomuch] = .99999 # calculate new g_z (Boltzmann weighting factors) u_prime = log((1.0 - phi_z) / (1.0 - phi_b)) u_int = 2 * chi * (correlate(phi_z, LAMBDA_ARRAY, 1) - phi_b) u_int[0] += chi_s u_z = u_prime + u_int g_z = exp(u_z) # normalize g_z for numerical stability u_z_avg = np.mean(u_z) g_z_norm = g_z / exp(u_z_avg) phi_z_new = calc_phi_z(g_z_norm, n_avg, sigma, phi_b, u_z_avg, p_i) eps_z = phi_z - phi_z_new if penalty_flag: np.copysign(penalty, eps_z, penalty) eps_z += penalty return eps_z
def _autocorrelation(means): from numpy.core import multiarray result = multiarray.correlate(means, means, mode=2) return result[round(result.size / 2):]
def _calc_g_zs_uniform(g_z, g_zs): segments = g_zs.shape[1] pg_zs = g_zs[:, 0] for r in range(1, segments): g_zs[:, r] = pg_zs = correlate(pg_zs, LAMBDA_ARRAY, 1) * g_z
def _calc_g_zs(g_z, c_i, g_zs): pg_zs = g_zs[:, 0] segment_iterator = enumerate(c_i[::-1]) next(segment_iterator) for r, c in segment_iterator: g_zs[:, r] = pg_zs = (correlate(pg_zs, LAMBDA_ARRAY, 1) + c) * g_z