예제 #1
0
    def test_expand(self):
        """
        Testing helper function to extend the convergence grid
        """
        self.maxDiff = None
        spec = get_spec('GW')
        struc = AbiStructure.from_file(abidata.cif_file("si.cif"))
        struc.item = 'test'

        wdir = tempfile.mkdtemp()
        print('wdir', wdir)

        os.chdir(wdir)
        shutil.copyfile(abidata.cif_file("si.cif"), os.path.join(wdir, 'si.cif'))
        shutil.copyfile(abidata.pseudo("14si.pspnc").path, os.path.join(wdir, 'Si.pspnc'))
        shutil.copyfile(os.path.join(abidata.dirpath, 'managers', 'shell_manager.yml'),
                        os.path.join(wdir, 'manager.yml'))
        shutil.copyfile(os.path.join(abidata.dirpath, 'managers', 'scheduler.yml'), os.path.join(wdir, 'scheduler.yml'))

        try:
            temp_ABINIT_PS_EXT = os.environ['ABINIT_PS_EXT']
            temp_ABINIT_PS = os.environ['ABINIT_PS']
        except KeyError:
            temp_ABINIT_PS_EXT = None
            temp_ABINIT_PS = None

        os.environ['ABINIT_PS_EXT'] = '.pspnc'
        os.environ['ABINIT_PS'] = wdir

        tests = SingleAbinitGWWork(struc, spec).convs
        tests_out = {'nscf_nbands': {'test_range': (40,),
                                     'control': 'gap', 'method': 'set_bands', 'level': 'nscf'},
                     'ecut': {'test_range': (50, 48, 46, 44),
                              'control': 'e_ks_max', 'method': 'direct', 'level': 'scf'},
                     'ecuteps': {'test_range': (4, 8, 12, 16, 20),
                                 'control': 'gap', 'method': 'direct', 'level': 'sigma'}}
        self.assertEqual(expand(tests, 1), tests_out)
        spec.data['code'] = 'VASP'

        if "VASP_PSP_DIR" in os.environ:
            spec.update_code_interface()
            tests = GWG0W0VaspInputSet(struc, spec).convs
            tests_out = {'ENCUTGW': {'test_range': (200, 400, 600, 800), 'control': 'gap', 'method': 'incar_settings'}}
            self.assertEqual(expand(tests, 1), tests_out)

        if temp_ABINIT_PS is not None:
            os.environ['ABINIT_PS_EXT'] = temp_ABINIT_PS_EXT
            os.environ['ABINIT_PS'] = temp_ABINIT_PS
예제 #2
0
    def test_kpath_api(self):
        """Testing Kpath API."""
        structure = abilab.Structure.as_structure(abidata.cif_file("si.cif"))

        knames = ["G", "X", "L", "G"]
        kpath = Kpath.from_names(structure, knames, line_density=5)
        repr(kpath)
        str(kpath)
        assert kpath.to_string(verbose=2, title="Kpath")
        assert not kpath.is_ibz and kpath.is_path
        assert kpath[0].is_gamma and kpath[-1].is_gamma
        #assert len(kpath.ds) == len(self) - 1
        #assert kpath.ksampling.kptopt == 1
        #self.assert_equal(kpath.ksampling.mpdivs, [4, 4, 4])

        assert len(kpath.ds) == len(kpath) - 1
        assert len(kpath.versors) == len(kpath) - 1
        assert len(kpath.lines) == len(knames) - 1
        self.assert_almost_equal(kpath.frac_bounds,
                                 structure.get_kcoords_from_names(knames))
        self.assert_almost_equal(
            kpath.cart_bounds,
            structure.get_kcoords_from_names(knames, cart_coords=True))

        r = kpath.find_points_along_path(kpath.get_cart_coords())
        assert len(r.ikfound) == len(kpath)
        self.assert_equal(
            r.ikfound,
            [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0])
예제 #3
0
def build_flow(options):
    # Working directory (default is the name of the script with '.py' removed and "run_" replaced by "flow_")
    workdir = options.workdir
    if not options.workdir:
        workdir = os.path.basename(__file__).replace(".py", "").replace(
            "run_", "flow_")

    pseudos = abidata.pseudos("14si.pspnc", "8o.pspnc")

    base_structure = abilab.Structure.from_file(abidata.cif_file("si.cif"))

    news, uparams = [], [0.2, 0.3]

    for u in uparams:
        new = special_positions(base_structure.lattice, u)
        news.append(new)

    flow = flowtk.Flow(workdir, manager=options.manager, remove=options.remove)

    # Create the list of workflows. Each workflow defines a band structure calculation.
    for new_structure, u in zip(news, uparams):
        # Generate the workflow and register it.
        flow.register_work(make_workflow(new_structure, pseudos))

    return flow
예제 #4
0
def build_flow(options):

    # Working directory (default is the name of the script with '.py' removed and "run_" replaced by "flow_")
    workdir = options.workdir
    if not options.workdir:
        workdir = os.path.basename(__file__).replace(".py", "").replace(
            "run_", "flow_")

    # Initialize structure and pseudos.
    structure = abilab.Structure.from_file(abidata.cif_file("si.cif"))
    pseudos = abidata.pseudos("14si.pspnc")

    # Initialize the flow.
    flow = flowtk.Flow(workdir=workdir,
                       manager=options.manager,
                       remove=options.remove)

    # Use ebands_input factory function to build inputs.
    multi = abilab.ebands_input(structure,
                                pseudos,
                                kppa=40,
                                nscf_nband=6,
                                ndivsm=10,
                                ecut=6)
    work = flowtk.BandStructureWork(scf_input=multi[0], nscf_input=multi[1])

    flow.register_work(work)
    return flow
예제 #5
0
def build_flow(options):
    # Working directory (default is the name of the script with '.py' removed and "run_" replaced by "flow_")
    if not options.workdir:
        if os.getenv("READTHEDOCS", False):
            __file__ = os.path.join(os.getcwd(), "run_phfrozen_ebands.py")
        options.workdir = os.path.basename(__file__).replace(
            ".py", "").replace("run_", "flow_")

    # build the structures
    base_structure = abilab.Structure.from_file(data.cif_file("si.cif"))
    modifier = abilab.StructureModifier(base_structure)

    etas = [-0.1, 0, +0.1]
    ph_displ = np.reshape(np.zeros(3 * len(base_structure)), (-1, 3))
    ph_displ[0, :] = [+1, 0, 0]
    ph_displ[1, :] = [-1, 0, 0]

    displaced_structures = modifier.displace(ph_displ, etas, frac_coords=False)

    flow = flowtk.Flow(options.workdir, manager=options.manager)

    for structure in displaced_structures:
        # Create the work for the band structure calculation.
        scf_input, nscf_input = make_scf_nscf_inputs(structure)

        work = flowtk.BandStructureWork(scf_input, nscf_input)
        flow.register_work(work)

    return flow
예제 #6
0
    def test_task_history_and_events(self):
        si = abilab.Structure.from_file(abidata.cif_file("si.cif"))
        si_relax_input = ion_ioncell_relax_input(si, abidata.pseudos("14si.pspnc"), ecut=2).split_datasets()[1]

        th = TaskHistory()
        th.log_initialization(task=RelaxFWTask(si_relax_input), initialization_info={"test_info": 1})
        th.log_autoparal({u'time': u'12:0:0', u'ntasks': 15, u'partition': 'defq', u'nodes': 1, u'mem_per_cpu': 3000})
        th.log_finalized(final_input=si_relax_input)
        th.log_restart(RestartInfo(os.path.abspath('.'), reset=True, num_restarts=2))
        th.log_unconverged()
        th.log_corrections([events.Correction(events.DilatmxErrorHandler(), {}, events.DilatmxError('', '', '',), )])
        th.log_abinit_stop(run_time=100)

        try:
            raise AbinitRuntimeError("test error")
        except AbinitRuntimeError as exc:
            th.log_error(exc)

        try:
            raise RuntimeError("test error")
        except RuntimeError as exc:
            th.log_error(exc)

        th.log_converge_params({'dilatmx': 1.03}, si_relax_input)

        self.assertMSONable(th)

        for te in th:
            self.assertMSONable(te)
예제 #7
0
def build_flow(options):
    # Set working directory (default is the name of the script with '.py' removed and "run_" replaced by "flow_")
    if not options.workdir:
        options.workdir = os.path.basename(sys.argv[0]).replace(".py", "").replace("run_", "flow_")

    # Build GS input file.
    pseudos = abidata.pseudos("Si.GGA_PBE-JTH-paw.xml")
    #silicon = abilab.Structure.zincblende(5.431, ["Si", "Si"], units="ang")
    silicon = abidata.cif_file("si.cif")

    scf_input = abilab.AbinitInput(silicon, pseudos)
    ecut = 12
    scf_input.set_vars(
        ecut=ecut,
        pawecutdg=40,
        nband=6,
        paral_kgb=0,
        iomode=3,
        toldfe=1e-9,
    )

    # K-point sampling (shifted)
    scf_input.set_autokmesh(nksmall=4)

    from abipy.flowtk.gs_works import EosWork
    flow = flowtk.Flow(options.workdir, manager=options.manager)

    # Si is cubic and atomic positions are fixed by symmetry so we
    # use move_atoms=False to compute E(V) with SCF-GS tasks instead of
    # performing a constant-volume optimization of the cell geometry.
    work = EosWork.from_scf_input(scf_input, move_atoms=False, ecutsm=0.5)
    flow.register_work(work)
    flow.allocate(use_smartio=True)

    return flow
예제 #8
0
    def test_helper_functions(self):
        """Testing AbinitInput helper functions."""
        inp = AbinitInput(structure=abidata.cif_file("si.cif"), pseudos=abidata.pseudos("14si.pspnc"))

        inp.set_kmesh(ngkpt=(1, 2, 3), shiftk=(1, 2, 3, 4, 5, 6))
        assert inp["kptopt"] == 1 and inp["nshiftk"] == 2

        inp.set_autokmesh(nksmall=2)
        assert inp["kptopt"] == 1 and np.all(inp["ngkpt"] == [2, 2, 2]) and inp["nshiftk"] == 4

        inp.set_kpath(ndivsm=3, kptbounds=None)
        assert inp["iscf"] == -2 and len(inp["kptbounds"]) == 12

        inp.set_kptgw(kptgw=(1, 2, 3, 4, 5, 6), bdgw=(1, 2))
        assert inp["nkptgw"] == 2 and np.all(inp["bdgw"].ravel() == np.array(len(inp["kptgw"]) * [1,2]).ravel())

        linps = inp.linspace("ecut", 2, 6, num=3, endpoint=True)
        assert len(linps) == 3 and (linps[0]["ecut"] == 2 and (linps[-1]["ecut"] == 6))

        ranginps = inp.arange("ecut", start=3, stop=5, step=1)
        assert len(ranginps) == 2 and (ranginps[0]["ecut"] == 3 and (ranginps[-1]["ecut"] == 4))

        prod_inps = inp.product("ngkpt", "tsmear", [[2,2,2], [4,4,4]], [0.1, 0.2, 0.3])
        #prod_inps = inp.product([("ngkpt", [[2,2,2], [4,4,4]]), ("tsmear", [0.1, 0.2, 0.3])])
        assert len(prod_inps) == 6 
        assert prod_inps[0]["ngkpt"] == [2,2,2] and prod_inps[0]["tsmear"] == 0.1
        assert prod_inps[-1]["ngkpt"] ==  [4,4,4] and prod_inps[-1]["tsmear"] == 0.3
def make_ngkpt_flow(ngkpt_list=((2, 2, 2), (4, 4, 4), (6, 6, 6), (8, 8, 8)), structure_file=None, metal=False):
    """
    A `factory function` (a function that returns an instance of the class defined above. If no specific system is
    specified, structure_file=None, an flow for silicon in constructed and returned.
    """
    # Defining the structure and adding the appropriate pseudo potentials
    if structure_file is None:
        multi = abilab.MultiDataset(structure=abidata.cif_file("si.cif"),
                                    pseudos=abidata.pseudos("14si.pspnc"), ndtset=len(ngkpt_list))
        workdir = "flow_lesson_Si_kpoint_convergence"
    else:
        structure = abilab.Structure.from_file(structure_file)
        pseudos = get_pseudos(structure)
        multi = abilab.MultiDataset(structure, pseudos=pseudos, ndtset=len(ngkpt_list))
        workdir = "flow_lesson_" + structure.composition.reduced_formula + "_kpoint_convergence"

    # Add mnemonics to input file.
    multi.set_mnemonics(True)

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

    if metal:
        multi.set_vars(occopt=7, tsmear=0.04)

    # Specific variables for the different calculations
    for i, ngkpt in enumerate(ngkpt_list):
        multi[i].set_kmesh(ngkpt=ngkpt, shiftk=[0, 0, 0])

    return flowtk.Flow.from_inputs(workdir=workdir, inputs=multi.split_datasets())
예제 #10
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
예제 #11
0
def build_flow(options):
    structure = abilab.Structure.from_file(abidata.cif_file("si.cif"))

    scf_kppa = 40
    nscf_nband = 6
    ndivsm = 5
    #dos_ngkpt = [4,4,4]
    #dos_shiftk = [0.1, 0.2, 0.3]

    extra_abivars = dict(
        ecut=6, 
    )

    # Working directory (default is the name of the script with '.py' removed and "run_" replaced by "flow_")
    workdir = options.workdir
    if not options.workdir:
        workdir = os.path.basename(__file__).replace(".py", "").replace("run_","flow_") 

    # Initialize the flow.
    flow = abilab.Flow(workdir=workdir, manager=options.manager)

    pseudos = abidata.pseudos("14si.pspnc")
    work = bandstructure_work(structure,  pseudos, scf_kppa, nscf_nband, ndivsm, 
                              spin_mode="unpolarized", smearing=None, **extra_abivars)

    flow.register_work(work)
    return flow
예제 #12
0
    def test_new_with_structure(self):
        """Testing new_with_structure."""

        si2_inp = AbinitInput(structure=abidata.cif_file("si.cif"), pseudos=abidata.pseudos("14si.pspnc"),
                abi_kwargs={"ecut": 4, "toldfe": 1e-10, "nband": 6, "ngkpt": [12, 12, 12]})

        # Build new input with same parameters and compressed unit cell.
        new_vol = 0.9 * si2_inp.structure.volume
        new_lattice = si2_inp.structure.lattice.scale(new_vol)
        new_structure = abilab.Structure(new_lattice, si2_inp.structure.species, si2_inp.structure.frac_coords)

        new_inp = si2_inp.new_with_structure(new_structure, scdims=None)
        assert new_inp.structure.volume == new_vol
        assert new_inp["ecut"] == 4

        #al2_structure = abilab.Structure.from_file(abidata.cif_file("al.cif"))

        # Let's build an input file for a (2, 3, 4) supercell
        #super_structure = si2_inp.structure.make_supercell
        scdims = np.array((2, 3, 4))
        # Note: This will return a pymatgen structure, not an Abipy structure.
        super_structure = si2_inp.structure * scdims
        sc_inp = si2_inp.new_with_structure(super_structure, scdims=scdims)
        assert isinstance(sc_inp.structure, abilab.Structure)
        assert len(sc_inp.structure) == 2 * scdims.prod()
        self.assert_almost_equal(sc_inp.structure.volume, si2_inp.structure.volume * scdims.prod())
        assert sc_inp["chkprim"] == 0
        assert sc_inp["nband"] == si2_inp["nband"] * scdims.prod()
        self.assert_equal(sc_inp["ngkpt"], [6, 4, 3])
        self.abivalidate_input(sc_inp)
예제 #13
0
def htg0w0_flow(workdir="ht_si_g0w0ppm"):
    structure = AbiStructure.asabistructure(data.cif_file("si.cif"))

    pseudos = data.pseudos("14si.pspnc")

    manager = abilab.TaskManager.from_user_config()

    # Initialize the flow.
    # FIXME
    # Don't know why protocol=-1 does not work here.
    flow = abilab.AbinitFlow(workdir, manager, pickle_protocol=0)

    scf_kppa = 40
    nscf_nband = 100
    #nscf_ngkpt = [4,4,4]
    #nscf_shiftk = [0.0, 0.0, 0.0]
    ecuteps, ecutsigx = 6, 8
    #scr_nband = 50
    #sigma_nband = 50

    extra_abivars = dict(
        ecut=8, 
        istwfk="*1",
        timopt=-1,
    )

    work = g0w0_with_ppmodel(structure, pseudos, scf_kppa, nscf_nband, ecuteps, ecutsigx,
                             accuracy="normal", spin_mode="unpolarized", smearing=None, 
                             ppmodel="godby", charge=0.0, inclvkb=2, sigma_nband=None, scr_nband=None,
                             **extra_abivars)
    
    flow.register_work(work)
    return flow.allocate()
예제 #14
0
def build_flow(options):
    """
    Create a `Flow` for phonon calculations with phonopy:
    """
    # Working directory (default is the name of the script with '.py' removed and "run_" replaced by "flow_")
    if not options.workdir:
        options.workdir = os.path.basename(__file__).replace(".py", "").replace("run_", "flow_")

    # Initialize structure and pseudos
    structure = abilab.Structure.from_file(abidata.cif_file("si.cif"))
    pseudos = abidata.pseudos("14si.pspnc")

    # Build input for GS calculation.
    gsinp = abilab.AbinitInput(structure, pseudos)
    gsinp.set_vars(ecut=4, nband=4, toldff=1.e-6)

    # This gives ngkpt = 4x4x4 with 4 shifts for the initial unit cell.
    # The k-point sampling will be rescaled when we build the supercell in PhonopyWork.
    gsinp.set_autokmesh(nksmall=4)
    #gsinp.set_vars(ngkpt=[4, 4, 4])

    flow = flowtk.Flow(workdir=options.workdir)

    # Use a 2x2x2 supercell to compute phonons with phonopy
    work = PhonopyWork.from_gs_input(gsinp, scdims=[2, 2, 2])
    flow.register_work(work)

    return flow
예제 #15
0
    def test_new_with_structure(self):
        """Testing new_with_structure."""

        si2_inp = AbinitInput(structure=abidata.cif_file("si.cif"), pseudos=abidata.pseudos("14si.pspnc"),
                abi_kwargs={"ecut": 4, "toldfe": 1e-10, "nband": 6, "ngkpt": [12, 12, 12]})

        # Build new input with same parameters and compressed unit cell.
        new_vol = 0.9 * si2_inp.structure.volume
        new_lattice = si2_inp.structure.lattice.scale(new_vol)
        new_structure = abilab.Structure(new_lattice, si2_inp.structure.species, si2_inp.structure.frac_coords)

        new_inp = si2_inp.new_with_structure(new_structure, scdims=None)
        assert new_inp.structure.volume == new_vol
        assert new_inp["ecut"] == 4

        #al2_structure = abilab.Structure.from_file(abidata.cif_file("al.cif"))

        # Let's build an input file for a (2, 3, 4) supercell
        #super_structure = si2_inp.structure.make_supercell
        scdims = np.array((2, 3, 4))
        # Note: This will return a pymatgen structure, not an Abipy structure.
        super_structure = si2_inp.structure * scdims
        sc_inp = si2_inp.new_with_structure(super_structure, scdims=scdims)
        assert isinstance(sc_inp.structure, abilab.Structure)
        assert len(sc_inp.structure) == 2 * scdims.prod()
        self.assert_almost_equal(sc_inp.structure.volume, si2_inp.structure.volume * scdims.prod())
        assert sc_inp["chkprim"] == 0
        assert sc_inp["nband"] == si2_inp["nband"] * scdims.prod()
        self.assert_equal(sc_inp["ngkpt"], [6, 4, 3])
        self.abivalidate_input(sc_inp)
예제 #16
0
        def make_scf_nscf_inputs():
            """Build ands return the input files for the GS-SCF and the GS-NSCF tasks."""

            multi = abilab.MultiDataset(structure=abidata.cif_file("si.cif"),
                                        pseudos=abidata.pseudos("14si.pspnc"),
                                        ndtset=2)

            # Set global variables (dataset1 and dataset2)
            multi.set_vars(ecut=6, nband=8)

            # Dataset 1 (GS-SCF run)
            multi[0].set_kmesh(ngkpt=[8, 8, 8], shiftk=[0, 0, 0])
            multi[0].set_vars(tolvrs=1e-6)

            # Dataset 2 (GS-NSCF run on a k-path)
            kptbounds = [
                [0.5, 0.0, 0.0],  # L point
                [0.0, 0.0, 0.0],  # Gamma point
                [0.0, 0.5, 0.5],  # X point
            ]

            multi[1].set_kpath(ndivsm=6, kptbounds=kptbounds)
            multi[1].set_vars(tolwfr=1e-12)

            # Return two input files for the GS and the NSCF run
            scf_input, nscf_input = multi.split_datasets()
            return scf_input, nscf_input
예제 #17
0
 def test_input_check_sum(self):
     """Testing the hash method of AbinitInput"""
     inp = ebands_input(abidata.cif_file("si.cif"), abidata.pseudos("14si.pspnc"), kppa=10, ecut=2)[0]
     inp_cs = inp.variable_checksum()
     ecut = inp.pop('ecut')
     inp.set_vars({'ecut': ecut})
     assert inp_cs == inp.variable_checksum()
예제 #18
0
    def test_abinit_calls(self):
        """Testing AbinitInput methods invoking Abinit."""
        inp = AbinitInput(structure=abidata.cif_file("si.cif"), pseudos=abidata.pseudos("14si.pspnc"))
        inp.set_kmesh(ngkpt=(2, 2, 2), shiftk=(0, 0, 0))

        # The code below invokes Abinit.
        if self.has_abinit():

            # Test validate with wrong input
            inp.set_vars(ecut=-1)
            v = inp.abivalidate()
            assert v.retcode != 0 and v.log_file.read()

            # Test validate with correct input
            inp.set_vars(ecut=2, toldfe=1e-6)
            v = inp.abivalidate()
            assert v.retcode == 0

            # Test abiget_ibz
            ibz = inp.abiget_ibz()
            assert np.all(ibz.points == [[ 0. ,  0. ,  0. ], [ 0.5,  0. ,  0. ], [ 0.5,  0.5,  0. ]])
            assert np.all(ibz.weights == [0.125,  0.5,  0.375])

            # Test abiget_irred_phperts
            # [{'idir': 1, 'ipert': 1, 'qpt': [0.0, 0.0, 0.0]}]
            irred_perts = inp.abiget_irred_phperts(qpt=(0, 0, 0))
            assert len(irred_perts) == 1
            pert = irred_perts[0]
            assert pert.idir == 1 and (pert.idir, pert.ipert) == (1, 1) and all(c == 0 for c in pert.qpt)

            # Test abiget_autoparal_pconfs
            inp["paral_kgb"] = 0
            pconfs = inp.abiget_autoparal_pconfs(max_ncpus=5)
            inp["paral_kgb"] = 1
            pconfs = inp.abiget_autoparal_pconfs(max_ncpus=5)
예제 #19
0
def build_flow(options):
    structure = abilab.Structure.from_file(abidata.cif_file("si.cif"))
    pseudos = abidata.pseudos("14si.pspnc")

    # Working directory (default is the name of the script with '.py' removed and "run_" replaced by "flow_")
    workdir = options.workdir
    if not options.workdir:
        workdir = os.path.basename(__file__).replace(".py", "").replace("run_","flow_") 

    # Initialize the flow.
    flow = abilab.Flow(workdir, manager=options.manager) 

    scf_kppa = 10
    nscf_nband = 10
    #nscf_ngkpt = [4,4,4]
    #nscf_shiftk = [0.0, 0.0, 0.0]
    ecut, ecuteps, ecutsigx = 4, 2, 3
    #scr_nband = 50
    #sigma_nband = 50

    extra_abivars = dict(
        ecut=ecut, 
        istwfk="*1",
    )

    work = g0w0_with_ppmodel_work(structure, pseudos, scf_kppa, nscf_nband, ecuteps, ecutsigx,
                                  accuracy="normal", spin_mode="unpolarized", smearing=None, 
                                  ppmodel="godby", charge=0.0, inclvkb=2, sigma_nband=None, gw_qprange=1,
                                  scr_nband=None, **extra_abivars)
    
    flow.register_work(work)
    return flow
예제 #20
0
 def setUpClass(cls):
     cls.si_structure = abilab.Structure.from_file(
         abidata.cif_file("si.cif"))
     cls.scf_inp = scf_input(cls.si_structure,
                             abidata.pseudos("14si.pspnc"),
                             ecut=2,
                             kppa=10)
예제 #21
0
def make_flow(workdir="ht_si_bsemdf"):
    pseudos = data.pseudos("14si.pspnc")
    structure = abilab.Structure.from_file(data.cif_file("si.cif"))

    manager = abilab.TaskManager.from_user_config()

    kppa = scf_kppa = 1
    nscf_nband = 6
    nscf_ngkpt = [4,4,4]
    nscf_shiftk = [0.1, 0.2, 0.3]
    bs_loband = 2
    soenergy = 0.7
    mdf_epsinf = 12
    max_ncpus = 1
    ecuteps = 2

    extra_abivars = dict(
        ecut=12, 
        istwfk="*1",
    )

    flow = abilab.AbinitFlow(workdir=workdir, manager=manager)

    # BSE calculation with model dielectric function.
    work = bse_with_mdf(structure, pseudos, scf_kppa, nscf_nband, nscf_ngkpt, nscf_shiftk,
                       ecuteps, bs_loband, soenergy, mdf_epsinf,
                       accuracy="normal", spin_mode="unpolarized", smearing=None,
                       charge=0.0, scf_solver=None, **extra_abivars)

    flow.register_work(work)
    return flow.allocate()
예제 #22
0
def build_flow(options):
    # Working directory (default is the name of the script with '.py' removed and "run_" replaced by "flow_")
    workdir = options.workdir
    if not options.workdir:
        workdir = os.path.basename(__file__).replace(".py", "").replace("run_","flow_") 

    # Instantiate the TaskManager.
    manager = abilab.TaskManager.from_user_config() if not options.manager else \
              abilab.TaskManager.from_file(options.manager)

    pseudos = data.pseudos("14si.pspnc", "8o.pspnc")

    base_structure = abilab.Structure.from_file(data.cif_file("si.cif"))

    news, uparams = [], [0.1, 0.2, 0.3]

    for u in uparams:
        new = special_positions(base_structure.lattice, u)
        news.append(new)

    flow = abilab.Flow(workdir, manager=manager)

    # Create the list of workflows. Each workflow defines a band structure calculation.
    for new_structure, u in zip(news, uparams):
        # Generate the workflow and register it.
        flow.register_work(make_workflow(new_structure, pseudos))

    return flow.allocate()
예제 #23
0
def ion_relaxation(tvars, ntime=50):
    structure = abilab.Structure.from_file(abidata.cif_file("si.cif"))

    # Perturb the structure (random perturbation of 0.1 Angstrom)
    structure.perturb(distance=0.02)

    global_vars = dict(
        ecut=6,
        ngkpt=[2, 2, 2],
        shiftk=[0, 0, 0],
        nshiftk=1,
        chksymbreak=0,
        paral_kgb=tvars.paral_kgb,
    )

    inp = abilab.AbinitInput(structure, pseudos=abidata.pseudos("14si.pspnc"))

    # Global variables
    inp.set_vars(global_vars)

    # Dataset 1 (Atom Relaxation)
    #inp[1].set_vars(
    # FIXME here there's a bug
    inp.set_vars(
        optcell=0,
        ionmov=2,
        tolrff=0.02,
        tolmxf=5.0e-5,
        ntime=ntime,
        #dilatmx=1.05, # FIXME: abinit crashes if I don't use this
    )

    return inp
예제 #24
0
def make_scf_nscf_inputs(paral_kgb=1):
    """Returns two input files: GS run and NSCF on a high symmetry k-mesh."""
    multi = abilab.MultiDataset(structure=abidata.cif_file("si.cif"),
                                pseudos=abidata.pseudos("14si.pspnc"),
                                ndtset=2)

    # Global variables
    ecut = 4
    global_vars = dict(ecut=ecut, nband=8, nstep=15, paral_kgb=paral_kgb)

    if multi.ispaw:
        global_vars.update(pawecutdg=2 * ecut)

    multi.set_vars(global_vars)

    # Dataset 1 (GS run)
    multi[0].set_kmesh(ngkpt=[2, 2, 2], shiftk=[0, 0, 0])
    multi[0].set_vars(tolvrs=1e-4)

    # Dataset 2 (NSCF run)
    kptbounds = [
        [0.5, 0.0, 0.0],  # L point
        [0.0, 0.0, 0.0],  # Gamma point
        [0.0, 0.5, 0.5],  # X point
    ]

    multi[1].set_kpath(ndivsm=2, kptbounds=kptbounds)
    multi[1].set_vars(tolwfr=1e-4)

    # Generate two input files for the GS and the NSCF run
    scf_input, nscf_input = multi.split_datasets()
    return scf_input, nscf_input
예제 #25
0
def make_scf_nscf_inputs(paral_kgb=1):
    """Returns two input files: GS run and NSCF on a high symmetry k-mesh."""
    multi = abilab.MultiDataset(structure=abidata.cif_file("si.cif"), 
                              pseudos=abidata.pseudos("14si.pspnc"), ndtset=2)

    # Global variables
    ecut = 4
    global_vars = dict(ecut=ecut, nband=8, nstep=15, paral_kgb=paral_kgb)

    if multi.ispaw:
        global_vars.update(pawecutdg=2*ecut)

    multi.set_vars(global_vars)

    # Dataset 1 (GS run)
    multi[0].set_kmesh(ngkpt=[2,2,2], shiftk=[0,0,0])
    multi[0].set_vars(tolvrs=1e-4)

    # Dataset 2 (NSCF run)
    kptbounds = [
        [0.5, 0.0, 0.0], # L point
        [0.0, 0.0, 0.0], # Gamma point
        [0.0, 0.5, 0.5], # X point
    ]

    multi[1].set_kpath(ndivsm=2, kptbounds=kptbounds)
    multi[1].set_vars(tolwfr=1e-4)
    
    # Generate two input files for the GS and the NSCF run 
    scf_input, nscf_input = multi.split_datasets()
    return scf_input, nscf_input
예제 #26
0
def make_relax_flow(structure_file=None):
    """
    Build and return a flow that perform a structural relaxation for different k-point samplings.
    """
    ngkpt_list = [[3, 3, 2], [6, 6, 4], [8, 8, 6]]

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

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

    # Add mnemonics to input file.
    multi.set_mnemonics(True)

    # Global variables
    multi.set_vars(
        ecut=20,
        tolrff=5.0e-2,
        nstep=30,
        optcell=2,
        ionmov=3,
        ntime=50,
        dilatmx=1.05,
        ecutsm=0.5,
        tolmxf=5.0e-5,
    )

    for i, ngkpt in enumerate(ngkpt_list):
        multi[i].set_kmesh(ngkpt=ngkpt, shiftk=[0, 0, 0])

    return abilab.Flow.from_inputs("flow_gan_relax", inputs=multi.split_datasets(), task_class=abilab.RelaxTask)
예제 #27
0
def get_gsinput_si(usepaw=0, as_task=False):
    """
    Build and return a GS input file for silicon or a Task if `as_task`
    """
    pseudos = abidata.pseudos(
        "14si.pspnc") if usepaw == 0 else abidata.pseudos(
            "Si.GGA_PBE-JTH-paw.xml")
    silicon = abidata.cif_file("si.cif")

    from abipy.abio.inputs import AbinitInput
    scf_input = AbinitInput(silicon, pseudos)
    ecut = 6
    scf_input.set_vars(
        ecut=ecut,
        nband=6,
        paral_kgb=0,
        iomode=3,
        toldfe=1e-9,
    )
    if usepaw:
        scf_input.set_vars(pawecutdg=4 * ecut)

    # K-point sampling (shifted)
    scf_input.set_autokmesh(nksmall=4)

    if not as_task:
        return scf_input
    else:
        from abipy.flowtk.tasks import ScfTask
        return ScfTask(scf_input)
예제 #28
0
def build_flow(options):
    """
    Create a `Flow` for phonon calculations with phonopy:
    """
    # Working directory (default is the name of the script with '.py' removed and "run_" replaced by "flow_")
    if not options.workdir:
        options.workdir = os.path.basename(__file__).replace(
            ".py", "").replace("run_", "flow_")

    # Initialize structure and pseudos
    structure = abilab.Structure.from_file(abidata.cif_file("si.cif"))
    pseudos = abidata.pseudos("14si.pspnc")

    # Build input for GS calculation.
    gsinp = abilab.AbinitInput(structure, pseudos)
    gsinp.set_vars(ecut=4, nband=4, toldff=1.e-6)

    # This gives ngkpt = 4x4x4 with 4 shifts for the initial unit cell.
    # The k-point sampling will be rescaled when we build the supercell in PhonopyWork.
    gsinp.set_autokmesh(nksmall=4)
    #gsinp.set_vars(ngkpt=[4, 4, 4])

    flow = flowtk.Flow(workdir=options.workdir)

    # Use a 2x2x2 supercell to compute phonons with phonopy
    work = PhonopyWork.from_gs_input(gsinp, scdims=[2, 2, 2])
    flow.register_work(work)

    return flow
예제 #29
0
    def test_abinit_calls(self):
        """Testing AbinitInput methods invoking Abinit."""
        inp = AbinitInput(structure=abidata.cif_file("si.cif"), pseudos=abidata.pseudos("14si.pspnc"))
        inp.set_kmesh(ngkpt=(2, 2, 2), shiftk=(0, 0, 0))

        # The code below invokes Abinit.
        # Test validate with wrong input
        inp.set_vars(ecut=-1)
        v = inp.abivalidate()
        assert v.retcode != 0 and v.log_file.read()

        # Test validate with correct input
        inp.set_vars(ecut=2, toldfe=1e-6)
        v = inp.abivalidate()
        assert v.retcode == 0

        # Test abiget_ibz
        ibz = inp.abiget_ibz()
        assert np.all(ibz.points == [[ 0. ,  0. ,  0. ], [ 0.5,  0. ,  0. ], [ 0.5,  0.5,  0. ]])
        assert np.all(ibz.weights == [0.125,  0.5,  0.375])

        # Test abiget_irred_phperts
        # [{'idir': 1, 'ipert': 1, 'qpt': [0.0, 0.0, 0.0]}]
        irred_perts = inp.abiget_irred_phperts(qpt=(0, 0, 0))
        assert len(irred_perts) == 1
        pert = irred_perts[0]
        assert pert.idir == 1 and (pert.idir, pert.ipert) == (1, 1) and all(c == 0 for c in pert.qpt)

        # Test abiget_autoparal_pconfs
        inp["paral_kgb"] = 0
        pconfs = inp.abiget_autoparal_pconfs(max_ncpus=5)
        inp["paral_kgb"] = 1
        pconfs = inp.abiget_autoparal_pconfs(max_ncpus=5)
예제 #30
0
def build_flow(options):
    # Init structure and pseudos.
    structure = abilab.Structure.from_file(abidata.cif_file("si.cif"))
    pseudos = abidata.pseudos("14si.pspnc")

    # Working directory (default is the name of the script with '.py' removed and "run_" replaced by "flow_")
    if not options.workdir:
        options.workdir = os.path.basename(__file__).replace(".py", "").replace("run_", "flow_")

    # Initialize the flow.
    flow = flowtk.Flow(options.workdir, manager=options.manager)

    scf_kppa = 120
    nscf_nband = 40
    ecut, ecuteps, ecutsigx = 6, 2, 4
    #scr_nband = 50
    #sigma_nband = 50

    multi = abilab.g0w0_with_ppmodel_inputs(
        structure, pseudos, scf_kppa, nscf_nband, ecuteps, ecutsigx,
        ecut=ecut, shifts=(0, 0, 0), # By default the k-mesh is shifted! TODO: Change default?
        accuracy="normal", spin_mode="unpolarized", smearing=None,
        #ppmodel="godby", charge=0.0, scf_algorithm=None, inclvkb=2, scr_nband=None,
        #sigma_nband=None, gw_qprange=1):
    )
    #multi.set_vars(paral_kgb=1)

    scf_input, nscf_input, scr_input, sigma_input = multi.split_datasets()
    work = flowtk.G0W0Work(scf_input, nscf_input, scr_input, sigma_input)
    flow.register_work(work)

    return flow
예제 #31
0
def make_electronic_structure_flow(ngkpts_for_dos=((2, 2, 2), (4, 4, 4),
                                                   (6, 6, 6), (8, 8, 8))):
    """Band structure calculation."""
    multi = abilab.MultiDataset(structure=abidata.cif_file("si.cif"),
                                pseudos=abidata.pseudos("14si.pspnc"),
                                ndtset=2 + len(ngkpts_for_dos))
    # Global variables
    multi.set_vars(ecut=10)

    # Dataset 1
    multi[0].set_vars(tolvrs=1e-9)
    multi[0].set_kmesh(ngkpt=[4, 4, 4], shiftk=[0, 0, 0])

    # Dataset 2
    multi[1].set_vars(tolwfr=1e-15)
    multi[1].set_kpath(ndivsm=5)

    # Dataset 3
    for i, ngkpt in enumerate(ngkpts_for_dos):
        multi[2 + i].set_vars(tolwfr=1e-15)
        multi[2 + i].set_kmesh(ngkpt=ngkpt, shiftk=[0, 0, 0])

    inputs = multi.split_datasets()
    scf_input, nscf_input, dos_input = inputs[0], inputs[1], inputs[2:]

    return flowtk.bandstructure_flow(workdir="flow_dos_bands",
                                     scf_input=scf_input,
                                     nscf_input=nscf_input,
                                     dos_inputs=dos_input)
예제 #32
0
def relax_flow():
    # Structural relaxation
    ngkpt_list = [(2, 2, 2), (4, 4, 4)]
    inp = abilab.AbiInput(pseudos=abidata.pseudos("14si.pspnc"), ndtset=len(ngkpt_list))
    inp.set_structure_from_file(abidata.cif_file("si.cif"))

    # Global variables
    inp.set_variables(
        ecut=10,
        tolvrs=1e-9,
        optcell=1,
        ionmov=3,
        ntime=10,
        dilatmx=1.05,
        ecutsm=0.5,
    )

    for i, ngkpt in enumerate(ngkpt_list):
        inp[i+1].set_kmesh(ngkpt=ngkpt, shiftk=[0,0,0])

    flow = abilab.Flow.from_inputs("flow_relax", inputs=inp.split_datasets(),
                                   task_class=abilab.RelaxTask)

    flow.make_scheduler().start()

    with abilab.GsrRobot.open(flow) as robot:
        data = robot.get_dataframe()
        robot.pairplot(x_vars="nkpts", y_vars=["a", "volume"]) #, hue="tsmear")
예제 #33
0
def make_ngkpt_flow(structure_file=None, metal=False):
    """
    A 'factory function' (a function that returns an instance of the class defined above. If no specific system is
    specified, structure_file=None, an example flow for silicon in constructed and returned.
    """
    ngkpt_list = [(2, 2, 2), (4, 4, 4), (6, 6, 6), (8, 8, 8)]

    # Defining the structure and adding the appropriate pseudo potentials
    if structure_file is None:
        inp = abilab.AbiInput(pseudos=abidata.pseudos("14si.pspnc"), ndtset=len(ngkpt_list))
        inp.set_structure(abidata.cif_file("si.cif"))
        workdir = "lesson_Si_kpoint_convergence"
    else:
        structure = abilab.Structure.from_file(structure_file)
        pseudos = abidata.pseudos(get_pseudos(structure))
        inp = abilab.AbiInput(pseudos=pseudos, ndtset=len(ngkpt_list))
        inp.set_structure(structure)
        workdir = "lesson_" + structure.composition.reduced_formula + "_kpoint_convergence"

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

    if metal:
        inp.set_variables(occopt=7, tsmear=0.04)

    # Specific variables for the different calculations
    for i, ngkpt in enumerate(ngkpt_list):
        inp[i+1].set_kmesh(ngkpt=ngkpt, shiftk=[0, 0, 0])

    return NgkptFlow.from_inputs(workdir=workdir, inputs=inp.split_datasets())
예제 #34
0
파일: run_eos.py 프로젝트: gpetretto/abipy
def build_flow(options):
    # Set working directory (default is the name of the script with '.py' removed and "run_" replaced by "flow_")
    if not options.workdir:
        options.workdir = os.path.basename(__file__).replace(".py", "").replace("run_", "flow_")

    # Build GS input file.
    pseudos = abidata.pseudos("Si.GGA_PBE-JTH-paw.xml")
    #silicon = abilab.Structure.zincblende(5.431, ["Si", "Si"], units="ang")
    silicon = abidata.cif_file("si.cif")

    scf_input = abilab.AbinitInput(silicon, pseudos)
    ecut = 12
    scf_input.set_vars(
        ecut=ecut,
        pawecutdg=40,
        nband=6,
        paral_kgb=0,
        iomode=3,
        toldfe=1e-9,
    )

    # K-point sampling (shifted)
    scf_input.set_autokmesh(nksmall=4)

    from abipy.flowtk.gs_works import EosWork
    flow = flowtk.Flow(options.workdir, manager=options.manager)

    # Si is cubic and atomic positions are fixed by symmetry so we
    # use move_atoms=False to compute E(V) with SCF-GS tasks instead of
    # performing a constant-volume optimization of the cell geometry.
    work = EosWork.from_scf_input(scf_input, move_atoms=False, ecutsm=0.5)
    flow.register_work(work)
    flow.allocate(use_smartio=True)

    return flow
예제 #35
0
def make_ngkpt_flow(ngkpt_list=[(2, 2, 2), (4, 4, 4), (6, 6, 6), (8, 8, 8)], structure_file=None, metal=False):
    """
    A `factory function` (a function that returns an instance of the class defined above. If no specific system is
    specified, structure_file=None, an flow for silicon in constructed and returned.
    """
    # Defining the structure and adding the appropriate pseudo potentials
    if structure_file is None:
        multi = abilab.MultiDataset(structure=abidata.cif_file("si.cif"),
                                    pseudos=abidata.pseudos("14si.pspnc"), ndtset=len(ngkpt_list))
        workdir = "flow_lesson_Si_kpoint_convergence"
    else:
        structure = abilab.Structure.from_file(structure_file)
        pseudos = get_pseudos(structure)
        multi = abilab.MultiDataset(structure, pseudos=pseudos, ndtset=len(ngkpt_list))
        workdir = "flow_lesson_" + structure.composition.reduced_formula + "_kpoint_convergence"

    # Add mnemonics to input file.
    multi.set_mnemonics(True)

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

    if metal:
        multi.set_vars(occopt=7, tsmear=0.04)

    # Specific variables for the different calculations
    for i, ngkpt in enumerate(ngkpt_list):
        multi[i].set_kmesh(ngkpt=ngkpt, shiftk=[0, 0, 0])

    return abilab.Flow.from_inputs(workdir=workdir, inputs=multi.split_datasets())
예제 #36
0
def make_ecut_flow(structure_file=None, ecut_list = (10, 12, 14, 16, 18)):
    """
    Build and return a `Flow` to perform a convergence study wrt to ecut.

    Args:
        structure_file: (optional) file containing the crystalline structure.  
            If None, crystalline silicon structure.
        ecut_list: List of cutoff energies to be investigated.
    """
    # Define the structure and add the necessary pseudos:
    if structure_file is None:
        multi = abilab.MultiDataset(structure=abidata.cif_file("si.cif"), 
                                  pseudos=abidata.pseudos("14si.pspnc"), ndtset=len(ecut_list))
        workdir = "flow_Si_ecut_convergence"
    else:
        structure = abilab.Structure.from_file(structure_file)
        pseudos = abilab.PseudoTable()  ## todo fix this
        multi = abilab.MultiDataset(structure, pseudos=pseudos, ndtset=len(ecut_list))
        workdir = "flow_" + structure.composition.reduced_formula + "_ecut_convergence"

    # Add mnemonics to the input files.
    multi.set_mnemonics(True)

    # Global variables
    multi.set_vars(tolvrs=1e-9)
    multi.set_kmesh(ngkpt=[4, 4, 4], shiftk=[0, 0, 0])

    # Here we set the value of ecut used by the i-th task.
    for i, ecut in enumerate(ecut_list):
        multi[i].set_vars(ecut=ecut)

    return abilab.Flow.from_inputs(workdir=workdir, inputs=multi.split_datasets())
예제 #37
0
def build_ebands_flow(options):
    """
    Band structure calculation.
    First, a SCF density computation, then a non-SCF band structure calculation.
    Similar to tbase3_5.in
    """
    multi = abilab.MultiDataset(structure=abidata.cif_file("si.cif"),
                                pseudos=abidata.pseudos("14si.pspnc"),
                                ndtset=2)
    # Global variables
    shiftk = [
        float(s)
        for s in "0.5 0.5 0.5 0.5 0.0 0.0 0.0 0.5 0.0 0.0 0.0 0.5".split()
    ]
    multi.set_vars(ecut=8, diemac=12, iomode=3)

    # Dataset 1
    multi[0].set_vars(tolvrs=1e-9)
    multi[0].set_kmesh(ngkpt=[4, 4, 4], shiftk=shiftk)

    # Dataset 2
    multi[1].set_vars(tolwfr=1e-15)
    multi[1].set_kpath(ndivsm=5)

    scf_input, nscf_input = multi.split_datasets()

    workdir = options.workdir if (options
                                  and options.workdir) else "flow_base3_ebands"

    return flowtk.bandstructure_flow(workdir,
                                     scf_input=scf_input,
                                     nscf_input=nscf_input)
예제 #38
0
def build_flow(options):
    # Working directory (default is the name of the script with '.py' removed and "run_" replaced by "flow_")
    workdir = options.workdir
    if not options.workdir:
        workdir = os.path.basename(__file__).replace(".py", "").replace("run_","flow_") 

    pseudos = abidata.pseudos("14si.pspnc")
    structure = abilab.Structure.from_file(abidata.cif_file("si.cif"))

    kppa = scf_kppa = 1
    nscf_nband = 6
    nscf_ngkpt = [4,4,4]
    nscf_shiftk = [0.1, 0.2, 0.3]
    bs_loband = 2
    bs_nband = nscf_nband
    soenergy = 0.7
    mdf_epsinf = 12
    max_ncpus = 1
    ecuteps = 2

    extra_abivars = dict(
        ecut=12, 
        istwfk="*1",
    )

    flow = abilab.Flow(workdir=workdir, manager=options.manager)

    # BSE calculation with model dielectric function.
    work = bse_with_mdf_work(structure, pseudos, scf_kppa, nscf_nband, nscf_ngkpt, nscf_shiftk,
                             ecuteps, bs_loband, bs_nband, soenergy, mdf_epsinf,
                             accuracy="normal", spin_mode="unpolarized", smearing=None,
                             charge=0.0, scf_solver=None, **extra_abivars)

    flow.register_work(work)
    return flow
예제 #39
0
    def test_mp_api(self):
        """Testing abistruct mp methods."""
        env = self.get_env()
        r = env.run(self.script,
                    "mp_id",
                    "mp-149",
                    self.loglevel,
                    self.verbose,
                    expect_stderr=self.expect_stderr)

        r = env.run(self.script,
                    "mp_match",
                    abidata.cif_file("gan2.cif"),
                    self.loglevel,
                    self.verbose,
                    expect_stderr=self.expect_stderr)

        r = env.run(self.script,
                    "mp_search",
                    "LiF",
                    "-f POSCAR",
                    "--select-spgnum=225",
                    self.loglevel,
                    self.verbose,
                    expect_stderr=self.expect_stderr)
예제 #40
0
def itest_dilatmxerror_handler(fwp):
    """Test the handler of DilatmxError. The test triggers:

        --- !DilatmxError
        message: |
            Dilatmx has been exceeded too many times (4)
            Restart your calculation from larger lattice vectors and/or a larger dilatmx
        src_file: mover.F90
        src_line: 840
        ...

    in variable cell structural optimizations.
    """
    #if fwp.on_travis:
    pytest.xfail(
        "dilatmxerror_handler is not portable and it's been disabled!")

    structure = abilab.Structure.from_file(abidata.cif_file("si.cif"))
    structure.scale_lattice(structure.volume * 0.8)
    # Perturb the structure (random perturbation of 0.1 Angstrom)
    #structure.perturb(distance=0.1)

    inp = abilab.AbinitInput(structure=structure,
                             pseudos=abidata.pseudos("14si.pspnc"))

    inp.set_vars(
        ecut=4,
        ngkpt=[4, 4, 4],
        shiftk=[0, 0, 0],
        nshiftk=1,
        chksymbreak=0,
        paral_kgb=1,
        optcell=1,
        ionmov=2,
        ecutsm=0.5,
        dilatmx=1.01,
        tolrff=0.02,
        tolmxf=5.0e-5,
        strfact=100,
        ntime=50,
        #ntime=5, To test the restart
    )

    # Create the flow
    flow = flowtk.Flow(fwp.workdir, manager=fwp.manager)
    flow.register_task(inp, task_class=flowtk.RelaxTask)

    flow.allocate()
    assert flow.make_scheduler().start() == 0

    flow.show_status()
    if not flow.all_ok:
        flow.debug()
        raise RuntimeError()

    task = flow[0][0]
    # Don't check the number of corrections as it's not portable.
    assert len(task.corrections)
    for i in range(task.num_corrections):
        assert task.corrections[i]["event"]["@class"] == "DilatmxError"
예제 #41
0
    def test_helper_functions(self):
        """Testing AbinitInput helper functions."""
        inp = AbinitInput(structure=abidata.cif_file("si.cif"), pseudos=abidata.pseudos("14si.pspnc"))

        nval_atoms = inp.valence_electrons_per_atom
        assert len(nval_atoms) == 2
        assert nval_atoms == [4, 4]

        inp.set_kmesh(ngkpt=(1, 2, 3), shiftk=(1, 2, 3, 4, 5, 6))
        assert inp["kptopt"] == 1 and inp["nshiftk"] == 2

        inp.set_autokmesh(nksmall=2)
        assert inp["kptopt"] == 1 and np.all(inp["ngkpt"] == [2, 2, 2]) and inp["nshiftk"] == 4

        inp.set_kpath(ndivsm=3, kptbounds=None)
        assert inp["iscf"] == -2 and len(inp["kptbounds"]) == 12

        inp.set_kptgw(kptgw=(1, 2, 3, 4, 5, 6), bdgw=(1, 2))
        assert inp["nkptgw"] == 2 and np.all(inp["bdgw"].ravel() == np.array(len(inp["kptgw"]) * [1,2]).ravel())

        linps = inp.linspace("ecut", 2, 6, num=3, endpoint=True)
        assert len(linps) == 3 and (linps[0]["ecut"] == 2 and (linps[-1]["ecut"] == 6))

        ranginps = inp.arange("ecut", start=3, stop=5, step=1)
        assert len(ranginps) == 2 and (ranginps[0]["ecut"] == 3 and (ranginps[-1]["ecut"] == 4))

        prod_inps = inp.product("ngkpt", "tsmear", [[2,2,2], [4,4,4]], [0.1, 0.2, 0.3])
        #prod_inps = inp.product([("ngkpt", [[2,2,2], [4,4,4]]), ("tsmear", [0.1, 0.2, 0.3])])
        assert len(prod_inps) == 6
        assert prod_inps[0]["ngkpt"] == [2,2,2] and prod_inps[0]["tsmear"] == 0.1
        assert prod_inps[-1]["ngkpt"] ==  [4,4,4] and prod_inps[-1]["tsmear"] == 0.3
예제 #42
0
def input_scf_si_low():
    pseudos = abidata.pseudos("14si.pspnc")
    cif_file = abidata.cif_file("si.cif")
    structure = abilab.Structure.from_file(cif_file)

    return ebands_input(structure, pseudos, kppa=100,
                        ecut=6).split_datasets()[0]
예제 #43
0
 def TestInputCheckSum(self):
     """Testing the hash method of AbinitInput"""
     inp = ebands_input(abidata.cif_file("si.cif"), abidata.pseudos("14si.pspnc"), kppa=10, ecut=2)[0]
     inp_cs = inp.variable_checksum()
     ecut = inp.pop('ecut')
     inp.set_vars({'ecut': ecut})
     self.assertEqual(inp_cs, inp.variable_checksum())
예제 #44
0
def make_electronic_structure_flow(ngkpts_for_dos=[(2, 2, 2), (4, 4, 4), (6, 6, 6), (8, 8, 8)]):
    """Band structure calculation."""
    multi = abilab.MultiDataset(structure=abidata.cif_file("si.cif"),
                                pseudos=abidata.pseudos("14si.pspnc"), ndtset=2 + len(ngkpts_for_dos))
    # Global variables
    multi.set_vars(ecut=10)

    # Dataset 1
    multi[0].set_vars(tolvrs=1e-9)
    multi[0].set_kmesh(ngkpt=[4, 4, 4], shiftk=[0, 0, 0])

    # Dataset 2
    multi[1].set_vars(tolwfr=1e-15)
    multi[1].set_kpath(ndivsm=5)

    # Dataset 3
    for i, ngkpt in enumerate(ngkpts_for_dos):
        multi[2+i].set_vars(tolwfr=1e-15)
        multi[2+i].set_kmesh(ngkpt=ngkpt, shiftk=[0,0,0])

    inputs = multi.split_datasets()
    scf_input, nscf_input, dos_input = inputs[0], inputs[1], inputs[2:]

    return abilab.bandstructure_flow(workdir="flow_dos_bands", scf_input=scf_input, nscf_input=nscf_input,
                                     dos_inputs=dos_input)
예제 #45
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
예제 #46
0
def build_flow(options):
    structure = abilab.Structure.from_file(abidata.cif_file("si.cif"))

    scf_kppa = 40
    nscf_nband = 6
    ndivsm = 5
    #dos_ngkpt = [4,4,4]
    #dos_shiftk = [0.1, 0.2, 0.3]

    extra_abivars = dict(
        ecut=6, 
        timopt=-1,
        accesswff=3, 
        istwfk="*1",
    )

    # Working directory (default is the name of the script with '.py' removed and "run_" replaced by "flow_")
    workdir = options.workdir
    if not options.workdir:
        workdir = os.path.basename(__file__).replace(".py", "").replace("run_","flow_") 

    # Instantiate the TaskManager.
    manager = abilab.TaskManager.from_user_config() if not options.manager else \
              abilab.TaskManager.from_file(options.manager)

    # Initialize the flow.
    # FIXME  Abistructure is not pickleable with protocol -1
    flow = abilab.AbinitFlow(workdir=workdir, manager=manager, pickle_protocol=0)

    work = bandstructure(structure, abidata.pseudos("14si.pspnc"), scf_kppa, nscf_nband, ndivsm, 
                         spin_mode="unpolarized", smearing=None, **extra_abivars)

    flow.register_work(work)
    return flow.allocate()
예제 #47
0
파일: testing.py 프로젝트: gonzex/abipy
def get_gsinput_si(usepaw=0, as_task=False):
    # Build GS input file.
    pseudos = abidata.pseudos("14si.pspnc") if usepaw == 0 else data.pseudos("Si.GGA_PBE-JTH-paw.xml")
    #silicon = abilab.Structure.zincblende(5.431, ["Si", "Si"], units="ang")
    silicon = abidata.cif_file("si.cif")

    from abipy.abio.inputs import AbinitInput
    scf_input = AbinitInput(silicon, pseudos)
    ecut = 6
    scf_input.set_vars(
        ecut=ecut,
        pawecutdg=40,
        nband=6,
        paral_kgb=0,
        iomode=3,
        toldfe=1e-9,
    )
    if usepaw:
        scf_input.set_vars(pawecutdg=4 * ecut)

    # K-point sampling (shifted)
    scf_input.set_autokmesh(nksmall=4)
    if not as_task:
        return scf_input
    else:
        from abipy.flowtk.tasks import ScfTask
        return ScfTask(scf_input)
예제 #48
0
def build_flow(options):
    # Working directory (default is the name of the script with '.py' removed and "run_" replaced by "flow_")
    if not options.workdir:
        if os.getenv("READTHEDOCS", False):
            __file__ = os.path.join(os.getcwd(), "run_ht_si_ebands.py")
        options.workdir = os.path.basename(__file__).replace(
            ".py", "").replace("run_", "flow_")

    # Initialize structure and pseudos.
    structure = abilab.Structure.from_file(abidata.cif_file("si.cif"))
    pseudos = abidata.pseudos("14si.pspnc")

    # Initialize the flow.
    flow = flowtk.Flow(workdir=options.workdir, manager=options.manager)

    # Use the ebands_input factory function to build a MultiDataset.
    # keyword args are optional (default values are given or computed automatically, see docs).
    multi = abilab.ebands_input(structure,
                                pseudos,
                                kppa=40,
                                dos_kppa=80,
                                nscf_nband=6,
                                ndivsm=10,
                                ecut=6,
                                spin_mode="unpolarized")

    work = flowtk.BandStructureWork(scf_input=multi[0],
                                    nscf_input=multi[1],
                                    dos_inputs=multi[2])
    flow.register_work(work)

    return flow
예제 #49
0
def build_flow(options):
    # Working directory (default is the name of the script with '.py' removed and "run_" replaced by "flow_")
    if not options.workdir:
        options.workdir = os.path.basename(__file__).replace(".py", "").replace("run_", "flow_")

    # build the structures
    base_structure = abilab.Structure.from_file(data.cif_file("si.cif"))
    modifier = abilab.StructureModifier(base_structure)

    etas = [-0.1, 0, +0.1]
    ph_displ = np.reshape(np.zeros(3*len(base_structure)), (-1,3))
    ph_displ[0,:] = [+1, 0, 0]
    ph_displ[1,:] = [-1, 0, 0]

    displaced_structures = modifier.displace(ph_displ, etas, frac_coords=False)

    flow = flowtk.Flow(options.workdir, manager=options.manager)

    for structure in displaced_structures:
        # Create the work for the band structure calculation.
        scf_input, nscf_input = make_scf_nscf_inputs(structure)

        work = flowtk.BandStructureWork(scf_input, nscf_input)
        flow.register_work(work)

    return flow
예제 #50
0
    def test_znucl_typat(self):
        """Test the order of typat and znucl in the Abinit input and enforce_typat, enforce_znucl."""

        # Ga  Ga1  1  0.33333333333333  0.666666666666667  0.500880  1.0
        # Ga  Ga2  1  0.66666666666667  0.333333333333333  0.000880  1.0
        # N  N3  1  0.333333333333333  0.666666666666667  0.124120  1.0
        # N  N4  1  0.666666666666667  0.333333333333333  0.624120  1.0
        gan2 = Structure.from_file(abidata.cif_file("gan2.cif"))

        # By default, znucl is filled using the first new type found in sites.
        def_vars = gan2.to_abivars()
        def_znucl = def_vars["znucl"]
        self.assert_equal(def_znucl, [31, 7])
        def_typat = def_vars["typat"]
        self.assert_equal(def_typat, [1, 1, 2, 2])

        # But it's possible to enforce a particular value of typat and znucl.
        enforce_znucl = [7 ,31]
        enforce_typat = [2, 2, 1, 1]
        enf_vars = gan2.to_abivars(enforce_znucl=enforce_znucl, enforce_typat=enforce_typat)
        self.assert_equal(enf_vars["znucl"], enforce_znucl)
        self.assert_equal(enf_vars["typat"], enforce_typat)
        self.assert_equal(def_vars["xred"], enf_vars["xred"])

        assert [s.symbol for s in gan2.species_by_znucl] == ["Ga", "N"]

        for itype1, itype2 in zip(def_typat, enforce_typat):
            assert def_znucl[itype1 - 1] == enforce_znucl[itype2 -1]

        with self.assertRaises(Exception):
            gan2.to_abivars(enforce_znucl=enforce_znucl, enforce_typat=None)
예제 #51
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
예제 #52
0
def ion_relaxation(tvars, ntime=50):
    pseudos = abidata.pseudos("14si.pspnc")
    cif_file = abidata.cif_file("si.cif")
    structure = abilab.Structure.from_file(cif_file)

    # Perturb the structure (random perturbation of 0.1 Angstrom)
    structure.perturb(distance=0.02)

    global_vars = dict(
        ecut=6,
        ngkpt=[2,2,2],
        shiftk=[0,0,0],
        nshiftk=1,
        chksymbreak=0,
        paral_kgb=tvars.paral_kgb,
    )

    inp = abilab.AbiInput(pseudos=pseudos)
    inp.set_structure(structure)

    # Global variables
    inp.set_variables(**global_vars)

    # Dataset 1 (Atom Relaxation)
    inp[1].set_variables(
        optcell=0,
        ionmov=2,
        tolrff=0.02,
        tolmxf=5.0e-5,
        ntime=ntime,
        #dilatmx=1.05, # FIXME: abinit crashes if I don't use this
    )

    return inp
예제 #53
0
def make_flow(workdir="tmp_ht_si_ebands"):
    structure = AbiStructure.asabistructure(data.cif_file("si.cif"))

    scf_kppa = 40
    nscf_nband = 6
    ndivsm = 5
    #dos_ngkpt = [4,4,4]
    #dos_shiftk = [0.1, 0.2, 0.3]

    extra_abivars = dict(
        ecut=6, 
        timopt=-1,
        accesswff=3, 
        istwfk="*1",
    )

    manager = abilab.TaskManager.from_user_config()

    # Initialize the flow.
    # FIXME  Abistructure is not pickleable with protocol -1
    flow = abilab.AbinitFlow(workdir=workdir, manager=manager, pickle_protocol=0)

    work = bandstructure(structure, data.pseudos("14si.pspnc"), scf_kppa, nscf_nband, ndivsm, 
                         spin_mode="unpolarized", smearing=None, **extra_abivars)

    flow.register_work(work)
    return flow.allocate()
예제 #54
0
def inputs_relax_si_low():
    pseudos = abidata.pseudos("14si.pspnc")
    cif_file = abidata.cif_file("si.cif")
    structure = abilab.Structure.from_file(cif_file)
    structure.apply_strain(0.005)
    structure.translate_sites(0, [0.001, -0.003, 0.005])
    structure.translate_sites(1, [0.007, 0.006, -0.005])
    return ion_ioncell_relax_input(structure, pseudos, kppa=100, ecut=4).split_datasets()