示例#1
0
 def test_ads_fp_gen(self):
     """Test the feature generation."""
     images = self.setup_atoms()
     images = autogen_info(images)
     print(str(len(images)) + ' training examples.')
     gen = FeatureGenerator()
     train_fpv = [
         gen.mean_chemisorbed_atoms,
         gen.count_chemisorbed_fragment,
         gen.count_ads_atoms,
         gen.count_ads_bonds,
         gen.mean_site,
         gen.sum_site,
         gen.mean_surf_ligands,
         gen.term,
         gen.bulk,
         gen.strain,
         gen.en_difference,
         # gen.ads_av,
         # gen.ads_sum,
     ]
     matrix = gen.return_vec(images, train_fpv)
     labels = gen.return_names(train_fpv)
     print(np.shape(matrix), type(matrix))
     if __name__ == '__main__':
         for i, l in enumerate(labels):
             print(i, l)
     self.assertTrue(len(labels) == np.shape(matrix)[1])
示例#2
0
def predict_catkit_demo(images):
    """Return a prediction of adsorption energies for structures generated with
    CatKitDemo.

    Parameters
    ----------
    images : list
        List of atoms objects representing adsorbate-surface structures.
    model : str
        Path and filename of Catlearn model pickle.
    """
    model_ref = {'H': 'H2', 'O': 'H2O, H2', 'C': 'CH4, H2'}

    # Make list of strings showing the references.
    display_ref = []
    for atoms in images:
        try:
            initial_state = [
                model_ref[s] for s in ase.atoms.string2symbols(
                    atoms.info['key_value_pairs']['species'])
            ]
        except KeyError:
            return {}
        display_ref.append('*, ' + ', '.join(list(np.unique(initial_state))))

    images = autogen_info(images)

    gen = FeatureGenerator(nprocs=1)
    train_fpv = default_fingerprinters(gen, 'adsorbates')
    train_fpv = [
        gen.mean_chemisorbed_atoms, gen.count_chemisorbed_fragment,
        gen.count_ads_atoms, gen.count_ads_bonds, gen.ads_av, gen.ads_sum,
        gen.bulk, gen.term, gen.strain, gen.mean_surf_ligands, gen.mean_site,
        gen.median_site, gen.max_site, gen.min_site, gen.sum_site,
        gen.generalized_cn, gen.en_difference_ads, gen.en_difference_chemi,
        gen.en_difference_active, gen.db_size, gen.delta_energy
    ]
    matrix = gen.return_vec(images, train_fpv)

    feature_index = np.load(clean_index_name)
    clean_feature_mean = np.load(clean_mean)

    impute = SimpleImputer(strategy='mean')
    impute.statistics_ = clean_feature_mean
    new_data = impute.transform(matrix[:, feature_index])

    prediction = gp.predict(new_data,
                            get_validation_error=False,
                            get_training_error=False,
                            uncertainty=True)

    output = {
        'mean': list(prediction['prediction']),
        'uncertainty': list(prediction['uncertainty']),
        'references': display_ref
    }
    return output
示例#3
0
    def test_recontruction(self):
        images = self.setup_atoms()
        slabs = []
        for atoms in images:
            slab = atoms.copy()
            slab.pop(-1)
            slabs.append(slab)
        images = autogen_info(images)
        slabs = images_connectivity(slabs)
        image_pairs = zip(images, slabs)
        reconstructed = check_reconstructions(image_pairs)

        self.assertTrue(len(reconstructed) == 0)
示例#4
0
 def test_tags(self):
     """Test the feature generation."""
     images = self.setup_atoms()
     images = autogen_info(images)
     print(str(len(images)) + ' training examples.')
     gen = FeatureGenerator(nprocs=1)
     train_fpv = default_fingerprinters(gen, 'adsorbates')
     matrix = gen.return_vec(images, train_fpv)
     labels = gen.return_names(train_fpv)
     print(np.shape(matrix), type(matrix))
     if __name__ == '__main__':
         for i, l in enumerate(labels):
             print(i, l)
     self.assertTrue(len(labels) == np.shape(matrix)[1])
示例#5
0
 def test_recontruction(self):
     images = database_to_list('data/ads_example.db')
     slabs = []
     for atoms in images:
         slab = atoms.copy()
         slab.pop(-1)
         slabs.append(slab)
     images = autogen_info(images)
     slabs = images_connectivity(slabs)
     image_pairs = zip(images, slabs)
     reconstructed = check_reconstructions(image_pairs)
     for i in range(len(images)):
         species = images[i].info['key_value_pairs']['species']
         connectivity2ads_index(images[i], species)
     self.assertTrue(len(reconstructed) == 0)
示例#6
0
 def test_db_ads(self):
     """Test the feature generation."""
     images = database_to_list('data/ads_example.db')
     images = autogen_info(images)
     print(str(len(images)) + ' training examples.')
     gen = FeatureGenerator(nprocs=1)
     train_fpv = default_fingerprinters(gen, 'adsorbates')
     train_fpv += [gen.db_size, gen.ctime, gen.dbid, gen.delta_energy]
     matrix = gen.return_vec(images, train_fpv)
     labels = gen.return_names(train_fpv)
     print(np.shape(matrix), type(matrix))
     if __name__ == '__main__':
         for i, l in enumerate(labels):
             print(i, l)
     self.assertTrue(len(labels) == np.shape(matrix)[1])
示例#7
0
 def test_db_ads(self):
     """Test the feature generation."""
     images = database_to_list('data/ads_example.db')
     [atoms.set_tags(np.zeros(len(atoms))) for atoms in images]
     images = autogen_info(images)
     print(str(len(images)) + ' training examples.')
     gen = FeatureGenerator(nprocs=1)
     train_fpv = default_fingerprinters(gen, 'adsorbates')
     # Test db specific functions.
     train_fpv += [gen.db_size, gen.ctime, gen.dbid, gen.delta_energy]
     # Old CatApp AxBy fingerprints.
     train_fpv += [gen.catapp_AB]
     matrix = gen.return_vec(images, train_fpv)
     labels = gen.return_names(train_fpv)
     print(np.shape(matrix), type(matrix))
     if __name__ == '__main__':
         for i, l in enumerate(labels):
             print(i, l)
     self.assertTrue(len(labels) == np.shape(matrix)[1])
示例#8
0
 def test_constrained_ads(self):
     """Test the feature generation."""
     images = self.setup_atoms()
     for atoms in images:
         c_atoms = [
             a.index for a in atoms if a.z < atoms.cell[2, 2] / 2. + 0.1
         ]
         atoms.set_constraint(FixAtoms(c_atoms))
     images = autogen_info(images)
     print(str(len(images)) + ' training examples.')
     gen = FeatureGenerator(nprocs=1)
     train_fpv = default_fingerprinters(gen, 'adsorbates')
     matrix = gen.return_vec(images, train_fpv)
     labels = gen.return_names(train_fpv)
     print(np.shape(matrix), type(matrix))
     if __name__ == '__main__':
         for i, l in enumerate(labels):
             print(i, l)
     self.assertTrue(len(labels) == np.shape(matrix)[1])