Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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)))
Exemple #12
0
 def test_connections(self):
     a = LazyValues(elements=ELEMENTS, coords=COORDS, numbers=NUMBERS)
     self.assertEqual(a.connections, CONNECTIONS)
Exemple #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
Exemple #14
0
 def test_no_unit_cell(self):
     a = LazyValues(elements=ELEMENTS, numbers=NUMBERS)
     with self.assertRaises(ValueError):
         a.unit_cell
Exemple #15
0
 def test_no_coords(self):
     a = LazyValues(elements=ELEMENTS, numbers=NUMBERS)
     with self.assertRaises(ValueError):
         a.coords
Exemple #16
0
 def test_ele_from_num(self):
     a = LazyValues(numbers=NUMBERS)
     self.assertEqual(a.elements.tolist(), ELEMENTS)
Exemple #17
0
 def test_num_from_ele(self):
     a = LazyValues(elements=ELEMENTS)
     self.assertEqual(a.numbers.tolist(), NUMBERS)
Exemple #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)
Exemple #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)))
Exemple #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)
Exemple #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)