PDielec.CastepOutputReader
#
CastepOutputReader module
Module Contents#
Classes#
Read the contents of a Castep output file. |
- class PDielec.CastepOutputReader.CastepOutputReader(filenames)[source]#
Bases:
PDielec.GenericOutputReader.GenericOutputReader
Read the contents of a Castep output file.
Inherits from
GenericOutputReader
Parameters#
- filenameslist
A list of filenames (strings) intended for initialization. The first filename in the list is used to determine the seedname and the types of files to be created (.castep and .phonon).
Notes#
This method assumes that the filenames provided in the list relate to CASTEP calculation outputs. Specifically, it looks for filenames ending in ‘.castep’ or ‘.phonon’ to set up the necessary output files for the instance.
The method does not return a value but initializes the instance with the necessary attributes for further processing and analysis of CASTEP output files.
- _read_born_charges(line)[source]#
Read the born charges from the castep file.
This function reads the born charges from a provided castep file and arranges the output tensor. Initially, each column of the output refers to a given field direction, and each row refers to the atomic displacement, organizing the numbers in the format [[a1x a2x a3x], [a1y a2y a3y], [a1z a2z a3z]]. The function then rearranges these numbers into the desired format: [[a1x a1y a1z], [a2x a2y a2z], [a3x a3y a3z]], where 1, 2, 3 are the field directions, and x, y, z represent the atomic displacements.
Parameters#
- linestr
The initial line from which to start reading in the file. This parameter is part of the method signature for demonstration but is immediately overwritten by the next line read from the file, hence not directly used.
Returns#
- ndarray
An array where each row represents the born charges for a particular atomic displacement arranged in the format [[a1x a1y a1z], [a2x a2y a2z], [a3x a3y a3z]].
- _read_cellcontents(line)[source]#
Read the cell contents from an input file and updates the class attributes accordingly.
This method reads the real lattice vectors, current cell volume, total number of ions, species, and fractional coordinates from the input file, and updates the relevant class attributes including unit_cells, volume, volumes, nions, nspecies, atom_type_list, species, ions_per_type, along with setting the fractional coordinates and element names for the latest unit cell.
Parameters#
- linestr
The initial line from which to start reading. This parameter is not used in the current implementation and could be omitted or replaced depending on the method’s usage context.
Returns#
None
- _read_convergence(line)[source]#
Reads convergence data from a file and updates internal lists with values.
This internal method reads specific lines from a file that is already opened and updates internal lists for de-ionization energy, maximum force (fmax), maximum displacement (dr_max), and maximum stress (smax) based on the values found in those lines.
Parameters#
- linestr
Not used but overwritten
Returns#
None
Notes#
This function assumes that the file being read follows a specific format where the required values are found at known line intervals and in a consistent column position (index 3 after splitting the line).
The function does not return any value, but it updates the internal state of the object it is a part of.
- _read_dielectric(line)[source]#
Read and parse dielectric data from a file.
This method reads dielectric data from the currently opened file associated with the object. It updates the object’s properties for zero-frequency optical and static dielectric constants.
Parameters#
- linestr
The initial line from which to start reading. Note: this parameter is actually unused in the function’s current implementation, and reading starts from the next line of the file descriptor’s current position.
Returns#
None
Notes#
The function assumes that the file’s current position is at the correct start point for reading dielectric data. It reads three consecutive lines from the file, each expected to contain six floating point numbers. The first three numbers of each line are appended to ‘zerof_optical_dielectric’, and the latter three numbers to ‘zerof_static_dielectric’.
This method modifies the state of the object by updating the ‘zerof_optical_dielectric’ and ‘zerof_static_dielectric’ lists with new data read from the file.
- _read_ediff(line)[source]#
Reads and sets the energy difference from a given line of text.
This is a private method intended to parse and store the energy difference from a standardized formatted line of text.
Parameters#
- linestr
A line of text, expected to contain numerical values from which the energy difference (ediff) is parsed. The value for ediff is expected to be the third element when splitting the line by whitespace.
Returns#
None
- _read_energies(line)[source]#
Read and store energy values from a given line.
Extracts energy-related data from a specified line and updates relevant attributes of the object. Assumes that the sixth (index 5) element in the second line contains the final free energy, the fifth (index 4) element in the given line contains the DFT energy, which is appended to a list, and also set as the final energy without entropy. Additionally, updates the number of geometry steps based on the length of the energiesDFT list.
Parameters#
- linestr
The line from which energy values are extracted.
Returns#
None
Notes#
This method expects that ‘line’ follows a specific format, where the fifth (index 4) element is the final energy without entropy and, on the subsequent line, the sixth (index 5) element is the final free energy. It further assumes ‘self.file_descriptor’ to be an open file object positioned at the line immediately following the line containing energy information.
The method updates four attributes of the object: - Appends the energy value to ‘self.energiesDFT’. - Sets ‘self.final_energy_without_entropy’ to the extracted energy value. - Reads the next line and sets ‘self.final_free_energy’ to the extracted value. - Updates ‘self.geomsteps’ to represent the total number of energy steps recorded.
- _read_energies2(line)[source]#
Parse a line of text to read energies and update properties.
This method reads energies from a given line of text and updates various energy related properties of the object.
Parameters#
- linestr
A line of text that contains energy values.
Notes#
This method specifically updates the energiesDFT, final_energy_without_entropy, final_free_energy, and geomsteps attributes of the object based on the energy value parsed from the given line. The energy value is expected to be located at the fourth position (index 3) when the line is split by spaces.
Returns#
None
- _read_energies3(line)[source]#
Read energy values from a line of text and append to class attributes.
This method parses a line of text, extracts the energy value from the sixth position (index 5), converts it into a float, and appends it to the class’s energiesDFT_disp attribute. It also updates the class attributes for the final energy without entropy, the final free energy, and the total number of geometry steps (geomsteps) based on the current energy readings.
Parameters#
- linestr
A string containing energy information, expected to have at least six words with the energy value at the sixth position.
Returns#
None
Notes#
This method directly modifies the attributes of the class instance it belongs to. It does not return any value.
- _read_energy_cutoff(line)[source]#
Extract the energy cutoff value from a given line and store it in the object.
This method reads a line of text, expects to find a numeric value at the 7th position (0-indexed) in a space-separated list, converts this value to a float, and stores it as the energy cutoff property of the object.
Parameters#
- linestr
A string containing the energy cutoff value at the 7th position in a space-separated list.
Returns#
None
- _read_external_pressure(line)[source]#
Parse an external pressure value from a string and set it.
Parameters#
- linestr
A string containing the pressure value to parse and set. The expected format is unspecified in this context, but the pressure value should be at the third position (index 2) when the string is split by whitespace.
Returns#
None
Notes#
This function updates the pressure attribute of the class instance based on the value parsed from the input string. The specific use case and format of the input string are not detailed, assuming some domain-specific knowledge is required.
- _read_frequencies(line)[source]#
Read and process frequencies, intensities, and normal modes from phonon file.
This method assumes a specific format of the input file, where frequencies, intensities, and normal mode coordinates are listed in a sequential order. Frequencies and intensities are read first, followed by normal mode vectors for each mode.
Parameters#
- linestr
The current line in the file from which to start reading the frequency data.
Returns#
None
Attributes Modified#
- mass_weighted_normal_modeslist
A list of mass-weighted normal modes. Each normal mode is represented as a list of 3D vectors (lists) for each ion in the structure.
- frequencieslist
A list of frequency values read from the file.
- _intensitieslist
A list of intensity values corresponding to each frequency.
Notes#
This method directly modifies the instance attributes mass_weighted_normal_modes, frequencies, and _intensities.
It is assumed that self.file_descriptor is an open file object from which the data is read.
The method relies on the internal variable self._nbranches to determine the number of modes to read, and self.nions for the number of ions per mode.
- _read_kpoint_grid(line)[source]#
Parse and set the k-point grid dimensions from the given line.
This method updates the kpoint_grid attribute of the object with the k-point grid dimensions obtained from parsing the specified line. The k-point grid dimensions are expected to be located at the 8th, 9th, and 10th positions (1-based indexing) in the line, separated by spaces.
Parameters#
- linestr
The line from which the k-point grid dimensions are to be extracted.
Returns#
None
- _read_kpoints(line)[source]#
Extract number of k-points from a given line of text and update the instance variable.
Parameters#
- linestr
The line of text from which the number of k-points is extracted.
Returns#
None
Notes#
This function assumes the number of k-points is always located at the 6th position (index 5) when the line is split by whitespace. It directly updates the kpoints attribute of the class instance.
- _read_masses(line)[source]#
Read and parse masses from a file, categorizing them by species.
This method reads lines from an opened file associated with the instance, extracting the species name, its mass, and the number of ions per species. It updates instance attributes to store this information, organizing masses both by type and in total.
Parameters#
- linestr
The initial line from which to start reading in the file. This parameter is part of the method signature for demonstration but is immediately overwritten by the next line read from the file, hence not directly used.
Returns#
None
- _read_nbands(line)[source]#
Extracts the number of bands from a given line and sets it to the ‘nbands’ attribute of the class.
Parameters#
- linestr
The line from which the number of bands is to be extracted. It is expected that the fifth element (index 4) when splitting the line by spaces is an integer representing the number of bands.
Returns#
None
- _read_nbranches(line)[source]#
Parse the number of branches from a line of text from the phonon file and set it to an instance variable.
Parameters#
- linestr
The line of text containing the number of branches information. It is expected that the number of branches can be found at the fourth position (index 3) when splitting the line by whitespace.
Returns#
None
Notes#
This function does not return anything as it sets the parsed number directly to an instance variable named _nbranches.
- _read_nelect(line)[source]#
Extracts the number of electrons from a line and assigns it.
Extracts the number of electrons from a string (line) by parsing it and assigns the value to the instance variable electrons.
Parameters#
- linestr
A string (typically a line from a file) that contains the number of electrons among other text, expected to be found at the fifth position (index 4) when the string is split.
Returns#
None
- _read_output_files()[source]#
Define the strings needed for searching the files process the output files
Parameters#
None
Returns#
None
- _read_pseudoatom(line)[source]#
Read and process a pseudoatom line from a data file.
Parameters#
- linestr
A string representing a line from a data file that contains information about a pseudoatom.
Returns#
None
Notes#
This method processes a line from a data file, extracting the species from the sixth (index 5) position in the whitespace-separated list. The species name is capitalized and stored, and indices related to the species and ion types are updated accordingly.
- _read_pspot(line)[source]#
Read potential spots from a file and store them.
This method reads a specific number of lines determined by the nspecies attribute from the file associated with file_descriptor, processes them to extract potential spot identifiers and their corresponding values, and stores them in the _pspots attribute.
Parameters#
- linestr
The line from which the reading starts. This initial line is often a header or an indicator that the following lines contain the potential spots data.
Returns#
None
- _read_skip4(line)[source]#
Read and skip the next four lines from the current file position.
This method reads and discards the next four lines from the file associated with this object’s file_descriptor attribute.
Parameters#
- linestr
This parameter is not used in the function body and serves no purpose in the context of this method’s operation.
Returns#
None
- _read_spin(line)[source]#
Read and set the spin value from a given line of text.
The spin is extracted from the sixth element (index 5) of the splitted line.
Parameters#
- linestr
The input line from which the spin is extracted. Expected to have at least six space-separated elements, with the sixth element being a string representation of the spin value.
Returns#
None