def build_flow(options):
    """
    Create an `AbinitFlow` for phonon calculations:

        1) One workflow for the GS run.

        2) nqpt workflows for phonon calculations. Each workflow contains 
           nirred tasks where nirred is the number of irreducible phonon perturbations
           for that particular q-point.
    """
    # 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)

    all_inps = scf_ph_inputs()
    scf_input, ph_inputs = all_inps[0], all_inps[1:]

    flow = abilab.Flow(workdir, manager=manager)
    from pymatgen.io.abinitio.works import build_oneshot_phononwork
    work = build_oneshot_phononwork(scf_input, ph_inputs)
    flow.register_work(work)

    return flow.allocate()
示例#2
0
def build_flow(options):
    """
    Create an `AbinitFlow` for phonon calculations:

        1) One workflow for the GS run.

        2) nqpt workflows for phonon calculations. Each workflow contains 
           nirred tasks where nirred is the number of irreducible phonon perturbations
           for that particular q-point.
    """
    # 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_")

    all_inps = scf_ph_inputs()
    scf_input, ph_inputs = all_inps[0], all_inps[1:]

    flow = abilab.Flow(workdir, manager=options.manager)
    from pymatgen.io.abinitio.works import build_oneshot_phononwork
    work = build_oneshot_phononwork(scf_input, ph_inputs)
    flow.register_work(work)

    return flow
示例#3
0
def itest_oneshot_phonon_work(fwp):
    """
    Test build_oneshot_phononwork i.e. computation of the phonon frequencies
    for all modes in a single task.
    """
    all_inps = scf_ph_inputs()

    # SCF + one-shot for the first 2 qpoints.
    scf_input, ph_inputs = all_inps[0], all_inps[1:3]

    from pymatgen.io.abinitio.works import build_oneshot_phononwork
    flow = abilab.Flow(fwp.workdir)

    # rfdir and rfatpol are missing!
    with pytest.raises(ValueError):
        phon_work = build_oneshot_phononwork(scf_input, ph_inputs)
    for phinp in ph_inputs: phinp.set_vars(rfdir=[1, 1, 1])

    with pytest.raises(ValueError):
        phon_work = build_oneshot_phononwork(scf_input, ph_inputs)
    for phinp in ph_inputs: phinp.set_vars(rfatpol=[1, len(phinp.structure)])

    # Now ph_inputs is ok
    phon_work = build_oneshot_phononwork(scf_input, ph_inputs)
    flow.register_work(phon_work)

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

    flow.check_status(show=True, verbose=1)
    assert all(work.finalized for work in flow)
    assert flow.all_ok
    
    # Read phonons from main output file.
    phonons_list = phon_work.read_phonons()
    assert len(phonons_list) == 2

    ph0, ph1 = phonons_list[0], phonons_list[1]
    assert ph0.qpt == [0, 0, 0]
    assert ph1.qpt == [2.50000000E-01,  0.00000000E+00,  0.00000000E+00]
    assert len(ph0.freqs) == 3 * len(scf_input.structure)
    assert len(ph1.freqs) == 3 * len(scf_input.structure)
    nptu.assert_almost_equal(ph0.freqs.to("Ha"), 
        [-1.219120E-05, -1.201501E-05, -1.198453E-05,  1.577646E-03,  1.577647E-03, 1.577647E-03])
    nptu.assert_almost_equal(ph1.freqs.to("Ha"), 
        [2.644207E-04, 2.644236E-04, 6.420904E-04, 1.532696E-03, 1.532697E-03, 1.707196E-03])
示例#4
0
    def work_for_pseudo(self, pseudo, **kwargs):
        """
        Create a :class:`Flow` for phonon calculations:

            1) One workflow for the GS run.

            2) nqpt workflows for phonon calculations. Each workflow contains
               nirred tasks where nirred is the number of irreducible phonon perturbations
               for that particular q-point.

            the kwargs are passed to scf_hp_inputs
        """
        try:
            qpt = kwargs['qpt']
        except IndexError:
            raise ValueError('A phonon test needs to specify a qpoint.')

        kwargs.pop('accuracy')

        pseudo = Pseudo.as_pseudo(pseudo)

        structure_or_cif = self.get_cif_path(pseudo.symbol)

        if not isinstance(structure_or_cif, Structure):
            # Assume CIF file
            structure = Structure.from_file(structure_or_cif, primitive=False)
        else:
            structure = structure_or_cif

        nat = len(structure)
        report = pseudo.read_dojo_report()
        ecut_str = '%.1f' % kwargs['ecut']
        #print(ecut_str)
        #print(report['deltafactor'][float(ecut_str)].keys())

        try:
            v0 = nat * report['deltafactor'][ecut_str]['v0']
        except KeyError:
            try:
                v0 = nat * report['deltafactor'][float(ecut_str)]['v0']
            except KeyError:
                # the df calculation at this ecut is not done already so the phonon task can not be created
                return None

        structure.scale_lattice(v0)
        all_inps = self.scf_ph_inputs(pseudos=[pseudo], structure=structure, **kwargs)
        scf_input, ph_inputs = all_inps[0], all_inps[1:]

        work = build_oneshot_phononwork(scf_input=scf_input, ph_inputs=ph_inputs, work_class=PhononDojoWork)
        #print('after build_oneshot_phonon')
        #print(work)
        work.set_dojo_trial(qpt)
        #print(scf_input.keys())
        work.ecut = scf_input['ecut']
        work._pseudo = pseudo
        return work