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

Nuffield #40

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
34 changes: 34 additions & 0 deletions carmm/analyse/vibrations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import matplotlib.pyplot as plt
from ase.io.trajectory import Trajectory
from ase import Atoms
from ase.io import read


def vib_analysis(model):
''' Returns a graph showing displacemet of bonds/atoms in a trajectory.

Parameters:
model: Atoms object
e.g trajectory file to calculate bond displacement

TODO: Plotting should be a different function i.e plot_vibrations()
Example needed in examples folder
'''
atot = Atoms.get_chemical_symbols(self=read(model))
# print(len(atot))

traj = Trajectory(model)

for i in range(len(atot) - 1):
for j in range(i + 1, len(atot)):
distances = []
for atoms in traj:
dist = atoms.get_distances(i, j)
distances.append(float(dist))
dist_list = distances
print(dist_list)
x = range(len(dist_list))
plt.plot(x, dist_list)
plt.xlabel("time step")
plt.ylabel('displacement')
plt.show()
104 changes: 103 additions & 1 deletion carmm/build/alloy.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,106 @@ def ternary_alloy(model, second_element, third_element, n_second_element, n_thir
new_model.set_chemical_symbols(new_labels)

return new_model



def change_conc(surface, end_conc0, end_conc1, end_conc2, end_conc3, end_conc4, end_conc5, end_conc6):
'''
Parameters:

surface: Atoms object
end_conc0: Float
Concentration value for Pd atoms with tag 0
end_conc1: Float
Concentration value for Pd atoms with tag 1
end_conc2: Float
Concentration value for Pd atoms with tag 2
end_conc3: Float
Concentration value for Pd atoms with tag 3
end_conc4: Float
Concentration value for Pd atoms with tag 4
end_conc5: Float
Concentration value for Pd atoms with tag 5
end_conc6: Float
Concentration value for Pd atoms with tag 6
'''
import random
# TODO: make end_conc a list of floats of len(set(atoms.tags))
end_conc = []
end_conc.append(end_conc0)
end_conc.append(end_conc1)
end_conc.append(end_conc2)
end_conc.append(end_conc3)
end_conc.append(end_conc4)
end_conc.append(end_conc5)
end_conc.append(end_conc6)

layer = []
layer_zn_index = []
layer_pd_index = []
layer_no_pd = []
layer_no_zn = []
no_loops = []

# TODO: Specify symbols for substitution
# TODO: Make the layer count dynamic based on tags
# TODO: Should the tag assignment be done automatically?
# TODO: Can work with arrays rather than lists
# TODO: Include mic and symmetry unique arrangements

# Calculating the conc. of Pd in layer
for i in range(0, 7):
for atom in surface:
if atom.tag == i:
layer.append(atom)
if atom.symbol == "Pd":
layer_no_pd.append(atom)
layer_pd_index.append(atom.index)
else:
layer_no_zn.append(atom)
layer_zn_index.append(atom.index)

initial_conc = len(layer_no_pd) / len(layer)

print("The initial concentration of Pd in layer", i, "is:", initial_conc)

# Changing the conc. to desired conc.
conc = len(layer_no_pd) / len(layer)

if conc < end_conc[i]: # Increases conc.
while conc < end_conc[i]:
for atom in surface:
conc = len(layer_no_pd)/len(layer)
if conc < end_conc[i] and atom.symbol == "Zn" and atom.index == random.choice(layer_zn_index):
atom.symbol = "Pd"
layer_no_pd.append(atom)
#print("Atom", atom.index, "is now Pd")
conc = len(layer_no_pd) / len(layer)
#print("Concentration:", conc)

no_loops.append("1")
elif end_conc[i] < conc: # Decreases conc.
while end_conc[i] < conc:
for atom in surface:
conc = len(layer_no_pd) / len(layer)
if end_conc[i] < conc and atom.symbol == "Pd" and atom.index == random.choice(layer_pd_index):
atom.symbol = "Zn"
del layer_no_pd[0]
#print("Atom", atom.index, "is now Pd")
conc = len(layer_no_pd) / len(layer)
#print("Concentration:", conc)
no_loops.append("1")

# Checking calculation
final_conc = len(layer_no_pd) / len(layer)
print("The final concentration of Pd in layer", i, "is:", final_conc)
print("Number of loops:", len(no_loops))
# Clearing variables
layer = []
layer_zn_index = []
layer_pd_index = []
layer_no_pd = []
layer_no_zn = []
no_loops = []

# TODO: Come up with sensible return statement
# TODO: come up with an example for testing