def test_direct_evaluation(self): a = FaceCenteredCubic('Au', size=[2,2,2]) a.rattle(0.1) calc = EAM('Au-Grochola-JCP05.eam.alloy') a.set_calculator(calc) f = a.get_forces() calc2 = EAM('Au-Grochola-JCP05.eam.alloy') i_n, j_n, dr_nc, abs_dr_n = neighbour_list('ijDd', a, cutoff=calc2.cutoff) epot, virial, f2 = calc2.energy_virial_and_forces(a.numbers, i_n, j_n, dr_nc, abs_dr_n) self.assertArrayAlmostEqual(f, f2) a = FaceCenteredCubic('Cu', size=[2,2,2]) calc = EAM('CuAg.eam.alloy') a.set_calculator(calc) FIRE(StrainFilter(a, mask=[1,1,1,0,0,0]), logfile=None).run(fmax=0.001) e_Cu = a.get_potential_energy()/len(a) a = FaceCenteredCubic('Ag', size=[2,2,2]) a.set_calculator(calc) FIRE(StrainFilter(a, mask=[1,1,1,0,0,0]), logfile=None).run(fmax=0.001) e_Ag = a.get_potential_energy()/len(a) self.assertTrue(abs(e_Ag+2.85)<1e-6) a = L1_2(['Ag', 'Cu'], size=[2,2,2], latticeconstant=4.0) a.set_calculator(calc) FIRE(UnitCellFilter(a, mask=[1,1,1,0,0,0]), logfile=None).run(fmax=0.001) e = a.get_potential_energy() syms = np.array(a.get_chemical_symbols()) self.assertTrue(abs((e-(syms=='Cu').sum()*e_Cu- (syms=='Ag').sum()*e_Ag)/len(a)-0.096)<0.0005) a = B1(['Ag', 'Cu'], size=[2,2,2], latticeconstant=4.0) a.set_calculator(calc) FIRE(UnitCellFilter(a, mask=[1,1,1,0,0,0]), logfile=None).run(fmax=0.001) e = a.get_potential_energy() syms = np.array(a.get_chemical_symbols()) self.assertTrue(abs((e-(syms=='Cu').sum()*e_Cu- (syms=='Ag').sum()*e_Ag)/len(a)-0.516)<0.0005) a = B2(['Ag', 'Cu'], size=[2,2,2], latticeconstant=4.0) a.set_calculator(calc) FIRE(UnitCellFilter(a, mask=[1,1,1,0,0,0]), logfile=None).run(fmax=0.001) e = a.get_potential_energy() syms = np.array(a.get_chemical_symbols()) self.assertTrue(abs((e-(syms=='Cu').sum()*e_Cu- (syms=='Ag').sum()*e_Ag)/len(a)-0.177)<0.0003) a = L1_2(['Cu', 'Ag'], size=[2,2,2], latticeconstant=4.0) a.set_calculator(calc) FIRE(UnitCellFilter(a, mask=[1,1,1,0,0,0]), logfile=None).run(fmax=0.001) e = a.get_potential_energy() syms = np.array(a.get_chemical_symbols()) self.assertTrue(abs((e-(syms=='Cu').sum()*e_Cu- (syms=='Ag').sum()*e_Ag)/len(a)-0.083)<0.0005)
def test_CuAg(self): a = FaceCenteredCubic('Cu', size=[2, 2, 2]) calc = EAM('CuAg.eam.alloy') a.set_calculator(calc) FIRE(StrainFilter(a, mask=[1, 1, 1, 0, 0, 0]), logfile=None).run(fmax=0.001) e_Cu = a.get_potential_energy() / len(a) a = FaceCenteredCubic('Ag', size=[2, 2, 2]) a.set_calculator(calc) FIRE(StrainFilter(a, mask=[1, 1, 1, 0, 0, 0]), logfile=None).run(fmax=0.001) e_Ag = a.get_potential_energy() / len(a) self.assertTrue(abs(e_Ag + 2.85) < 1e-6) a = L1_2(['Ag', 'Cu'], size=[2, 2, 2], latticeconstant=4.0) a.set_calculator(calc) FIRE(UnitCellFilter(a, mask=[1, 1, 1, 0, 0, 0]), logfile=None).run(fmax=0.001) e = a.get_potential_energy() syms = np.array(a.get_chemical_symbols()) self.assertTrue( abs((e - (syms == 'Cu').sum() * e_Cu - (syms == 'Ag').sum() * e_Ag) / len(a) - 0.096) < 0.0005) a = B1(['Ag', 'Cu'], size=[2, 2, 2], latticeconstant=4.0) a.set_calculator(calc) FIRE(UnitCellFilter(a, mask=[1, 1, 1, 0, 0, 0]), logfile=None).run(fmax=0.001) e = a.get_potential_energy() syms = np.array(a.get_chemical_symbols()) self.assertTrue( abs((e - (syms == 'Cu').sum() * e_Cu - (syms == 'Ag').sum() * e_Ag) / len(a) - 0.516) < 0.0005) a = B2(['Ag', 'Cu'], size=[2, 2, 2], latticeconstant=4.0) a.set_calculator(calc) FIRE(UnitCellFilter(a, mask=[1, 1, 1, 0, 0, 0]), logfile=None).run(fmax=0.001) e = a.get_potential_energy() syms = np.array(a.get_chemical_symbols()) self.assertTrue( abs((e - (syms == 'Cu').sum() * e_Cu - (syms == 'Ag').sum() * e_Ag) / len(a) - 0.177) < 0.0003) a = L1_2(['Cu', 'Ag'], size=[2, 2, 2], latticeconstant=4.0) a.set_calculator(calc) FIRE(UnitCellFilter(a, mask=[1, 1, 1, 0, 0, 0]), logfile=None).run(fmax=0.001) e = a.get_potential_energy() syms = np.array(a.get_chemical_symbols()) self.assertTrue( abs((e - (syms == 'Cu').sum() * e_Cu - (syms == 'Ag').sum() * e_Ag) / len(a) - 0.083) < 0.0005)
def test_utilities(): eps = 1e-5 atoms = Icosahedron('Cu', 3) atoms.numbers[[0, 13, 15, 16, 18, 19, 21, 22, 24, 25, 27, 28, 30]] = 79 atoms.center(vacuum=0.0) atoms.calc = EMT() with FIRE(atoms, logfile=None) as opt: opt.run(fmax=0.05) rmax = 8. nbins = 5 rdf, dists = get_rdf(atoms, rmax, nbins) calc_dists = np.arange(rmax / (2 * nbins), rmax, rmax / nbins) assert all(abs(dists - calc_dists) < eps) calc_rdf = [0., 0.84408157, 0.398689, 0.23748934, 0.15398546] assert all(abs(rdf - calc_rdf) < eps) dm = atoms.get_all_distances() s = np.zeros(5) for c in [(29, 29), (29, 79), (79, 29), (79, 79)]: inv_norm = len(np.where(atoms.numbers == c[0])[0]) / len(atoms) s += get_rdf(atoms, rmax, nbins, elements=c, distance_matrix=dm, no_dists=True) * inv_norm assert all(abs(s - calc_rdf) < eps) AuAu = get_rdf(atoms, rmax, nbins, elements=(79, 79), distance_matrix=dm, no_dists=True) assert all(abs(AuAu[-2:] - [0.12126445, 0.]) < eps) bulk = L1_2(['Au', 'Cu'], size=(3, 3, 3), latticeconstant=2 * np.sqrt(2)) rdf = get_rdf(bulk, 4.2, 5)[0] calc_rdf = [0., 0., 1.43905094, 0.36948605, 1.34468694] assert all(abs(rdf - calc_rdf) < eps)
def makeatoms(causetrouble): atoms = L1_2(size=(10,10,10), symbol=('Au', 'Cu'), latticeconstant=4.0) r = atoms.get_positions() r += np.random.normal(0.0, 0.0001, r.shape) if causetrouble: r[100] = r[110] atoms.set_positions(r) return atoms
def test_hessian_crystalline_alloy(self): """Calculate Hessian matrix of crystalline alloy Reference: finite difference approximation of Hessian from ASE """ calculator = EAM('ZrCu.onecolumn.eam.alloy') lattice_size = [4, 4, 4] # The lattice parameters are not correct, but that should be irrelevant # CuZr3 atoms = L1_2(['Cu', 'Zr'], size=lattice_size, latticeconstant=4.0) self._test_hessian(atoms, calculator) # Cu3Zr atoms = L1_2(['Zr', 'Cu'], size=lattice_size, latticeconstant=4.0) self._test_hessian(atoms, calculator) # CuZr atoms = B2(['Zr', 'Cu'], size=lattice_size, latticeconstant=3.3) self._test_hessian(atoms, calculator)
def test_CuZr(self): # This is a test for the potential published in: # Mendelev, Sordelet, Kramer, J. Appl. Phys. 102, 043501 (2007) a = FaceCenteredCubic('Cu', size=[2, 2, 2]) calc = EAM('CuZr_mm.eam.fs', kind='eam/fs') a.set_calculator(calc) FIRE(StrainFilter(a, mask=[1, 1, 1, 0, 0, 0]), logfile=None).run(fmax=0.001) a_Cu = a.cell.diagonal().mean() / 2 #print('a_Cu (3.639) = ', a_Cu) self.assertAlmostEqual(a_Cu, 3.639, 3) a = HexagonalClosedPacked('Zr', size=[2, 2, 2]) a.set_calculator(calc) FIRE(StrainFilter(a, mask=[1, 1, 1, 0, 0, 0]), logfile=None).run(fmax=0.001) a, b, c = a.cell / 2 #print('a_Zr (3.220) = ', norm(a), norm(b)) #print('c_Zr (5.215) = ', norm(c)) self.assertAlmostEqual(norm(a), 3.220, 3) self.assertAlmostEqual(norm(b), 3.220, 3) self.assertAlmostEqual(norm(c), 5.215, 3) # CuZr3 a = L1_2(['Cu', 'Zr'], size=[2, 2, 2], latticeconstant=4.0) a.set_calculator(calc) FIRE(UnitCellFilter(a, mask=[1, 1, 1, 0, 0, 0]), logfile=None).run(fmax=0.001) self.assertAlmostEqual(a.cell.diagonal().mean() / 2, 4.324, 3) # Cu3Zr a = L1_2(['Zr', 'Cu'], size=[2, 2, 2], latticeconstant=4.0) a.set_calculator(calc) FIRE(UnitCellFilter(a, mask=[1, 1, 1, 0, 0, 0]), logfile=None).run(fmax=0.001) self.assertAlmostEqual(a.cell.diagonal().mean() / 2, 3.936, 3) # CuZr a = B2(['Zr', 'Cu'], size=[2, 2, 2], latticeconstant=3.3) a.set_calculator(calc) FIRE(UnitCellFilter(a, mask=[1, 1, 1, 0, 0, 0]), logfile=None).run(fmax=0.001) self.assertAlmostEqual(a.cell.diagonal().mean() / 2, 3.237, 3)
def MakeCu3Ni(T=300): print "Preparing", T, "K NiCu3 system." atoms = L1_2(directions=[[1, 0, 0], [0, 1, 0], [0, 0, 1]], symbol=('Ni', 'Cu'), latticeconstant=3.61, size=(29, 29, 30)) atoms.set_calculator(EMT()) MaxwellBoltzmannDistribution(atoms, 2 * T * units.kB) #dyn = VelocityVerlet(atoms, 5*units.fs) dyn = Langevin(atoms, 5 * units.fs, T * units.kB, 0.05) dyn.run(50) print "Done. Temperature =", temperature(atoms), \ "K. Number of atoms: ", len(atoms) return atoms
kpts = (2, 2, 2) QNA = { 'alpha': 2.0, 'name': 'QNA', 'stencil': 1, 'orbital_dependent': False, 'parameters': { 'Au': (0.125, 0.1), 'Cu': (0.0795, 0.005) }, 'setup_name': 'PBE', 'type': 'qna-gga' } atoms = L1_2(['Au', 'Cu'], latticeconstant=3.74) # Displace atoms to have non-zero forces in the first place atoms[0].position[0] += 0.1 dx_array = [-0.005, 0.000, 0.005] E = [] for i, dx in enumerate(dx_array): calc = GPAW(mode=PW(ecut), experimental={'niter_fixdensity': 2}, xc=QNA, kpts=kpts, parallel={'domain': 1}, txt=name + '%.0f.txt' % ecut) atoms[0].position[0] += dx
rmax = 8. nbins = 5 rdf, dists = get_rdf(atoms, rmax, nbins) calc_dists = np.arange(rmax / (2 * nbins), rmax, rmax / nbins) assert all(abs(dists - calc_dists) < eps) calc_rdf = [0., 0.84408157, 0.398689, 0.23748934, 0.15398546] assert all(abs(rdf - calc_rdf) < eps) dm = atoms.get_all_distances() s = np.zeros(5) for c in [(29, 29), (29, 79), (79, 29), (79, 79)]: inv_norm = len(np.where(atoms.numbers == c[0])[0]) / len(atoms) s += get_rdf( atoms, rmax, nbins, elements=c, distance_matrix=dm, no_dists=True) * inv_norm assert all(abs(s - calc_rdf) < eps) AuAu = get_rdf(atoms, rmax, nbins, elements=(79, 79), distance_matrix=dm, no_dists=True) assert all(abs(AuAu[-2:] - [0.12126445, 0.]) < eps) bulk = L1_2(['Au', 'Cu'], size=(3, 3, 3), latticeconstant=2 * np.sqrt(2)) rdf = get_rdf(bulk, 4.2, 5)[0] calc_rdf = [0., 0., 1.43905094, 0.36948605, 1.34468694] assert all(abs(rdf - calc_rdf) < eps)
def get_structure(self, name, elements, a=None, c=None, l=None): # Check number of elements if name[:3] in ['fcc', 'hcp']: if len(elements) != 1: raise ValueError("Tuple of elements must be of length one") if name[:3] in ['l12', 'l10'] or name[:2] == 'B2': if len(elements) != 2: raise ValueError("Tuple of elements must be of length two") # Get lattice constants if a is None: if name[:2] == 'B2': a = self.get_lattice_constant_a(name[:2], elements) elif name[:3] in ['fcc', 'hcp', 'bcc', 'l12', 'l10']: a = self.get_lattice_constant_a(name[:3], elements) if c is None: if name[:3] in ['hcp', 'l10']: c = self.get_lattice_constant_c(name[:3], elements) # Get size if name in ['fcc', 'hcp', 'bcc', 'l12', 'l10', 'B2']: size = self.properties[name + '_size'] elif name in ['fcc100', 'fcc111', 'hcp0001']: size = self.properties[name + '_size'][:2] + (l, ) # Make structure if name == 'fcc': atoms = FaceCenteredCubic(symbol=elements[0], size=size, latticeconstant=a) elif name == 'hcp': atoms = HexagonalClosedPacked(symbol=elements[0], size=size, directions=[[2, -1, -1, 0], [0, 1, -1, 0], [0, 0, 0, 1]], latticeconstant=(a, c)) elif name == 'bcc': atoms = BodyCenteredCubic(symbol=elements[0], size=size, latticeconstant=a) elif name == 'B2': atoms = B2(symbol=elements, size=size, latticeconstant=a) elif name == 'l12': atoms = L1_2(symbol=elements, size=size, latticeconstant=a) elif name == 'l10': atoms = L1_0(symbol=elements, size=size, latticeconstant=(a, c)) elif name == 'fcc100': atoms = fcc100(symbol=elements[0], size=size, a=a, vacuum=10.0) elif name == 'fcc111': atoms = fcc111(symbol=elements[0], size=size, a=a, vacuum=10.0, orthogonal=True) elif name == 'hcp0001': atoms = hcp0001(symbol=elements[0], size=size, a=a, c=c, vacuum=10.0, orthogonal=True) elif name == 'hcp1010A': raise ValueError("Structure '%s' not supported" % (name, )) atoms = None elif name == 'hcp1010B': raise ValueError("Structure '%s' not supported" % (name, )) atoms = None elif name == 'l12100': n = (l + 1) / 2 atoms = L1_2(symbol=elements, size=(8, 8, n), latticeconstant=a) atoms.set_pbc([True, True, False]) # Remove layers atoms = atoms[atoms.get_positions()[:, 2] > 0.1 * a] # Set vacuum atoms.center(axis=2, vacuum=10.0) elif name == 'l12111': if l % 3 == 0: n = l / 3 c = 0 else: n = l / 3 + 1 c = 3 - l % 3 atoms = L1_2( symbol=elements, size=(8, 4, n), #directions=[[1,-1,0],[1,0,-1],[1,1,1]], latticeconstant=a) directions=[[1, -1, 0], [1, 1, -2], [1, 1, 1]], latticeconstant=a) atoms.set_pbc([True, True, False]) # Wrap positions scpos = atoms.get_scaled_positions() scpos[scpos > (1.0 - 1e-12)] = 0.0 atoms.set_scaled_positions(scpos) # Remove layers if c > 0: atoms = atoms[atoms.get_positions()[:, 2] > (c - 0.5) * a / np.sqrt(3.0)] # Set vacuum atoms.center(axis=2, vacuum=10.0) else: raise ValueError("Structure '%s' not supported" % (name, )) return atoms
def test_mix_eam_alloy(self): if False: source, parameters, F, f, rep = read_eam("CuAu_Zhou.eam.alloy", kind="eam/alloy") source1, parameters1, F1, f1, rep1 = mix_eam( ["Cu_Zhou.eam.alloy", "Au_Zhou.eam.alloy"], "eam/alloy", "weight") write_eam(source1, parameters1, F1, f1, rep1, "CuAu_mixed.eam.alloy", kind="eam/alloy") calc0 = EAM('CuAu_Zhou.eam.alloy') calc1 = EAM('CuAu_mixed.eam.alloy') a = FaceCenteredCubic('Cu', size=[2, 2, 2]) a.set_calculator(calc0) FIRE(StrainFilter(a, mask=[1, 1, 1, 0, 0, 0]), logfile=None).run(fmax=0.001) e0 = a.get_potential_energy() / len(a) a = FaceCenteredCubic('Cu', size=[2, 2, 2]) a.set_calculator(calc1) FIRE(StrainFilter(a, mask=[1, 1, 1, 0, 0, 0]), logfile=None).run(fmax=0.001) e1 = a.get_potential_energy() / len(a) self.assertTrue(e0 - e1 < 0.0005) a = FaceCenteredCubic('Au', size=[2, 2, 2]) a.set_calculator(calc0) FIRE(StrainFilter(a, mask=[1, 1, 1, 0, 0, 0]), logfile=None).run(fmax=0.001) e0 = a.get_potential_energy() / len(a) a = FaceCenteredCubic('Au', size=[2, 2, 2]) a.set_calculator(calc1) FIRE(StrainFilter(a, mask=[1, 1, 1, 0, 0, 0]), logfile=None).run(fmax=0.001) e1 = a.get_potential_energy() / len(a) self.assertTrue(e0 - e1 < 0.0005) a = L1_2(['Au', 'Cu'], size=[2, 2, 2], latticeconstant=4.0) a.set_calculator(calc0) FIRE(UnitCellFilter(a, mask=[1, 1, 1, 0, 0, 0]), logfile=None).run(fmax=0.001) e0 = a.get_potential_energy() / len(a) a = L1_2(['Au', 'Cu'], size=[2, 2, 2], latticeconstant=4.0) a.set_calculator(calc1) FIRE(UnitCellFilter(a, mask=[1, 1, 1, 0, 0, 0]), logfile=None).run(fmax=0.001) e1 = a.get_potential_energy() / len(a) self.assertTrue(e0 - e1 < 0.0005) a = L1_2(['Cu', 'Au'], size=[2, 2, 2], latticeconstant=4.0) a.set_calculator(calc0) FIRE(UnitCellFilter(a, mask=[1, 1, 1, 0, 0, 0]), logfile=None).run(fmax=0.001) e0 = a.get_potential_energy() / len(a) a = L1_2(['Cu', 'Au'], size=[2, 2, 2], latticeconstant=4.0) a.set_calculator(calc1) FIRE(UnitCellFilter(a, mask=[1, 1, 1, 0, 0, 0]), logfile=None).run(fmax=0.001) e1 = a.get_potential_energy() / len(a) self.assertTrue(e0 - e1 < 0.0005) a = B1(['Au', 'Cu'], size=[2, 2, 2], latticeconstant=4.0) a.set_calculator(calc0) FIRE(UnitCellFilter(a, mask=[1, 1, 1, 0, 0, 0]), logfile=None).run(fmax=0.001) e0 = a.get_potential_energy() / len(a) a = B1(['Au', 'Cu'], size=[2, 2, 2], latticeconstant=4.0) a.set_calculator(calc1) FIRE(UnitCellFilter(a, mask=[1, 1, 1, 0, 0, 0]), logfile=None).run(fmax=0.001) e1 = a.get_potential_energy() / len(a) self.assertTrue(e0 - e1 < 0.0005) os.remove("CuAu_mixed.eam.alloy")
def L12_BM_LC_Calculator(self, EMT, PARAMETERS): # Return 0 is used when the method is not desired to be used # return 0 """ The method L12_BM_LC_Calculator uses the EMT calculator to find the lattice constant which gives the lowest possible energy for an alloy of two elements and from a polynomial fit of the energy as a function of the lattice constant it calculates and returns the Bulk modulus, the volume of the system at the lowest possible energy and this energy """ # Three values for the lattice constant, a0, are chosen. The highest and lowest value is chosen so that it # is certain that these are to high/low respectively compared to the "correct" value. This is done by using the # experimental value of the lattice constant, a0_exp, as the middle value and to high/low values are then: # a0_exp +- a0_mod, a0_mod = a0_exp/10 a0_exp = ((PARAMETERS[self.Element[0]][1] + 3 * PARAMETERS[self.Element[1]][1]) * numpy.sqrt(2) * beta * Bohr / 4) a0_mod = a0_exp * 0.20 a0_guesses = numpy.array([a0_exp - a0_mod, a0_exp, a0_exp + a0_mod]) # An atoms object consisting of atoms of the chosen element is initialized atoms = L1_2(size=(self.Size, self.Size, self.Size), symbol=self.Element, latticeconstant=a0_exp) atoms.set_calculator(EMT) # An identity matrix for the system is saved to a variable IdentityMatrix = numpy.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]]) # An array for the energy for the chosen guesses for a0 is initialized: E_guesses = numpy.zeros(5) # The energies are calculated for i in range(3): # Changes the lattice constant for the atoms object atoms.set_cell(a0_guesses[i] * self.Size * IdentityMatrix, scale_atoms=True) # Calculates the energy of the system for the new lattice constant E_guesses[i] = atoms.get_potential_energy() # Bisection is used in order to find a small interval of the lattice constant for the minimum of the energy (an # abitrary interval length is chosen), This is possible because we are certian from theory that there is only # one minimum of the energy function in the interval of interest and thus we wont "fall" into a local minimum # and stay there by accident. while (a0_guesses[2] - a0_guesses[0]) >= self.Tol: if min([E_guesses[0], E_guesses[2]]) == E_guesses[0]: # A new guess for the lattice constant is introduced a0_new_guess = 0.67 * a0_guesses[1] + 0.33 * a0_guesses[2] # The energy for this new guess is calculated atoms.set_cell(a0_new_guess * self.Size * IdentityMatrix, scale_atoms=True) E_new_guess = atoms.get_potential_energy() # A check for changes in the energy minimum is made and the guesses for a0 and their corrosponding # energies are ajusted. if min(E_new_guess, min(E_guesses[0:3])) != E_new_guess: a0_guesses[2] = a0_new_guess E_guesses[2] = E_new_guess else: a0_guesses[0] = a0_guesses[1] a0_guesses[1] = a0_new_guess E_guesses[0] = E_guesses[1] E_guesses[1] = E_new_guess elif min([E_guesses[0], E_guesses[2]]) == E_guesses[2]: # A new guess for the lattice constant is introduced a0_new_guess = 0.33 * a0_guesses[0] + 0.67 * a0_guesses[1] # The energy for this new guess is calculated atoms.set_cell(a0_new_guess * self.Size * IdentityMatrix, scale_atoms=True) E_new_guess = atoms.get_potential_energy() # A check for changes in the energy minimum is made and the guesses for a0 and their corrosponding # energies are ajusted. if min(E_new_guess, min(E_guesses[0:3])) != E_new_guess: a0_guesses[0] = a0_new_guess E_guesses[0] = E_new_guess else: a0_guesses[2] = a0_guesses[1] a0_guesses[1] = a0_new_guess E_guesses[2] = E_guesses[1] E_guesses[1] = E_new_guess # An estimate of the minimum energy can now be found from a second degree polynomial fit through the three # current guesses for a0 and the corresponding values of the energy. Poly = numpyfit.polyfit(a0_guesses, E_guesses[0:3], 2) # The lattice constant corresponding to the lowest energy from the Polynomiel fit is found a0 = -Poly[1] / (2 * Poly[0]) # Now five guesses for a0 and the corresponding energy are evaluated from and around the current a0. a0_guesses = a0 * numpy.array([ 1 - 2 * self.Tol / 5, 1 - self.Tol / 5, 1, 1 + self.Tol / 5, 1 + 2 * self.Tol / 5 ]) for i in range(5): # Changes the lattice constant for the atoms object atoms.set_cell(a0_guesses[i] * self.Size * IdentityMatrix, scale_atoms=True) # Calculates the energy of the system for the new lattice constant E_guesses[i] = atoms.get_potential_energy() # The method EquationOfState is now used to find the Bulk modulus and the minimum energy for the system. # The volume of the sample for the given a0_guesses Vol = (self.Size * a0_guesses)**3 # The equilibrium volume, energy and bulk modulus are calculated (Vol0, E0, B) = EquationOfState(Vol.tolist(), E_guesses.tolist()).fit() return (Vol0, E0, B, Vol0**(1. / 3) / self.Size)
rmax = 8. nbins = 5 rdf, dists = get_rdf(atoms, rmax, nbins) calc_dists = np.arange(rmax / (2 * nbins), rmax, rmax / nbins) assert all(abs(dists - calc_dists) < eps) calc_rdf = [0., 0.84408157, 0.398689, 0.23748934, 0.15398546] assert all(abs(rdf - calc_rdf) < eps) dm = atoms.get_all_distances() s = np.zeros(5) for c in [(29, 29), (29, 79), (79, 29), (79, 79)]: inv_norm = len(np.where(atoms.numbers == c[0])[0]) / len(atoms) s += get_rdf( atoms, rmax, nbins, elements=c, distance_matrix=dm, no_dists=True) * inv_norm assert all(abs(s - calc_rdf) < eps) AuAu = get_rdf(atoms, rmax, nbins, elements=(79, 79), distance_matrix=dm, no_dists=True) assert all(abs(AuAu[-2:] - [0.12126445, 0.]) < eps) bulk = L1_2(['Au', 'Cu'], size=(2, 2, 2), latticeconstant=np.sqrt(2)) dm = bulk.get_all_distances(mic=True) rdf = get_rdf(bulk, 5., 3, distance_matrix=dm)[0] calc_rdf = [0.54694216, 0.08334357, 0.] assert all(abs(rdf - calc_rdf) < eps)
latticeconstant=3.61, size=(29, 29, 30)) atoms.set_calculator(EMT()) MaxwellBoltzmannDistribution(atoms, 2 * T * units.kB) #dyn = VelocityVerlet(atoms, 5*units.fs) dyn = Langevin(atoms, 5 * units.fs, T * units.kB, 0.05) dyn.run(50) print "Done. Temperature =", temperature(atoms), \ "K. Number of atoms: ", len(atoms) return atoms # Make sure that CPU speed is revved up. dummy = L1_2(directions=[[1, 0, 0], [0, 1, 0], [0, 0, 1]], symbol=('Au', 'Cu'), latticeconstant=4.08, size=(10, 10, 10), debug=0) dummy.set_calculator(EMT()) dyn = Langevin(dummy, 5 * units.fs, 300 * units.kB, 0.05) dyn.run(10) del dummy logger.write("\n\nRunning on %s %s\n" % (host, when)) modelname = "Unknown CPU model name" cpumhz = "Unknown CPU speed" try: lines = open("/proc/cpuinfo").readlines() for line in lines: if line[:10] == "model name": modelname = line