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])
Exemple #3
0
def autogen_info(images):
    """Return a list of atoms objects with atomic group information
    attached to atoms.subsets.
    This information is  needed by some functions in the
    AdsorbateFingerprintGenerator.

    Parameters
    ----------
    images : list
        list of atoms objects representing adsorbates on slabs.
        No further information is required in atoms.subsets.
    """
    images = images_connectivity(images)
    for i, atoms in tqdm(enumerate(images)):
        # Pre-allocate subsets dictionary.
        if not hasattr(atoms, 'subsets'):
            atoms.subsets = {}

        # Identify adsorbate atoms.
        if 'ads_atoms' not in atoms.subsets:
            ads_atoms = detect_adsorbate(atoms)
            atoms.subsets['ads_atoms'] = ads_atoms
            if len(ads_atoms) == 0:
                continue

        # Identify slab atoms.
        if 'slab_atoms' not in atoms.subsets:
            atoms.subsets['slab_atoms'] = slab_index(atoms)
        if not (len(atoms.subsets['slab_atoms']) +
                len(atoms.subsets['ads_atoms']) ==
                len(atoms)):
            raise AssertionError("all atoms must belong to slab or adsorbate.")

        # Identify atoms at node distance 0 and 1 from the surface-ads bond.
        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

        # Identify surface layers.
        if ('bulk_atoms' not in atoms.subsets or
            'termination_atoms' not in atoms.subsets or
           'subsurf_atoms' not in atoms.subsets):
            bulk, term, subsurf = detect_termination(atoms)
            atoms.subsets['bulk_atoms'] = bulk
            atoms.subsets['termination_atoms'] = term
            atoms.subsets['subsurf_atoms'] = subsurf
    return images
Exemple #4
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)
     r_index = 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(r_index) == 0)
Exemple #5
0
def autogen_info(images):
    """Return a list of atoms objects with atomic group information
    attached to atoms.subsets.
    This information is  needed by some functions in the
    AdsorbateFingerprintGenerator.

    Parameters
    ----------
    images : list
        list of atoms objects representing adsorbates on slabs.
        No further information is required in atoms.subsets.
    """
    images = images_connectivity(images)
    for atoms in tqdm(images):
        if not hasattr(atoms, 'subsets'):
            atoms.subsets = {}
        if 'ads_atoms' not in atoms.subsets:
            ads_atoms = detect_adsorbate(atoms)
            if ads_atoms is None:
                continue
            else:
                atoms.subsets['ads_atoms'] = ads_atoms
        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
        if ('key_value_pairs' not in atoms.subsets
                or 'term' not in atoms.info['key_value_pairs']
                or 'bulk' not in atoms.info['key_value_pairs']):
            bulk, subsurf, term = detect_termination(atoms)
            atoms.subsets['bulk_atoms'] = bulk
            atoms.subsets['termination_atoms'] = term
            atoms.subsets['subsurf_atoms'] = subsurf
    return images