IMLCV.base.CV#
Module Contents#
Classes#
class to keep track of topology of given CV. Identifies the periodicitie of CVs and maps to unit square with correct peridicities |
|
used to instantiate flax linen CvTrans |
|
creates bijective CV function based on a distrax flow. The seup function should initialize the bijector |
|
f can either be a single CV tranformation or a list of transformations |
|
Base class for all neural network modules. Layers and models should subclass this class. |
|
normalizing flow. _ProtoCvTransNN are stored separately because they need to be initialized by this module in setup |
|
- class IMLCV.base.CV.SystemParams[source]#
-
- __getitem__(slices) SystemParams[source]#
- batch() SystemParams[source]#
- unbatch() SystemParams[source]#
- _get_neighbour_list(r_cut, r_skin: float = 0.0, z_array: tuple[int] | None = None, z_unique: tuple[int] | None = None, num_z_unique: tuple[int] | None = None, num_neighs: int | None = None, nxyz: tuple[int] | None = None) tuple[bool, NeighbourList | None][source]#
- minkowski_reduce() tuple[SystemParams, jax.Array][source]#
base on code from ASE: https://wiki.fysik.dtu.dk/ase/_modules/ase/geometry/minkowski_reductsp.cellion.html#minkowski_reduce
- wrap_positions(min=False) tuple[SystemParams, jax.Array][source]#
wrap pos to lie within unit cell
- class IMLCV.base.CV.NeighbourList[source]#
-
- r_cut: jax_dataclasses.Static[jax.numpy.floating][source]#
- r_skin: jax_dataclasses.Static[jax.numpy.floating][source]#
- sp_orig: SystemParams | None[source]#
- apply_fun_neighbour(sp: SystemParams, func, r_cut=None, fill_value=0, reduce='full', split_z=False, exclude_self=False)[source]#
- apply_fun_neighbour_pair(sp: SystemParams, func_double, func_single=None, r_cut=None, fill_value=0, reduce='full', split_z=False, exclude_self=True, unique=True)[source]#
Args:#
func_single=lambda r_ij, atom_index_j: (1,), func_double=lambda r_ij, atom_index_j, data_j, r_ik, atom_index_k, data_k: (
r_ij, atom_index_j, r_ik, atom_index_k,
),
- update(sp: SystemParams) tuple[bool, NeighbourList][source]#
- static match_kernel(p1: jax.Array, p2: jax.Array, nl1: NeighbourList, nl2: NeighbourList, matching='REMatch', alpha=0.01, mode='divergence', jit=True)[source]#
- static stack(*nls: NeighbourList) NeighbourList[source]#
- class IMLCV.base.CV.CV[source]#
- class IMLCV.base.CV.CvMetric(periodicities, bounding_box=None)[source]#
class to keep track of topology of given CV. Identifies the periodicitie of CVs and maps to unit square with correct peridicities
- __periodic_wrap(xs: jax.Array, min=False)[source]#
Translate cvs such over unit cell.
min=True calculates distances, False translates one vector inside box
- grid(n, endpoints=None, margin=None)[source]#
forms regular grid in mapped space. If coordinate is periodic, last rows are ommited.
- Parameters:
n – number of points in each dim
map – boolean. True: work in mapped space (default), False: calculate grid in space without metric
endpoints – if
- Returns:
meshgrid and vector with distances between points
- class IMLCV.base.CV.CvFunBase[source]#
-
- cv_input: CvFunInput | None[source]#
- calc(x: CV, nl: NeighbourList | None, reverse=False, log_det=False) tuple[CV, Array | None][source]#
- class IMLCV.base.CV.CvFunNn[source]#
Bases:
flax.linen.Module,CvFunBaseused to instantiate flax linen CvTrans
- abstract setup()[source]#
Initializes a Module lazily (similar to a lazy
__init__).setupis called once lazily on a module instance when a module is bound, immediately before any other methods like__call__are invoked, or before asetup-defined attribute on self is accessed.This can happen in three cases:
Immediately when invoking
apply(),init()orinit_and_output().Once the module is given a name by being assigned to an attribute of another module inside the other module’s
setupmethod (see__setattr__()):class MyModule(nn.Module): def setup(self): submodule = Conv(...) # Accessing `submodule` attributes does not yet work here. # The following line invokes `self.__setattr__`, which gives # `submodule` the name "conv1". self.conv1 = submodule # Accessing `submodule` attributes or methods is now safe and # either causes setup() to be called once.
Once a module is constructed inside a method wrapped with
compact(), immediately before another method is called orsetupdefined attribute is accessed.
- class IMLCV.base.CV.CvFunDistrax[source]#
Bases:
flax.linen.Module,CvFunBasecreates bijective CV function based on a distrax flow. The seup function should initialize the bijector
- class RealNVP(CvFunDistrax):
_: dataclasses.KW_ONLY latent_dim: int
- def setup(self):
self.s = Dense(features=self.latent_dim) self.t = Dense(features=self.latent_dim)
# Alternating binary mask. self.bijector = distrax.as_bijector(
- tfp.bijectors.RealNVP(
fraction_masked=0.5, shift_and_log_scale_fn=self.shift_and_scale,
)
)
- def shift_and_scale(self, x0, input_depth, **condition_kwargs):
return self.s(x0), self.t(x0)
- class IMLCV.base.CV.CombinedCvFun[source]#
Bases:
CvFunBase
- class IMLCV.base.CV.CvTrans[source]#
f can either be a single CV tranformation or a list of transformations
- static from_array_function(f: collections.abc.Callable[[jax.Array, NeighbourList | None, None], jax.Array])[source]#
- static from_cv_function(f: collections.abc.Callable[[CV, NeighbourList | None, CV | None], CV]) CvTrans[source]#
- class IMLCV.base.CV.CvTransNN[source]#
Bases:
flax.linen.Module,CvTransBase class for all neural network modules. Layers and models should subclass this class.
All Flax Modules are Python 3.7 dataclasses. Since dataclasses take over
__init__, you should instead overridesetup(), which is automatically called to initialize the module.Modules can contain submodules, and in this way can be nested in a tree structure. Submodels can be assigned as regular attributes inside the
setup()method.You can define arbitrary “forward pass” methods on your Module subclass. While no methods are special-cased,
__call__is a popular choice because it allows you to use module instances as if they are functions:from flax import linen as nn class Module(nn.Module): features: Tuple[int, ...] = (16, 4) def setup(self): self.dense1 = Dense(self.features[0]) self.dense2 = Dense(self.features[1]) def __call__(self, x): return self.dense2(nn.relu(self.dense1(x)))
Optionally, for more concise module implementations where submodules definitions are co-located with their usage, you can use the
compact()wrapper.- setup() None[source]#
Initializes a Module lazily (similar to a lazy
__init__).setupis called once lazily on a module instance when a module is bound, immediately before any other methods like__call__are invoked, or before asetup-defined attribute on self is accessed.This can happen in three cases:
Immediately when invoking
apply(),init()orinit_and_output().Once the module is given a name by being assigned to an attribute of another module inside the other module’s
setupmethod (see__setattr__()):class MyModule(nn.Module): def setup(self): submodule = Conv(...) # Accessing `submodule` attributes does not yet work here. # The following line invokes `self.__setattr__`, which gives # `submodule` the name "conv1". self.conv1 = submodule # Accessing `submodule` attributes or methods is now safe and # either causes setup() to be called once.
Once a module is constructed inside a method wrapped with
compact(), immediately before another method is called orsetupdefined attribute is accessed.
- class IMLCV.base.CV.NormalizingFlow[source]#
Bases:
flax.linen.Modulenormalizing flow. _ProtoCvTransNN are stored separately because they need to be initialized by this module in setup
- setup() None[source]#
Initializes a Module lazily (similar to a lazy
__init__).setupis called once lazily on a module instance when a module is bound, immediately before any other methods like__call__are invoked, or before asetup-defined attribute on self is accessed.This can happen in three cases:
Immediately when invoking
apply(),init()orinit_and_output().Once the module is given a name by being assigned to an attribute of another module inside the other module’s
setupmethod (see__setattr__()):class MyModule(nn.Module): def setup(self): submodule = Conv(...) # Accessing `submodule` attributes does not yet work here. # The following line invokes `self.__setattr__`, which gives # `submodule` the name "conv1". self.conv1 = submodule # Accessing `submodule` attributes or methods is now safe and # either causes setup() to be called once.
Once a module is constructed inside a method wrapped with
compact(), immediately before another method is called orsetupdefined attribute is accessed.
- class IMLCV.base.CV.CvFlow(func: collections.abc.Callable[[SystemParams, NeighbourList | None], CV], trans: CvTrans | None = None)[source]#
- static from_function(f: collections.abc.Callable[[SystemParams, NeighbourList | None], jax.Array], atomic=False) CvFlow[source]#
- compute_cv_flow(x: SystemParams, nl: NeighbourList | None = None, jit=True, chunk_size: int | None = None) CV[source]#
- find_sp(x0: SystemParams, target: CV, target_nl: NeighbourList, nl0: NeighbourList | None = None, maxiter=10000, tol=0.0001, norm=lambda cv1, cv2, nl1, nl2: ..., solver=jaxopt.GradientDescent) SystemParams[source]#