def __init__(self, universe, name, units,
                 data=None, dtype=None, element_shape=None):
        api.validate_type(universe, Universe, "universe")
        self._universe = universe
        api.validate_label(name, "name")
        self._name = name
        api.validate_units(units, "units")
        self._units = units
        if data is None:
            if dtype is None:
                dtype = N.float64
            if dtype not in self._allowed_dtypes:
                raise ValueError("dtype must be " +
                                 " or ".join(str(t)
                                             for t in self._allowed_dtypes))
            if element_shape is None:
                element_shape = ()
            array_shape = (self._number_of_values(),) + element_shape

            self._data = N.empty(array_shape, dtype)
        else:
            api.validate_array(data, None, self._allowed_dtypes, "data")
            if dtype is not None and data.dtype != dtype:
                raise ValueError("elements of data array do not have "
                                 "the requested type")
            if data.shape[0] != self._number_of_values():
                raise ValueError("data array has incorrect shape")
            if element_shape is not None and data.shape[1:] != element_shape:
                raise ValueError("elements of data array do not have "
                                 "the requested shape")
            self._data = data
Esempio n. 2
0
 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
Esempio n. 3
0
 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
Esempio n. 4
0
 def __init__(self, universe, name, strings):
     api.validate_type(universe, Universe, "universe")
     self._universe = universe
     api.validate_label(name, "name")
     self._name = name
     api.validate_sequence(strings, str, "strings")
     if len(strings) != self._number_of_values():
         raise ValueError("incorrect number of strings")
     for s in strings:
         api.validate_ascii_string(s, "label")
     self._strings = ImmutableTuple(strings)
Esempio n. 5
0
 def __init__(self, universe, name, units, data):
     api.validate_type(universe, Universe, "universe")
     self._universe = universe
     api.validate_label(name, "name")
     self._name = name
     api.validate_units(units, "units")
     self._units = units
     api.validate_array(data, None, self._allowed_dtypes, "data")
     if data.shape[0] != self._number_of_values():
         raise ValueError("data array has incorrect shape")
     self._data = data
Esempio n. 6
0
    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)
Esempio n. 7
0
    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 convention(self, new_convention):
     api.validate_label(new_convention, "convention")
     self._convention = new_convention
 def species(self, new_species):
     api.validate_label(new_species, "Fragment.species")
     self._species = new_species
 def label(self, new_label):
     api.validate_label(new_label, "Fragment.label")
     self._label = new_label
 def label(self, new_label):
     api.validate_label(new_label, "Atom.label")
     self._label = new_label
Esempio n. 12
0
 def _validate_name(cls, name):
     api.validate_label(name, "name")