eon.fileio¶
Con(figuration) i/o library.
.con frames are read and written with the readcon package
(:class:readcon.ConFrame). The in-memory working type is
- class:
eon.structure.Structure(aliasAtoms).
Module Contents¶
Classes¶
Functions¶
Path of the persisted numpy PRNG pickle. |
|
Rewrite a file in one step, for callers that truncate and rewrite whole. path: destination file mode: ‘w’ or ‘wb’ The body writes to a temporary file in the destination’s own directory, which is renamed over the destination on a clean exit. A reader sees either the old contents or the new ones, and a write that fails partway (a full disk, a killed process) leaves the destination as it was. mkstemp opens at 0600, so the destination’s own mode carries over, or the umask default for a file that does not exist yet. |
|
Load the first frame of an XYZ/PDB/GRO file via readcon chemfiles ingress. |
|
Load every POSCAR frame from filename (VASP 4 or VASP 5). |
|
Load a con file via readcon; return a Structure. filein: may be either a filename or a file-like object |
|
Save a con file via readcon. fileout: can be either a file name or a file-like object p: Structure (or Structure-like) to save w: write/append flag |
|
Reads a mode.dat file into an N by 3 numpy array modefilein: may be either a file-like object of a filename |
|
Saves an Nx3 numpy array into a mode.dat file. modefileout: may be either a filename or file-like object displace_vector: the mode (Nx3 numpy array) free: optional (N,) or (N,3) mask; a 0 axis is written as 0 17 significant digits round trip a double exactly, and match what the client’s printf writers emit for the same value. |
|
Saves a results.dat file from a dictionary
fileout: may be either a filename or a file-like object
results: dictionary of values, written one “ |
|
Reads a results.dat file and gives a dictionary of the values contained therein |
|
Load a VASP POSCAR (or one frame of a multi-frame movie). |
|
Save a VASP 5 POSCAR (species on the comment line and again before the counts). movie.py uses this for visualization; loadposcar reads this layout and the VASP 4 layout kdb produces. fileout: name to save it under p: Structure (or Structure-like) to save w: write/append flag |
|
Data¶
API¶
- eon.fileio.logger¶
‘getLogger(…)’
- eon.fileio.prng_state_path(config)[source]¶
Path of the persisted numpy PRNG pickle.
ConfigClass.init restores from this file under path_root, so every writer and reset must use the same location rather than the process CWD.
- eon.fileio.DEFAULT_FILE_MODE¶
None
- eon.fileio.DEFAULT_DIR_MODE¶
None
- eon.fileio.atomic_write(path, mode='w')[source]¶
Rewrite a file in one step, for callers that truncate and rewrite whole. path: destination file mode: ‘w’ or ‘wb’ The body writes to a temporary file in the destination’s own directory, which is renamed over the destination on a clean exit. A reader sees either the old contents or the new ones, and a write that fails partway (a full disk, a killed process) leaves the destination as it was. mkstemp opens at 0600, so the destination’s own mode carries over, or the umask default for a file that does not exist yet.
- eon.fileio.loadxyz(filename)[source]¶
Load the first frame of an XYZ/PDB/GRO file via readcon chemfiles ingress.
Requires a chemfiles-linked readcon (
pip install readcon-chemfiles). The .con path stays on readcon-core; this is the foreign-format edge.
- eon.fileio.loadcon(filein, reset=True)[source]¶
Load a con file via readcon; return a Structure. filein: may be either a filename or a file-like object
- eon.fileio.savecon(fileout, p, w='w')[source]¶
Save a con file via readcon. fileout: can be either a file name or a file-like object p: Structure (or Structure-like) to save w: write/append flag
Append of an uncompressed file concatenates one serialized frame. A gzip or zstd target cannot be extended in place, so those still read the existing frames and rewrite the file.
- eon.fileio.load_mode(modefilein)[source]¶
Reads a mode.dat file into an N by 3 numpy array modefilein: may be either a file-like object of a filename
- eon.fileio.save_mode(modefileout, displace_vector, free=None)[source]¶
Saves an Nx3 numpy array into a mode.dat file. modefileout: may be either a filename or file-like object displace_vector: the mode (Nx3 numpy array) free: optional (N,) or (N,3) mask; a 0 axis is written as 0 17 significant digits round trip a double exactly, and match what the client’s printf writers emit for the same value.
- eon.fileio.save_results_dat(fileout, results)[source]¶
Saves a results.dat file from a dictionary fileout: may be either a filename or a file-like object results: dictionary of values, written one “
” line each
- eon.fileio.parse_results(filein)[source]¶
Reads a results.dat file and gives a dictionary of the values contained therein
- eon.fileio.loadposcar(filein)[source]¶
Load a VASP POSCAR (or one frame of a multi-frame movie).
POSCAR is the one structure format that does not go through readcon: the kdb tool emits VASP 4, and movie.py writes VASP 5 for external viewers. The reader accepts both. After the cell, a line of integer counts is VASP 4 (species taken from the comment); a line of species names followed by the counts is VASP 5.
filein: filename or file-like object
- eon.fileio.saveposcar(fileout, p, w='w', direct=False)[source]¶
Save a VASP 5 POSCAR (species on the comment line and again before the counts). movie.py uses this for visualization; loadposcar reads this layout and the VASP 4 layout kdb produces. fileout: name to save it under p: Structure (or Structure-like) to save w: write/append flag
- class eon.fileio.ini(filenames)[source]¶
Bases:
configparser.ConfigParser
- class eon.fileio.Dynamics(filename)[source]¶
The Dynamics class handles I/O for the dynamics.txt file of an aKMC simulation.
Initialization
- class eon.fileio.Table(filename, columns=None, overwrite=False)[source]¶
A class that provides a nice io abstraction for table like data. The data is saved in a pretty printed format. Also provides nice data retrival methods.
t = Table(“sample.tbl”, [‘id’, ‘name’, ‘age’ ]) t.eagerwrite = False t.add_row({‘id’:0,’name’:”Sam”,”age”:24}) t.add_row({‘id’:1,’name’:”David”,”age”:50}) t.add_row({‘id’:2,’name’:”Anna”,”age”:21}) t #doctest: +NORMALIZE_WHITESPACE id name age
-- ----- --- 0 Sam 24 1 David 50 2 Anna 21
Rows can be accessed directly:
t.rows[1] #doctest: +SKIP {‘age’: 50, ‘id’: 1, ‘name’: ‘David’} t.max_value(‘age’) #doctest: +NORMALIZE_WHITESPACE 50 t.min_row(‘age’) #doctest: +NORMALIZE_WHITESPACE +SKIP {‘age’: 21, ‘id’: 2, ‘name’: ‘Anna’} sorted(t.min_row(‘id’).items()) #doctest: +NORMALIZE_WHITESPACE [(‘age’, 24), (‘id’, 0), (‘name’, ‘Sam’)] len(t) #doctest: +NORMALIZE_WHITESPACE 3 sum(t.getcolumn(‘age’)) #doctest: +NORMALIZE_WHITESPACE 95 t.write() #doctest: +SKIP
The table can be loaded from disk without specifying columns. This is slightly unsafe because the columns can’t be checked, but it could cut down on the verbosity in some places.
t2 = Table(“sample.tbl”) #doctest: +SKIP
Initialization