def generate_cell_angle_gamma_frame(atoms, molecule1_atoms_index, space_group, sigma=0.1): st = ase_atoms_to_structure(atoms) old_positions = st.getXYZ() old_xyz = old_positions[0] molecule1_vectors = np.array( [old_positions[i] for i in molecule1_atoms_index]) a, b, c, alpha, beta, gamma = atoms.get_cell_lengths_and_angles() new_cell_params = [a, b, c, alpha, beta, gamma + random_draw(sigma)] atoms.set_cell(new_cell_params, scale_atoms=True) new_cell_params = atoms.get_cell() new_xyz = atoms.get_positions()[0] new_a_vector, new_b_vector, new_c_vector = new_cell_params[ 0], new_cell_params[1], new_cell_params[2] new_molecule1_vectors = get_xyz_after_move(old_xyz, new_xyz, molecule1_vectors) sites = [] for pos in new_molecule1_vectors: for rot, trans in space_group.get_symop(): trans_a, trans_b, trans_c = trans[:] site = np.dot( rot, pos ) + trans_a * new_a_vector + trans_b * new_b_vector + trans_c * new_c_vector sites.append(site) new_positions = np.array(sites) atoms.set_positions(new_positions)
def generate_translate_frame(atoms, molecule1_atoms_index, space_group, sigma=0.1): st = ase_atoms_to_structure(atoms) my_atoms = atoms.copy() my_atoms.set_positions(st.getXYZ()) current_XYZ = st.getXYZ() molecule1_XYZ = [current_XYZ[i] for i in molecule1_atoms_index] translation = [random_draw(sigma), random_draw(sigma), random_draw(sigma)] molecule1_XYZ_after_translation = [] for row in molecule1_XYZ: new_row = row + translation molecule1_XYZ_after_translation.append(new_row) sites = [] cell_params = my_atoms.get_cell() for pos in molecule1_XYZ_after_translation: for rot, trans in space_group.get_symop(): trans_a, trans_b, trans_c = trans[:] site = np.dot(rot, pos) + trans_a * cell_params[ 0] + trans_b * cell_params[1] + trans_c * cell_params[2] sites.append(site) new_positions = np.array(sites) ret_atoms = Atoms(get_name(atoms.get_atomic_numbers()), positions=new_positions, cell=my_atoms.get_cell(), pbc=[1, 1, 1]) return ret_atoms
def generate_cell_length_c_frame(atoms, molecule1_atoms_index, space_group, sigma=0.1): name = get_name(atoms.get_atomic_numbers()) st = ase_atoms_to_structure(atoms) my_atoms = atoms.copy() my_atoms.set_positions(st.getXYZ()) molecules = molecule_lists(my_atoms) old_positions = my_atoms.get_positions() molecule1_vectors = np.array([old_positions[i] for i in molecules[0]]) # set the perturbation new_atoms = my_atoms.copy() a, b, c, alpha, beta, gamma = my_atoms.get_cell_lengths_and_angles() if a != b and b != c and c != a: new_a, new_b, new_c = a, b, c + random_draw(sigma) elif a != b and b == c: new_a, new_c = a, c + random_draw(sigma) new_b = new_c elif a != b and a == c: new_c, new_b = c + random_draw(sigma), b new_a = new_c elif a == b and a != c: new_b, new_c = b, c + random_draw(sigma) new_a = new_b else: new_c = c + random_draw(sigma) new_a = new_c new_b = new_c # scaled_atoms = True new_atoms.set_cell([new_a, new_b, new_c, alpha, beta, gamma], scale_atoms=True) new_cell_params = new_atoms.get_cell() new_a_vector, new_b_vector, new_c_vector = new_cell_params[ 0], new_cell_params[1], new_cell_params[2] new_molecule1_vectors = get_xyz_after_move(my_atoms.get_positions()[0], new_atoms.get_positions()[0], molecule1_vectors) sites = [] for pos in new_molecule1_vectors: for rot, trans in space_group.get_symop(): trans_a, trans_b, trans_c = trans[:] site = np.dot( rot, pos ) + trans_a * new_a_vector + trans_b * new_b_vector + trans_c * new_c_vector sites.append(site) new_positions = np.array(sites) ret_atoms = Atoms(name, positions=new_positions, cell=new_atoms.get_cell(), pbc=[1, 1, 1]) return ret_atoms
def generate_rotation_frame(atoms, molecule1_atoms_index, space_group, mu=0.1, sigma=0.1): st = ase_atoms_to_structure(atoms) my_atoms = atoms.copy() my_atoms.set_positions(st.getXYZ()) current_XYZ = st.getXYZ() molecule1_XYZ = [current_XYZ[i] for i in molecule1_atoms_index] delta_theta_x = random_draw(mu, sigma) delta_theta_y = random_draw(mu, sigma) delta_theta_z = random_draw(mu, sigma) pi = math.pi theta_x = delta_theta_x / 180 * pi theta_y = delta_theta_y / 180 * pi theta_z = delta_theta_z / 180 * pi cos_theta_x, sin_theta_x = math.cos(theta_x), math.sin(theta_x) cos_theta_y, sin_theta_y = math.cos(theta_y), math.sin(theta_y) cos_theta_z, sin_theta_z = math.cos(theta_z), math.sin(theta_z) rotation_x = [[1, 0, 0], [0, cos_theta_x, -sin_theta_x], [0, sin_theta_x, cos_theta_x]] rotation_y = [[cos_theta_y, 0, sin_theta_y], [0, 1, 0], [-sin_theta_y, 0, cos_theta_y]] rotation_z = [[cos_theta_z, -sin_theta_z, 0], [sin_theta_z, cos_theta_z, 0], [0, 0, 1]] molecule1_XYZ_after_rotate = np.matmul(np.array(molecule1_XYZ), np.array(rotation_x)) cell_params = my_atoms.get_cell() all_new_molecules = [] for rot, trans in space_group.get_symop(): trans_a, trans_b, trans_c = trans[:] translation = trans_a * cell_params[0] + trans_b * cell_params[ 1] + trans_c * cell_params[2] translation_span = [translation for i in molecule1_atoms_index] new_molecule = np.matmul(molecule1_XYZ_after_rotate, rot) + translation_span all_new_molecules.append(new_molecule) new_XYZ_to_set = [] molecule1, molecule2, molecule3, moleclue4 = all_new_molecules[:] for row1, row2, row3, row4 in zip(molecule1, molecule2, molecule3, moleclue4): new_XYZ_to_set.append(row1) new_XYZ_to_set.append(row2) new_XYZ_to_set.append(row3) new_XYZ_to_set.append(row4) writer = Atoms(get_name(atoms.get_atomic_numbers()), positions=np.array(new_XYZ_to_set), cell=atoms.get_cell(), pbc=[1, 1, 1]) return writer
def move_molecule1(atoms, space_group): print("atoms.get_distance(1,5): ", atoms.get_distance(1, 5, mic=False, vector=True)) print("atoms.get_distance(1,21): ", atoms.get_distance(1, 21, mic=False, vector=True)) a, b, c, alpha, beta, gamma = atoms.get_cell_lengths_and_angles() X = atoms.get_positions() old_scaled_position = atoms.get_scaled_positions() print("a, b, c, alpha, beta, gamma: ", a, b, c, alpha, beta, gamma) #print("X: ", X) #print("old_scaled_position: ", old_scaled_position) molecule1 = molecule_lists(atoms)[0] st = ase_atoms_to_structure(atoms) x_com1 = center_of_mass(st, molecule1) X_molecule1 = np.array([X[x - 1] for x in molecule1]) #print("X_molecule1: ", X_molecule1) F = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]]) delta_a, delta_b, delta_c = random_draw(0.1, 0.1), random_draw( 0.1, 0.1), random_draw(0.1, 0.1) new_F = F + np.array([[delta_a, 0, 0], [0, delta_b, 0], [0, 0, delta_c]]) x_com1_new = np.dot(x_com1, new_F) diff_com = x_com1_new - x_com1 #print("diff_com: ", diff_com) new_X = [] for i, row in enumerate(X): if i + 1 in molecule1: new_X.append(row + diff_com) else: new_X.append(row) L = atoms.get_cell() new_L = np.dot(L, new_F) new_atoms = atoms.copy() new_atoms.set_positions(new_X) new_atoms.set_cell(new_L, scale_atoms=False) scaled_positions = new_atoms.get_scaled_positions() molecule1_scaled_positions = [scaled_positions[i - 1] for i in molecule1] final_scaled_positions = get_equivalent_sites(molecule1_scaled_positions, space_group) #print("final_scaled_positions: ", final_scaled_positions) new_atoms.set_scaled_positions(final_scaled_positions) print("new_atoms.get_distance(1,5): ", new_atoms.get_distance(1, 5, mic=False, vector=True)) print("new_atoms.get_distance(1,21): ", new_atoms.get_distance(1, 21, mic=False, vector=True)) return new_atoms
def get_com(atoms, molecule_lists): """ return a (n_molecules, 3) for center of mass """ ret_arr = [] st = ase_atoms_to_structure(atoms) for molecule_list in molecule_lists: com = center_of_mass(st, molecule_list) ret_arr.append(com) return np.array(ret_arr)
def generate_cell_angle_frame(atoms, molecule1_atoms_index, space_group, mu=0.1, sigma=0.1): # get names and molecule idx name = get_name(atoms.get_atomic_numbers()) st = ase_atoms_to_structure(atoms) my_atoms = atoms.copy() my_atoms.set_positions(st.getXYZ()) molecules = molecule_lists(my_atoms) old_positions = my_atoms.get_positions() molecule1_vectors = np.array([old_positions[i] for i in molecules[0]]) # set the perturbation new_atoms = my_atoms.copy() a, b, c, alpha, beta, gamma = my_atoms.get_cell_lengths_and_angles() new_cell_params = [a, b, c] for angle in [alpha, beta, gamma]: if angle != 90: new_cell_params.append(angle + random_draw(mu, sigma)) else: new_cell_params.append(angle) new_atoms.set_cell(new_cell_params, scale_atoms=True) new_cell_params = new_atoms.get_cell() new_a_vector, new_b_vector, new_c_vector = new_cell_params[ 0], new_cell_params[1], new_cell_params[2] new_molecule1_vectors = get_xyz_after_move(my_atoms.get_positions()[0], new_atoms.get_positions()[0], molecule1_vectors) sites = [] for pos in new_molecule1_vectors: for rot, trans in space_group.get_symop(): trans_a, trans_b, trans_c = trans[:] site = np.dot( rot, pos ) + trans_a * new_a_vector + trans_b * new_b_vector + trans_c * new_c_vector sites.append(site) new_positions = np.array(sites) ret_atoms = Atoms(name, positions=new_positions, cell=new_atoms.get_cell(), pbc=[1, 1, 1]) return ret_atoms
def change_cell_length(atoms, space_group): name = get_name(atoms.get_atomic_numbers()) #molecule1, molecule2, molecule3, molecule4 = molecule_lists(atoms)[0], molecule_lists(atoms)[1], molecule_lists(atoms)[2], molecule_lists(atoms)[3] # [1,5,9,13,17,21,etc] st = ase_atoms_to_structure(atoms) #print("myxyz: ", st.getXYZ()) my_atoms = atoms.copy() my_atoms.set_positions(st.getXYZ()) molecules = [] for molecule in st.molecule: mole_list = [] for atom in molecule.atom: mole_list.append(atom.index - 1) molecules.append(mole_list) old_positions = my_atoms.get_positions() #get xyz coordinate for original molecules molecule1_vectors = np.array([old_positions[i] for i in molecules[0]]) cell_params = my_atoms.get_cell() new_atoms = my_atoms.copy() new_atoms.set_cell(cell_params + np.array([[3.0, 0, 0], [0, 3.0, 0], [0.0, 0, 3.0]]), scale_atoms=True) new_cell_params = new_atoms.get_cell() new_a_vector, new_b_vector, new_c_vector = new_cell_params[ 0], new_cell_params[1], new_cell_params[2] new_molecule1_vectors = get_xyz_after_move(my_atoms.get_positions()[0], new_atoms.get_positions()[0], molecule1_vectors) sites = [] for pos in new_molecule1_vectors: for rot, trans in space_group.get_symop(): trans_a, trans_b, trans_c = trans[:] site = np.dot( rot, pos ) + trans_a * new_a_vector + trans_b * new_b_vector + trans_c * new_c_vector sites.append(site) new_positions = np.array(sites) writer = Atoms(name, positions=new_positions, cell=new_atoms.get_cell(), pbc=[1, 1, 1]) return writer
def calculate(self, atoms=None, properties=['energy'], system_changes=ase.calculators.calculator.all_changes, compute_hessian=False): """ calculate properties """ super(Calculator, self).calculate(atoms, properties, system_changes) st = ase_atoms_to_structure(atoms) mm.mmlewis_apply(st) mm.mmffld_enterMol(self.mmffld_handle, st.handle) mm.mmffld_deleteMol(self.mmffld_handle, st.handle) (ret_force_array, ret_energy_array) = mm.mmffld_getEnergyForce( self.mmffld_handle) self.results['energy'] = ret_energy_array if 'force' in properties: self.results['force'] = ret_force_array