def __init__(self, hdf5_group_or_filename, universe=None, author_name='unknown', author_email=None, file_mode=None, float_type=np.float32, mosaic_data = {}): """ :param hdf5_group_or_filename: a group in an open HDF5 file, or a string interpreted as a file name :type hdf5_group_or_filename: str or ``h5py.Group`` :param file_mode: ``'r'`` or ``'w'``, used only with a filename argument :type file_mode: str :param universe: the universe associated with the trajectory :type universe: :class:`mosaic.api.MosaicUniverse` :param mosaic_data: additional MOSAIC data items to be stored """ if isstring(hdf5_group_or_filename): if file_mode is None: file_mode = 'r' self.root = h5py.File(hdf5_group_or_filename, file_mode) self._close = True else: api.validate_value(file_mode, [None], "file_mode") self.root = hdf5_group_or_filename self._close = False self.float_type = float_type self._mosaic_group(universe, mosaic_data) self._create_h5md_group(author_name, author_email) self._create_particles_group()
def __init__(self, universe, indices, selection_type): api.validate_type(universe, Universe, "universe") api.validate_array(indices, None, [N.uint8, N.uint16, N.uint32, N.uint64], "indices") api.validate_value(selection_type, self._allowed_types, "selection_type") self._universe = universe self._indices = indices self._type = selection_type
def __init__(self, universe, name, strings, label_type): api.validate_type(universe, Universe, "universe") api.validate_label(name, "name") api.validate_sequence(strings, str, "strings") api.validate_value(label_type, self._allowed_types, "label_type") self._universe = universe self._name = name self._string_array = N.array(list('\0'.join(strings) + '\0'), dtype='S') self._type = label_type
def __init__(self, universe, name, units, data, property_type): api.validate_type(universe, Universe, "universe") api.validate_label(name, "name") api.validate_units(units, "units") api.validate_array(data, None, self._allowed_dtypes, "data") api.validate_value(property_type, self._allowed_types, "property_type") self._universe = universe self._name = name self._units = units self._data = data self._type = property_type
def __init__(self, args): cell_shape, molecules, symmetry_transformations, convention = args api.validate_type(cell_shape, str, "cell_shape") api.validate_value(cell_shape, list(self._cell_parameter_array_shapes.keys()), "cell_shape") api.validate_sequence( molecules, ImmutableTuple, "molecules", ( (lambda p: len(p) == 3, "must have length 3"), ( lambda p: isinstance(p[0], Fragment) and isascii(p[1]) and isinstance(p[2], int), "elements must be (fragment, label, count) " "triples", ), ), ) api.validate_sequence( symmetry_transformations, ImmutableTuple, "symmetry_transformations", ( (lambda p: len(p) == 2, "must have length 2"), ( lambda p: hasattr(p[0], "shape") and p[0].shape == (3, 3) and p[0].dtype == N.float64, "rotation matrix must be float64 " "and have shape (3,3)", ), ( lambda p: hasattr(p[1], "shape") and p[1].shape == (3,) and p[0].dtype == N.float64, "translation vector must be float64 " "and have shape (3,)", ), ), ) if cell_shape == "infinite" and len(symmetry_transformations) > 0: raise ValueError("Symmetry transformations are allowed " "only in periodic universes") api.validate_label(convention, "Universe.convention") self._cell_shape = cell_shape self._molecules = ImmutableTuple( ImmutableTuple((FragmentRef(label, fragment), count)) for fragment, label, count in molecules ) self._symmetry_transformations = symmetry_transformations self._convention = convention self._fragments = ImmutableTuple(ImmutableTuple((f, l)) for f, l, c in molecules) self._molecule_counts = ImmutableTuple(c for f, l, c in molecules) self._atom_counts = ImmutableTuple(f.number_of_atoms for f, l, c in molecules) self._site_counts = ImmutableTuple(f.number_of_sites for f, l, c in molecules) self._bond_counts = ImmutableTuple(f.number_of_bonds for f, l, c in molecules)
def __init__(self, hdf5_group_or_filename, file_mode=None): """ :param hdf5_group_or_filename: a group in an open HDF5 file, or a string interpreted as a file name :type hdf5_group_or_filename: str or ``h5py.Group`` :param file_mode: ``'r'`` or ``'w'``, used only with a filename argument :type file_mode: str """ if isstring(hdf5_group_or_filename): if file_mode is None: file_mode = 'r' self.root = h5py.File(hdf5_group_or_filename, file_mode) self._close = True else: api.validate_value(file_mode, [None], "file_mode") self.root = hdf5_group_or_filename self._close = False self._path_map = weakref.WeakKeyDictionary() self._data_map = weakref.WeakValueDictionary() self._factory = mosaic.array_model.Factory()
def __init__(self, args): species, fragments, atoms, bonds = args api.validate_label(species, "species") self.species = species labels = set() api.validate_sequence(fragments, ImmutableTuple, "fragments", ((lambda p: len(p) == 2, "must have length 2"),)) for label, fragment in fragments: api.validate_label(label, "fragment label") if label in labels: raise ValueError("label %s occurs more than once" % label) labels.add(label) api.validate_type(fragment, Fragment, "fragment template") self.fragments = fragments api.validate_sequence(atoms, ImmutableTuple, "atoms", ((lambda p: len(p) == 2, "must have length 2"),)) for label, atom in atoms: api.validate_label(label, "atom label") if label in labels: raise ValueError("label %s occurs more than once" % label) labels.add(label) api.validate_type(atom, Atom, "atom") self.atoms = atoms self.attrs = ImmutableDict(IT.chain(fragments, atoms)) api.validate_sequence(bonds, tuple, "bonds", ((lambda p: len(p) == 3, "must have length 3"),)) for a1, a2, order in bonds: self._validate_bond_atom(a1) self._validate_bond_atom(a2) if a1.split(".")[0] == a2.split(".")[0]: raise ValueError( "bond between %s and %s must be defined " "in fragment %s" % (a1, a2, a1.split(".")[0]) ) api.validate_value(order, api.MosaicFragment._bond_orders, "bond order") self.bonds = bonds
def cell_shape(self, new_cell_shape): api.validate_type(new_cell_shape, str, "cell_shape") api.validate_value(new_cell_shape, self._cell_parameter_array_shapes.keys(), "cell_shape") self._cell_shape = new_cell_shape
def polymer_type(self, new_polymer_type): api.validate_value(new_polymer_type, self._polymer_types, 'polymer_type') self._polymer_type = new_polymer_type