示例#1
0
文件: ifc.py 项目: jbouquiaux/abipy
    def from_file(cls, filepath):
        """Create the object from a netcdf_ file."""
        with ETSF_Reader(filepath) as r:
            try:
                structure = r.read_structure()
                atoms_indices = r.read_value("ifc_atoms_indices") - 1
                neighbours_indices = r.read_value("ifc_neighbours_indices") - 1
                distances = r.read_value("ifc_distances")
                ifc_cart_coord = r.read_value("ifc_matrix_cart_coord")
                ifc_cart_coord_short_range = r.read_value(
                    "ifc_matrix_cart_coord_short_range", default=None)
                local_vectors = r.read_value("ifc_local_vectors", default=None)
                # The following are set to None by default to keep backward
                # compatibility with anaddb.nc files generated by versions of abinit<9.2
                atoms_cart_coord = r.read_value("ifc_atoms_cart_coord",
                                                default=None)
                ifc_weights = r.read_value("ifc_weights", default=None)
            except Exception:
                import traceback
                msg = traceback.format_exc()
                msg += (
                    "Error while trying to read IFCs from file.\n"
                    "Verify that the required variables are used in anaddb: ifcflag, natifc, atifc, ifcout\n"
                )
                raise ValueError(msg)

            return cls(structure=structure,
                       atoms_indices=atoms_indices,
                       neighbours_indices=neighbours_indices,
                       ifc_cart_coord=ifc_cart_coord,
                       ifc_cart_coord_short_range=ifc_cart_coord_short_range,
                       local_vectors=local_vectors,
                       distances=distances,
                       atoms_cart_coord=atoms_cart_coord,
                       ifc_weights=ifc_weights)
示例#2
0
    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
示例#3
0
    def from_file(cls, filepath):
        """
        Reads the non analytical directions, frequencies and displacements from the anaddb.nc file specified.
        Non existence of displacements is accepted for compatibility with abinit 8.0.6
        Raises an error if the other values are not present in anaddb.nc.
        """
        with ETSF_Reader(filepath) as r:
            directions = r.read_value("non_analytical_directions")
            phfreq = r.read_value("non_analytical_phonon_modes")

            # need a default as the first abinit version including IFCs in the netcdf doesn't have this attribute
            phdispl_cart = r.read_value("non_analytical_phdispl_cart",
                                        cmode="c",
                                        default=None)

            structure = r.read_structure()

            amu_list = r.read_value("atomic_mass_units", default=None)
            if amu_list is not None:
                # ntypat arrays
                atomic_numbers = r.read_value("atomic_numbers")
                amu = {at: a for at, a in zip(atomic_numbers, amu_list)}
            else:
                amu = None

            return cls(structure=structure,
                       directions=directions,
                       phfreqs=phfreq,
                       phdispl_cart=phdispl_cart,
                       amu=amu)
示例#4
0
文件: v1sym.py 项目: xue-smile/abipy
 def __init__(self, filepath):
     super().__init__(filepath)
     self.reader = r = ETSF_Reader(filepath)
     # Read dimensions.
     self.nfft = r.read_dimvalue("nfft")
     self.nspden = r.read_dimvalue("nspden")
     self.natom3 = len(self.structure) * 3
     self.symv1scf = r.read_value("symv1scf")
示例#5
0
 def __init__(self, filepath):
     super().__init__(filepath)
     self.reader = r = ETSF_Reader(filepath)
     self.has_zeff = bool(r.read_value("has_zeff"))
     self.has_dielt = bool(r.read_value("has_dielt"))
     self.has_quadrupoles = bool(r.read_value("has_quadrupoles"))
     self.dvdb_add_lr = r.read_value("dvdb_add_lr")
     self.symv1 = bool(r.read_value("symv1"))
示例#6
0
 def __init__(self, filepath):
     super().__init__(filepath)
     self.reader = r = ETSF_Reader(filepath)
     # Read medadata
     self.has_zeff = bool(r.read_value("has_zeff"))
     self.has_dielt = bool(r.read_value("has_dielt"))
     self.has_quadrupoles = bool(r.read_value("has_quadrupoles"))
     self.has_efield = bool(r.read_value("has_efield", default=False))
     self.dvdb_add_lr = r.read_value("dvdb_add_lr")
     self.symv1scf = r.read_value("symv1scf")
     self.interpolated = bool(r.read_value("interpolated"))
     self.qdamp = r.read_value("qdamp")
示例#7
0
 def from_file(cls, filepath):
     """
     Creates the tensor from a anaddb.nc netcdf file containing ``dchide``.
     This requires to run anaddb with ``tnlflag`` > 0
     """
     with ETSF_Reader(filepath) as reader:
         try:
             return cls(reader.read_value("dchide"))
         except Exception as exc:
             import traceback
             msg = traceback.format_exc()
             msg += ("Error while trying to read from file.\n"
                     "Verify that nlflag > 0 in anaddb\n")
             raise ValueError(msg)
示例#8
0
    def OnAddLoTo(self, event):
        """Add LO-TO splitting data to the phbands in the active tab"""
        dialog = wx.FileDialog(self, message="Choose an anaddb.nc file", defaultDir=os.getcwd(),
                       wildcard="Netcdf files (*.nc)|*.nc",
                       style=wx.OPEN | wx.CHANGE_DIR)

        if dialog.ShowModal() == wx.ID_CANCEL: return

        with ETSF_Reader(dialog.GetPath()) as r:
            directions = r.read_value("non_analytical_directions")
            non_anal_phfreq = r.read_value("non_analytical_phonon_modes")

            self.phbands.non_anal_directions = directions
            self.phbands.non_anal_phfreqs = non_anal_phfreq
示例#9
0
文件: wr.py 项目: jbouquiaux/abipy
    def __init__(self, filepath):
        super().__init__(filepath)
        self.reader = r = ETSF_Reader(filepath)

        # Read dimensions.
        self.nfft = r.read_dimvalue("nfft")
        self.nspden = r.read_dimvalue("nspden")
        self.natom3 = len(self.structure) * 3
        self.method = r.read_value("method")
        assert self.method == 0
        self.ngqpt = r.read_value("ngqpt")
        self.rpt = r.read_value("rpt")
        self.nrpt = len(self.rpt)
        # FFT mesh.
        self.ngfft = r.read_value("ngfft")
示例#10
0
    def from_file(cls, filepath):
        """
        Create the object from an anaddb.nc netcdf file.

        Args:
            filepath: path to the netcdf file.

        Returns:
            An instance of Raman.
        """

        with ETSF_Reader(filepath) as r:
            try:
                susceptibility = r.read_value("raman_sus").T
                phfreqs = r.read_value("gamma_phonon_modes")
                non_anal_susceptibility = r.read_value(
                    "non_analytical_raman_sus", default=None)
                if non_anal_susceptibility is not None:
                    non_anal_susceptibility = non_anal_susceptibility.T
                non_anal_phfreqs = r.read_value("non_analytical_phonon_modes",
                                                default=None)
                non_anal_directions = r.read_value("non_analytical_directions",
                                                   default=None)
            except Exception:
                import traceback
                msg = traceback.format_exc()
                msg += (
                    "Error while trying to read Raman from file.\n"
                    "Verify that the required variables are used in anaddb: nlflag\n"
                )
                raise ValueError(msg)

            return cls(susceptibility=susceptibility,
                       phfreqs=phfreqs,
                       non_anal_susceptibility=non_anal_susceptibility,
                       non_anal_phfreqs=non_anal_phfreqs,
                       non_anal_directions=non_anal_directions)
示例#11
0
 def __init__(self, filepath):
     super(AbinitNcFile, self).__init__(filepath)
     self.reader = ETSF_Reader(filepath)
     self._structure = self.reader.read_structure()
示例#12
0
 def from_file(cls, path):
     """Initialize the object from the data stored in a netcdf file."""
     with ETSF_Reader(path) as r:
         mesh = r.get_a2fmesh()
         values = r.get_a2fvalues()
         return cls(mesh, values)
示例#13
0
 def __init__(self, filepath):
     super().__init__(filepath)
     self.reader = ETSF_Reader(filepath)
示例#14
0
文件: anaddbnc.py 项目: w6ye/abipy
 def __init__(self, filepath):
     super(AnaddbNcFile, self).__init__(filepath)
     self.reader = ETSF_Reader(filepath)