def metric(point): # Update molecular configuration based on given configuration molecule.set_positions(convert_vector_to_atoms(point)) # Evaluate the value of sqrt(2(E-V)), replacing E-V with 1E-9 if V > E. cf = math.sqrt(max([2*(energy - molecule.get_potential_energy()), 1E-9])) # Return sqrt(2(E-V)) and it's gradient return [cf, molecule.get_forces().flatten()/cf]
def integrand(t, x_1, x_2): x = np.add(np.subtract(x_2, x_1) * t, x_1) curve.configuration['molecule'].set_positions( convert_vector_to_atoms(x)) metric_cf = 1 / math.sqrt( 2 * (curve.energy - curve.configuration['molecule'].get_potential_energy())) return metric_cf * math.sqrt( np.inner(np.subtract(x_2, x_1), mass_matrix.dot(np.subtract(x_2, x_1))))
def write_xyz_animation(curve_pickle, filename): """ This function takes a curve object that has been pickled and writes out an XYZ animation file to use with JMol. Args: curve_pickle (str): The location of a pickled curve object. filename (str): The location of where to write the XYZ animation. """ # Unpickle the curve object curve = pickle.load(open(curve_pickle, "rb")) # Extract the trajectories points trajectory = curve.get_points() # Reparameterise to determine physical times times = get_times(curve) # Index to determine correct time i = 0 # Extract the curves molecular configuration as described by an ASE atoms object molecule = curve.configuration['molecule'] # Create a new file for the animation to be stored animation_file = open(filename, 'w') # For each node along the curve... for state in trajectory: # Determine the molecular configuration in ASE molecule.set_positions(convert_vector_to_atoms(state)) # Produce a snapshot XYZ file of the configuration at that point in time write('current_state.xyz', molecule, format='xyz') # Increase index i += 1 # Open the newly produced XYZ file current_state = open('current_state.xyz', 'r') # Append the snapshot XYZ file into the animation file for line in current_state: animation_file.write(line) current_state.close() # Once finished close the file so that other programs can access it animation_file.close() # Delete the temporary file used to store current snapshots os.remove('current_state.xyz')
def metric(point): # Update molecular configuration based on given configuration molecule.set_positions(convert_vector_to_atoms(point[:-9])) # Compute -grad(V) minus_grad_V = molecule.get_forces().flatten() # Extract cell information from the point cell = np.reshape(convert_vector_to_atoms(point[-9:]), (3, 3)) # Compute the cell volume scaled by pressure cell_volume = pressure * abs(np.linalg.det(cell)) # Compute gradient of the volume grad_cell_volume = -cell_volume * np.linalg.inv(cell).transpose().flatten() # Update the molecule's cell molecule.set_cell(cell) # Evaluate the value of sqrt(2(E-V)), replacing E-V with 1E-9 if V > E. cf = math.sqrt(max([2*(energy - molecule.get_potential_energy() - cell_volume), 1E-9])) return [cf, np.hstack((minus_grad_V, grad_cell_volume))/cf]
def metric(point, Q_I_matrix, x_k): # Update molecular configuration based on given configuration molecule.set_positions(convert_vector_to_atoms(point)) # Evaluate the value of sqrt(2(E-V)), replacing E-V with 1E-9 if V > E. x_k = np.asarray(x_k) Q_I_matrix = np.asarray(Q_I_matrix) # print Q_I_matrix b = Q_I_matrix.dot(x_k) # print b c = np.absolute(np.inner(x_k, b)) # print c cf = math.sqrt(max([c, 1E-9])) # Return sqrt(2(E-V)) and it's gradient return [cf, molecule.get_forces().flatten() / cf]
def metric(point, Q_I_matrix, x_k): # Update molecular configuration based on given configuration molecule.set_positions(convert_vector_to_atoms(point)) # Evaluate the value of sqrt(2(E-V)), replacing E-V with 1E-9 if V > E. x_k = np.asarray(x_k) Q_I_matrix = np.asarray(Q_I_matrix) # print Q_I_matrix b = Q_I_matrix.dot(x_k) # print b c = np.absolute(np.inner(x_k, b)) # print c cf = math.sqrt(max([c, 1E-9])) # Return sqrt(2(E-V)) and it's gradient return [cf, molecule.get_forces().flatten()/cf]
def integrand(t, x_1, x_2): x = np.add(np.subtract(x_2, x_1)*t, x_1) curve.configuration['molecule'].set_positions(convert_vector_to_atoms(x)) metric_cf = 1/math.sqrt(2*(curve.energy - curve.configuration['molecule'].get_potential_energy())) return metric_cf * math.sqrt(np.inner(np.subtract(x_2, x_1), mass_matrix.dot(np.subtract(x_2, x_1))))