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 (alias Atoms).

Module Contents

Classes

ini

Dynamics

The Dynamics class handles I/O for the dynamics.txt file of an aKMC simulation.

Table

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.

Functions

prng_state_path

Path of the persisted numpy PRNG pickle.

save_prng_state

get_prng_state

atomic_write

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.

loadcons

loadxyz

Load the first frame of an XYZ/PDB/GRO file via readcon chemfiles ingress.

loadposcars

Load every POSCAR frame from filename (VASP 4 or VASP 5).

loadcon

Load a con file via readcon; return a Structure. filein: may be either a filename or a file-like object

savecon

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

load_mode

Reads a mode.dat file into an N by 3 numpy array modefilein: may be either a file-like object of a filename

save_mode

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.

save_results_dat

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

modify_config

parse_results

Reads a results.dat file and gives a dictionary of the values contained therein

loadposcar

Load a VASP POSCAR (or one frame of a multi-frame movie).

saveposcar

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

load_potfiles

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.save_prng_state(path)[source]
eon.fileio.get_prng_state(path)[source]
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.loadcons(filename)[source]
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.loadposcars(filename)[source]

Load every POSCAR frame from filename (VASP 4 or VASP 5).

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.modify_config(config_path, changes)[source]
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

read()[source]
get(section, option, default='ini_no_default', **kwargs)[source]
abstractmethod getint(*args)[source]
abstractmethod getfloat(*args)[source]
abstractmethod getboolean(*args)[source]
set(section, option, value)[source]
class eon.fileio.Dynamics(filename)[source]

The Dynamics class handles I/O for the dynamics.txt file of an aKMC simulation.

Initialization

append(reactant_id, process_id, product_id, step_time, total_time, barrier, rate, energy)[source]
append_sb(reactant_id, process_id, product_id, step_time, total_time, basin_id, rate, energy)[source]
get()[source]
eon.fileio.load_potfiles(pot_dir)[source]
exception eon.fileio.TableException[source]

Bases: Exception

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

init()[source]

Checks to see if self.filename exists. If it does self.rows will be initialized from disk.

read(filename)[source]
write()[source]
writefilehandle(filehandle)[source]
add_row(row)[source]
delete_row(column, value)[source]
delete_row_func(column, func)[source]
find_value(column, func)[source]
find_row(column, func)[source]
min_value(column)[source]
min_row(column)[source]
max_value(column)[source]
max_row(column)[source]
get_row(column, value)[source]
get_rows(column, value)[source]
get_column(column)[source]