from __future__ import print_function
import numpy as np
from ase import Atoms
from ase.units import eV, Ang, GPa
d = 2.5*Ang
a = Atoms('2Cu', positions=[(0., 0., 0.), (0., 0., d)])
import sys
sys.path.append(r'files')
import Morse
calc = Morse.MorsePotential()
a.set_calculator(calc)
a.get_potential_energy()
p = a.get_positions()
p
p[1,2] = 2.8
p
a.set_positions(p)
a.get_potential_energy()
a.positions[1,2] = 2.9
a.get_positions()
f = a.get_forces()
f
from ase.build import bulk
cu = bulk("Cu", "fcc", a=3.6, cubic=True)
cu.cell
np.array(cu.cell)
cu.get_positions()
cu.set_calculator(calc)
print("Number of atoms: ", cu.get_global_number_of_atoms())
print("Potential energy per atom: ", cu.get_potential_energy()/cu.get_global_number_of_atoms())
cu222 = cu.copy() # creating a copy of an Atoms object
cu222.set_calculator(calc) # copying DOES NOT bring the attached calculator, so we need to set it again
cu222 *= (2,2,2) # replicating the unit cell is accomplished by the multiplying operator
print("Number of atoms: ", cu222.get_global_number_of_atoms())
print("Potential energy per atom: ", cu222.get_potential_energy()/cu222.get_global_number_of_atoms())
cell = cu.get_cell()
cell *= 0.99
cu.set_cell(cell, scale_atoms=True) # To apply strain, the atomic positions need to be scaled together with the unit cell
cu.get_cell()
cu.get_potential_energy()/cu.get_number_of_atoms()
cu.get_stress(voigt=False)
# Those who browse the documentation of ASE can discover that it has functionality to fit the equation of state
# and extract parameters using more accurate methods. Compare your result above to those computed by ASE.
# The call below takes two arrays: the variable V is an array of volumes/atom and E
# is an array of corresponding potential energy values, again per atom. If you want to execute this
# notebook cell, you will need to substitute your own arrays for V and E.
from ase.eos import EquationOfState
from ase.units import kJ
eos = EquationOfState(V, E, eos="birchmurnaghan") # Birch-Murnaghan is a particular functional form fitted to the equation of state
v0, e0, B = eos.fit()
print('Bulk modulus: ', B / kJ * 1.0e24, 'GPa')
eos.plot()