コード例 #1
0
    def test_attribute_generator(self):
        entries = [CompositionEntry(composition="NaCl"), CompositionEntry(
            composition="Fe"), CompositionEntry(composition="ZrO2"),
                   CompositionEntry(composition="UF6"), CompositionEntry(
                composition="Na2CoOSe")]
        cg = ChargeDependentAttributeGenerator()
        features = cg.generate_features(entries)

        # NaCl.
        np_tst.assert_array_almost_equal([-1, 1, 2, 1.0, 0, 5.139076, 349,
                                          3.16 - 0.93], features.values[0])

        # Fe.
        np_tst.assert_array_equal([np.nan] * features.values[1].size,
                                  features.values[1])

        # ZrO2.
        np_tst.assert_array_almost_equal([-2, 4, 6, 8.0 / 3, 8.0 / 9, 77.0639,
                                141 * 2, 3.44 - 1.33], features.values[2])

        # UF6.
        np_tst.assert_array_almost_equal([-1, 6, 7, 12.0 / 7, 1.224489796],
                                         features.values[3][:5])
        np_tst.assert_array_equal([np.nan] * 3, features.values[3][5:])

        # Na2CoOSe.
        np_tst.assert_array_almost_equal([-2, 2, 4, 1.6, 0.48, 5.139076 * 2 /
        3 + 24.96501 / 3, 141.0 + 195.0, 2.995 - 1.246666667],
                                         features.values[4])
コード例 #2
0
    def test_attribute_generator(self):
        # Create the hull data set.
        g = GCLPAttributeGenerator()
        g.set_phases([CompositionEntry(composition="NiAl")],[-1.0])

        # Create the test set.
        entries = [CompositionEntry(composition="Al"), CompositionEntry(
            composition="Ni3Al"), CompositionEntry(composition="NiAl")]

        # Compute features.
        features = g.generate_features(entries)

        # Test results.
        np.assert_array_almost_equal([0.0, 1, 0, 0, 0], features.values[0])
        np.assert_array_almost_equal([-0.5, 2, sqrt(0.125), sqrt(0.125),
                                      log(0.5)], features.values[1])
        np.assert_array_almost_equal([-1.0, 1, 0, 0, 0], features.values[2])

        # Set "no-count".
        g.set_count_phases(False)

        # Compute features.
        features = g.generate_features(entries)

        # Test results.
        np.assert_array_almost_equal([0.0, 0, 0], features.values[0])
        np.assert_array_almost_equal([-0.5, sqrt(0.125), sqrt(0.125)],
                                     features.values[1])
        np.assert_array_almost_equal([-1.0, 0, 0], features.values[2])
コード例 #3
0
    def test_attribute_generator(self):
        # Make a list of CompositionEntry's.
        entries = [CompositionEntry(composition="Na0.9Cl1.1"),
                   CompositionEntry(composition="CuCl2"), CompositionEntry(
                composition="FeAl"), CompositionEntry(composition="Fe")]

        # Make the generator and set options.
        ig = IonicCompoundProximityAttributeGenerator()
        ig.set_max_formula_unit(10)

        # Run the generator.
        features = ig.generate_features(entries)

        # Test results.
        self.assertEqual(1, len(features.columns))
        np_tst.assert_array_almost_equal([0.1, 0, 2, 1], features.iloc[:,0])

        # Now decrease the maximum size to 2, which means CuCl2 should match
        # CuCl.
        ig.set_max_formula_unit(2)

        # Run the generator.
        features = ig.generate_features(entries)

        # Test results.
        self.assertEqual(1, len(features.columns))
        np_tst.assert_array_almost_equal([0.1, 1.0 / 3, 2, 1],
                                         features.iloc[:,0])
コード例 #4
0
    def test_optimal_solver(self):
        # Get the radii lookup table.
        radii = LookUpData.load_property("MiracleRadius")

        # Find the best Cu cluster.
        entry = CompositionEntry(composition="Cu")
        ape = APEAttributeGenerator.determine_optimal_APE(28, entry, radii)
        self.assertAlmostEqual(0.976006 / 1.0, ape, delta=1e-6)

        # Find the best Cu-centered Cu64.3Zr35.7.
        entry = CompositionEntry(composition="Cu64.3Zr35.7")
        ape = APEAttributeGenerator.determine_optimal_APE(28, entry, radii)
        self.assertAlmostEqual(0.902113 / 0.916870416, ape, delta=1e-6)
コード例 #5
0
def load_comp_energy():
    """Load and return composition entries and formation energies (eV).
    From Magpie https://bitbucket.org/wolverton/magpie

    =================   ======================
    rows                                   630
    header                    formation_energy
    molecules rep.                 composition
    Features                                 0
    Returns             1 dataframe and 1 list
    =================   ======================

    Returns
    -------
    entries : list
        The list of composition entries from CompositionEntry class.

    energy : pandas dataframe
        The formation energy for each composition.

    Examples
    --------
    >>> from chemml.datasets import load_comp_energy
    >>> entries, df = load_comp_energy()
    >>> print(df.shape)
    (630, 1)
    """
    DATA_PATH = pkg_resources.resource_filename('chemml', os.path.join('datasets', 'data', 'magpie_python_test', 'small_set_comp.txt'))
    TARGET_PATH = pkg_resources.resource_filename('chemml', os.path.join('datasets', 'data', 'magpie_python_test', 'small_set_delta_e.txt'))
    from chemml.chem.magpie_python import CompositionEntry
    entries = CompositionEntry.import_composition_list(DATA_PATH)
    df = pd.read_csv(TARGET_PATH,header=None)
    df.columns = ['formation_energy']
    return entries, df
コード例 #6
0
    def test_attribute_generator(self):
        # Make a list of CompositionEntry's.
        entries = [CompositionEntry(composition="FeO")]

        # Make generators.
        eg = ElementFractionAttributeGenerator()
        mg = MeredigAttributeGenerator()
        vg = ValenceShellAttributeGenerator()

        # Generate features.
        f1 = eg.generate_features(entries)
        f2 = mg.generate_features(entries)
        f3 = vg.generate_features(entries)

        # Final results.
        features = pd.concat([f1, f2, f3], axis=1)

        # Test results.
        self.assertEqual(129, len(features.columns))
        self.assertEqual(129, features.values[0].size)

        self.assertEqual(0.5, features.values[0][25])
        self.assertEqual(0.5, features.values[0][7])
        np_tst.assert_array_almost_equal([
            35.92, 12.0, 3.0, 18, 17, 66, 99, 1.61, 2.635, 2, 2, 3, 0,
            2.0 / 7.0, 2.0 / 7.0, 3.0 / 7.0, 0
        ],
                                         features.values[0][112:],
                                         decimal=2)
コード例 #7
0
    def test_composition(self):
        # Make a fake cluster output.
        clusters = []
        elements = [0, 1]

        # Central type 0.
        l1 = [[12, 0], [5, 5]]
        clusters.append(l1)

        # Central type 1.
        l2 = [[2, 5]]
        clusters.append(l2)

        # Run the conversion.
        comps = APEAttributeGenerator.compute_cluster_compositions(
            elements, clusters)
        self.assertEqual(3, len(comps))
        self.assertTrue(CompositionEntry(composition="H") in comps)
        self.assertTrue(CompositionEntry(composition="H6He5") in comps)
        self.assertTrue(CompositionEntry(composition="H2He6") in comps)
コード例 #8
0
    def test_many_types(self):
        # This test is based on 6 as the max # of types.
        self.assertEqual(6, APEAttributeGenerator.max_n_types)

        # Make a 6 and 6+1 component alloy.
        entries = [
            CompositionEntry(composition="ScTiHfZrCrMo"),
            CompositionEntry(composition="ScTiHfZrCrMoP0.9")
        ]

        aag = APEAttributeGenerator()

        features = aag.generate_features(entries)
        feat_values = features.values

        # Make sure the features are not identical.
        for i in range(feat_values[0].size):
            self.assertNotAlmostEqual(feat_values[0][i],
                                      feat_values[1][i],
                                      delta=1e-6)
コード例 #9
0
    def test_attribute_generator(self):
        # Make a list of CompositionEntry's.
        entries = [
            CompositionEntry(composition="ZrHfTiCuNi"),
            CompositionEntry(composition="CuNi"),
            CompositionEntry(composition="CoCrFeNiCuAl0.3"),
            CompositionEntry(composition="CoCrFeNiCuAl")
        ]

        # Make the generator.
        yg = YangOmegaAttributeGenerator()

        # Run the generator.
        features = yg.generate_features(entries)

        # Test results.
        self.assertEqual(2, len(features.columns))

        # Results for ZrHfTiCuNi.
        self.assertAlmostEqual(0.95, features.values[0][0], delta=1e-2)
        self.assertAlmostEqual(0.1021, features.values[0][1], delta=1e-2)

        # Results for CuNi.
        self.assertAlmostEqual(2.22, features.values[1][0], delta=1e-2)
        self.assertAlmostEqual(0.0, features.values[1][1], delta=1e-2)
        # Miracle gives Cu+Ni the same radii as above.

        # Results for CoCrFeNiCuAl0.3.
        # Unable to reproduce paper for CoCrFeNiCuAl0.3, Ward et al. get
        # exactly 1/10th the value of deltaH as reported in the paper. They
        # have repeated this calculation by hand (read: Excel), and believe
        # their result to be correct. They get the same values for deltaS and
        #  T_m. They do get the same value for CoCrFeNiCuAl, so they've
        # concluded this is just a typo in the paper.
        self.assertAlmostEqual(158.5, features.values[2][0], delta=2e-1)
        self.assertAlmostEqual(0.0315, features.values[2][1], delta=1e-2)

        # Results for CoCrFeNiCuAl.
        self.assertAlmostEqual(5.06, features.values[3][0], delta=2e-1)
        self.assertAlmostEqual(0.0482, features.values[3][1], delta=1e-2)
コード例 #10
0
    def test_attribute_generator(self):
        # Make list of CompositionEntry's.
        entries = [
            CompositionEntry(composition="NaCl"),
            CompositionEntry(composition="Fe")
        ]

        # Make generator.
        el = ElementFractionAttributeGenerator()

        # Run generator.
        features = el.generate_features(entries)

        # Test results.
        self.assertEqual(len(LookUpData.element_names),
                         features.values[0].size)
        self.assertAlmostEqual(1.0, sum(features.values[0]), delta=1e-6)
        self.assertAlmostEqual(0.0, min(features.values[0]), delta=1e-6)
        self.assertAlmostEqual(0.5, features.values[0][10], delta=1e-6)
        self.assertAlmostEqual(1.0, sum(features.values[1]), delta=1e-6)
        self.assertAlmostEqual(0.0, min(features.values[1]), delta=1e-6)
        self.assertAlmostEqual(1.0, features.values[1][25], delta=1e-6)
コード例 #11
0
    def test_easy(self):
        # Make list of CompositionEntry's.
        entries = [
            CompositionEntry(composition="NaCl"),
            CompositionEntry(composition="Fe2O3")
        ]

        # Make generator and add property.
        el = ElementalPropertyAttributeGenerator(use_default_properties=False)
        el.add_elemental_property("Number")

        # Run generator.
        features = el.generate_features(entries)

        # Test results.
        self.assertEqual(6, features.values[0].size)

        # Results for NaCl.
        np_test.assert_array_almost_equal([14, 6, 3, 17, 11, 14],
                                          features.values[0])

        # Results for Fe2O3.
        np_test.assert_array_almost_equal([15.2, 18, 8.64, 26, 8, 8],
                                          features.values[1])
コード例 #12
0
    def test_attribute_generator(self):
        # Make a list of CompositionEntry's.
        entries = [
            CompositionEntry(composition="NaCl"),
            CompositionEntry(composition="CeFeO3")
        ]

        # Make the generator.
        vg = ValenceShellAttributeGenerator()

        # Run the generator.
        features = vg.generate_features(entries)

        # Test results.
        self.assertEqual(4, len(features.columns))
        self.assertEqual(4, features.values[0].size)

        # Results for NaCl.
        np_tst.assert_array_almost_equal([0.375, 0.625, 0, 0],
                                         features.values[0])

        # Results for CeFeO3.
        np_tst.assert_array_almost_equal([2.0 / 6, 2.4 / 6, 1.4 / 6, 0.2 / 6],
                                         features.values[1])
コード例 #13
0
    def test_attribute_generator(self):
        # Make a list of CompositionEntry's.
        entries = [CompositionEntry(composition="NaCl")]

        # Make the generator and set options.
        sg = StoichiometricAttributeGenerator(use_default_norms=False)
        sg.add_p_norm(2)
        sg.add_p_norm(3)

        # Run the generator.
        features = sg.generate_features(entries)

        # Test results.
        self.assertEqual(3, len(features.columns))
        self.assertEqual(3, features.values[0].size)
        np_tst.assert_array_almost_equal([2, sqrt(0.5), 0.25 ** (1.0 / 3)],
                                         features.values[0])
コード例 #14
0
    def test_attribute_generation(self):
        # Make a fake list of CompositionEntry's.
        entries = [CompositionEntry(composition="Cu64.3Zr35.7")]

        # Make attribute generator.
        aag = APEAttributeGenerator()

        # Set options.
        aag.set_packing_threshold(0.01)
        aag.set_n_nearest_to_eval([1, 3])

        # Compute features.
        features = aag.generate_features(entries)

        # Test results.
        self.assertEqual(4, features.size)
        self.assertEqual(features.size, features.values.size)
        self.assertTrue(features.values[0][0] < features.values[0][1])
        self.assertAlmostEqual(0.979277669, features.values[0][2], delta=1e-6)
        self.assertAlmostEqual(0.020722331, features.values[0][3], delta=1e-6)
コード例 #15
0
    def test_with_missing(self):
        # Make list of CompositionEntry's.
        entries = [CompositionEntry(composition="HBr")]

        # Make generator and add properties.
        el = ElementalPropertyAttributeGenerator(use_default_properties=False)
        el.add_elemental_property("Number")
        el.add_elemental_property("ZungerPP-r_d")
        el.add_elemental_property("Row")

        # Run generator.
        features = el.generate_features(entries)

        # Test results.
        self.assertEqual(18, features.values[0].size)

        # Results for HBr, only bothering testing mean and max.
        self.assertAlmostEqual(18, features.values[0][0], delta=1e-6)
        self.assertAlmostEqual(35, features.values[0][3], delta=1e-6)
        self.assertTrue(np.isnan(features.values[0][6]))
        self.assertTrue(np.isnan(features.values[0][9]))
        self.assertAlmostEqual(2.5, features.values[0][12], delta=1e-6)
        self.assertAlmostEqual(4, features.values[0][15], delta=1e-6)