PDielec.Utilities
#
Utility Functions.
A set of utility functions that may be used anywhere in the package.
Module Contents#
Classes#
A class aimed at providing a structured way to include debug messages in code. |
Functions#
|
Determine the simulation program from a given filename. |
|
Get the appropriate output reader based on the simulation program and, if specified, the quantum mechanical program. |
|
Print 4x4 matrices or 4 vectors. |
- class PDielec.Utilities.Debug(debug, text, level=0)[source]#
A class aimed at providing a structured way to include debug messages in code.
Methods#
- print(args, level=0)
Prints debug messages based on the debug level provided as argument compared to the object’s debug level.
- state()
Returns the current state (enabled or disabled) of debugging.
Notes#
The print method provides a flexible way to include additional information along with the base debug message, allowing for a detailed and adjustable debugging output.
- print(*args, level=0)[source]#
Print message if debugging level allows.
Parameters#
- args
Variable length argument list for the message to be printed.
- levelint, optional
The level of the message that determines if it gets printed or not, based on the instance’s level. Default value is 0.
Notes#
This method will only print the message if the instance’s debug flag is True and the provided level is less than or equal to the instance’s level.
- PDielec.Utilities.find_program_from_name(filename)[source]#
Determine the simulation program from a given filename.
Parameters#
- filenamestr
The complete path (absolute or relative) to a file.
Returns#
- (str1,str2)
A tuple of 2 strings, the first, str1, is the program name that was used to calculate the frequencies. In the case of phonopy, the second string is the QM program that calculates the forces
Notes#
This function examines the file extension and, in some cases, the presence of specific files in the same directory, to determine the associated simulation program. It recognizes files from several popular materials simulation programs, such as ‘phonopy’, ‘gulp’, ‘vasp’, and others.
Examples#
program = find_program_from_name('./data/structure.castep') print(program) # Output: ("castep","") program = find_program_from_name('path/to/simulation/OUTCAR') print(program) # Output: ("phonopy","vasp") # Depends on the presence of 'phonopy.yaml'
- PDielec.Utilities.get_reader(name, program, qmprogram, debug=False)[source]#
Get the appropriate output reader based on the simulation program and, if specified, the quantum mechanical program.
This function is designed to create an output reader object for various simulation programs (like CASTEP, VASP, etc.) and, for phonopy simulations, it can additionally create a quantum mechanical output reader based on the specified quantum mechanical program.
Parameters#
- namestr
The primary filepath or name associated with the output file(s).
- programstr
The name of the simulation program. Supported values are ‘castep’, ‘vasp’, ‘gulp’, ‘crystal’, ‘abinit’, ‘qe’, and ‘phonopy’.
- qmprogramstr
The name of the quantum mechanical program used in conjunction with phonopy. Supported values are the same as for program, but its relevance is exclusive to when program is set to ‘phonopy’.
- debugboolean
Optional. If true print debug information. Default is false
Returns#
- object
An instance of the appropriate output reader class based on the input program and, if applicable, qmprogram.
Notes#
For phonopy simulations, both phonon and quantum mechanical output files are considered. If the qmprogram is not compatible or not specified, the function will exit.
Examples#
>>> reader = get_reader("output.log", "castep", "") >>> reader = get_reader("output", "phonopy", "vasp")