def from_arrays(cls, atom_array, bond_array, fragment_array, polymer_array, molecule_array, symbols, symmetry_transformations, cell_shape, convention): assert atom_array.dtype == atom_array_dtype assert bond_array.dtype == bond_array_dtype assert fragment_array.dtype == fragment_array_dtype if polymer_array is None: polymer_array = N.zeros((0,), dtype=polymer_array_dtype) assert polymer_array.dtype == polymer_array_dtype assert molecule_array.dtype == molecule_array_dtype assert isinstance(symbols, tuple) assert symmetry_transformations.dtype == st_array_dtype assert isascii(cell_shape) assert isascii(convention) universe = cls.__new__(cls) universe._atom_array = atom_array universe._bond_array = bond_array universe._fragment_array = fragment_array universe._polymer_array = polymer_array universe._molecule_array = molecule_array universe._symbols = tuple(symbols) universe._symmetry_transformations = symmetry_transformations universe._cell_shape = cell_shape universe._convention = convention return universe
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)