Ejemplo n.º 1
0
    def validate_constructor_arguments(file_path, lattice, sites):

        Path.validate(path=file_path, allow_none=True)

        if file_path == None:
            if lattice == None:
                raise Exception("A lattice must be specified.")
            else:
                Lattice.validate_lattice_representation(lattice)

            if not sites:
                raise Exception(
                    "A sites list or SiteColleciton instance must be specified."
                )
            else:
                SiteCollection.validate_sites(sites)
Ejemplo n.º 2
0
    def from_poscar_file_path(self, file_path):

        Path.validate(path=file_path, allow_none=False)
        Path.expand(file_path)

        poscar = Poscar(file_path)
        self.lattice = Lattice(poscar.lattice)
        self.sites = SiteCollection()

        poscar_coordinate_mode = poscar.coordinate_mode
        poscar_coordinates_list = poscar.coordinates

        species_index = 0
        for i, specie in enumerate(poscar.species_list):
            for j in range(poscar.species_count_list[i]):
                new_site = Site()
                new_site['coordinate_mode'] = poscar_coordinate_mode
                new_site['position'] = poscar_coordinates_list[species_index]
                new_site['type'] = specie

                self.sites.append(new_site)

                species_index += 1