Beispiel #1
0
 def test_fill_in_crystal_units_list(self):
     a = LazyValues(elements=ELEMENTS, coords=COORDS, numbers=NUMBERS,
                    connections=CONNECTIONS, unit_cell=UNIT_CELL)
     a.fill_in_crystal(units=[1, 2, 3])
     length = 3 * 5 * 7
     self.assertEqual(a.elements.tolist(), ELEMENTS * length)
     self.assertEqual(a.numbers.tolist(), NUMBERS * length)
Beispiel #2
0
 def test_fill_in_crystal_units_list(self):
     a = LazyValues(elements=ELEMENTS, coords=COORDS, numbers=NUMBERS,
                    connections=CONNECTIONS, unit_cell=UNIT_CELL)
     a.fill_in_crystal(units=[1, 2, 3])
     length = 3 * 5 * 7
     self.assertEqual(a.elements.tolist(), ELEMENTS * length)
     self.assertEqual(a.numbers.tolist(), NUMBERS * length)
Beispiel #3
0
 def test_fill_in_crystal(self):
     a = LazyValues(elements=ELEMENTS, coords=COORDS, numbers=NUMBERS,
                    connections=CONNECTIONS, unit_cell=UNIT_CELL)
     a.fill_in_crystal(radius=1.)
     length = 3
     self.assertEqual(a.elements.tolist(), ELEMENTS * length)
     expected_results = numpy.array([
         [0.99826008, -0.00246000, -1.00436000],
         [2.09021016, -0.00243000, -0.99586000],
         [0.63379005,  1.02686007, -0.99586000],
         [0.62704006, -0.52773003, -0.12188990],
         [0.64136006, -0.50747003, -1.90540005],
         [0.99826008, -0.00246000, -0.00436000],
         [2.09021016, -0.00243000,  0.00414000],
         [0.63379005,  1.02686007,  0.00414000],
         [0.62704006, -0.52773003,  0.87811010],
         [0.64136006, -0.50747003, -0.90540005],
         [0.99826008, -0.00246000,  0.99564000],
         [2.09021016, -0.00243000,  1.00414000],
         [0.63379005,  1.02686007,  1.00414000],
         [0.62704006, -0.52773003,  1.87811010],
         [0.64136006, -0.50747003,  0.09459995],
     ])
     try:
         numpy.testing.assert_array_almost_equal(
             a.coords,
             expected_results)
     except AssertionError as e:
         self.fail(e)
     self.assertEqual(a.numbers.tolist(), NUMBERS * length)
Beispiel #4
0
 def test_fill_in_crystal(self):
     a = LazyValues(elements=ELEMENTS, coords=COORDS, numbers=NUMBERS,
                    connections=CONNECTIONS, unit_cell=UNIT_CELL)
     a.fill_in_crystal(radius=1.)
     length = 3
     self.assertEqual(a.elements.tolist(), ELEMENTS * length)
     expected_results = numpy.array([
         [0.99826008, -0.00246000, -1.00436000],
         [2.09021016, -0.00243000, -0.99586000],
         [0.63379005,  1.02686007, -0.99586000],
         [0.62704006, -0.52773003, -0.12188990],
         [0.64136006, -0.50747003, -1.90540005],
         [0.99826008, -0.00246000, -0.00436000],
         [2.09021016, -0.00243000,  0.00414000],
         [0.63379005,  1.02686007,  0.00414000],
         [0.62704006, -0.52773003,  0.87811010],
         [0.64136006, -0.50747003, -0.90540005],
         [0.99826008, -0.00246000,  0.99564000],
         [2.09021016, -0.00243000,  1.00414000],
         [0.63379005,  1.02686007,  1.00414000],
         [0.62704006, -0.52773003,  1.87811010],
         [0.64136006, -0.50747003,  0.09459995],
     ])
     try:
         numpy.testing.assert_array_almost_equal(
             a.coords,
             expected_results)
     except AssertionError as e:
         self.fail(e)
     self.assertEqual(a.numbers.tolist(), NUMBERS * length)
Beispiel #5
0
 def test_fill_in_crystal_conn(self):
     eles = ['H']
     coords = numpy.array([[0.0, 0.0, 0.0]])
     nums = [1]
     connections = {0: {}}
     unit_cell = numpy.array([[1., 0, 0], [0, 1., 0], [0, 0, 1.]])
     a = LazyValues(elements=eles,
                    coords=coords,
                    numbers=nums,
                    connections=connections,
                    unit_cell=unit_cell)
     a.fill_in_crystal(radius=1.)
     self.assertEqual(a.elements.tolist(), eles * 7)
     expected = {
         0: {
             3: '1'
         },
         1: {
             3: '1'
         },
         2: {
             3: '1'
         },
         3: {
             0: '1',
             1: '1',
             2: '1',
             4: '1',
             5: '1',
             6: '1'
         },
         4: {
             3: '1'
         },
         5: {
             3: '1'
         },
         6: {
             3: '1'
         },
     }
     self.assertEqual(a.connections, expected)
Beispiel #6
0
 def test_fill_in_crystal_conn(self):
     eles = ['H']
     coords = numpy.array([[0.0, 0.0, 0.0]])
     nums = [1]
     connections = {0: {}}
     unit_cell = numpy.array([[1., 0, 0],
                              [0, 1., 0],
                              [0, 0, 1.]])
     a = LazyValues(elements=eles, coords=coords, numbers=nums,
                    connections=connections, unit_cell=unit_cell)
     a.fill_in_crystal(radius=1.)
     self.assertEqual(a.elements.tolist(), eles * 7)
     expected = {
         0: {3: '1'},
         1: {3: '1'},
         2: {3: '1'},
         3: {0: '1', 1: '1', 2: '1', 4: '1', 5: '1', 6: '1'},
         4: {3: '1'},
         5: {3: '1'},
         6: {3: '1'},
     }
     self.assertEqual(a.connections, expected)
Beispiel #7
0
    def test_fill_in_crystal_null(self):
        a = LazyValues()
        with self.assertRaises(ValueError):
            a.fill_in_crystal(radius=1.)

        a = LazyValues(unit_cell=UNIT_CELL)
        with self.assertRaises(ValueError):
            a.fill_in_crystal(radius=1.)

        length = 3
        a = LazyValues(numbers=NUMBERS, coords=COORDS, unit_cell=UNIT_CELL)
        a.fill_in_crystal(radius=1.)
        self.assertEqual(a.numbers.tolist(), NUMBERS * length)

        a = LazyValues(elements=ELEMENTS, coords=COORDS, unit_cell=UNIT_CELL)
        a.fill_in_crystal(radius=1.)
        self.assertEqual(a.elements.tolist(), ELEMENTS * length)
Beispiel #8
0
    def test_fill_in_crystal_null(self):
        a = LazyValues()
        with self.assertRaises(ValueError):
            a.fill_in_crystal(radius=1.)

        a = LazyValues(unit_cell=UNIT_CELL)
        with self.assertRaises(ValueError):
            a.fill_in_crystal(radius=1.)

        length = 3
        a = LazyValues(numbers=NUMBERS, coords=COORDS, unit_cell=UNIT_CELL)
        a.fill_in_crystal(radius=1.)
        self.assertEqual(a.numbers.tolist(), NUMBERS * length)

        a = LazyValues(elements=ELEMENTS, coords=COORDS, unit_cell=UNIT_CELL)
        a.fill_in_crystal(radius=1.)
        self.assertEqual(a.elements.tolist(), ELEMENTS * length)
Beispiel #9
0
    def test_fill_in_crystal_units_list_invalid(self):
        a = LazyValues(elements=ELEMENTS, coords=COORDS, numbers=NUMBERS,
                       connections=CONNECTIONS, unit_cell=UNIT_CELL)
        with self.assertRaises(ValueError):
            a.fill_in_crystal(units=[1, 2, 3, 4])

        with self.assertRaises(ValueError):
            a.fill_in_crystal(units=[1, 2])

        with self.assertRaises(ValueError):
            a.fill_in_crystal(units=[1, 2], radius=2)
Beispiel #10
0
    def test_fill_in_crystal_units_list_invalid(self):
        a = LazyValues(elements=ELEMENTS, coords=COORDS, numbers=NUMBERS,
                       connections=CONNECTIONS, unit_cell=UNIT_CELL)
        with self.assertRaises(ValueError):
            a.fill_in_crystal(units=[1, 2, 3, 4])

        with self.assertRaises(ValueError):
            a.fill_in_crystal(units=[1, 2])

        with self.assertRaises(ValueError):
            a.fill_in_crystal(units=[1, 2], radius=2)
Beispiel #11
0

# Define some base data
H_ELES = ['H']
H_NUMS = [1]
H_COORDS = numpy.array([
    [0.0, 0.0, 0.0],
])
H_CONNS = {
    0: {},
}
H_UNIT = numpy.array([
    [1., 0., 0.],
    [0., 1., 0.],
    [0., 0., 1.],
])
radius = 3


if __name__ == "__main__":
    vals = LazyValues(coords=H_COORDS, unit_cell=H_UNIT,
                      elements=H_ELES, numbers=H_NUMS)
    vals.fill_in_crystal(radius=radius)
    plot_cell(vals.coords, radius, vals.unit_cell,
              connections=vals.connections)

    vals = read_cry_data("../tests/data/methane.cry")
    vals.fill_in_crystal(radius=radius)
    plot_cell(vals.coords, radius, vals.unit_cell,
              connections=vals.connections)
Beispiel #12
0
H_COORDS = numpy.array([
    [0.0, 0.0, 0.0],
])
H_CONNS = {
    0: {},
}
H_UNIT = numpy.array([
    [1., 0., 0.],
    [0., 1., 0.],
    [0., 0., 1.],
])
radius = 3

if __name__ == "__main__":
    vals = LazyValues(coords=H_COORDS,
                      unit_cell=H_UNIT,
                      elements=H_ELES,
                      numbers=H_NUMS)
    vals.fill_in_crystal(radius=radius)
    plot_cell(vals.coords,
              radius,
              vals.unit_cell,
              connections=vals.connections)

    vals = read_cry_data("../tests/data/methane.cry")
    vals.fill_in_crystal(radius=radius)
    plot_cell(vals.coords,
              radius,
              vals.unit_cell,
              connections=vals.connections)