Output

Class which contains various methods to print the output of different ways of using FLARE, such as training a GP from an AIMD run, or running an MD simulation updated on-the-fly.

class flare.output.Output(basename: str = 'otf_run', verbose: str = 'INFO', print_as_xyz: bool = False, always_flush: bool = False)

This is an I/O class that hosts the log files for OTF and Trajectories class. It is also used in get_neg_like_grad and get_neg_likelihood in gp_algebra to print intermediate results.

It opens and print files with the basename prefix and different suffixes corresponding to different kinds of output data.

Parameters:
  • basename (str, optional) – Base output file name, suffixes will be added
  • verbose (str, optional) – print level. The same as logging level. It can be CRITICAL, ERROR, WARNING, INFO, DEBUG, NOTSET
  • always_flush – Always write to file instantly
conclude_run(extra_strings: List[str] = None)

destruction function that closes all files

open_new_log(filetype: str, suffix: str, verbose='info')

Open files. If files with the same name are exist, they are backed up with a suffix “-bak”.

Parameters:
  • filetype – the key name for logging
  • suffix – the suffix of the file to be opened
  • verbose – the verbose level for the logger
write_gp_dft_comparison(curr_step, frame, start_time, dft_forces, dft_energy, error, local_energies=None, KE=None, mgp=False, cell=None, stress=None)

Write the comparison to logfile.

Parameters:
  • curr_step – current timestep
  • frame – Structure object that contains the current GP calculation results.
  • start_time – start time for time profiling
  • dft_forces – list of forces computed by DFT
  • dft_energy – total energy computed by DFT
  • error – list of force differences between DFT and GP prediction
  • local_energies – local atomic energy
  • KE – total kinetic energy
  • cell – print the unit cell of the structure
  • stress – print the stress acting on the cell
Returns:

write_header(gp_str: str, dt: float = None, Nsteps: int = None, structure: flare.struc.Structure = None, std_tolerance: Union[float, int] = None, optional: dict = None)

TO DO: this should be replace by the string method of GP and OTF, GPFA

Write header to the log function. Designed for Trajectory Trainer and OTF runs and can take flexible input for both.

Parameters:
  • gp_str – string representation of the GP
  • dt – timestep for OTF MD
  • Nsteps – total number of steps for OTF MD
  • structure – initial structure
  • std_tolerance – tolarence for active learning
  • optional – a dictionary of all the other parameters
write_hyps(hyp_labels, hyps, start_time, like, like_grad, name='log', hyps_mask=None)

write hyperparameters to logfile

Parameters:
  • name
  • hyp_labels – labels for hyper-parameters. can be None
  • hyps – list of hyper-parameters
  • start_time – start time for time profiling
  • like – likelihood
  • like_grad – gradient of likelihood
Returns:

write_md_config(dt, curr_step, structure, temperature, KE, start_time, dft_step, velocities)

write md configuration in log file

Parameters:
  • dt – timestemp of OTF MD
  • curr_step – current timestep of OTF MD
  • structure – atomic structure
  • temperature – current temperature
  • KE – current total kinetic energy
  • local_energies – local energy
  • start_time – starting time for time profiling
  • dft_step – # of DFT calls
  • velocities – list of velocities
Returns:

write_to_log(logstring: str, name: str = 'log', flush: bool = False)

Write any string to logfile

Parameters:
  • logstring – the string to write
  • name – the key name of the file to logger named ‘log’
  • flush – whether it should be flushed
write_xyz_config(curr_step, structure, forces: <sphinx.ext.autodoc.importer._MockObject object at 0x7f30802d8a90> = None, stds: <sphinx.ext.autodoc.importer._MockObject object at 0x7f30802d8b10> = None, dft_forces: <sphinx.ext.autodoc.importer._MockObject object at 0x7f30802d8b50> = None, dft_energy=0, predict_energy=nan, target_atoms=None)

write atomic configuration in xyz file

Parameters:
  • curr_step – Int, number of frames to note in the comment line
  • structure – Structure, contain positions and forces
  • forces – Optional list of forces to xyz file
  • stds – Optional list of uncertanties to xyz file
  • dft_forces – Optional second list of forces (e.g. DFT forces)
Returns:

flare.output.add_file(logger: logging.Logger, filename: str, verbose: str = 'info')

set up file handler to the logger with handlers

Parameters:
  • logger – the logger
  • filename (str) – name of the logfile
  • verbose (str) – verbose level
flare.output.add_stream(logger: logging.Logger, verbose: str = 'info')

set up screen sctream handler to the logger with handlers

Parameters:
  • logger – the logger
  • verbose (str) – verbose level
flare.output.set_logger(name: str, stream: bool, fileout_name: str = None, verbose: str = 'info')

set up a logger with handlers

Parameters:
  • name (str) – unique name of the logger in logging module
  • stream (bool) – if True, set up a screen output
  • fileout_name (str) – name for log file
  • verbose (str) – verbose level