pymatgen.io.abinit.utils module¶
Tools and helper functions for abinit calculations
-
class
Condition(cmap=None)[source]¶ Bases:
objectThis object receives a dictionary that defines a boolean condition whose syntax is similar to the one used in mongodb (albeit not all the operators available in mongodb are supported here).
Example:
$gt: {field: {$gt: value} }
$gt selects those documents where the value of the field is greater than (i.e. >) the specified value.
$and performs a logical AND operation on an array of two or more expressions (e.g. <expression1>, <expression2>, etc.) and selects the documents that satisfy all the expressions in the array.
{ $and: [ { <expression1> }, { <expression2> } , … , { <expressionN> } ] }
Consider the following example:
db.inventory.find( { qty: { $gt: 20 } } ) This query will select all documents in the inventory collection where the qty field value is greater than 20. Consider the following example:
db.inventory.find( { qty: { $gt: 20 } } ) db.inventory.find({ $and: [ { price: 1.99 }, { qty: { $lt: 20 } }, { sale: true } ] } )
-
class
Directory(path)[source]¶ Bases:
objectVery simple class that provides helper functions wrapping the most commonly used functions defined in os.path.
-
basename¶ Directory basename.
-
copy_abiext(inext, outext)[source]¶ Copy the Abinit file with extension inext to a new file withw extension outext
-
exists¶ True if file exists.
-
find_1den_files()[source]¶ Abinit adds the idir-ipert index at the end of the 1DEN file and this breaks the extension e.g. out_DEN1. This method scans the files in the directories and returns a list of namedtuple Each named tuple gives the path of the 1DEN file and the pertcase index.
-
find_1wf_files()[source]¶ Abinit adds the idir-ipert index at the end of the 1WF file and this breaks the extension e.g. out_1WF4. This method scans the files in the directories and returns a list of namedtuple Each named tuple gives the path of the 1FK file and the pertcase index.
-
find_last_timden_file()[source]¶ ABINIT produces lots of out_TIM1_DEN files for each step and we need to find the lat one in order to prepare the restart or to connect other tasks to the structural relaxation.
This function finds all the TIM?_DEN files in self and return a namedtuple (path, step) where path is the path of the last TIM?_DEN file and step is the iteration number. Returns None if the directory does not contain TIM?_DEN files.
-
has_abiext(ext)[source]¶ Returns the absolute path of the ABINIT file with extension ext. Support both Fortran files and netcdf files. In the later case, we check whether a file with extension ext + “.nc” is present in the directory. Returns empty string is file is not present.
Raises: - ValueError if multiple files with the given ext are found.
- This implies that this method is not compatible with multiple datasets.
-
list_filepaths(wildcard=None)[source]¶ Return the list of absolute filepaths in the directory.
Parameters: wildcard – String of tokens separated by “|”. Each token represents a pattern. If wildcard is not None, we return only those files that match the given shell pattern (uses fnmatch). .. rubric:: Example
wildcard=”.nc|.pdf” selects only those files that end with .nc or .pdf
-
makedirs()[source]¶ Super-mkdir; create a leaf directory and all intermediate ones. Works like mkdir, except that any intermediate path segment (not just the rightmost) will be created if it does not exist.
-
path¶ Absolute path of the directory.
-
path_join(*p)[source]¶ Join two or more pathname components, inserting ‘/’ as needed. If any component is an absolute path, all previous path components will be discarded.
-
relpath¶ Relative path.
-
remove_exts(exts)[source]¶ Remove the files with the given extensions. Unlike rmtree, this function preserves the directory path. Return list with the absolute paths of the files that have been removed.
-
-
class
Editor(editor=None)[source]¶ Bases:
objectWrapper class that calls the editor specified by the user or the one specified in the $EDITOR env variable.
If editor is None, $EDITOR is used.
-
class
File(path)[source]¶ Bases:
objectVery simple class used to store file basenames, absolute paths and directory names. Provides wrappers for the most commonly used functions defined in os.path.
-
basename¶ File basename.
-
dirname¶ Absolute path of the directory where the file is located.
-
exists¶ True if file exists.
-
getsize()[source]¶ Return the size, in bytes, of path. Return 0 if the file is empty or it does not exist.
-
isncfile¶ True if self is a NetCDF file
-
move(dst)[source]¶ Recursively move a file or directory to another location. This is similar to the Unix “mv” command.
-
path¶ Absolute path of the file.
-
relpath¶ Relative path.
-
-
class
FilepathFixer[source]¶ Bases:
objectThis object modifies the names of particular output files produced by ABINIT so that the file extension is preserved. Having a one-to-one mapping between file extension and data format is indeed fundamental for the correct behaviour of abinit since:
- We locate the output file by just inspecting the extension
- We select the variables that must be added to the input file on the basis of the extension specified by the user during the initialization of the AbinitFlow.
Unfortunately, ABINIT developers like to append extra stuff to the initial extension and therefore we have to call FilepathFixer to fix the output files produced by the run.
Example:
>>> fixer = FilepathFixer() >>> assert fixer.fix_paths('/foo/out_1WF17') == {'/foo/out_1WF17': '/foo/out_1WF'} >>> assert fixer.fix_paths('/foo/out_1WF5.nc') == {'/foo/out_1WF5.nc': '/foo/out_1WF.nc'}
-
class
SparseHistogram(items, key=None, num=None, step=None)[source]¶ Bases:
object-
plot(ax=None, **kwargs)[source]¶ - Plot the histogram with matplotlib, returns matplotlib figure.
keyword arguments controlling the display of the figure:
kwargs Meaning title Title of the plot (Default: None). show True to show the figure (default: True). savefig ‘abc.png’ or ‘abc.eps’ to save the figure to a file. size_kwargs Dictionary with options passed to fig.set_size_inches example: size_kwargs=dict(w=3, h=4) tight_layout True if to call fig.tight_layout (default: False)
-
-
abi_splitext(filename)[source]¶ Split the ABINIT extension from a filename. “Extension” are found by searching in an internal database.
Returns “(root, ext)” where ext is the registered ABINIT extension The final “.nc” is included (if any)
>>> assert abi_splitext("foo_WFK") == ('foo_', 'WFK') >>> assert abi_splitext("/home/guido/foo_bar_WFK.nc") == ('foo_bar_', 'WFK.nc')
-
as_bool(s)[source]¶ Convert a string into a boolean.
>>> assert as_bool(True) is True and as_bool("Yes") is True and as_bool("false") is False
-
irdvars_for_ext(ext)[source]¶ Returns a dictionary with the ABINIT variables that must be used to read the file with extension ext.
-
map2rpn(map, obj)[source]¶ Convert a Mongodb-like dictionary to a RPN list of operands and operators.
Reverse Polish notation (RPN) is a mathematical notation in which every operator follows all of its operands, e.g.
3 - 4 + 5 –> 3 4 - 5 +
>>> d = {2.0: {'$eq': 1.0}} >>> assert map2rpn(d, None) == [2.0, 1.0, '$eq']