예제 #1
0
 def container_factory(self, name, primitive_cell, size, origin):
     self.group = self.handle.create_group(self.handle.root, name)
     return H5Lattice.create_new(self.group,
                                 primitive_cell,
                                 size,
                                 origin,
                                 record=CustomRecord)
예제 #2
0
    def test_version(self):
        filename = os.path.join(self.temp_dir, "test_file.cuds")
        group_name = "dummy_component_name"
        with tables.open_file(filename, "w") as handle:
            group = handle.create_group(handle.root, group_name)

            # given/when
            H5Lattice.create_new(group, PrimitiveCell.for_cubic_lattice(0.2), size=(5, 10, 15), origin=(-2, 0, 1))

            # then
            self.assertTrue(isinstance(group._v_attrs.cuds_version, int))

        # when
        with tables.open_file(filename, "a") as handle:
            handle.get_node("/{}".format(group_name))._v_attrs.cuds_version = -1

        # then
        with tables.open_file(filename, "a") as handle:
            with self.assertRaises(ValueError):
                H5Lattice(handle.get_node("/" + group_name))
예제 #3
0
 def test_initialization_from_existing_lattice_in_file(self):
     lattice = H5Lattice(self.group)
     self.assertEqual(lattice.name, 'my_name')
     self.assertEqual(lattice.primitive_cell.bravais_lattice,
                      BravaisLattice.CUBIC)
     assert_array_almost_equal(lattice.primitive_cell.p1,
                               self.primitive_cell.p1)
     assert_array_almost_equal(lattice.primitive_cell.p2,
                               self.primitive_cell.p2)
     assert_array_almost_equal(lattice.primitive_cell.p3,
                               self.primitive_cell.p3)
     self.assertItemsEqual(lattice.size, self.size)
     assert_array_equal(lattice.origin, self.origin)
예제 #4
0
    def test_version(self):
        filename = os.path.join(self.temp_dir, 'test_file.cuds')
        group_name = "dummy_component_name"
        with tables.open_file(filename, 'w') as handle:
            group = handle.create_group(handle.root, group_name)

            # given/when
            H5Lattice.create_new(group,
                                 PrimitiveCell.for_cubic_lattice(0.2),
                                 size=(5, 10, 15),
                                 origin=(-2, 0, 1))

            # then
            self.assertTrue(isinstance(group._v_attrs.cuds_version, int))

        # when
        with tables.open_file(filename, 'a') as handle:
            handle.get_node(
                "/{}".format(group_name))._v_attrs.cuds_version = -1

        # then
        with tables.open_file(filename, 'a') as handle:
            with self.assertRaises(ValueError):
                H5Lattice(handle.get_node("/" + group_name))
예제 #5
0
    def _add_lattice(self, lattice):
        """Add lattice to the file.

        Parameters
        ----------
        lattice : Lattice
            lattice to be added

        Returns
        ----------
        H5Lattice
            The lattice newly added to the file.

        """
        name = lattice.name
        lattice_root = self._root.lattice

        group = tables.Group(lattice_root, name=name, new=True)
        h5_lattice = H5Lattice.create_new(
            group, lattice.primitive_cell, lattice.size, lattice.origin)
        h5_lattice.data = lattice.data
        h5_lattice.update_nodes(lattice.iter_nodes())
예제 #6
0
 def container_factory(self, name, primitive_cell, size, origin):
     self.group = self.handle.create_group(self.handle.root, name)
     return H5Lattice.create_new(self.group, primitive_cell, size, origin)