def print_esym_orientation(self, group, axis=None, axis2=None, center=None, output=sys.stdout): """ Prints down an xyz file of the molecule with the orientation_axis :param group: Symmetry group :type group: string :param axis: Main symmetry axis of group :type axis: list :param axis2: Secondary symmetry axis of group :type axis2: list :param center: Center :type center: list :param output: Display hook :type output: hook """ txt = '' for molecule in self._molecules: txt += file_io.get_file_xyz_txt(molecule.geometry) txt = txt.replace(str(molecule.geometry.get_n_atoms()), str(molecule.geometry.get_n_atoms() + 3), 1) axis_info = molecule.get_symmetry_axes(group, axis=axis, axis2=axis2, center=center) txt += 'X1 ' + ' '.join(['{:11.6f}'.format(s) for s in axis_info['axis']]) txt += '\n' txt += 'X1 ' + ' '.join(['{:11.6f}'.format(s) for s in axis_info['axis2']]) txt += '\n' txt += 'X2 ' + ' '.join(['{:11.6f}'.format(s) for s in axis_info['center']]) txt += '\n' output.write(txt)
def print_symmetry_nearest_structure(self, label, central_atom=0, center=None, output=sys.stdout): """ Prints the nearest structure to ideal symmetric structure :param label: Symmetry point group label :type label: str :param central_atom: Position of the central atom :type central_atom: int :param center: Center of symmetry in Cartesian coordinates. If None center is optimized :type center: int :param output: Display hook :type output: hook """ kwargs = _get_symmetry_arguments(locals()) for idm, molecule in enumerate(self._molecules): geometry = molecule.geometry.get_symmetry_nearest_structure(**kwargs) output.write(file_io.get_file_xyz_txt(geometry))
def print_shape_structure(self, shape_reference, central_atom=0, fix_permutation=False, output=sys.stdout): """ Prints the nearest shape structure in format :param shape_reference: List of references and/or geometries :type shape_reference: list :param central_atom: Position of the central atom :type central_atom: int :param fix_permutation: Do not permute atoms during shape calculations :type fix_permutation: bool :param output: Display hook :type output: hook """ shape_results_structures = [] references = [] sym_labels = [] for reference in shape_reference: if isinstance(reference, str): references.append(reference) sym_labels.append(get_sym_from_label(reference)) else: references.append(reference.name) sym_labels.append('') shape_results_structures.append(self.get_shape_measure(reference, 'structure', central_atom, fix_permutation)) geometries = [] for idm, molecule in enumerate(self._molecules): geometries.append(molecule.geometry) for idl, reference in enumerate(references): shape_results_structures[idl][idm].set_name(molecule.name + ' ' + reference + ' ' + sym_labels[idl]) geometries.append(shape_results_structures[idl][idm]) print("\nOriginal structures vs reference polyhedra in file {}\n".format(output.name)) for geometry in geometries: output.write(file_io.get_file_xyz_txt(geometry))
def print_minimum_distortion_path_shape(self, shape_label1, shape_label2, central_atom=0, min_dev=None, max_dev=None, min_gco=None, max_gco=None, num_points=20, output=None): """ Print the minimum distortion path :param shape_label1: First reference shape label :type shape_label1: str :param shape_label2: Second reference shape label :type shape_label2: str :param central_atom: Position of the central atom :type central_atom: int :param min_dev: :type min_dev: float :param max_dev: :type max_dev: float :param min_gco: :type min_gco: float :param max_gco: :type max_gco: float :param num_points: Number of points :type num_points: int :param output1: Display hook :type output1: hook """ if output is not None: output_name, file_extension = os.path.splitext(output.name) output1 = open(output_name + '_pth.csv', 'w') output2 = open(output_name + '_pth.xyz', 'w') output3 = output else: output1 = sys.stdout output2 = sys.stdout output3 = sys.stdout csm, devpath, gen_coord = self.get_path_parameters(shape_label1, shape_label2, central_atom=central_atom) txt_params = '' if min_dev is not None: txt_params = 'Deviation threshold to calculate Path deviation function: ' \ '{:2.1f}% - {:2.1f}%\n'.format(min_dev, max_dev) if min_gco is not None: txt_params += 'Deviation threshold to calculate Generalized Coordinate: ' \ '{:2.1f}% - {:2.1f}%\n'.format(min_gco, max_gco) txt_params += '\n' txt_params += '{:9} '.format('structure'.upper()) for csm_label in list(csm.keys()): txt_params += '{:^8} '.format(csm_label) txt_params += '{:^8} {:^8}'.format('DevPath', 'GenCoord') txt_params += '\n' if min_gco is not None and min_dev is not None: filter_mask = [min_dev <= dv <= max_dev and min_gco <= gc <= max_gco for dv, gc in zip(devpath, gen_coord)] elif min_gco is not None: filter_mask = [min_gco <= gc <= max_gco for gc in gen_coord] elif min_dev is not None: filter_mask = [min_dev <= dv <= max_dev for dv in devpath] else: filter_mask = [True for _ in range(len(self._molecules))] for idx, molecule in enumerate(self._molecules): if not filter_mask[idx]: continue txt_params += '{:9} '.format(molecule.name.strip()) for label in list(csm.keys()): txt_params += '{:^8.3f} '.format(csm[label][idx]) txt_params += '{:^8.1f} {:^8.1f}'.format(devpath[idx], gen_coord[idx]) txt_params += '\n' # self.print_shape_measure() txt_params += 'skipped {} structure/s\n\n'.format(filter_mask.count(False)) output3.write(txt_params) if isinstance(shape_label1, Geometry): label1_name = shape_label1.name else: label1_name = shape_label1 if isinstance(shape_label2, Geometry): label2_name = shape_label2.name else: label2_name = shape_label2 path = get_shape_path(shape_label1, shape_label2, num_points) txt_path = 'Minimum distortion path\n' txt_path += ' {:^6} {:^6}\n'.format(label1_name, label2_name) for idx, value in enumerate(path[0]): txt_path += '{:6.3f} {:6.3f}'.format(path[0][idx], path[1][idx]) txt_path += '\n' txt_path += '\n' output1.write(txt_path) test_structures = [] for ids, structure in enumerate(path[2]): test_structures.append(Geometry(symbols=['' for _ in range(len(structure))], positions=structure, name='map_structure{}'.format(ids))) output2.write(file_io.get_file_xyz_txt(test_structures)) if output1 is sys.stdout: plt.plot(path[0], path[1], 'k', linewidth=2.0) plt.scatter(np.array(csm[label1_name])[filter_mask], np.array(csm[label2_name])[filter_mask], linewidths=0.01) plt.xlabel(label1_name) plt.ylabel(label2_name) plt.show()
def get_nm_vibration_path(geometry, normal_mode, points=10, backward=False, k=1.5): nm_np_matrix = np.array(normal_mode) geom_np = np.array(geometry) if backward: x = np.linspace(-k, k, points) else: x = np.linspace(k/points, k, points) structures_path = [] for dx in x: structures_path.append(geom_np + dx*nm_np_matrix) return structures_path molecule = read_generic_structure_file('sf6.fchk') freq, nm_martices = read_normal_modes_gaussian('../old_examples/sf6_freq.out') k_points = 1.5 points = 10 n_freq = 1 path = get_nm_vibration_path(molecule.geometry.get_positions(), nm_martices[n_freq - 1], k=k_points) x = np.linspace(k_points/points, k_points, points) output = open('sf6_freq{}.xyz'.format(n_freq), 'w') for ids, structure in enumerate(path): xi = '{:.2f}'.format(x[ids]).replace('.', '') txt = get_file_xyz_txt(Geometry(structure, symbols=molecule.geometry.get_symbols(), name='freq : ' + str(freq[0]) + ' ' + str(xi))) output.write(txt)