Skip to content

Commit

Permalink
add HCO bond counting back
Browse files Browse the repository at this point in the history
  • Loading branch information
mhangaard committed Aug 15, 2018
1 parent 4b927ef commit 67a2db3
Showing 1 changed file with 83 additions and 29 deletions.
112 changes: 83 additions & 29 deletions catlearn/fingerprint/adsorbate_fingerprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def term(self, atoms=None):
Parameters
----------
atoms : object
atoms : object
"""
labels = make_labels(self.slab_params, '', '_term')
labels.append('ground_state_magmom_term')
Expand Down Expand Up @@ -110,7 +110,7 @@ def bulk(self, atoms=None):
Parameters
----------
atoms : object
atoms : object
"""
labels = make_labels(self.slab_params, '', '_bulk')
labels.append('ground_state_magmom_bulk')
Expand Down Expand Up @@ -170,7 +170,7 @@ def mean_site(self, atoms=None):
Parameters
----------
atoms : object
atoms : object
"""
labels = make_labels(self.slab_params, '', '_site_av')
labels.append('ground_state_magmom_site_av')
Expand All @@ -191,7 +191,7 @@ def min_site(self, atoms=None):
Parameters
----------
atoms : object
atoms : object
"""
labels = make_labels(self.slab_params, '', '_site_min')
labels.append('ground_state_magmom_site_min')
Expand All @@ -212,7 +212,7 @@ def max_site(self, atoms=None):
Parameters
----------
atoms : object
atoms : object
"""
labels = make_labels(self.slab_params, '', '_site_max')
labels.append('ground_state_magmom_site_max')
Expand All @@ -233,7 +233,7 @@ def median_site(self, atoms=None):
Parameters
----------
atoms : object
atoms : object
"""
labels = make_labels(self.slab_params, '', '_site_med')
labels.append('ground_state_magmom_site_med')
Expand Down Expand Up @@ -274,10 +274,10 @@ def generalized_cn(self, atoms):
Parameters
----------
atoms : object
atoms : object
"""
if atoms is None:
return ['cn_site', 'gcn_site', 'cn_ads1', 'gcn_ads1']
return ['av_cn_site', 'cn_site', 'gcn_site', 'cn_ads1', 'gcn_ads1']
site = atoms.subsets['site_atoms']

if len(site) == 1:
Expand All @@ -299,11 +299,14 @@ def generalized_cn(self, atoms):

site_neighbors = list(np.unique(atoms.subsets['ligand_atoms']))

# Site coordination number.
cn_site = len(site_neighbors)

# Average coordination number of the site.
cn_site = 0.
av_cn_site = 0.
for j, atom in enumerate(site):
cn_site += np.sum(cm[atom, :][slab])
cn_site /= len(site)
av_cn_site += np.sum(cm[atom, :][slab])
av_cn_site /= len(site)

# Generalized coordination number.
gcn_site = 0.
Expand All @@ -323,9 +326,9 @@ def generalized_cn(self, atoms):
for j, btom in enumerate(row):
if btom > 0:
cn = len([k for k in cm[btom, :] if k > 0])
gcn_chemi += btom * cn / cn_max
gcn_chemi += btom * cn / 12

return [cn_site, gcn_site,
return [av_cn_site, cn_site, gcn_site,
cn_chemi / len(chemi), gcn_chemi / len(chemi)]

def coordination_counts(self, atoms):
Expand All @@ -335,7 +338,7 @@ def coordination_counts(self, atoms):
Parameters
----------
atoms : object
atoms : object
"""
labels = ['count_' + str(j) + 'nn_site' for j in range(3, 31)]
if atoms is None:
Expand All @@ -361,7 +364,7 @@ def bag_atoms_ads(self, atoms=None):
Parameters
----------
atoms : object
atoms : object
"""
if atoms is None:
try:
Expand All @@ -383,10 +386,14 @@ def count_chemisorbed_fragment(self, atoms=None):
"""Function that takes an atoms objects and returns a fingerprint
vector containing the count of C, O, H, N and also metal atoms,
that are neighbors to the binding atom.
Parameters
----------
atoms : object
"""
if atoms is None:
labels = ['bag_chemi_nn_' + chemical_symbols[z] for z in
self.atom_types] + ['boc_site']
self.atom_types] + ['boc_site', 'n_site']
return labels
else:
chemi = atoms.subsets['chemisorbed_atoms']
Expand All @@ -396,8 +403,55 @@ def count_chemisorbed_fragment(self, atoms=None):
bag[j] += np.sum(cm[:, chemi] * np.vstack(atoms.numbers == z))

boc_site = np.sum(cm[:, chemi][atoms.subsets['site_atoms'], :])
site = len(atoms.subsets['site_atoms'])

return list(bag) + [boc_site, site]

return list(bag) + [boc_site]
def count_ads_bonds(self, atoms=None):
"""Function that takes an atoms object and returns a fingerprint
vector with the number of C-H bonds and C-C bonds in the adsorbate.
The adsorbate atoms must be specified in advance in
atoms.subsets['ads_atoms']
Parameters
----------
atoms : object
"""
if atoms is None:
return ['nC-C', 'ndouble', 'nC-H', 'nO-H']
else:
ads_atoms = atoms[atoms.subsets['ads_atoms']]
A = atoms.connectivity[:, ads_atoms][ads_atoms, :]
Hindex = [a.index for a in ads_atoms if a.symbol == 'H']
Cindex = [a.index for a in ads_atoms if a.symbol == 'C']
Oindex = [a.index for a in ads_atoms if a.symbol == 'O']
nCC = 0
nCH = 0
nC2 = 0
nOH = 0
nOdouble = 0
nCdouble = 0
nCtriple = 0
nCquad = 0
for o in Oindex:
nOH += np.sum(A[Hindex, o])
Onn = np.sum(A[:, o])
if Onn == 1:
nOdouble += 1
for c in Cindex:
nCC += np.sum(A[Cindex, c])
nCH += np.sum(A[Hindex, c])
Cnn = np.sum(A[:, c])
if Cnn == 3:
nCdouble += 1
elif Cnn == 2:
if nCH > 0:
nCtriple += 1
else:
nCdouble += 2
elif Cnn == 1:
nCquad += 1
nC2 += 4 - (nCC + nCH)
return [nCC, nC2, nCH, nOH]

def mean_surf_ligands(self, atoms=None):
"""Function that takes an atoms objects and returns a fingerprint
Expand All @@ -406,7 +460,7 @@ def mean_surf_ligands(self, atoms=None):
Parameters
----------
atoms : object
atoms : object
"""
labels = ['nn_surf_ligands', 'identnn_surf_ligands']
labels += make_labels(self.slab_params, '', '_surf_ligands')
Expand All @@ -431,7 +485,7 @@ def ads_sum(self, atoms=None):
Parameters
----------
atoms : object
atoms : object
"""
ads_params = default_params + ['econf', 'ionenergies']
labels = make_labels(ads_params, '', '_ads_sum')
Expand All @@ -452,7 +506,7 @@ def ads_av(self, atoms=None):
Parameters
----------
atoms : object
atoms : object
"""
ads_params = default_params + ['econf', 'ionenergies']
labels = make_labels(ads_params, '', '_ads_av')
Expand All @@ -473,7 +527,7 @@ def strain(self, atoms=None):
Parameters
----------
atoms : object
atoms : object
"""
if atoms is None:
return ['strain_site', 'strain_term']
Expand Down Expand Up @@ -522,7 +576,7 @@ def bag_connections_ads(self, atoms):
Parameters
----------
atoms : object
atoms : object
"""
# range of element types
n_elements = len(self.atom_types)
Expand Down Expand Up @@ -563,7 +617,7 @@ def en_difference_ads(self, atoms=None):
Parameters
----------
atoms : object
atoms : object
"""
labels = ['dist_' + s + '_ads' for s in electronegativities]
if atoms is None:
Expand All @@ -585,7 +639,7 @@ def en_difference_chemi(self, atoms=None):
Parameters
----------
atoms : object
atoms : object
"""
labels = ['dist_' + s + '_chemi' for s in electronegativities]
if atoms is None:
Expand All @@ -610,7 +664,7 @@ def en_difference_active(self, atoms=None):
Parameters
----------
atoms : object
atoms : object
"""
labels = ['dist_' + s + '_active' for s in electronegativities]
if atoms is None:
Expand Down Expand Up @@ -799,7 +853,7 @@ def delta_energy(self, atoms=None):
Parameters
----------
atoms : object
atoms : object
"""
if atoms is None:
return ['delta_energy']
Expand Down Expand Up @@ -841,7 +895,7 @@ def name(self, atoms=None):
Parameters
----------
atoms : object
atoms : object
"""
if atoms is None:
return ['catapp_name']
Expand All @@ -855,7 +909,7 @@ def dbid(self, atoms=None):
Parameters
----------
atoms : object
atoms : object
"""
if atoms is None:
return ['id']
Expand All @@ -869,7 +923,7 @@ def ctime(self, atoms=None):
Parameters
----------
atoms : object
atoms : object
"""
if atoms is None:
return ['time_float']
Expand Down

0 comments on commit 67a2db3

Please sign in to comment.