def setup_voronoi_list(self, indices, voronoi_cutoff): """ Set up of the voronoi list of neighbours by calling qhull :param indices: indices of the sites for which the Voronoi is needed :param voronoi_cutoff: Voronoi cutoff for the search of neighbours :raise RuntimeError: If an infinite vertex is found in the voronoi construction """ self.voronoi_list2 = [None] * len(self.structure) logging.info('Getting all neighbors in structure') struct_neighbors = self.structure.get_all_neighbors(voronoi_cutoff, include_index=True) t1 = time.clock() logging.info('Setting up Voronoi list :') for jj, isite in enumerate(indices): logging.info( ' - Voronoi analysis for site #{:d} ({:d}/{:d})'.format( isite, jj + 1, len(indices))) site = self.structure[isite] neighbors1 = [(site, 0.0, isite)] neighbors1.extend(struct_neighbors[isite]) distances = [i[1] for i in sorted(neighbors1, key=lambda s: s[1])] neighbors = [i[0] for i in sorted(neighbors1, key=lambda s: s[1])] qvoronoi_input = [s.coords for s in neighbors] voro = Voronoi(points=qvoronoi_input, qhull_options="o Fv") all_vertices = voro.vertices results2 = [] maxangle = 0.0 mindist = 10000.0 for iridge, ridge_points in enumerate(voro.ridge_points): if 0 in ridge_points: ridge_vertices_indices = voro.ridge_vertices[iridge] if -1 in ridge_vertices_indices: raise RuntimeError("This structure is pathological," " infinite vertex in the voronoi " "construction") ridge_point2 = max(ridge_points) facets = [all_vertices[i] for i in ridge_vertices_indices] sa = my_solid_angle(site.coords, facets) maxangle = max([sa, maxangle]) mindist = min([mindist, distances[ridge_point2]]) for iii, sss in enumerate(self.structure): if neighbors[ridge_point2].is_periodic_image(sss): myindex = iii break results2.append({ 'site': neighbors[ridge_point2], 'angle': sa, 'distance': distances[ridge_point2], 'index': myindex }) for dd in results2: dd['normalized_angle'] = dd['angle'] / maxangle dd['normalized_distance'] = dd['distance'] / mindist self.voronoi_list2[isite] = results2 t2 = time.clock() logging.info('Voronoi list set up in {:.2f} seconds'.format(t2 - t1))
def setup_voronoi_list(self, indices, voronoi_cutoff): """ Set up of the voronoi list of neighbours by calling qhull :param indices: indices of the sites for which the Voronoi is needed :param voronoi_cutoff: Voronoi cutoff for the search of neighbours :raise RuntimeError: If an infinite vertex is found in the voronoi construction """ self.voronoi_list2 = [None] * len(self.structure) logging.info('Getting all neighbors in structure') struct_neighbors = self.structure.get_all_neighbors(voronoi_cutoff, include_index=True) t1 = time.clock() logging.info('Setting up Voronoi list :') for jj, isite in enumerate(indices): logging.info(' - Voronoi analysis for site #{:d} ({:d}/{:d})'.format(isite, jj+1, len(indices))) site = self.structure[isite] neighbors1 = [(site, 0.0, isite)] neighbors1.extend(struct_neighbors[isite]) distances = [i[1] for i in sorted(neighbors1, key=lambda s: s[1])] neighbors = [i[0] for i in sorted(neighbors1, key=lambda s: s[1])] qvoronoi_input = [s.coords for s in neighbors] voro = Voronoi(points=qvoronoi_input, qhull_options="o Fv") all_vertices = voro.vertices results2 = [] maxangle = 0.0 mindist = 10000.0 for iridge, ridge_points in enumerate(voro.ridge_points): if 0 in ridge_points: ridge_vertices_indices = voro.ridge_vertices[iridge] if -1 in ridge_vertices_indices: raise RuntimeError("This structure is pathological," " infinite vertex in the voronoi " "construction") ridge_point2 = max(ridge_points) facets = [all_vertices[i] for i in ridge_vertices_indices] try: sa = solid_angle(site.coords, facets) except ValueError: sa = my_solid_angle(site.coords, facets) maxangle = max([sa, maxangle]) mindist = min([mindist, distances[ridge_point2]]) for iii, sss in enumerate(self.structure): if neighbors[ridge_point2].is_periodic_image(sss): myindex = iii break results2.append({'site': neighbors[ridge_point2], 'angle': sa, 'distance': distances[ridge_point2], 'index': myindex}) for dd in results2: dd['normalized_angle'] = dd['angle'] / maxangle dd['normalized_distance'] = dd['distance'] / mindist self.voronoi_list2[isite] = results2 t2 = time.clock() logging.info('Voronoi list set up in {:.2f} seconds'.format(t2-t1))
def setup_voronoi_list(self, indices, voronoi_cutoff): """ Set up of the voronoi list of neighbours by calling qhull. Args: indices: indices of the sites for which the Voronoi is needed. voronoi_cutoff: Voronoi cutoff for the search of neighbours. Raises: RuntimeError: If an infinite vertex is found in the voronoi construction. """ self.voronoi_list2 = [None] * len(self.structure) self.voronoi_list_coords = [None] * len(self.structure) logging.debug("Getting all neighbors in structure") struct_neighbors = self.structure.get_all_neighbors(voronoi_cutoff, include_index=True) t1 = time.process_time() logging.debug("Setting up Voronoi list :") for jj, isite in enumerate(indices): logging.debug( " - Voronoi analysis for site #{:d} ({:d}/{:d})".format( isite, jj + 1, len(indices))) site = self.structure[isite] neighbors1 = [(site, 0.0, isite)] neighbors1.extend(struct_neighbors[isite]) distances = [i[1] for i in sorted(neighbors1, key=lambda s: s[1])] neighbors = [i[0] for i in sorted(neighbors1, key=lambda s: s[1])] qvoronoi_input = [s.coords for s in neighbors] voro = Voronoi(points=qvoronoi_input, qhull_options="o Fv") all_vertices = voro.vertices results2 = [] maxangle = 0.0 mindist = 10000.0 for iridge, ridge_points in enumerate(voro.ridge_points): if 0 in ridge_points: ridge_vertices_indices = voro.ridge_vertices[iridge] if -1 in ridge_vertices_indices: raise RuntimeError("This structure is pathological," " infinite vertex in the voronoi " "construction") ridge_point2 = max(ridge_points) facets = [all_vertices[i] for i in ridge_vertices_indices] sa = my_solid_angle(site.coords, facets) maxangle = max([sa, maxangle]) mindist = min([mindist, distances[ridge_point2]]) for iii, sss in enumerate(self.structure): if neighbors[ridge_point2].is_periodic_image( sss, tolerance=1.0e-6): myindex = iii break results2.append({ "site": neighbors[ridge_point2], "angle": sa, "distance": distances[ridge_point2], "index": myindex, }) for dd in results2: dd["normalized_angle"] = dd["angle"] / maxangle dd["normalized_distance"] = dd["distance"] / mindist self.voronoi_list2[isite] = results2 self.voronoi_list_coords[isite] = np.array( [dd["site"].coords for dd in results2]) t2 = time.process_time() logging.debug("Voronoi list set up in {:.2f} seconds".format(t2 - t1))