Exemplo n.º 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)
Exemplo n.º 2
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)
Exemplo n.º 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)
Exemplo n.º 4
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)
Exemplo n.º 5
0
 def test_all(self):
     a = LazyValues(elements=ELEMENTS, coords=COORDS, numbers=NUMBERS,
                    connections=CONNECTIONS, unit_cell=UNIT_CELL)
     self.assertEqual(a.elements.tolist(), ELEMENTS)
     self.assertEqual(a.coords.tolist(), COORDS)
     self.assertEqual(a.numbers.tolist(), NUMBERS)
     self.assertEqual(a.connections, CONNECTIONS)
     self.assertEqual(a.unit_cell.tolist(), UNIT_CELL)
Exemplo n.º 6
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)
Exemplo n.º 7
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)
Exemplo n.º 8
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)
Exemplo n.º 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)
Exemplo n.º 10
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)
Exemplo n.º 11
0
    feat = CoulombMatrix()
    H2_conn = (H2_ELES, H2_COORDS, H2_CONNS)
    HCN_conn = (HCN_ELES, HCN_COORDS, HCN_CONNS)
    print(feat.fit_transform([H2_conn, HCN_conn]))
    print()

    # Example of generating the Coulomb matrix using a specified input_type
    print("User specified input_type")
    feat = CoulombMatrix(input_type=("coords", "numbers"))
    H2_spec = (H2_COORDS, H2_NUMS)
    HCN_spec = (HCN_COORDS, HCN_NUMS)
    print(feat.fit_transform([H2_spec, HCN_spec]))
    print()

    # Example of generating the Local Coulomb matrix (atom-wise
    # representation)
    print("Atom feature")
    feat = LocalCoulombMatrix()
    print(feat.fit_transform([H2, HCN]))

    # Example of generating AtomKernel
    print("Atom Kernel")
    feat = AtomKernel(transformer=LocalCoulombMatrix())
    print(feat.fit_transform([H2, HCN]))

    # Example of using arbitrary function to load data
    # This example is useless, but it shows the possibility
    feat = CoulombMatrix(
        input_type=lambda x: LazyValues(elements=HCN_ELES, coords=HCN_COORDS))
    feat.fit_transform(list(range(10)))
Exemplo n.º 12
0
 def test_connections(self):
     a = LazyValues(elements=ELEMENTS, coords=COORDS, numbers=NUMBERS)
     self.assertEqual(a.connections, CONNECTIONS)
Exemplo n.º 13
0
 def test_no_ele_or_num(self):
     a = LazyValues(coords=COORDS)
     with self.assertRaises(ValueError):
         a.elements
     with self.assertRaises(ValueError):
         a.numbers
Exemplo n.º 14
0
 def test_no_unit_cell(self):
     a = LazyValues(elements=ELEMENTS, numbers=NUMBERS)
     with self.assertRaises(ValueError):
         a.unit_cell
Exemplo n.º 15
0
 def test_no_coords(self):
     a = LazyValues(elements=ELEMENTS, numbers=NUMBERS)
     with self.assertRaises(ValueError):
         a.coords
Exemplo n.º 16
0
 def test_ele_from_num(self):
     a = LazyValues(numbers=NUMBERS)
     self.assertEqual(a.elements.tolist(), ELEMENTS)
Exemplo n.º 17
0
 def test_num_from_ele(self):
     a = LazyValues(elements=ELEMENTS)
     self.assertEqual(a.numbers.tolist(), NUMBERS)
Exemplo n.º 18
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)
Exemplo n.º 19
0
    feat = CoulombMatrix()
    H2_conn = (H2_ELES, H2_COORDS, H2_CONNS)
    HCN_conn = (HCN_ELES, HCN_COORDS, HCN_CONNS)
    print(feat.fit_transform([H2_conn, HCN_conn]))
    print()

    # Example of generating the Coulomb matrix using a specified input_type
    print("User specified input_type")
    feat = CoulombMatrix(input_type=("coords", "numbers"))
    H2_spec = (H2_COORDS, H2_NUMS)
    HCN_spec = (HCN_COORDS, HCN_NUMS)
    print(feat.fit_transform([H2_spec, HCN_spec]))
    print()

    # Example of generating the Local Coulomb matrix (atom-wise
    # representation)
    print("Atom feature")
    feat = LocalCoulombMatrix()
    print(feat.fit_transform([H2, HCN]))

    # Example of generating AtomKernel
    print("Atom Kernel")
    feat = AtomKernel(transformer=LocalCoulombMatrix())
    print(feat.fit_transform([H2, HCN]))

    # Example of using arbitrary function to load data
    # This example is useless, but it shows the possibility
    feat = CoulombMatrix(input_type=lambda x: LazyValues(elements=HCN_ELES,
                                                         coords=HCN_COORDS))
    feat.fit_transform(list(range(10)))
Exemplo n.º 20
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)
Exemplo n.º 21
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)