def test_adsorption(self): images = database_to_list('data/bajdichWO32018_ads.db') images = images_connectivity(images) slabs = database_to_list('data/bajdichWO32018_slabs.db') slabs_dict = {} for slab in slabs: slabs_dict[slab.info['id']] = slab for i, atoms in enumerate(images): species = atoms.info['key_value_pairs']['species'] atoms.subsets['ads_atoms'] = \ slab_positions2ads_index(atoms, slabs[i], species) if 'slab_atoms' not in atoms.subsets: atoms.subsets['slab_atoms'] = slab_index(atoms) if ('chemisorbed_atoms' not in atoms.subsets or 'site_atoms' not in atoms.subsets or 'ligand_atoms' not in atoms.subsets): chemi, site, ligand = info2primary_index(atoms) atoms.subsets['chemisorbed_atoms'] = chemi atoms.subsets['site_atoms'] = site atoms.subsets['ligand_atoms'] = ligand attach_cations(atoms, anion_number=8) charges = formal_charges(atoms) atoms.set_initial_charges(charges) gen = FeatureGenerator(nprocs=1) train_fpv = default_fingerprinters(gen, 'chalcogenides') matrix = gen.return_vec(images, train_fpv) labels = gen.return_names(train_fpv) if __name__ == '__main__': for i, l in enumerate(labels): print(i, l) print(atoms.get_initial_charges()) self.assertTrue(len(labels) == np.shape(matrix)[1])
def test_bulk_fp_gen(self): """Test the feature generation.""" images = self.setup_metal() images = images_connectivity(images) gen = FeatureGenerator() train_fpv = default_fingerprinters(gen, 'bulk') + [gen.bag_edges] matrix = gen.return_vec(images, train_fpv) labels = gen.return_names(train_fpv) print(np.shape(matrix), print(type(matrix))) self.assertTrue(len(labels) == np.shape(matrix)[1])
def test_tags(self): """Test the feature generation.""" images = self.setup_metals() images = autogen_info(images) print(str(len(images)) + ' training examples.') gen = FeatureGenerator(nprocs=1) train_fpv = default_fingerprinters(gen, 'adsorbates') train_fpv += [ gen.formal_charges, gen.bag_edges_ads, 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])
def test_constrained_ads(self): """Test the feature generation.""" images = self.setup_metals() [atoms.set_tags(np.zeros(len(atoms))) for atoms in images] 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])
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) layers2ads_index(images[0], images[0].info['key_value_pairs']['species']) 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])