def _get_xyz_dset(f: File) -> Tuple[np.ndarray, Dict[str, List[int]]]: """Return the ``"xyz"zz dataset from **f**. Parameters ---------- f : |h5py.File|_ An opened hdf5 file. Returns ------- :math:`k*m*n*3` |np.ndarray|_ and |dict|_: An array of :math:`k` MultiMolecule instances with :math:`m` molecules and :math:`n` atoms. """ key = 'xyz' # Construct a dictionary with atomic symbols and matching atomic indices iterator = enumerate(f[key].attrs['atoms']) idx_dict = group_by_values(iterator) # Extract the Cartesian coordinates; sort in chronological order i = f.attrs['sub-iteration'] j = f[key].shape[0] - i ret: np.ndarray = np.empty_like(f[key]) ret[:j] = f[key][i:] ret[j:] = f[key][:i] return ret, idx_dict
def mol_from_hdf5(filename: PathType, i: int = -1, j: int = 0) -> Tuple3: """Read a single dataset from a (multi) .xyz.hdf5 file. Returns values for the :class:`MultiMolecule` ``coords``, ``atoms`` and ``bonds`` parameters. Parameters ---------- filename : :class:`str` The path+name of the .xyz.hdf5 file. i : :class:`int` The (sub-)iteration number of the to-be returned trajectory. j : :class:`int` The index of the to-be returned dataset. For example: :code:`j=0`is equivalent to the :code:`'xyz.0'` dataset. Returns ------- :class:`numpy.ndarray`, :class:`dict` [:class:`str`, :class:`list` [:class:`int`]] and :class:`numpy.ndarray`. * A 3D array with Cartesian coordinates of :math:`m` molecules with :math:`n` atoms. * A dictionary with atomic symbols as keys and lists of matching atomic indices as values. * A 2D array of bonds and bond-orders. """ # noqa with h5py.File(filename, 'r', libver='latest') as f: dset = f[f'xyz.{j}'] return (dset[i], group_by_values( enumerate(dset.attrs['atoms'].astype(str).tolist())), dset.attrs['bonds'])
def get_indices(mol: Molecule) -> Dict[str, np.ndarray]: """Construct a dictionary with atomic symbols as keys and arrays of indices as values.""" elements = [at.symbol for at in mol.atoms] symbol_enumerator = enumerate(elements) idx_dict = group_by_values(symbol_enumerator) for k, v in idx_dict.items(): idx_dict[k] = np.fromiter(v, dtype=int, count=len(v)) return idx_dict
def _get_idx_dict(kf: KFReader) -> IdxDict: """Extract atomic symbols and matching atomic indices from **kf**. Parameters ---------- kf : |plams.KFReader|_ A KFReader instance constructed from a KF binary file. Returns ------- |dict|_ [|str|_, |list|_ [|int|_]]: A dictionary with atomic symbols and a list of matching atomic indices. """ at_list = kf.read('Molecule', 'AtomSymbols').split() return group_by_values(enumerate(at_list))
def _get_idx_dict(f: Iterable[str], atom_count: int) -> Dict[str, List[int]]: """Extract atomic symbols and matching atomic indices from **f**. Parameters ---------- f : |io.TextIOWrapper|_ An opened .xyz file. atom_count : int The number of atoms per molecule. Returns ------- |dict|_ [|str|_, |list|_ [|int|_]]: A dictionary with atomic symbols and a list of matching atomic indices. """ stop = 1 + atom_count atom_list = [at.split(maxsplit=1)[0].capitalize() for at in islice(f, 1, stop)] return group_by_values(enumerate(atom_list))