Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GCN.py #125

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
72 changes: 72 additions & 0 deletions carmm/analyse/GCN.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
def coord_number(atoms, a=3.615, lattice='fcc'):

Check warning on line 1 in carmm/analyse/GCN.py

View check run for this annotation

Codecov / codecov/patch

carmm/analyse/GCN.py#L1

Added line #L1 was not covered by tests
# The list that stores coordination number for each atom
cn_list = []

Check warning on line 3 in carmm/analyse/GCN.py

View check run for this annotation

Codecov / codecov/patch

carmm/analyse/GCN.py#L3

Added line #L3 was not covered by tests
# The list that stores the indices of first nearst neighbours for each atom
# This will be a list of lists
fnn_list = []

Check warning on line 6 in carmm/analyse/GCN.py

View check run for this annotation

Codecov / codecov/patch

carmm/analyse/GCN.py#L6

Added line #L6 was not covered by tests

if lattice == 'fcc':
bond = round(a / 2 ** 0.5, 3)
elif lattice == 'bcc':
bond = round(a * (3 ** 0.5) / 2, 3)

Check warning on line 11 in carmm/analyse/GCN.py

View check run for this annotation

Codecov / codecov/patch

carmm/analyse/GCN.py#L8-L11

Added lines #L8 - L11 were not covered by tests
# Add an if statement to make this function also works for bcc

# Distances with minimum image conversion.
# A big enough model is still needed, e.g. (3*3*3)
distances = atoms.get_all_distances(mic=True)

Check warning on line 16 in carmm/analyse/GCN.py

View check run for this annotation

Codecov / codecov/patch

carmm/analyse/GCN.py#L16

Added line #L16 was not covered by tests

for atom_i in atoms:
i = atom_i.index
cn = 0

Check warning on line 20 in carmm/analyse/GCN.py

View check run for this annotation

Codecov / codecov/patch

carmm/analyse/GCN.py#L18-L20

Added lines #L18 - L20 were not covered by tests
# List for first nearest neighbours of atom i
fnn = []

Check warning on line 22 in carmm/analyse/GCN.py

View check run for this annotation

Codecov / codecov/patch

carmm/analyse/GCN.py#L22

Added line #L22 was not covered by tests
# Counting coordination number for atom i
for atom_j in atoms:
j = atom_j.index

Check warning on line 25 in carmm/analyse/GCN.py

View check run for this annotation

Codecov / codecov/patch

carmm/analyse/GCN.py#L24-L25

Added lines #L24 - L25 were not covered by tests
# Skip the iteration if we are considering the distance
# between atom i and itself
if i == j:
continue

Check warning on line 29 in carmm/analyse/GCN.py

View check run for this annotation

Codecov / codecov/patch

carmm/analyse/GCN.py#L28-L29

Added lines #L28 - L29 were not covered by tests
# Check if atom i and atom j are first nearst neighbours
if round(distances[i][j], 3) == bond:
cn += 1
fnn.append(j)

Check warning on line 33 in carmm/analyse/GCN.py

View check run for this annotation

Codecov / codecov/patch

carmm/analyse/GCN.py#L31-L33

Added lines #L31 - L33 were not covered by tests

# Append coordination number and first nearest neighbours to the lists every time the second j loop finishes.
cn_list.append(cn)
fnn_list.append(fnn)

Check warning on line 37 in carmm/analyse/GCN.py

View check run for this annotation

Codecov / codecov/patch

carmm/analyse/GCN.py#L36-L37

Added lines #L36 - L37 were not covered by tests

return cn_list, fnn_list

Check warning on line 39 in carmm/analyse/GCN.py

View check run for this annotation

Codecov / codecov/patch

carmm/analyse/GCN.py#L39

Added line #L39 was not covered by tests


def general_coord_number(atoms, a, lattice, site):

Check warning on line 42 in carmm/analyse/GCN.py

View check run for this annotation

Codecov / codecov/patch

carmm/analyse/GCN.py#L42

Added line #L42 was not covered by tests

"""
:param atoms: Surface model (should be large enough, e.g.(3*3*3))
:param a: lattice parameter
:param lattice: crystal structure
:param site: An atomic index for an ontop site or a list of atomic indices for a multi-atom adsorption site.
:return: gcn. Generalized coordination number
"""
# Hi Luca, you can try to complete this function for ontop sites using the coord_number function above.
# The cn_max for fcc ontop sites is 12

cn_max = 12
cn, fnn = coord_number(atoms, a, lattice)
fnn_site = fnn[site] # extracting the fnn of the site
sum_fnn_cn = 0
for indices in fnn_site:
sum_fnn_cn += cn[indices] # calculating cn(j)

Check warning on line 59 in carmm/analyse/GCN.py

View check run for this annotation

Codecov / codecov/patch

carmm/analyse/GCN.py#L54-L59

Added lines #L54 - L59 were not covered by tests

gcn = sum_fnn_cn / cn_max # dividing summation by cn_max (can do as cn_max is a constant)

Check warning on line 61 in carmm/analyse/GCN.py

View check run for this annotation

Codecov / codecov/patch

carmm/analyse/GCN.py#L61

Added line #L61 was not covered by tests

return gcn

Check warning on line 63 in carmm/analyse/GCN.py

View check run for this annotation

Codecov / codecov/patch

carmm/analyse/GCN.py#L63

Added line #L63 was not covered by tests


from ase.build import bulk, fcc111, fcc110, fcc100 # for fcc110, the gcn varies with size

Check warning on line 66 in carmm/analyse/GCN.py

View check run for this annotation

Codecov / codecov/patch

carmm/analyse/GCN.py#L66

Added line #L66 was not covered by tests

Cu = bulk('Cu', crystalstructure='fcc', a=3.615, cubic=True)
Cu = Cu.repeat((2, 2, 2))
Cuslab = fcc110('Cu', a=3.615, size=(5, 5, 5), vacuum=10, periodic=True)
gcn = general_coord_number(Cuslab, a=3.615, lattice='fcc', site=Cuslab[-1].index)
print(gcn)

Check warning on line 72 in carmm/analyse/GCN.py

View check run for this annotation

Codecov / codecov/patch

carmm/analyse/GCN.py#L68-L72

Added lines #L68 - L72 were not covered by tests