def anaget_emacro_and_becs(self, chneut=1, workdir=None, manager=None, verbose=0): """ Call anaddb to compute the macroscopic dielectric tensor and the Born effective charges. Args: chneut: Anaddb input variable. See official documentation. manager: :class:`TaskManager` object. If None, the object is initialized from the configuration file verbose: verbosity level. Set it to a value > 0 to get more information Return: emacro, becs """ inp = AnaddbInput(self.structure, anaddb_kwargs={"chneut": chneut}) task = AnaddbTask.temp_shell_task(inp, ddb_node=self.filepath, workdir=workdir, manager=manager) if verbose: print("ANADDB INPUT:\n", inp) print("workdir:", task.workdir) # Run the task here. task.start_and_wait(autoparal=False) report = task.get_event_report() if not report.run_completed: raise self.AnaddbError(task=task, report=report) # Read data from the netcdf output file produced by anaddb. with ETSF_Reader(os.path.join(task.workdir, "anaddb.nc")) as r: structure = r.read_structure() emacro = Tensor.from_cartesian_tensor(r.read_value("emacro_cart"), structure.lattice, space="r"), becs = Becs(r.read_value("becs_cart"), structure, chneut=inp["chneut"], order="f") return emacro, becs
def calc_phmodes_at_qpoint(self, qpoint=None, asr=2, chneut=1, dipdip=1, workdir=None, manager=None, verbose=0, ret_task=False): """ Execute anaddb to compute phonon modes at the given q-point. Args: qpoint: Reduced coordinates of the qpoint where phonon modes are computed asr, chneut, dipdp: Anaddb input variable. See official documentation. workdir: Working directory. If None, a temporary directory is created. manager: :class:`TaskManager` object. If None, the object is initialized from the configuration file verbose: verbosity level. Set it to a value > 0 to get more information """ if qpoint is None: qpoint = self.qpoints[0] if len(self.qpoints) != 1: raise ValueError("%s contains %s qpoints and the choice is ambiguous.\n" "Please specify the qpoint in calc_phmodes_at_qpoint" % (self, len(self.qpoints))) inp = AnaddbInput.modes_at_qpoint(self.structure, qpoint, asr=asr, chneut=chneut, dipdip=dipdip) if manager is None: manager = TaskManager.from_user_config() if workdir is None: workdir = tempfile.mkdtemp() if verbose: print("workdir:", workdir) print("ANADDB INPUT:\n", inp) task = AnaddbTask(inp, self.filepath, workdir=workdir, manager=manager.to_shell_manager(mpi_procs=1)) if ret_task: return task # Run the task here task.start_and_wait(autoparal=False) report = task.get_event_report() if not report.run_completed: raise TaskException(task=task, report=report) with task.open_phbst() as ncfile: return ncfile.phbands
def anaget_phmodes_at_qpoint(self, qpoint=None, asr=2, chneut=1, dipdip=1, workdir=None, manager=None, verbose=0): """ Execute anaddb to compute phonon modes at the given q-point. Args: qpoint: Reduced coordinates of the qpoint where phonon modes are computed. asr, chneut, dipdp: Anaddb input variable. See official documentation. workdir: Working directory. If None, a temporary directory is created. manager: :class:`TaskManager` object. If None, the object is initialized from the configuration file verbose: verbosity level. Set it to a value > 0 to get more information Return: :class:`PhononBands` object. """ if qpoint is None: qpoint = self.qpoints[0] if len(self.qpoints) != 1: raise ValueError("%s contains %s qpoints and the choice is ambiguous.\n" "Please specify the qpoint." % (self, len(self.qpoints))) # Check if qpoint is in the DDB. try: self.qindex(qpoint) except: raise ValueError("input qpoint %s not in ddb.qpoints:%s\n" % (qpoint, self.qpoints)) inp = AnaddbInput.modes_at_qpoint(self.structure, qpoint, asr=asr, chneut=chneut, dipdip=dipdip) task = AnaddbTask.temp_shell_task(inp, ddb_node=self.filepath, workdir=workdir, manager=manager) if verbose: print("ANADDB INPUT:\n", inp) print("workdir:", task.workdir) # Run the task here task.start_and_wait(autoparal=False) report = task.get_event_report() if not report.run_completed: raise self.AnaddbError(task=task, report=report) with task.open_phbst() as ncfile: return ncfile.phbands
def anaget_phbst_and_phdos_files(self, nqsmall=10, ndivsm=20, asr=2, chneut=1, dipdip=1, dos_method="tetra", ngqpt=None, workdir=None, manager=None, verbose=0): """ Execute anaddb to compute the phonon band structure and the phonon DOS Args: nqsmall: Defines the homogeneous q-mesh used for the DOS. Gives the number of divisions used to sample the smallest lattice vector. ndivsm: Number of division used for the smallest segment of the q-path asr, chneut, dipdp: Anaddb input variable. See official documentation. dos_method: Technique for DOS computation in Possible choices: "tetra", "gaussian" or "gaussian:0.001 eV". In the later case, the value 0.001 eV is used as gaussian broadening ngqpt: Number of divisions for the q-mesh in the DDB file. Auto-detected if None (default) workdir: Working directory. If None, a temporary directory is created. manager: :class:`TaskManager` object. If None, the object is initialized from the configuration file verbose: verbosity level. Set it to a value > 0 to get more information Returns: :class:`PhbstFile` with the phonon band structure. :class:`PhdosFile` with the the phonon DOS. """ if ngqpt is None: ngqpt = self.guessed_ngqpt inp = AnaddbInput.phbands_and_dos( self.structure, ngqpt=ngqpt, ndivsm=ndivsm, nqsmall=nqsmall, q1shft=(0,0,0), qptbounds=None, asr=asr, chneut=chneut, dipdip=dipdip, dos_method=dos_method) task = AnaddbTask.temp_shell_task(inp, ddb_node=self.filepath, workdir=workdir, manager=manager) if verbose: print("ANADDB INPUT:\n", inp) print("workdir:", task.workdir) # Run the task here. task.start_and_wait(autoparal=False) report = task.get_event_report() if not report.run_completed: raise self.AnaddbError(task=task, report=report) return task.open_phbst(), task.open_phdos()
def calc_phbands_and_dos(self, ngqpt=None, ndivsm=20, nqsmall=10, asr=2, chneut=1, dipdip=1, dos_method="tetra", workdir=None, manager=None, verbose=0, plot=True, ret_task=False): """ Execute anaddb to compute the phonon band structure and the phonon DOS Args: ngqpt: Number of divisions for the q-mesh in the DDB file. Auto-detected if None (default) asr, chneut, dipdp: Anaddb input variable. See official documentation. workdir: Working directory. If None, a temporary directory is created. manager: :class:`TaskManager` object. If None, the object is initialized from the configuration file verbose: verbosity level. Set it to a value > 0 to get more information """ if ngqpt is None: ngqpt = self.guessed_ngqpt inp = AnaddbInput.phbands_and_dos( self.structure, ngqpt=ngqpt, ndivsm=ndivsm, nqsmall=nqsmall, q1shft=(0,0,0), qptbounds=None, asr=asr, chneut=chneut, dipdip=dipdip, dos_method=dos_method) if manager is None: manager = TaskManager.from_user_config() if workdir is None: workdir = tempfile.mkdtemp() if verbose: print("workdir:", workdir) print("ANADDB INPUT:\n", inp) task = AnaddbTask(inp, self.filepath, workdir=workdir, manager=manager.to_shell_manager(mpi_procs=1)) if ret_task: return task # Run the task here. task.start_and_wait(autoparal=False) report = task.get_event_report() if not report.run_completed: raise TaskException(task=task, report=report) with task.open_phbst() as phbst_ncfile, task.open_phdos() as phdos_ncfile: phbands, phdos = phbst_ncfile.phbands, phdos_ncfile.phdos if plot: phbands.plot_with_phdos(phdos, title="Phonon bands and DOS of %s" % self.structure.formula) return phbands, phdos