mxtaltools.common.utils
- mxtaltools.common.utils.batch_compute_dipole(pos, batch, z, electronegativity_tensor)[source]
Compute a rough dipole moment for a flat batch of molecules, as the simple weighted sum of electronegativities. Do this in a batch fashion assuming the input is a flat list of graphs, indexed by batch
- Parameters:
pos (torch.tensor(n,3)) – 3d coordinates
batch (torch.tensor(n)) – batch index
z (torch.tensor(n)) – atom types
electronegativity_tensor – fixed electronegativities for each atom type
- Returns:
dipole_moment
- Return type:
torch.tensor(num_graphs,3)
- mxtaltools.common.utils.block_repeat_interleave(lengths: Tensor, repeats: Tensor) Tensor[source]
Repeat ragged blocks of a flat tensor in parallel on GPU.
- Parameters:
lengths – (num_blocks,) tensor of block lengths.
repeats – (num_blocks,) tensor of repeat counts per block.
- Returns:
1D tensor with each block repeated blockwise.
- mxtaltools.common.utils.chunkify(lst: list, n: int)[source]
break up a list into n chunks of equal size (up to last chunk)
- mxtaltools.common.utils.flatten_dict(dictionary, parent_key=False, separator='_')[source]
From : https://stackoverflow.com/questions/6027558/flatten-nested-dictionaries-compressing-keys Recursively convert a nested dictionary into a flattened dictionary
- Parameters:
dictionary
parent_key
separator
- Return type:
Dict with all nested dict flattened, with longer keys instead of nesting.
- mxtaltools.common.utils.histogram_overlap_np(d1: ndarray, d2: ndarray)[source]
Compute the symmetric overlap of two histograms
- Parameters:
d1 (np.array(n))
d2 (np.array(n))
- Returns:
overlap
- Return type:
- mxtaltools.common.utils.invert_softplus_shift(y: Tensor, min_val: float | Tensor | None = 0.01, beta: float | None = 10) Tensor[source]
- mxtaltools.common.utils.namespace2dict(namespace_dict, higher_level='')[source]
Convert a dict from an optionally nested namespace to an optionally nested dict.
- Parameters:
namespace_dict (dict for the higher level namespace)
higher_level (key for high level dict)
- Return type:
Dict matching higher level namespace
- mxtaltools.common.utils.normalize_np(x: ndarray)[source]
normalize an input by its span subtract min_x so that range is fixed on [0,1]
- Parameters:
x (np.array)
- Returns:
normed_x
- Return type:
np.array
- mxtaltools.common.utils.parse_to_torch(array: Tensor | ndarray | list, device: device | str, dtype=<class 'torch.float32'>) Tensor[source]
- mxtaltools.common.utils.repeat_interleave(repeats: List[int], device: device | None = None)[source]
# todo why do we have this? There are builtin methods in torch. # TODO replace and deprecate Alternate implementation of torch.repeat_interleave borrowed from torch_geometric.data.collate
- Parameters:
repeats (list of ints)
device (str or torch.device)
- Return type:
Repeated tensor which has the same shape as input, except along the given axis.
- mxtaltools.common.utils.sample_triangular_right(n_samples, start, stop, device='cpu')[source]
sample from the CDF of a uniform distribution the right-aligned triangular distribution
- mxtaltools.common.utils.smooth_constraint(value: Tensor, threshold: float, mode: str, hardness: float)[source]
- mxtaltools.common.utils.softmax_np(x: ndarray, temperature: float = 1)[source]
softmax function implemented in numpy
- Parameters:
x (np.array)
temperature (float) – softmax temperature
- Returns:
softmax_x
- Return type:
np.array
- mxtaltools.common.utils.softplus_shift(x: Tensor, min_val: float | Tensor | None = 0.01, beta: float | None = 10) Tensor[source]
- mxtaltools.common.utils.standardize_np(data: ndarray, return_standardization: bool = False, known_mean=None, known_std=None)[source]
standardize an input 1D array by subtracting mean and dividing by standard deviation