def raman_flow(): # Get the unperturbed structure. base_structure = abilab.Structure.from_abivars(unit_cell) pseudos = ["14si.pspnc"] workdir = os.path.join(os.path.dirname(__file__), "test_abipy_new") manager = abilab.TaskManager.from_user_config() #manager = abilab.TaskManager.from_file("bfo_manager.yml") policy = TaskPolicy(autoparal=0) gs_manager = manager.deepcopy() # Initialize flow. Each workflow in the flow defines a complete BSE calculation for given eta. flow = abilab.Flow(workdir, manager) # There will be kppa/natom kpoints in the unit cell ! kppa = 3456 # ngkpt = [12,12,12] for the primitive cell kppa_gs = 1728 # ngkpt = [8,8,8] for the primitive cell etas = [-1, 0, 1] # Anyway, it rescales everything at the end :-) eta = 0.01 scale_matrix = [[-1, 0, 1], [-1, 1, 0], [-1, -1, 0]] ph_tot = np.array([[0.01, 0.011, 0.021], [-0.01, 0.041, -0.02]]) modifier = abilab.StructureModifier(base_structure) displaced_structure = modifier.frozen_phonon([0.5, 0.5, 0.5], ph_tot, do_real=True, frac_coords=False, scale_matrix=scale_matrix) structure = displaced_structure ksampgs = KSampling.automatic_density(structure, kppa_gs, chksymbreak=0, shifts=[0, 0, 0]) gs_inp = gs_input(structure, pseudos, ksampgs) wflow = abilab.Work() gs_t = wflow.register_scf_task(gs_inp) gs_t.set_manager(gs_manager) flow.register_work(wflow, workdir="gs_task") ksamp = KSampling.automatic_density(structure, kppa, chksymbreak=0, shifts=[1 / 4, 1 / 4, 1 / 4]) flow.register_work(raman_workflow(structure, pseudos, gs_t, ksamp), workdir="bse_task") return flow.allocate()
def test_base(self): monkhorst = KSampling.monkhorst((3, 3, 3), (0.5, 0.5, 0.5), 0, False, False) gamma_centered = KSampling.gamma_centered((3, 3, 3), False, False) monkhorst.to_abivars() # Test dict methods self.assertMSONable(monkhorst) self.assertMSONable(gamma_centered)
def raman_flow(): # Get the unperturbed structure. base_structure = abilab.Structure.from_abivars(unit_cell) pseudos=["14si.pspnc"] workdir = os.path.join(os.path.dirname(__file__), "test_abipy_new") manager = abilab.TaskManager.from_user_config() #manager = abilab.TaskManager.from_file("bfo_manager.yml") policy = TaskPolicy(autoparal=0) gs_manager = manager.deepcopy() # Initialize flow. Each workflow in the flow defines a complete BSE calculation for given eta. flow = abilab.Flow(workdir, manager) # There will be kppa/natom kpoints in the unit cell ! kppa = 3456 # ngkpt = [12,12,12] for the primitive cell kppa_gs = 1728 # ngkpt = [8,8,8] for the primitive cell etas = [-1,0,1] # Anyway, it rescales everything at the end :-) eta=0.01 scale_matrix = [[-1,0,1],[-1,1,0],[-1,-1,0]] ph_tot = np.array([[0.01,0.011,0.021],[-0.01,0.041,-0.02]]) modifier = abilab.StructureModifier(base_structure) displaced_structure = modifier.frozen_phonon([0.5,0.5,0.5],ph_tot,do_real=True,frac_coords=False,scale_matrix=scale_matrix) structure = displaced_structure ksampgs = KSampling.automatic_density(structure,kppa_gs,chksymbreak=0,shifts=[0,0,0]) gs_inp = gs_input(structure,pseudos, ksampgs) wflow = abilab.Work() gs_t = wflow.register_scf_task(gs_inp) gs_t.set_manager(gs_manager) flow.register_work(wflow,workdir="gs_task") ksamp = KSampling.automatic_density(structure,kppa,chksymbreak=0,shifts=[1/4,1/4,1/4]) flow.register_work(raman_workflow(structure, pseudos, gs_t, ksamp),workdir="bse_task") return flow.allocate()
def __init__(self, a_guess, struct_type, pseudo, ecut_list=None, pawecutdg=None, ngkpt=(8, 8, 8), spin_mode="unpolarized", include_soc=False, tolvrs=1.e-10, smearing="fermi_dirac:0.001 Ha", ecutsm=0.05, chksymbreak=0, workdir=None, manager=None): """ Build a :class:`Work` for the computation of the relaxed lattice parameter. Args: structure_type: fcc, bcc pseudo: :class:`Pseudo` object. ecut_list: Cutoff energy in Hartree ngkpt: MP divisions. spin_mode: Spin polarization mode. toldfe: Tolerance on the energy (Ha) smearing: Smearing technique. workdir: String specifing the working directory. manager: :class:`TaskManager` responsible for the submission of the tasks. """ super(RelaxWithGbrvParamsWork, self).__init__(workdir=workdir, manager=manager) self_pseudo = pseudo self.include_soc = include_soc self.struct_type = struct_type if struct_type == "bcc": structure = Structure.bcc(a_guess, species=[pseudo.symbol]) elif struct_type == "fcc": structure = Structure.fcc(a_guess, species=[pseudo.symbol]) # Set extra_abivars. extra_abivars = dict( pawecutdg=pawecutdg, tolvrs=tolvrs, prtwf=-1, fband=3.0, nstep=100, ntime=50, ecutsm=ecutsm, dilatmx=1.1, ) self.ecut_list = ecut_list smearing = Smearing.as_smearing(smearing) # Kpoint sampling: shiftk depends on struct_type shiftk = {"fcc": [0, 0, 0], "bcc": [0.5, 0.5, 0.5]}.get(struct_type) spin_mode = SpinMode.as_spinmode(spin_mode) ksampling = KSampling.monkhorst(ngkpt, chksymbreak=chksymbreak, shiftk=shiftk, use_time_reversal=spin_mode.nspinor==1) relax_algo = RelaxationMethod.atoms_and_cell() inp = abilab.AbinitInput(structure, pseudo) inp.add_abiobjects(ksampling, relax_algo, spin_mode, smearing) inp.set_vars(extra_abivars) # Register structure relaxation task. for ecut in self.ecut_list: self.relax_task = self.register_relax_task(inp.new_with_vars(ecut=ecut))
def __init__(self, structure, struct_type, pseudo, ecut=None, pawecutdg=None, ngkpt=(8, 8, 8), spin_mode="unpolarized", include_soc=False, toldfe=1.e-9, smearing="fermi_dirac:0.001 Ha", ecutsm=0.05, chksymbreak=0, workdir=None, manager=None, **kwargs): """ Build a :class:`Work` for the computation of the relaxed lattice parameter. Args: structure: :class:`Structure` object structure_type: fcc, bcc pseudo: :class:`Pseudo` object. ecut: Cutoff energy in Hartree ngkpt: MP divisions. spin_mode: Spin polarization mode. toldfe: Tolerance on the energy (Ha) smearing: Smearing technique. workdir: String specifing the working directory. manager: :class:`TaskManager` responsible for the submission of the tasks. """ super(GbrvRelaxAndEosWork, self).__init__(workdir=workdir, manager=manager) self.struct_type = struct_type # nband must be large enough to accomodate fractional occupancies. self._pseudo = pseudo self.include_soc = include_soc def gbrv_nband(pseudo): # nband/fband are usually too small for the GBRV calculations. # FIXME this is not optimal nband = pseudo.Z_val nband += 0.5 * nband nband = int(nband) nband = max(nband, 8) # Use even numer of bands. Needed when nspinor == 2 if nband % 2 != 0: nband += 1 return nband nband = gbrv_nband(self.dojo_pseudo) # Set extra_abivars. self.extra_abivars = dict( ecut=ecut, pawecutdg=pawecutdg, toldfe=toldfe, prtwf=-1, nband=nband, #ecutsm=0.5, #paral_kgb=paral_kgb ) self.extra_abivars.update(**kwargs) self.ecut = ecut self.smearing = Smearing.as_smearing(smearing) # Kpoint sampling: shiftk depends on struct_type shiftk = {"fcc": [0, 0, 0], "bcc": [0.5, 0.5, 0.5]}.get(struct_type) self.spin_mode = SpinMode.as_spinmode(spin_mode) self.ksampling = KSampling.monkhorst(ngkpt, chksymbreak=chksymbreak, shiftk=shiftk, use_time_reversal=self.spin_mode.nspinor==1) relax_algo = RelaxationMethod.atoms_and_cell() inp = abilab.AbinitInput(structure, pseudo) inp.add_abiobjects(self.ksampling, relax_algo, self.spin_mode, self.smearing) inp.set_vars(self.extra_abivars) # Register structure relaxation task. self.relax_task = self.register_relax_task(inp)
def __init__(self, structure, pseudo, kppa, connect, ecut=None, pawecutdg=None, ecutsm=0.5, spin_mode="polarized", include_soc=False, toldfe=1.e-9, smearing="fermi_dirac:0.1 eV", chksymbreak=0, workdir=None, manager=None, **kwargs): """ Build a :class:`Work` for the computation of the deltafactor. Args: structure: :class:`Structure` object pseudo: :class:`Pseudo` object. kppa: Number of k-points per reciprocal atom. connect: True if the SCF run should be initialized from the previous run. spin_mode: Spin polarization mode. toldfe: Tolerance on the energy (Ha) smearing: Smearing technique. workdir: String specifing the working directory. manager: :class:`TaskManager` responsible for the submission of the tasks. """ super(DeltaFactorWork, self).__init__(workdir=workdir, manager=manager) self._pseudo = pseudo self.include_soc = include_soc spin_mode = SpinMode.as_spinmode(spin_mode) smearing = Smearing.as_smearing(smearing) # Compute the number of bands from the pseudo and the spin-polarization. # Add 6 bands to account for smearing. #nval = structure.num_valence_electrons(self.pseudo) #nband = int(nval / spin_mode.nsppol) + 6 # Set extra_abivars self.ecut, self.pawecutdg = ecut, pawecutdg extra_abivars = dict( ecut=ecut, pawecutdg=pawecutdg, ecutsm=ecutsm, toldfe=toldfe, prtwf=-1 if not connect else 1, chkprim=0, nstep=200, fband=2.0, # 0.5 is the default value but it's not large enough from some systems. #paral_kgb=paral_kgb, #nband=nband, #mem_test=0, ) extra_abivars.update(**kwargs) self._input_structure = structure v0 = structure.volume # From 94% to 106% of the equilibrium volume. self.volumes = v0 * np.arange(94, 108, 2) / 100. for vol in self.volumes: # Build new structure new_lattice = structure.lattice.scale(vol) new_structure = Structure(new_lattice, structure.species, structure.frac_coords) ksampling = KSampling.automatic_density(new_structure, kppa, chksymbreak=chksymbreak, use_time_reversal=spin_mode.nspinor==1) scf_input = abilab.AbinitInput(structure=new_structure, pseudos=self.dojo_pseudo) scf_input.add_abiobjects(ksampling, smearing, spin_mode) scf_input.set_vars(extra_abivars) # Magnetic materials with nspinor = 2 requires connection # and a double SCF run (nsppol = 2 first then nspinor = 2). if connect and spin_mode.nspinor == 2: print("Using collinear then noncollinear scf task") self.register_collinear_then_noncollinear_scf_task(scf_input) else: self.register_scf_task(scf_input) if connect: logger.info("Connecting SCF tasks using previous WFK file") middle = len(self.volumes) // 2 filetype = "WFK" for i, task in enumerate(self[:middle]): task.add_deps({self[i + 1]: filetype}) for i, task in enumerate(self[middle+1:]): task.add_deps({self[middle + i]: filetype})
def __init__(self, structure, pseudo, kppa, maxene, ecut=None, pawecutdg=None, ecutsm=0.5, spin_mode="unpolarized", include_soc=False, tolwfr=1.e-15, smearing="fermi_dirac:0.1 eV", chksymbreak=0, workdir=None, manager=None, **kwargs): """ Build a :class:`Work` for the computation of a bandstructure to check for ghosts. Args: structure: :class:`Structure` object pseudo: String with the name of the pseudopotential file or :class:`Pseudo` object. kppa: Number of k-points per reciprocal atom. maxene: 250 eV spin_mode: Spin polarization mode. include_soc=True of SOC should be included. tolwfr: Stopping criterion. smearing: Smearing technique. workdir: String specifing the working directory. manager: :class:`TaskManager` responsible for the submission of the tasks. """ super(GhostsWork, self).__init__(workdir=workdir, manager=manager) self._pseudo = pseudo self.include_soc = include_soc spin_mode = SpinMode.as_spinmode(spin_mode) smearing = Smearing.as_smearing(smearing) # Here we find an initial guess for the number of bands # The goal is to reach maxene eV above the fermi level. # Assume ~ b4ev fact eV per band # Add a buffer of nbdbuf states and enforce an even number of states nval = structure.num_valence_electrons(self.dojo_pseudo) self.maxene = maxene b4ev = 1.3 nband = int(nval + int(b4ev * self.maxene)) #nband = nval // 2 + 10 if spin_mode.nsppol == 1: nband // 2 nbdbuf = max(int(0.1 * nband), 4) nband += nbdbuf nband += nband % 2 # Set extra_abivars self.ecut, self.pawecutdg = ecut, pawecutdg extra_abivars = dict( ecut=ecut, pawecutdg=pawecutdg, ecutsm=ecutsm, nband=int(nband), nbdbuf=int(nbdbuf), tolwfr=tolwfr, #prtwf=0, nstep=200, chkprim=0, mem_test=0 ) extra_abivars.update(**kwargs) # Disable time-reversal if nspinor == 2 self.kppa = kppa ksampling = KSampling.automatic_density(structure, kppa, chksymbreak=chksymbreak, use_time_reversal=spin_mode.nspinor==1) scf_input = abilab.AbinitInput(structure=structure, pseudos=self.dojo_pseudo) scf_input.add_abiobjects(ksampling, smearing, spin_mode) scf_input.set_vars(extra_abivars) self.register_scf_task(scf_input) self.dojo_status = 0
def get_anaddb_input(self, item): """ creates the AnaddbInput object. It also returns the list of qpoints labels for generating the PhononBandStructureSymmLine. """ ngqpt = item["abinit_input.ngqpt"] q1shft = [(0, 0, 0)] structure = Structure.from_dict(item["abinit_input.structure"]) hs = HighSymmKpath(structure, symprec=1e-2) spgn = hs._sym.get_space_group_number() if spgn != item["spacegroup.number"]: raise RuntimeError("Parsed specegroup number {} does not match " "calculation spacegroup {}".format(spgn, item["spacegroup.number"])) # for the moment use gaussian smearing prtdos = 1 dossmear = 3 / Ha_cmm1 lo_to_splitting = True dipdip = 1 asr = 2 chneut = 1 ng2qppa = 50000 inp = AnaddbInput(structure, comment="ANADB input for phonon bands and DOS") inp.set_vars( ifcflag=1, ngqpt=np.array(ngqpt), q1shft=q1shft, nqshft=len(q1shft), asr=asr, chneut=chneut, dipdip=dipdip, ) # Parameters for the dos. ng2qpt = KSampling.automatic_density(structure, kppa=ng2qppa).kpts[0] inp.set_vars(prtdos=prtdos, dosdeltae=None, dossmear=dossmear, ng2qpt=ng2qpt) # Parameters for the BS qpts, labels_list = hs.get_kpoints(line_density=18, coords_are_cartesian=False) n_qpoints = len(qpts) qph1l = np.zeros((n_qpoints, 4)) qph1l[:, :-1] = qpts qph1l[:, -1] = 1 inp['qph1l'] = qph1l.tolist() inp['nph1l'] = n_qpoints if lo_to_splitting: kpath = hs.kpath directions = [] for qptbounds in kpath['path']: for i, qpt in enumerate(qptbounds): if np.array_equal(kpath['kpoints'][qpt], (0, 0, 0)): # anaddb expects cartesian coordinates for the qph2l list if i > 0: directions.extend(structure.lattice.reciprocal_lattice_crystallographic.get_cartesian_coords( kpath['kpoints'][qptbounds[i - 1]])) directions.append(0) if i < len(qptbounds) - 1: directions.extend(structure.lattice.reciprocal_lattice_crystallographic.get_cartesian_coords( kpath['kpoints'][qptbounds[i + 1]])) directions.append(0) if directions: directions = np.reshape(directions, (-1, 4)) inp.set_vars( nph2l=len(directions), qph2l=directions ) return inp, labels_list
def __init__(self, structure, formula, struct_type, pseudos, xc, accuracy, ecut=None, pawecutdg=None, ngkpt=(8, 8, 8), fband=2.0, spin_mode="unpolarized", smearing="fermi_dirac:0.001 Ha", chksymbreak=0, workdir=None, manager=None): """ Build a :class:`Work` for the computation of the relaxed lattice parameter. Args: structure: :class:`Structure` object. struct_type: fcc, bcc pseudos: Pseudopotentials xc: Exchange-correlation type. accuracy: ecut: Cutoff energy in Hartree ngkpt: Divisions for k-mesh. fband: Input variable, used to compute the number of bands. spin_mode: Spin polarization mode. smearing: Smearing technique. chksymbreak: Input variable. workdir: String specifing the working directory. manager: :class:`TaskManager` responsible for the submission of the tasks. """ super(GbrvCompoundRelaxAndEosWork, self).__init__(workdir=workdir, manager=manager) self.pseudos = pseudos self.xc = xc if (any(xc != p.xc for p in pseudos)): raise ValueError("Input XC does not agree with XC from pseudos.") self.formula = formula self.struct_type = struct_type self.accuracy = accuracy self.ecut, self.pawecutdg = ecut, pawecutdg # Set extra_abivars. # Use tolvrs for the relaxation, toldfe for the EOS self.extra_abivars = dict( ecut=ecut, pawecutdg=pawecutdg, tolvrs=1e-10, ecutsm=0.5, mem_test=0, fband=fband, # nband must be large enough to accomodate fractional occupancies. #paral_kgb=kwargs.pop("paral_kgb", 0), #nband=nband, ) self.smearing = Smearing.as_smearing(smearing) # Kpoint sampling: shiftk depends on struct_type #shiftk = {"fcc": [0, 0, 0], "bcc": [0.5, 0.5, 0.5]}.get(struct_type) shiftk = [0, 0, 0] self.ksampling = KSampling.monkhorst(ngkpt, chksymbreak=chksymbreak, shiftk=shiftk) self.spin_mode = SpinMode.as_spinmode(spin_mode) relax_algo = RelaxationMethod.atoms_and_cell() inp = abilab.AbinitInput(structure, pseudos) inp.add_abiobjects(self.ksampling, relax_algo, self.spin_mode, self.smearing) inp.set_vars(self.extra_abivars) # Register structure relaxation task. self.relax_task = self.register_relax_task(inp)