예제 #1
0
def make_eos_flow(structure_file=None):
    """
    Build and return a Flow to compute the equation of state 
    of an isotropic material for different k-point samplings.
    """
    scale_volumes = np.arange(94, 108, 2) / 100.

    if structure_file is None:
        structure = abilab.Structure.from_file(abidata.cif_file("si.cif"))
    else:
        structure = abilab.Structure.from_file(structure_file)

    multi = abilab.MultiDataset(structure=structure,
                                pseudos=get_pseudos(structure),
                                ndtset=len(scale_volumes))

    # Global variables
    multi.set_vars(ecut=16, tolvrs=1e-16)

    multi.set_kmesh(ngkpt=[4, 4, 4],
                    shiftk=[[0.5, 0.5, 0.5], [0.5, 0.0, 0.0], [0.0, 0.5, 0.0],
                            [0.0, 0.0, 0.5]])

    for idt, scal_vol in enumerate(scale_volumes):
        new_lattice = structure.lattice.scale(structure.volume * scal_vol)

        new_structure = Structure(new_lattice, structure.species,
                                  structure.frac_coords)

        multi[idt].set_structure(new_structure)

    eos_flow = abilab.Flow.from_inputs("flow_si_relax",
                                       inputs=multi.split_datasets())
    eos_flow.volumes = structure.volume * scale_volumes
    return eos_flow
예제 #2
0
def make_relax_si_flow():
    # Structural relaxation for different k-point samplings.
    scale_volumes = np.arange(94, 108, 2) / 100.

    inp = abilab.AbiInput(pseudos=abidata.pseudos("14si.pspnc"), ndtset=len(scale_volumes))

    structure = Structure.from_file(abidata.cif_file("si.cif"))

    # Global variables
    inp.set_variables(
        ecut=16,
        tolvrs=1e-16
    )

    inp.set_kmesh(ngkpt=[4, 4, 4], shiftk=[[0.5, 0.5, 0.5], [0.5, 0.0, 0.0], [0.0, 0.5, 0.0], [0.0, 0.0, 0.5]])

    for idt, scal_vol in enumerate(scale_volumes):
        new_lattice = structure.lattice.scale(structure.volume*scal_vol)

        new_structure = Structure(new_lattice, structure.species, structure.frac_coords)

        inp[idt+1].set_structure(new_structure)

    si_flow = RelaxSiFlow.from_inputs("flow_si_relax", inputs=inp.split_datasets(), task_class=abilab.RelaxTask)
    si_flow.volumes = structure.volume*scale_volumes
    return si_flow
예제 #3
0
 def test_structure_from_ncfiles(self):
     """Init Structure objects from Netcdf data files"""
     ncfiles = ALL_NCFILES
     assert ncfiles
     for filename in ncfiles:
         print("Reading file %s" % filename)
         structure = Structure.from_file(filename)
         print(structure)
예제 #4
0
파일: input.py 프로젝트: yanikou19/abipy
    def structure(self):
        """Returns the `Structure` associated to this dataset."""
        try:
            return self._structure

        except AttributeError:
            structure = Structure.from_abivars(self.allvars)

            self.set_structure(structure)
            return self._structure
예제 #5
0
    def test_silicon(self):
        """Test silicon space group."""
        structure = Structure.from_file(get_ncfile("si_nscf_WFK-etsf.nc"))

        spgrp = structure.spacegroup
        print(spgrp)

        self.assertTrue(spgrp.spgid == 227)
        self.assertTrue(spgrp.has_timerev)
        self.assertTrue(len(spgrp) == 48 * 2)
        self.assertTrue(spgrp.num_spatial_symmetries == 48)

        self.assertTrue(spgrp.is_group())
        # TODO
        #si_symrel = 
        si_tnons = np.reshape(24 * [0, 0, 0, 0.25, 0.25, 0.25], (48, 3))
        si_symafm = np.ones(48, dtype=np.int)

        self.assert_almost_equal(si_tnons, spgrp.tnons)
        self.assert_almost_equal(si_symafm, spgrp.symafm)

        for (idx, symmop) in enumerate(spgrp):
            self.assertTrue(symmop in spgrp)
            self.assertTrue(spgrp.count(symmop) == 1)
            self.assertTrue(spgrp.find(symmop) == idx)
            self.assertTrue(abs(symmop.det) == 1)

        for idx in range(len(spgrp)-1):
            self.assertTrue(spgrp[idx] == spgrp[idx])
            self.assertTrue(spgrp[idx] != spgrp[idx+1])

        for fmop in spgrp.fm_symmops:
            self.assertTrue(fmop.is_fm)

        ucell_coords = np.reshape([site.frac_coords for site in structure], (len(structure), 3))

        for site in structure:
            for symop in spgrp:
                rot_coords = symop.rotate_r(site.frac_coords, in_ucell=True)

                found = False
                for atom_coords in ucell_coords:
                    #print (atom_coords - rot_coords)
                    if np.allclose(atom_coords,  rot_coords):
                        found = True
                        break

                self.assertTrue(found)
예제 #6
0
    def visualize(self, *args, **kwargs):
        # TODO Here I have to decide if this method should be defined
        # in a subclass of Launcher e.g GSLauncher or in the base class
        from .utils import find_file
        what_visualize = kwargs.get("what_visualize", "crystal")

        visualizer = abipy_env.get_uservar("visualizer", kwargs)

        # Find the correct output file
        out_files = self.odat_files()
        gsfname = find_file(out_files, "GSR")

        if gsfname is None:
            raise RuntimeError("Cannot find GSR file among " % out_files)

        if what_visualize == "crystal":

            structure = Structure.from_file(gsfname)
            structure.visualize(visualizer)()

        elif what_visualize == "density":
            raise NotImplementedError("den_fname?")

            density = Density.from_file(den_fname)
            density.visualize(visualizer)()

        elif what_visualize in [
                "electrons",
                "fermisurface",
        ]:
            from ..electrons import ElectronBands
            energies = ElectronBands.from_file(gsfname)

            if what_visualize == "electrons": energies.plot()
            if what_visualize == "fermisurface":
                raise RuntimeError("No hanlder found for fermisurface")
                #visu = energies.visualize(self, visualizer, structure)
                #visu()
        else:
            raise RuntimeError("No handler found for %s" % what_visualize)
예제 #7
0
파일: wfkfile.py 프로젝트: sponce24/abipy
    def __init__(self, filepath):
        """
        Initialized the object from a Netcdf file.
        """
        super(WFK_File, self).__init__(filepath)

        # Initialize the  structure from file.
        self.structure = Structure.from_file(filepath)

        # Initialize the band energies.
        self.bands = ElectronBands.from_file(filepath)

        self.kpoints = kpoints_factory(filepath)
        self.nkpt = len(self.kpoints)

        with WFK_Reader(filepath) as reader:
            assert reader.has_pwbasis_set
            assert reader.cplex_ug == 2
            self.npwarr = reader.npwarr
            self.nband_sk = reader.nband_sk

            self.nspinor = reader.nspinor
            self.nsppol = reader.nsppol
            self.nspden = reader.nspden

        # FFT mesh (augmented divisions reported in the WFK file)
        self.fft_mesh = Mesh3D(reader.fft_divs, self.structure.lattice_vectors())

        # Build G-spheres for each k-point
        gspheres = len(self.kpoints) * [None]
        ecut = reader.ecut
        for k, kpoint in enumerate(self.kpoints):
            gvec_k, istwfk = reader.read_gvec_istwfk(k)
            gspheres[k] = GSphere(ecut, self.structure.reciprocal_lattice, kpoint, gvec_k, istwfk=istwfk)

        self._gspheres = tuple(gspheres)

        # Save reference to the reader.
        self.reader = reader
예제 #8
0
파일: launcher.py 프로젝트: sponce24/abipy
    def visualize(self, *args, **kwargs):
        # TODO Here I have to decide if this method should be defined
        # in a subclass of Launcher e.g GSLauncher or in the base class
        from .utils import find_file
        what_visualize = kwargs.get("what_visualize", "crystal")

        visualizer = abipy_env.get_uservar("visualizer", kwargs)

        # Find the correct output file
        out_files = self.odat_files() 
        gsfname = find_file(out_files, "GSR")
                                                                          
        if gsfname is None:
            raise RuntimeError("Cannot find GSR file among " % out_files)



        if what_visualize == "crystal":

            structure = Structure.from_file(gsfname)
            structure.visualize(visualizer)()

        elif what_visualize == "density":
            raise NotImplementedError("den_fname?")

            density = Density.from_file(den_fname)
            density.visualize(visualizer)()

        elif what_visualize in ["electrons", "fermisurface",]:
            from ..electrons import ElectronBands
            energies = ElectronBands.from_file(gsfname)

            if what_visualize == "electrons": energies.plot()
            if what_visualize == "fermisurface":
                raise RuntimeError("No hanlder found for fermisurface")
                #visu = energies.visualize(self, visualizer, structure)
                #visu()
        else:
            raise RuntimeError("No handler found for %s" % what_visualize)
예제 #9
0
    def test_silicon(self):
        """Test silicon space group."""
        structure = Structure.from_file(abidata.ref_file("si_scf_WFK.nc"))

        self.assertTrue(structure.has_spacegroup)
        self.assertTrue(structure.is_symmorphic)

        print(structure)
        print("composition:", structure.composition)
        self.serialize_with_pickle(structure, test_eq=True)

        spgrp = structure.spacegroup
        print("spgrp:\n", spgrp)

        #print("mult_tables:\n", spgrp.mult_table)
        # Classes cover the entire group.
        self.assertEqual(sum(len(cls) for cls in spgrp.groupby_class()),
                         len(spgrp))

        # Operation in the same class have the same trace and determinant.
        for cls in spgrp.groupby_class():
            #print(cls)
            op0 = cls[0]
            ref_trace, ref_det = op0.trace, op0.det
            for op in cls[1:]:
                self.assertEqual(op.trace, ref_trace)
                self.assertEqual(op.det, ref_det)

        assert spgrp == spgrp
        # FIXME: Temporary disabled spgid is set to 0 in the WFK file.
        #assert spgrp.spgid == 227
        assert spgrp.has_timerev
        assert len(spgrp) == 48 * 2
        assert spgrp.num_spatial_symmetries == 48

        assert spgrp.is_group()
        # TODO
        #si_symrel =
        si_tnons = np.reshape(24 * [0, 0, 0, 0.25, 0.25, 0.25], (48, 3))
        si_symafm = np.ones(48, dtype=np.int)

        self.assert_almost_equal(si_tnons, spgrp.tnons)
        self.assert_almost_equal(si_symafm, spgrp.symafm)

        for (idx, symmop) in enumerate(spgrp):
            self.assertTrue(symmop in spgrp)
            self.assertTrue(spgrp.count(symmop) == 1)
            self.assertTrue(spgrp.find(symmop) == idx)
            self.assertTrue(abs(symmop.det) == 1)

        # Test pickle
        self.serialize_with_pickle(spgrp[0], protocols=None, test_eq=True)

        for idx in range(len(spgrp) - 1):
            self.assertTrue(spgrp[idx] == spgrp[idx])
            self.assertTrue(spgrp[idx] != spgrp[idx + 1])

        for fmop in spgrp.fm_symmops:
            self.assertTrue(fmop.is_fm)

        ucell_coords = np.reshape([site.frac_coords for site in structure],
                                  (len(structure), 3))

        err_msg = ""
        for site in structure:
            for symop in spgrp:
                rot_coords = symop.rotate_r(site.frac_coords, in_ucell=True)

                for atom_coords in ucell_coords:
                    #print (atom_coords - rot_coords)
                    if np.allclose(atom_coords, rot_coords):
                        break
                else:
                    err_msg += "Cannot find symmetrical image of %s\n" % str(
                        rot_coords)

                self.assertFalse(err_msg)
예제 #10
0
    def test_silicon(self):
        """Test silicon space group."""
        structure = Structure.from_file(abidata.ref_file("si_scf_WFK.nc"))

        self.assertTrue(structure.has_spacegroup)
        self.assertTrue(structure.is_symmorphic)

        print(structure)
        print("composition:", structure.composition)
        self.serialize_with_pickle(structure, test_eq=True)

        spgrp = structure.spacegroup
        print("spgrp:\n", spgrp)

        #print("mult_tables:\n", spgrp.mult_table)
        # Classes cover the entire group.
        self.assertEqual(sum(len(cls) for cls in spgrp.groupby_class()), len(spgrp))

        # Operation in the same class have the same trace and determinant.
        for cls in spgrp.groupby_class():
            #print(cls)
            op0 = cls[0]
            ref_trace, ref_det = op0.trace, op0.det
            for op in cls[1:]:
                self.assertEqual(op.trace, ref_trace)
                self.assertEqual(op.det, ref_det)

        assert spgrp == spgrp
        # FIXME: Temporary disabled spgid is set to 0 in the WFK file.
        #assert spgrp.spgid == 227
        assert spgrp.has_timerev
        assert len(spgrp) == 48 * 2
        assert spgrp.num_spatial_symmetries == 48

        assert spgrp.is_group()
        # TODO
        #si_symrel =
        si_tnons = np.reshape(24 * [0, 0, 0, 0.25, 0.25, 0.25], (48, 3))
        si_symafm = np.ones(48, dtype=np.int)

        self.assert_almost_equal(si_tnons, spgrp.tnons)
        self.assert_almost_equal(si_symafm, spgrp.symafm)

        for (idx, symmop) in enumerate(spgrp):
            self.assertTrue(symmop in spgrp)
            self.assertTrue(spgrp.count(symmop) == 1)
            self.assertTrue(spgrp.find(symmop) == idx)
            self.assertTrue(abs(symmop.det) == 1)

        # Test pickle
        self.serialize_with_pickle(spgrp[0], protocols=None, test_eq=True)

        for idx in range(len(spgrp)-1):
            self.assertTrue(spgrp[idx] == spgrp[idx])
            self.assertTrue(spgrp[idx] != spgrp[idx+1])

        for fmop in spgrp.fm_symmops:
            self.assertTrue(fmop.is_fm)

        ucell_coords = np.reshape([site.frac_coords for site in structure], (len(structure), 3))

        err_msg = ""
        for site in structure:
            for symop in spgrp:
                rot_coords = symop.rotate_r(site.frac_coords, in_ucell=True)

                for atom_coords in ucell_coords:
                    #print (atom_coords - rot_coords)
                    if np.allclose(atom_coords,  rot_coords):
                        break
                else:
                    err_msg += "Cannot find symmetrical image of %s\n" % str(rot_coords)

                self.assertFalse(err_msg)
예제 #11
0
    def test_silicon(self):
        """Test silicon space group."""
        structure = Structure.from_file(abidata.ref_file("si_scf_WFK.nc"))

        assert structure.has_abi_spacegroup
        assert structure.abi_spacegroup.is_symmorphic
        spgrp = structure.abi_spacegroup
        repr(spgrp); str(spgrp)
        self.serialize_with_pickle(spgrp, test_eq=True)

        # Classes cover the entire group.
        assert sum(len(cls) for cls in spgrp.groupby_class()) == len(spgrp)

        # Multiplication table.
        mtable = spgrp.mult_table
        for i, oi in enumerate(spgrp):
            for j, oj in enumerate(spgrp):
                ij = mtable[i, j]
                assert ij is not None
                assert oi * oj == spgrp[ij]

        # Operation in the same class have the same trace and determinant.
        for cls in spgrp.groupby_class():
            #print(cls)
            op0 = cls[0]
            ref_trace, ref_det = op0.trace, op0.det
            for op in cls[1:]:
                assert op.trace == ref_trace
                assert op.det == ref_det

        assert spgrp == spgrp
        # FIXME: Temporary disabled spgid is set to 0 in the WFK file.
        #assert spgrp.spgid == 227
        assert spgrp.has_timerev
        assert len(spgrp) == 48 * 2
        assert spgrp.num_spatial_symmetries == 48

        assert spgrp.is_group()
        # TODO
        #si_symrel =
        si_tnons = np.reshape(24 * [0, 0, 0, 0.25, 0.25, 0.25], (48, 3))
        si_symafm = np.ones(48, dtype=np.int)

        self.assert_almost_equal(si_tnons, spgrp.tnons)
        self.assert_almost_equal(si_symafm, spgrp.symafm)
        assert not spgrp.afm_symmops

        for idx, symmop in enumerate(spgrp):
            repr(symmop); str(symmop)
            symmop.to_string(verbose=2)
            assert symmop in spgrp
            assert spgrp.count(symmop) == 1
            assert spgrp.find(symmop) == idx
            if symmop.det == 1: assert symmop.is_proper

        # Test pickle
        self.serialize_with_pickle(spgrp[0], protocols=None, test_eq=True)

        for idx in range(len(spgrp)-1):
            assert spgrp[idx] == spgrp[idx]
            assert spgrp[idx] != spgrp[idx+1]

        for fmop in spgrp.fm_symmops:
            assert fmop.is_fm and not fmop.is_afm

        ucell_coords = np.reshape([site.frac_coords for site in structure], (len(structure), 3))

        err_msg = ""
        for site in structure:
            for symop in spgrp:
                rot_coords = symop.rotate_r(site.frac_coords, in_ucell=True)

                for atom_coords in ucell_coords:
                    #print (atom_coords - rot_coords)
                    if np.allclose(atom_coords,  rot_coords):
                        break
                else:
                    err_msg += "Cannot find symmetrical image of %s\n" % str(rot_coords)

                assert not err_msg

        k1, k2 = [0.5, 0, 0], [0, 0.5, 0]
        ktab = spgrp.symeq(k1, k2, atol=None)
        assert ktab.isym != -1
        self.assert_equal(spgrp[ktab.isym].rotate_k(k1) - np.array(k2), ktab.g0)

        k1, k2 = [0.0, 0, 0], [0, 0.5, 0]
        ktab = spgrp.symeq(k1, k2, atol=None)
        assert ktab.isym == -1

        # Test little group with Gamma point.
        lg_gamma = spgrp.find_little_group(kpoint=[0, 0, 0])
        assert len(lg_gamma) == len(spgrp)
        repr(lg_gamma); str(lg_gamma)
        assert lg_gamma.is_symmorphic and not lg_gamma.on_bz_border
        for o1, (o2, g0) in zip(spgrp, lg_gamma.iter_symmop_g0()):
            assert o1 == o2
            assert np.all(g0 == 0)

        # Little group with X point.
        #    'G' : (0.000, 0.000, 0.000),
        #    'X' : (0.500, 0.000, 0.500),
        #    'W' : (0.500, 0.250, 0.750),
        #    'L' : (0.500, 0.500, 0.500),
        #    'K' : (0.375, 0.375, 0.750),
        #    'U' : (0.625, 0.250, 0.625)

        lg_x = spgrp.find_little_group(kpoint=[0.5, 0, 0.5])
        assert len(lg_x) == 32
        repr(lg_x); str(lg_x)
        assert lg_x.is_symmorphic and lg_x.on_bz_border

        # This is just to test from_structure but one should always try to init from file.
        other_spgroup = AbinitSpaceGroup.from_structure(structure, has_timerev=True)
        assert other_spgroup.has_timerev
        assert other_spgroup.spgid == 227
        assert len(other_spgroup) == 48 * 2
예제 #12
0
    def test_silicon(self):
        """Test silicon space group."""
        structure = Structure.from_file(abidata.ref_file("si_scf_WFK.nc"))

        assert structure.has_abi_spacegroup
        assert structure.abi_spacegroup.is_symmorphic
        spgrp = structure.abi_spacegroup
        repr(spgrp)
        str(spgrp)
        self.serialize_with_pickle(spgrp, test_eq=True)

        # Classes cover the entire group.
        assert sum(len(cls) for cls in spgrp.groupby_class()) == len(spgrp)

        # Multiplication table.
        mtable = spgrp.mult_table
        for i, oi in enumerate(spgrp):
            for j, oj in enumerate(spgrp):
                ij = mtable[i, j]
                assert ij is not None
                assert oi * oj == spgrp[ij]

        # Operation in the same class have the same trace and determinant.
        for cls in spgrp.groupby_class():
            #print(cls)
            op0 = cls[0]
            ref_trace, ref_det = op0.trace, op0.det
            for op in cls[1:]:
                assert op.trace == ref_trace
                assert op.det == ref_det

        assert spgrp == spgrp
        # FIXME: Temporary disabled spgid is set to 0 in the WFK file.
        #assert spgrp.spgid == 227
        assert spgrp.has_timerev
        assert len(spgrp) == 48 * 2
        assert spgrp.num_spatial_symmetries == 48
        assert spgrp.get_spglib_hall_number() == 525

        assert spgrp.is_group()
        # TODO
        #si_symrel =
        si_tnons = np.reshape(24 * [0, 0, 0, 0.25, 0.25, 0.25], (48, 3))
        si_symafm = np.ones(48, dtype=int)

        self.assert_almost_equal(si_tnons, spgrp.tnons)
        self.assert_almost_equal(si_symafm, spgrp.symafm)
        assert not spgrp.afm_symmops

        for idx, symmop in enumerate(spgrp):
            repr(symmop)
            str(symmop)
            symmop.to_string(verbose=2)
            assert symmop in spgrp
            assert spgrp.count(symmop) == 1
            assert spgrp.find(symmop) == idx
            if symmop.det == 1: assert symmop.is_proper

        # Test pickle
        self.serialize_with_pickle(spgrp[0], protocols=None, test_eq=True)

        for idx in range(len(spgrp) - 1):
            assert spgrp[idx] == spgrp[idx]
            assert spgrp[idx] != spgrp[idx + 1]

        for fmop in spgrp.fm_symmops:
            assert fmop.is_fm and not fmop.is_afm

        ucell_coords = np.reshape([site.frac_coords for site in structure],
                                  (len(structure), 3))

        err_msg = ""
        for site in structure:
            for symop in spgrp:
                rot_coords = symop.rotate_r(site.frac_coords, in_ucell=True)

                for atom_coords in ucell_coords:
                    #print (atom_coords - rot_coords)
                    if np.allclose(atom_coords, rot_coords):
                        break
                else:
                    err_msg += "Cannot find symmetrical image of %s\n" % str(
                        rot_coords)

                assert not err_msg

        k1, k2 = [0.5, 0, 0], [0, 0.5, 0]
        ktab = spgrp.symeq(k1, k2, atol=None)
        assert ktab.isym != -1
        self.assert_equal(spgrp[ktab.isym].rotate_k(k1) - np.array(k2),
                          ktab.g0)

        k1, k2 = [0.0, 0, 0], [0, 0.5, 0]
        ktab = spgrp.symeq(k1, k2, atol=None)
        assert ktab.isym == -1

        # Test little group with Gamma point.
        lg_gamma = spgrp.find_little_group(kpoint=[0, 0, 0])
        assert len(lg_gamma) == len(spgrp)
        repr(lg_gamma)
        str(lg_gamma)
        assert lg_gamma.is_symmorphic and not lg_gamma.on_bz_border
        for o1, (o2, g0) in zip(spgrp, lg_gamma.iter_symmop_g0()):
            assert o1 == o2
            assert np.all(g0 == 0)

        # Little group with X point.
        #    'G' : (0.000, 0.000, 0.000),
        #    'X' : (0.500, 0.000, 0.500),
        #    'W' : (0.500, 0.250, 0.750),
        #    'L' : (0.500, 0.500, 0.500),
        #    'K' : (0.375, 0.375, 0.750),
        #    'U' : (0.625, 0.250, 0.625)

        lg_x = spgrp.find_little_group(kpoint=[0.5, 0, 0.5])
        assert len(lg_x) == 32
        repr(lg_x)
        str(lg_x)
        assert lg_x.is_symmorphic and lg_x.on_bz_border

        # This is just to test from_structure but one should always try to init from file.
        other_spgroup = AbinitSpaceGroup.from_structure(structure,
                                                        has_timerev=True)
        assert other_spgroup.has_timerev
        assert other_spgroup.spgid == 227
        assert len(other_spgroup) == 48 * 2
예제 #13
0
파일: input.py 프로젝트: yanikou19/abipy
 def set_structure_from_file(self, filepath, dtset=0):
     """Set the `Structure` object for the specified dtset (data is read from filepath)."""
     structure = Structure.from_file(filepath)
     self.set_structure(structure, dtset=dtset)
     return structure