wfl package#

Subpackages#

Submodules#

wfl.configset module#

class wfl.configset.ConfigSet(items, *, file_root=None, read_kwargs={}, _open_reader=None, _cur_at=None, _file_loc=None, _enclosing_loc='')#

Bases: object

Abstraction layer for storing and looping through collections of atomic configurations, either in memory or in files. Ignores existing Atom.info[“_ConfigSet_loc”] fields in Atoms objects that are passed in

If created from a list of Atoms, potentially nested, the stored nested structure (which is returned by the iterators) is that of the nested lists. If created from one file (str or Path), the top level of nesting returned by the iterators corresponds to individual Atoms or sub-lists within the file. If created from a list of files (even of length 1), the top level of nesting returned by the iterators corresponds to each file.

Iterating over the ConfigSet returns a flattened list of configurations in the object, with information about the nested structure (necessary for reproducing it in the output, see OutputSpec.store() below) available from the ConfigSet’s cur_loc property or in the returned returned objects in Atoms.info[“_ConfigSet_loc”].

Parameters
  • items (Atoms / list(Atoms) / list(list...(Atoms)) / str / Path / list(str) / list(Path)) – configurations to store, or list of file name globs for the configurations.

  • file_root (str / Path. default None) – path component to prepend to all file names

  • read_kwargs (dict, default {"index": ":", "parallel": False}) – optional kwargs passed to ase.io.iread function, overriding these default values

property cur_loc#

When looping over ConfigSet, which returns a flattened list of configurations, current location string, which can be passed to OutputSpec.store() to ensure that outputs retain same nesting structure as inputs. Alternative to Atoms.info[“_ConfigSet_loc”] in the most recently-returned Atoms object

groups()#

Generator returning a sequence of Atoms, or a sequence of ConfigSets, one for each sub-list. Nesting structure reflects the input, as described in the ConfigSet class/constructor docstring. If items argument to constructor was a single file, iterator will return individual configs, or ConfigSets for sub-lists. If argument was a list of files, iterator will return a sequence of ConfigSets, one for the content of each file. If argument was an Atoms or (nested) list of Atoms, iterator will reconstruct top level of initial nested structure.

one_file()#

Returns info on whether ConfigSet consists of exactly one file

Returns

one_file_name

Return type

Path of the one file, or False otherwise

class wfl.configset.OutputSpec(files=None, *, file_root=None, overwrite=False, flush=True, write_kwargs={}, tags={})#

Bases: object

Abstraction for writing to a ConfigSet, preserving tree structure.

Parameters
  • files (str / Path / iterable(str / Path), default None) – list of files to store configs in, or store in memory if None

  • file_root (str / Path, default None) – root directory relative to which all files will be taken

  • overwrite (str, default False) – Overwrite already existing files. Default False, but note that many functions, including any wrapped by autoparallelize, will actually reuse existing output if all of it appears to be present.

  • flush (bool, default True) – flush output after every write

  • write_kwargs (dict) – optional extra kwargs to ase.io.write

  • tags (dict) – dict of extra Atoms.info keys to set in written configs

all_written()#

Determine if all output has been created and writing operation is done from a previous run, even before any configurations have been written. Never true for in-memory storage.

Since files are initially written to under temporary names and renamed to their final names only after OutpuSpec.close(), this will only return true if close has been called.

NOTE: This will return false if a file specified in the constructor does not exist, which might happen if no input_CS_loc passed to OutputSpec.store() specified that file.

close()#

Finishes OutputSpec writing, closing all open files and renaming temporaries

store(configs, input_CS_loc='')#

Store Atoms or iterable containing Atoms or other iterables in a form that can be used to create a ConfigSet. If output ConfigSet is to have same structure as input ConfigSet, configs must come in the same order as the input ConfigSet’s flat iterator, with the store loc containing the _ConfigSet_loc values returned by that iterator.

This function is generally called by wfl’s built-in autoparallelization functions. An example that does the same thing is shown in the following construction:

cs = ConfigSet(["in0.xyz", "in1.xyz"])
os = OutputSpec(["out0.xyz", "out1.xyz"])
for at_in in cs:
    # define at_out, either an Atoms or a (nested) list of Atoms, based on at_in
    .
    .
    # the next line can also use at_in.info["_ConfigSet_loc"] instead of cs.get_loc()
    os.store(at_out, cs.get_loc())
os.close()
Parameters
  • configs (Atoms / iterable(Atoms / iterable)) – configurations to store

  • input_CS_loc (str, default "") – location in input iterable (source ConfigSet) so that output iterable has same structure as source ConfigSet. Available from the ConfigSet that is’s being iterated over via ConfigSet.cur_loc or the ConfigSet iterator’s returned Atoms.info[“_ConfigSet_loc”]. Required when writing to multiple files (since top level of location indicates which file), otherwise defaults to appending to single file or top level list of configs.

to_ConfigSet()#
write(configs)#

Write a set of configurations to this OutputSpec

Parameters

configs (iterable(Atoms)) – Configurations to write. If ConfigSet, location will be saved

wfl.descriptor_heuristics module#

wfl.descriptor_heuristics.descriptor_2brn_uniform_file(descriptor, ident='', desc_i=0)#

Write uniform-in-deformed-space sparse points file for 2-body polynomial descriptors

UNTESTED!!!!

Parameters
  • descriptor (dict) – nested structure with some contained dicts that have ‘sparse_method’ = ‘_2BRN_UNIFORM_FILE_’, and also n_sparse, exponents, cutoff

  • ident (str, default '') – identifier string to add to sparsepoints filename

  • desc_i (int, default 0) – offset to descriptor number in filename

Returns

desc_i – newly incremented desc_i

Return type

int

wfl.descriptor_heuristics.descriptors_from_length_scales(descriptors, Zs, length_scales, SOAP_hypers=None)#

Create all descriptors needed for all species in system

Parameters
  • descriptors (dict or list(dict)) – templates of descriptors to have templated contents replaced and optionally (depending on value of add_species) duplicated to account for all species.

  • Zs (list(int)) – list of atomic numbers present in the system

  • length_scales (dict) – length scales for each species. Keys are atomic numbers. For each atomic number has key ‘bond_len’, which points to tuple/list with first element being bond length

  • SOAP_hypers (dict, default None) – SOAP hypers from universal SOAP heuristics. Dict with atomic numbers as keys, values are dicts with keys ‘cutoff’, ‘cutoff_transition_width’, and ‘atom_gaussian_width’.

wfl.descriptor_heuristics.len_scale_pair(length_scales, t, Z1, Z2)#

Returns length scale for a pair of elements

Parameters
  • length_scales (dict) – dict with Z as keys

  • t (str) – type of length scale, key in length_scales[Z1] and Z2

  • Z1 (int) – atomic numbers of 2 atoms involved, keys for length_scales

  • Z2 (int) – atomic numbers of 2 atoms involved, keys for length_scales

Returns

Z1-Z2 length scale

Return type

int

wfl.map module#

wfl.map.map(*args, **kwargs)#

apply an arbitrary function to a set of atomic configurations

Parameters
  • inputs (iterable(Atoms)) – input quantities of type Atoms

  • outputs (OutputSpec or None) – where to write output atomic configs, or None for no output (i.e. only side-effects)

  • args (list) – positional arguments to function

  • kwargs (dict) – keyword arguments to function

  • autopara_info (AutoParaInfo / dict, optional) – information for automatic parallelization

Returns

co – output configs

Return type

ConfigSet

Module contents#