Ejemplo n.º 1
0
    def generate_fingerprints(self,
                              feature_methods=['voronoi'],
                              completed=False):
        self.Workflow._connect()
        ase_db = self.Workflow.ase_db
        atoms_list = []
        target_list = {}

        ids = self.Workflow.get_new_fingerprint_ids(completed=completed)
        if not ids:
            print('Fingerprints up do date!')
            return

        targets_df = pd.DataFrame(columns=['id', 'Ef'])

        for id in ids:
            row = ase_db.get(id=id)
            atoms_list += [row.toatoms()]
            if row.get('Ef', None) is not None:
                targets_df = targets_df.append({
                    'id': id,
                    'Ef': row.Ef
                },
                                               ignore_index=True)

        targets_df = targets_df.astype({'id': int, 'Ef': float})

        # Catlearn Magpie interface
        VF = VoronoiFingerprintGenerator(atoms_list)
        fingerprints_df = VF.generate().assign(id=ids)
        fingerprints_df = fingerprints_df.astype({'id': int})

        self.Workflow.write_dataframe(table='fingerprint', df=fingerprints_df)

        self.Workflow.write_dataframe(table='target', df=targets_df)
Ejemplo n.º 2
0
    def test_voronoi_fp_gen(self):
        """Test the feature generation."""
        alist = self.get_data()
        voro = VoronoiFingerprintGenerator(alist)
        features = voro.generate()

        self.assertEqual(np.shape(features)[0], 10)
Ejemplo n.º 3
0
    def __init__(self, atoms_list):
        """Voronoi fingerprinting setup.

        Parameters
        ----------
        atoms_list : list
            A list of ase atoms objects to be featurized.


        Development Notes:
        ------------------
        * This featurizing method is specific to atoms objects, for the sake
        of generality lets just assume that inputs can be anything, therefore
        check that inputs are atoms objects

        """
        self.check_inputs(atoms_list)
        self.Voro_inst = VoronoiFingerprintGenerator(atoms_list,
                                                     delete_temp=False)
Ejemplo n.º 4
0
class VoronoiFingerprint:
    """
    Uses the CatLearn interface to MagPie Voronoi Fingerprint

    """
    from catlearn.fingerprint.voro import VoronoiFingerprintGenerator

    def __init__(self, atoms_list):
        """Voronoi fingerprinting setup.

        Parameters
        ----------
        atoms_list : list
            A list of ase atoms objects to be featurized.


        Development Notes:
        ------------------
        * This featurizing method is specific to atoms objects, for the sake
        of generality lets just assume that inputs can be anything, therefore
        check that inputs are atoms objects

        """
        self.check_inputs(atoms_list)
        self.Voro_inst = VoronoiFingerprintGenerator(atoms_list,
                                                     delete_temp=False)

    def check_inputs(self, atoms_list):
        # check atoms list
        from ase import Atoms

        type_check_list = [
            isinstance(atoms_i, Atoms) for atoms_i in atoms_list
        ]
        err_mess = "Inputs to Voronoi must be atom objects"
        assert all(type_check_list), err_mess

    def generate_fingerprints(self):
        self.features = self.Voro_inst.generate()

    def get_fingerprints(self):
        self.generate_features()
        return self.features
Ejemplo n.º 5
0
# Check the size of the atomic strucures.
size = []
for a in alist:
    size.append(len(a))

print('min: {0}, mean: {1:.0f}, max: {2} atoms size'.format(
    min(size), sum(size)/len(size), max(size)))


# Now we generate the Voronoi fingerprints for our atoms objects. `voro.generate()` returns a Pandas dataframe.

# In[4]:


voro = VoronoiFingerprintGenerator(alist)
data_frame = voro.generate()


# In cases, where the generated featues does not apply to the input data, `NaN`s are returned.
# There are various ways of filling in this kind of data and the simplest is simply to remove features containing infinite values.
# 
# The conventional data format in CatLearn is a matrix, so we first convert the Pandas dataframe into a numpy array.

# In[5]:


matrix = data_frame.to_numpy()
finite_numeric_data = clean_infinite(matrix)
print(np.shape(finite_numeric_data['train']))