예제 #1
0
    def from_file(cls, filepath):
        """
        Return a new Structure instance from a NetCDF file 

        Args:
            filename:
                netcdf file with crystallographic data in the ETSF-IO format.
                or any other file format supported by `pymatgen.io.smartio`.
        """
        if filepath.endswith(".nc"):
            file, closeit = as_etsfreader(filepath)

            new = file.read_structure()
            # Change the class of new.
            new.__class__ = cls

            new.set_spacegroup(SpaceGroup.from_file(file))

            if closeit:
                file.close()
        else:
            # TODO: Spacegroup is missing here.
            #from pymatgen.io.smartio import read_structure
            #new = read_structure(filepath)
            new = super(Structure, cls).from_file(filepath)
            # Change the class of new.
            new.__class__ = cls

        return new
예제 #2
0
    def from_file(cls, filepath, primitive=True, sort=False):
        """
        Reads a structure from a file. For example, anything ending in
        a "cif" is assumed to be a Crystallographic Information Format file.
        Supported formats include CIF, POSCAR/CONTCAR, CHGCAR, LOCPOT,
        vasprun.xml, CSSR, Netcdf and pymatgen's JSON serialized structures.

        Args:
            filename (str): The filename to read from.
            primitive (bool): Whether to convert to a primitive cell
                Only available for cifs, POSCAR, CSSR, JSON, YAML
                Defaults to True.
            sort (bool): Whether to sort sites. Default to False.

        Returns:
            :class:`Structure` object
        """
        if filepath.endswith(".nc"):
            from pymatgen.io.abinitio.netcdf import as_etsfreader
            file, closeit = as_etsfreader(filepath)

            new = file.read_structure(cls=cls)
            new.set_spacegroup(SpaceGroup.from_file(file))
            if closeit: file.close()

        else:
            # TODO: Spacegroup is missing here.
            new = super(Structure, cls).from_file(filepath, primitive=primitive, sort=sort)
            # Change the class of new.
            if new.__class__ != cls: new.__class__ = cls

        return new
예제 #3
0
    def __init__(self, filepath):
        super(DdbFile, self).__init__(filepath)

        self._header = self._parse_header()

        self._structure = Structure.from_abivars(**self.header)
        # Add Spacegroup (needed in guessed_ngkpt)
        # FIXME: has_timerev is always True
        spgid, has_timerev, h = 0, True, self.header
        self._structure.set_spacegroup(SpaceGroup(spgid, h.symrel, h.tnons, h.symafm, has_timerev))

        frac_coords = self._read_qpoints()
        self._qpoints = KpointList(self.structure.reciprocal_lattice, frac_coords, weights=None, names=None)

        # Guess q-mesh
        self._guessed_ngqpt = self._guess_ngqpt()
예제 #4
0
    def from_file(cls, filepath, primitive=True, sort=False):
        """
        Reads a structure from a file. For example, anything ending in
        a "cif" is assumed to be a Crystallographic Information Format file.
        Supported formats include CIF, POSCAR/CONTCAR, CHGCAR, LOCPOT,
        vasprun.xml, CSSR, Netcdf and pymatgen's JSON serialized structures.

        Netcdf files supported:
            All files produced by ABINIT with info of the crystalline geometry 
            HIST_FILEs, in this case the last structure of the history is returned.

        Args:
            filename (str): The filename to read from.
            primitive (bool): Whether to convert to a primitive cell
                Only available for cifs, POSCAR, CSSR, JSON, YAML
                Defaults to True.
            sort (bool): Whether to sort sites. Default to False.

        Returns:
            :class:`Structure` object
        """
        if filepath.endswith(".nc"):
            from pymatgen.io.abinitio.netcdf import as_etsfreader
            file, closeit = as_etsfreader(filepath)

            new = file.read_structure(cls=cls)
            new.set_spacegroup(SpaceGroup.from_file(file))
            if closeit: file.close()

        elif filepath.endswith("_HIST") or filepath.endswith("_HIST.nc"):
            # Abinit history file. In this case we return the last structure!
            from abipy.dynamics.hist import HistFile
            with HistFile(filepath) as hist:
                return hist.structures[-1]

        else:
            # TODO: Spacegroup is missing here.
            new = super(Structure, cls).from_file(filepath,
                                                  primitive=primitive,
                                                  sort=sort)
            # Change the class of new.
            if new.__class__ != cls: new.__class__ = cls

        return new
예제 #5
0
    def from_file(cls, filepath, primitive=True, sort=False):
        """
        Reads a structure from a file. For example, anything ending in
        a "cif" is assumed to be a Crystallographic Information Format file.
        Supported formats include CIF, POSCAR/CONTCAR, CHGCAR, LOCPOT,
        vasprun.xml, CSSR, Netcdf and pymatgen's JSON serialized structures.

        Netcdf files supported:
            All files produced by ABINIT with info of the crystalline geometry 
            HIST_FILEs, in this case the last structure of the history is returned.

        Args:
            filename (str): The filename to read from.
            primitive (bool): Whether to convert to a primitive cell
                Only available for cifs, POSCAR, CSSR, JSON, YAML
                Defaults to True.
            sort (bool): Whether to sort sites. Default to False.

        Returns:
            :class:`Structure` object
        """
        if filepath.endswith("_HIST") or filepath.endswith("_HIST.nc"):
            # Abinit history file. In this case we return the last structure!
            # Note that HIST does not follow the etsf-io conventions.
            from abipy.dynamics.hist import HistFile
            with HistFile(filepath) as hist:
                return hist.structures[-1]

        elif filepath.endswith(".nc"):
            from pymatgen.io.abinit.netcdf import as_etsfreader
            file, closeit = as_etsfreader(filepath)
                                                                  
            new = file.read_structure(cls=cls)
            new.set_spacegroup(SpaceGroup.from_file(file))
            if closeit: file.close()

        else:
            # TODO: Spacegroup is missing here.
            new = super(Structure, cls).from_file(filepath, primitive=primitive, sort=sort)
            # Change the class of new.
            if new.__class__ != cls: new.__class__ = cls

        return new