How to use the pymatgen.core.structure.Structure.from_sites function in pymatgen

To help you get started, we’ve selected a few pymatgen examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github materialsproject / pymatgen / pymatgen / analysis / dimensionality.py View on Github external
# 3rd column is unitary norm)
                index = 2 if dimensionality == 2 else 0
                orientation = get_integer_index(vh[index, :])
            else:
                orientation = None

            component['orientation'] = orientation

        if inc_site_ids:
            component['site_ids'] = tuple(graph.nodes())

        if inc_molecule_graph and dimensionality == 0:
            component['molecule_graph'] = zero_d_graph_to_molecule_graph(
                bonded_structure, graph)

        component_structure = Structure.from_sites(
            [bonded_structure.structure[n] for n in sorted(graph.nodes())])

        sorted_graph = nx.convert_node_labels_to_integers(
            graph, ordering="sorted")
        component_graph = StructureGraph(
            component_structure,
            graph_data=json_graph.adjacency_data(sorted_graph))
        component['structure_graph'] = component_graph

        components.append(component)
    return components
github uw-cmg / MAST / libraries / pymatgen / pymatgen / symmetry / finder.py View on Github external
gamma = math.pi * struct.lattice.lengths_and_angles[1][2] / 180
            new_matrix = [[a, 0, 0],
                          [b * cos(gamma), b * sin(gamma), 0.0],
                          [c * cos(beta),
                           c * (cos(alpha) - cos(beta) * cos(gamma)) /
                           sin(gamma),
                           c * math.sqrt(sin(gamma) ** 2 - cos(alpha) ** 2
                                         - cos(beta) ** 2
                                         + 2 * cos(alpha) * cos(beta)
                                         * cos(gamma)) / sin(gamma)]]
            new_sites = []
            for s in struct._sites:
                new_sites.append(
                    PeriodicSite(s.specie, s.frac_coords, Lattice(new_matrix),
                                 to_unit_cell=False, properties=s.properties))
            results = Structure.from_sites(new_sites)

        return results.get_sorted_structure()
github materialsproject / pymatgen / pymatgen / core / surface.py View on Github external
def get_sorted_structure(self, key=None, reverse=False):
        """
        Get a sorted copy of the structure. The parameters have the same
        meaning as in list.sort. By default, sites are sorted by the
        electronegativity of the species. Note that Slab has to override this
        because of the different __init__ args.

        Args:
            key: Specifies a function of one argument that is used to extract
                a comparison key from each list element: key=str.lower. The
                default value is None (compare the elements directly).
            reverse (bool): If set to True, then the list elements are sorted
                as if each comparison were reversed.
        """
        sites = sorted(self, key=key, reverse=reverse)
        s = Structure.from_sites(sites)
        return Slab(s.lattice, s.species_and_occu, s.frac_coords,
                    self.miller_index, self.oriented_unit_cell, self.shift,
                    self.scale_factor, site_properties=s.site_properties,
                    reorient_lattice=self.reorient_lattice)
github materialsproject / pymatgen / pymatgen / analysis / defects / point_defects.py View on Github external
def get_structure_with_nodes(self):
        """
        Get the modified structure with the voronoi nodes inserted. The
        species is set as a DummySpecie X.
        """
        new_s = Structure.from_sites(self.structure)
        for v in self.vnodes:
            new_s.append("X", v.frac_coords)
        return new_s
github hackingmaterials / robocrystallographer / robocrys / condense / component.py View on Github external
mol_components, components = filter_molecular_components(components)

        if mol_components:
            lattice = mol_components[0]['structure_graph'].structure.lattice

            mol_sites = [
                PeriodicSite(c['structure_graph'].structure[0].specie,
                             c['molecule_graph'].molecule.center_of_mass,
                             lattice, coords_are_cartesian=True)
                for c in mol_components]

    if components:
        other_sites = [site for c in components
                       for site in c['structure_graph'].structure]

    return Structure.from_sites(other_sites + mol_sites)
github uw-cmg / MAST / libraries / pymatgen / pymatgen / command_line / enumlib_caller.py View on Github external
simplify matters, we generate the input file only with disordered sites
        and exclude the ordered sites from the enumeration. The fact that
        different disordered sites with the exact same species may belong to
        different equivalent sites is dealt with by having determined the
        spacegroup earlier and labelling the species differently.
        """

        # index_species and index_amounts store mappings between the indices
        # used in the enum input file, and the actual species and amounts.
        index_species = []
        index_amounts = []

        #Let"s group and sort the sites by symmetry.
        site_symmetries = []
        for sites in symmetrized_structure.equivalent_sites:
            finder = SymmetryFinder(Structure.from_sites(sites),
                                    self.symm_prec)
            sgnum = finder.get_spacegroup_number()
            site_symmetries.append((sites, sgnum))

        site_symmetries = sorted(site_symmetries, key=lambda s: s[1])

        #Stores the ordered sites, which are not enumerated.
        min_sg_num = site_symmetries[0][1]
        ordered_sites = []
        disordered_sites = []
        coord_str = []
        min_disordered_sg = 300
        for (sites, sgnum) in site_symmetries:
            if sites[0].is_ordered:
                ordered_sites.append(sites)
            else:
github uw-cmg / MAST / libraries / pymatgen / pymatgen / command_line / enumlib_caller.py View on Github external
transformation = [[int(round(cell)) for cell in row]
                                      for row in transformation]
                    logger.debug("Supercell matrix: {}".format(transformation))
                    maker = SupercellMaker(ordered_structure, transformation)
                    sites.extend([site.to_unit_cell
                                  for site in maker.modified_structure])
                    super_latt = sites[-1].lattice
                else:
                    super_latt = new_latt

                for site in sub_structure:
                    if site.specie.symbol != "X":  # We exclude vacancies.
                        sites.append(PeriodicSite(site.species_and_occu,
                                                  site.frac_coords,
                                                  super_latt).to_unit_cell)
                structs.append(Structure.from_sites(sorted(sites)))

        logger.debug("Read in a total of {} structures.".format(num_structs))
        return structs
github materialsproject / pymatgen / pymatgen / transformations / standard_transformations.py View on Github external
if not site.species.almost_equals(sp):
                    continue
                if self.symmetrized_structures:
                    sym_equiv = structure.find_equivalent_sites(ex)
                    sym_test = site in sym_equiv
                else:
                    sym_test = True
                if sym_test:
                    equivalent_sites[j].append(i)
                    break
            else:
                equivalent_sites.append([i])
                exemplars.append(site)

        # generate the list of manipulations and input structure
        s = Structure.from_sites(structure)

        m_list = []
        for g in equivalent_sites:
            total_occupancy = sum([structure[i].species for i in g],
                                  Composition())
            total_occupancy = dict(total_occupancy.items())
            # round total occupancy to possible values
            for k, v in total_occupancy.items():
                if abs(v - round(v)) > 0.25:
                    raise ValueError("Occupancy fractions not consistent "
                                     "with size of unit cell")
                total_occupancy[k] = int(round(v))
            # start with an ordered structure
            initial_sp = max(total_occupancy.keys(),
                             key=lambda x: abs(x.oxi_state))
            for i in g:
github uw-cmg / MAST / pymatgen / vis / structure_vtk.py View on Github external
def set_structure(self, structure, reset_camera=True):
        """
        Add a structure to the visualizer.

        Args:
            structure:
                structure to visualize
            reset_camera:
                Set to True to reset the camera to a default determined based
                on the structure.
        """
        self.ren.RemoveAllViewProps()
        m = SupercellMaker(structure, self.supercell)
        s = m.modified_structure
        all_sites = [site.to_unit_cell for site in s]
        s = Structure.from_sites(all_sites)

        inc_coords = []
        for site in s:
            self.add_site(site)
            inc_coords.append(site.coords)

        count = 0
        labels = ["a", "b", "c"]
        colors = [(1, 0, 0), (0, 1, 0), (0, 0, 1)]
        matrix = s.lattice.matrix

        if self.show_unit_cell:
            self.add_text([0, 0, 0], "o")
            for vec in matrix:
                self.add_line((0, 0, 0), vec, colors[count])
                self.add_text(vec, labels[count], colors[count])
github materialsproject / pymatgen / pymatgen / core / organized_surface.py View on Github external
b = slab_scale
        term_slab = structure.copy()
        term_slab.make_supercell(b)
        term_slab = organize(term_slab)[0]

        new_sites = []

        # Get the sites of the surface atoms
        term_slab = organize(term_slab)[0]

        for site in term_slab:
            if shift_list[i] <= np.dot(site.coords, normal) < length +\
                    shift_list[i]:
                new_sites.append(site)

        term_slab = Structure.from_sites(new_sites)
        if lll_reduce:
            lll_slab = term_slab.copy(sanitize=True)
            mapping = lll_slab.lattice.find_mapping(term_slab.lattice)
            slab_scale_factor = np.dot(mapping[2], b)
            term_slab = lll_slab
        else:
            slab_scale_factor = b

        slab = Slab(term_slab.lattice, term_slab.species, normal, slab_scale_factor,
                    term_slab.sites, term_slab, miller_index)


        min_c = []
        index = []
        for ii in range(0, len(slab)):
            min_c.append(slab[ii].frac_coords[2])