def _prepare_data(self, k_point=None): """ Sets all necessary fields for 1D calculations. Sorts atom indices to improve parallelism. :returns: number of atoms, sorted atom indices """ # load powder data for one k clerk = abins.IO(input_filename=self._input_filename, group_name=abins.parameters.hdf_groups['powder_data']) powder_data = clerk.load(list_of_datasets=["powder_data"]) self._a_tensors = powder_data["datasets"]["powder_data"]["a_tensors"][ k_point] self._b_tensors = powder_data["datasets"]["powder_data"]["b_tensors"][ k_point] self._a_traces = np.trace(a=self._a_tensors, axis1=1, axis2=2) self._b_traces = np.trace(a=self._b_tensors, axis1=2, axis2=3) # load dft data for one k point clerk = abins.IO( input_filename=self._input_filename, group_name=abins.parameters.hdf_groups['ab_initio_data']) dft_data = clerk.load(list_of_datasets=["frequencies", "weights"]) frequencies = dft_data["datasets"]["frequencies"][int(k_point)] indx = frequencies > ACOUSTIC_PHONON_THRESHOLD self._fundamentals_freq = frequencies[indx] self._weight = dft_data["datasets"]["weights"][int(k_point)] # free memory gc.collect()
def _prepare_data(self, k_point=None): """ Sets all necessary fields for 1D calculations. Sorts atom indices to improve parallelism. :returns: number of atoms, sorted atom indices """ # load powder data for one k clerk = abins.IO(input_filename=self._input_filename, group_name=abins.parameters.hdf_groups['powder_data']) powder_data = abins.PowderData.from_extracted( clerk.load( list_of_datasets=["powder_data"])["datasets"]["powder_data"]) self._a_tensors = powder_data.get_a_tensors()[k_point] self._b_tensors = powder_data.get_b_tensors()[k_point] self._a_traces = np.trace(a=self._a_tensors, axis1=1, axis2=2) self._b_traces = np.trace(a=self._b_tensors, axis1=2, axis2=3) self._fundamentals_freq = powder_data.get_frequencies()[k_point] # load dft data to get k-point weighting clerk = abins.IO( input_filename=self._input_filename, group_name=abins.parameters.hdf_groups['ab_initio_data']) dft_data = clerk.load(list_of_datasets=["frequencies", "weights"]) self._weight = dft_data["datasets"]["weights"][k_point] # free memory gc.collect()
def __init__(self, *, filename: str, abins_data: abins.AbinsData) -> None: """ :param filename: name of input DFT filename :param abins_data: object of type AbinsData with data from input DFT file """ if not isinstance(abins_data, abins.AbinsData): raise ValueError("Object of AbinsData was expected.") k_data = abins_data.get_kpoints_data() # type: abins.KpointsData self._frequencies = {} # type: Dict[str, np.ndarray] self._displacements = {} # type: Dict[str, np.ndarray] atoms_data = abins_data.get_atoms_data() # Populate data, removing imaginary modes for k, k_point_data in enumerate(k_data): mask = k_point_data.frequencies > ACOUSTIC_PHONON_THRESHOLD self._frequencies[k] = k_point_data.frequencies[mask] self._displacements[k] = k_point_data.atomic_displacements[:, mask] self._masses = np.asarray( [atoms_data[atom]["mass"] for atom in range(len(atoms_data))]) self._clerk = abins.IO( input_filename=filename, group_name=abins.parameters.hdf_groups['powder_data'])
def __init__(self, input_ab_initio_filename=None): self._num_k = None self._num_atoms = None self._sample_form = None self._ab_initio_program = None self._clerk = abins.IO(input_filename=input_ab_initio_filename, group_name=abins.parameters.hdf_groups['ab_initio_data'])
def __init__(self, filename=None, abins_data=None): """ :param filename: name of input DFT filename :param abins_data: object of type AbinsData with data from input DFT file """ if not isinstance(abins_data, abins.AbinsData): raise ValueError("Object of AbinsData was expected.") k_data = abins_data.get_kpoints_data().extract() self._frequencies = k_data["frequencies"] self._displacements = k_data["atomic_displacements"] self._num_atoms = self._displacements[GAMMA_POINT].shape[0] self._atoms_data = abins_data.get_atoms_data().extract() self._clerk = abins.IO(input_filename=filename, group_name=abins.parameters.hdf_groups['powder_data'])
def __init__(self, filename=None, temperature=None, abins_data=None, instrument=None, quantum_order_num=None, bin_width=1.0): """ :param filename: name of input DFT file (CASTEP: foo.phonon) :param temperature: temperature in K for which calculation of S should be done :param sample_form: form in which experimental sample is: Powder or SingleCrystal (str) :param abins_data: object of type AbinsData with data from phonon file :param instrument: name of instrument (str) :param quantum_order_num: number of quantum order events taken into account during the simulation :param bin_width: bin width used in rebining in wavenumber """ if not isinstance(temperature, (int, float)): raise ValueError( "Invalid value of the temperature. Number was expected.") if temperature < 0: raise ValueError("Temperature cannot be negative.") self._temperature = float(temperature) self._sample_form = "Powder" if isinstance(abins_data, abins.AbinsData): self._abins_data = abins_data else: raise ValueError("Object of type AbinsData was expected.") self._q2_indices = list( self._abins_data.get_kpoints_data().extract()["k_vectors"].keys()) self._atoms = self._abins_data.get_atoms_data().extract() if isinstance(abins_data, abins.AbinsData): self._abins_data = abins_data else: raise ValueError("Object of type AbinsData was expected.") min_order = FUNDAMENTALS max_order = FUNDAMENTALS + HIGHER_ORDER_QUANTUM_EVENTS if isinstance(quantum_order_num, int) and min_order <= quantum_order_num <= max_order: self._quantum_order_num = quantum_order_num else: raise ValueError("Invalid number of quantum order events.") if isinstance(instrument, Instrument): self._instrument = instrument else: raise ValueError("Unknown instrument %s" % instrument) if isinstance(filename, str): if filename.strip() == "": raise ValueError("Name of the file cannot be an empty string!") self._input_filename = filename else: raise ValueError( "Invalid name of input file. String was expected!") self._clerk = abins.IO( input_filename=filename, group_name=( "{s_data_group}/{instrument}/{sample_form}/{temperature}K" ).format(s_data_group=abins.parameters.hdf_groups['s_data'], instrument=self._instrument, sample_form=self._sample_form, temperature=self._temperature)) self._freq_generator = abins.FrequencyPowderGenerator() self._calculate_order = { QUANTUM_ORDER_ONE: self._calculate_order_one, QUANTUM_ORDER_TWO: self._calculate_order_two, QUANTUM_ORDER_THREE: self._calculate_order_three, QUANTUM_ORDER_FOUR: self._calculate_order_four } self._bin_width = bin_width # This is only here to store in s_data. Is that necessary/useful? self._bins = np.arange( start=abins.parameters.sampling['min_wavenumber'], stop=abins.parameters.sampling['max_wavenumber'] + bin_width, step=bin_width, dtype=FLOAT_TYPE) self._frequencies = self._bins[:-1] + (bin_width / 2) self._freq_size = self._bins.size - 1 self._num_atoms = len(self._abins_data.get_atoms_data().extract()) self._powder_atoms_data = None self._a_traces = None self._b_traces = None self._atoms_data = None self._fundamentals_freq = None