def export(self, filename): """ Export the real space data on file filename. Format is defined by the extension in filename. See :class:`Visualizer` for the list of applications and formats supported. """ if "." not in filename: raise ValueError(" Cannot detect file extension in filename: %s " % filename) tokens = filename.strip().split(".") ext = tokens[-1] if not tokens[0]: # filename == ".ext" ==> Create temporary file. import tempfile filename = tempfile.mkstemp(suffix="."+ext, text=True)[1] with open(filename, mode="w") as fh: if ext == "xsf": # xcrysden xsf.xsf_write_structure(fh, self.structure) xsf.xsf_write_data(fh, self.structure, self.datar, add_replicas=True) else: raise NotImplementedError("extension %s is not supported." % ext) return Visualizer.from_file(filename)
def export_ur2(self, filename, structure): """ Export the wavefunction on file filename. Format is defined by the extension in filename. """ if "." not in filename: raise ValueError("Cannot detect file extension in: %s" % filename) tokens = filename.strip().split(".") ext = tokens[-1] if not tokens[0]: # fname == ".ext" ==> Create temporary file. filename = tempfile.mkstemp(suffix="." + ext, text=True)[1] print("Creating temporary file: %s" % filename) # Compute |u(r)|2 and write data according to ext. ur2 = np.reshape(self.ur2, (1,) + self.ur2.shape) with open(filename, mode="w") as fh: if ext == "xsf": # xcrysden xsf_write_structure(fh, structures=[structure]) xsf_write_data(fh, structure, ur2, add_replicas=True) else: raise NotImplementedError("extension %s is not supported." % ext) return Visualizer.from_file(filename)
def xsf_write(filename, datar): with open(filename, mode="wt") as fh: xsf.xsf_write_structure(fh, self.structure) xsf.xsf_write_data(fh, self.structure, datar, add_replicas=True)
def visualize_qpoint_nu(self, qpoint, nu, spin=0, appname="vesta"): iq, qpoint = self._find_iqpt_qpoint(qpoint) # Fortran array nctkarr_t("v1_qnu", "dp", "two, nfft, nspden, natom3, nqlist")]) v1_qnu = self.reader.read_variable("v1_qnu")[iq, nu, spin] v1_qnu = v1_qnu[:, 0] + 1j * v1_qnu[:, 1] #wqnu = self.reader.read_variable["phfreqs"][nu] #v1_qnu /= np.sqrt(2 * wqnu) datar = np.reshape(np.abs(v1_qnu), self.ngfft) visu = Visualizer.from_name(appname) ext = "xsf" if ext not in visu.supported_extensions(): raise ValueError("Visualizer %s does not support XSF files" % visu) from abipy.core.globals import abinb_mkstemp _, filename = abinb_mkstemp(suffix="." + ext, text=True) with open(filename, mode="wt") as fh: if ext == "xsf": xsf.xsf_write_structure(fh, self.structure) xsf.xsf_write_data(fh, self.structure, datar, add_replicas=True) else: raise NotImplementedError("extension %s is not supported." % ext) return visu(filename)
def export(self, filename, visu=None, verbose=1): """ Export the real space data to file filename. Args: filename: String specifying the file path and the file format. The format is defined by the file extension. filename="prefix.xsf", for example, will produce a file in XSF format (xcrysden_). An *empty* prefix, e.g. ".xsf" makes the code use a temporary file. visu: :class:`Visualizer` subclass. By default, this method returns the first available visualizer that supports the given file format. If visu is not None, an instance of visu is returned. See :class:`Visualizer` for the list of applications and formats supported. verbose: Verbosity level Returns: Instance of :class:`Visualizer` """ if "." not in filename: raise ValueError("Cannot detect file extension in filename: %s " % filename) tokens = filename.strip().split(".") ext = tokens[-1] if verbose: print("tokens", tokens, "ext", ext) if not tokens[0]: # filename == ".ext" ==> Create temporary file. # dir = os.getcwd() is needed when we invoke the method from a notebook. # nbworkdir in cwd is needed when we invoke the method from a notebook. from abipy.core.globals import abinb_mkstemp _, filename = abinb_mkstemp(suffix="." + ext, text=True) with open(filename, mode="wt") as fh: if ext == "xsf": # xcrysden xsf.xsf_write_structure(fh, self.structure) xsf.xsf_write_data(fh, self.structure, self.datar, add_replicas=True) #elif ext == "POSCAR": else: raise NotImplementedError("extension %s is not supported." % ext) if visu is None: return Visualizer.from_file(filename) else: return visu(filename)
def export_ur2(self, filename, visu=None): """ Export :math:`|u(r)|^2` to file ``filename``. Args: filename: String specifying the file path and the file format. The format is defined by the file extension. filename="prefix.xsf", for example, will produce a file in XSF format. An *empty* prefix, e.g. ".xsf" makes the code use a temporary file. visu: :class:`Visualizer` subclass. By default, this method returns the first available visualizer that supports the given file format. If visu is not None, an instance of visu is returned. See :class:`Visualizer` for the list of applications and formats supported. Returns: Instance of :class:`Visualizer` """ if "." not in filename: raise ValueError("Cannot detect file extension in: %s" % filename) tokens = filename.strip().split(".") ext = tokens[-1] if not tokens[0]: # fname == ".ext" ==> Create temporary file. # dir = os.getcwd() is needed when we invoke the method from a notebook. from abipy.core.globals import abinb_mkstemp _, filename = abinb_mkstemp(suffix="." + ext, text=True) print("Creating temporary file: %s" % filename) # Compute |u(r)|2 and write data according to ext. ur2 = np.reshape(self.ur2, (1, ) + self.ur2.shape) with open(filename, mode="wt") as fh: if ext == "xsf": # xcrysden xsf_write_structure(fh, structures=self.structure) xsf_write_data(fh, self.structure, ur2, add_replicas=True) else: raise NotImplementedError("extension %s is not supported." % ext) if visu is None: return Visualizer.from_file(filename) else: return visu(filename)
def export_ur2(self, filename, structure, visu=None): """ Export u(r)**2 on file filename. Args: filename: String specifying the file path and the file format. The format is defined by the file extension. filename="prefix.xsf", for example, will produce a file in XSF format. An *empty* prefix, e.g. ".xsf" makes the code use a temporary file. structure: Structure object. visu: `Visualizer` subclass. By default, this method returns the first available visualizer that supports the given file format. If visu is not None, an instance of visu is returned. See :class:`Visualizer` for the list of applications and formats supported. Returns: Instance of :class:`Visualizer` """ if "." not in filename: raise ValueError("Cannot detect file extension in: %s" % filename) tokens = filename.strip().split(".") ext = tokens[-1] if not tokens[0]: # fname == ".ext" ==> Create temporary file. filename = tempfile.mkstemp(suffix="." + ext, text=True)[1] print("Creating temporary file: %s" % filename) # Compute |u(r)|2 and write data according to ext. ur2 = np.reshape(self.ur2, (1,) + self.ur2.shape) with open(filename, mode="w") as fh: if ext == "xsf": # xcrysden xsf_write_structure(fh, structures=[structure]) xsf_write_data(fh, structure, ur2, add_replicas=True) else: raise NotImplementedError("extension %s is not supported." % ext) if visu is None: return Visualizer.from_file(filename) else: return visu(filename)
def export(self, filename, visu=None): """ Export the real space data on file filename. Args: filename: String specifying the file path and the file format. The format is defined by the file extension. filename="prefix.xsf", for example, will produce a file in XSF format. An *empty* prefix, e.g. ".xsf" makes the code use a temporary file. visu: :class:`Visualizer` subclass. By default, this method returns the first available visualizer that supports the given file format. If visu is not None, an instance of visu is returned. See :class:`Visualizer` for the list of applications and formats supported. Returns: Instance of :class:`Visualizer` """ if "." not in filename: raise ValueError(" Cannot detect file extension in filename: %s " % filename) tokens = filename.strip().split(".") ext = tokens[-1] if not tokens[0]: # filename == ".ext" ==> Create temporary file. import tempfile filename = tempfile.mkstemp(suffix="." + ext, text=True)[1] with open(filename, mode="w") as fh: if ext == "xsf": # xcrysden xsf.xsf_write_structure(fh, self.structure) xsf.xsf_write_data(fh, self.structure, self.datar, add_replicas=True) else: raise NotImplementedError("extension %s is not supported." % ext) if visu is None: return Visualizer.from_file(filename) else: return visu(filename)