# quaternion to be used for disturbing the orientation of each body quaternion_shift = Quaternion(np.array([1,0,0,0])) # for each step in the Markov chain, disturb each body's location and orientation and obtain the new list of r_vectors # of each blob. Calculate the potential of the new state, and accept or reject it according to the Markov chain rules: # 1. if Ej < Ei, always accept the state 2. if Ej < Ei, accept the state according to the probability determined by # exp(-(Ej-Ei)/kT). Then record data. # Important: record data also when staying in the same state (i.e. when a sample state is rejected) for step in range(read.initial_step, read.n_steps): blob_index = 0 for i, body in enumerate(bodies): # distrub bodies body.location_new = body.location + np.random.uniform(-max_translation, max_translation, 3) # make small change to location quaternion_shift = Quaternion.from_rotation(np.random.normal(0,1,3) * max_angle_shift) body.orientation_new = quaternion_shift * body.orientation sample_r_vectors[blob_index : blob_index + bodies[i].Nblobs] = body.get_r_vectors(body.location_new, body.orientation_new) blob_index += body.Nblobs # calculate potential of proposed new state sample_state_energy = many_body_potential_pycuda.compute_total_energy(bodies, sample_r_vectors, periodic_length = periodic_length, debye_length_wall = read.debye_length_wall, repulsion_strength_wall = read.repulsion_strength_wall, debye_length = read.debye_length, repulsion_strength = read.repulsion_strength, weight = weight, blob_radius = blob_radius) # accept or reject the sample state and collect data accordingly if np.random.uniform(0.0, 1.0) < np.exp(-(sample_state_energy - current_state_energy) / kT):
# for each step in the Markov chain, disturb each body's location and orientation and obtain the new list of r_vectors # of each blob. Calculate the potential of the new state, and accept or reject it according to the Markov chain rules: # 1. if Ej < Ei, always accept the state 2. if Ej < Ei, accept the state according to the probability determined by # exp(-(Ej-Ei)/kT). Then record data. # Important: record data also when staying in the same state (i.e. when a sample state is rejected) for step in range(read.initial_step, read.n_steps): blob_index = 0 for i, body in enumerate(bodies): # distrub bodies body.location_new = body.location + np.random.uniform( -max_translation, max_translation, 3) # make small change to location quaternion_shift = Quaternion.from_rotation( np.random.normal(0, 1, 3) * max_angle_shift) body.orientation_new = quaternion_shift * body.orientation sample_r_vectors[blob_index:blob_index + bodies[i].Nblobs] = body.get_r_vectors( body.location_new, body.orientation_new) blob_index += body.Nblobs # calculate potential of proposed new state sample_state_energy = many_body_potential_pycuda.compute_total_energy( bodies, sample_r_vectors, periodic_length=periodic_length, debye_length_wall=read.debye_length_wall, repulsion_strength_wall=read.repulsion_strength_wall, debye_length=read.debye_length, repulsion_strength=read.repulsion_strength, weight=weight, blob_radius=blob_radius) # accept or reject the sample state and collect data accordingly
def slip_extensile_rod(body): ''' Creates slip for a extensile rod. The slip is along the axis pointing to the closest end. We assume the blobs are equispaced. In this version the slip is constant. ''' # Slip speed speed = -20.0 # Identify blobs at the extremities depending on the resolution if body.Nblobs == 14: Nblobs_covering_ends = 0 Nlobs_perimeter = 0 elif body.Nblobs == 86: Nblobs_covering_ends = 1 Nlobs_perimeter = 6 elif body.Nblobs == 324: Nblobs_covering_ends = 6 Nlobs_perimeter = 12 slip = np.empty((body.Nblobs, 3)) # Get rod orientation r_vectors = body.get_r_vectors() # Compute end-to-end vector if body.Nblobs > 14: axis = r_vectors[body.Nblobs - 2 * Nblobs_covering_ends - 2] - r_vectors[Nlobs_perimeter - 2] else: axis = r_vectors[body.Nblobs - 1] - r_vectors[0] length_rod = np.linalg.norm(axis) + 2.0 * body.blob_radius # axis = orientation vector axis = axis / np.sqrt(np.dot(axis, axis)) # Choose the portion of the surface covered with a tangential slip length_covered = 0.8 lower_bound = length_rod / 2.0 - length_covered upper_bound = length_rod / 2.0 # Create slip slip_blob = [] for i in range(body.Nblobs): # Blobs at the extremities are passive if (Nblobs_covering_ends > 0) and (i >= body.Nblobs - 2 * Nblobs_covering_ends): slip_blob = [0., 0., 0.] else: dist_COM_along_axis = np.dot(r_vectors[i] - body.location, axis) if (dist_COM_along_axis > lower_bound) and (dist_COM_along_axis <= upper_bound): slip_blob = -speed * axis elif (dist_COM_along_axis < -lower_bound) and (dist_COM_along_axis >= -upper_bound): slip_blob = speed * axis else: slip_blob = [0., 0., 0.] slip[i] = slip_blob return slip