def make_sc_100_cell(size=(1, 1, 1), symbols=['Ni'], pbc=(1, 1, 1)): direction_x = [1, 0, 0] direction_y = [0, 1, 0] direction_z = [0, 0, 1] directions = [direction_x, direction_y, direction_z] atoms = None try: atoms = SimpleCubic(\ directions=[direction_x,direction_y,direction_z], size=size, symbol=symbols[0], pbc=pbc) except ValueError as e: if str( e ) == 'Cannot guess the sc lattice constant of an element with crystal structure fcc.': r = get_atomic_radius(symbol=symbols[0]) a0 = 2 * r atoms = SimpleCubic(\ directions=directions, size=size, symbol=symbols[0], pbc=pbc, latticeconstant=a0) else: raise ValueError('cannot create the simple cubic structure') return atoms
def check_xyz_cell(struct): cell = struct.get_cell() if cell.any() == 0.0: dist = struct.get_all_distances() latt_cubic = np.max(dist) * 1.25 # same than VESTA lattice = SimpleCubic(symbol='Cu', latticeconstant=latt_cubic) cell = latt_cubic struct.cell = lattice.get_cell() print(struct.get_cell()) return struct
def TestEnergyConservation(): print "Running TestEnergyConservation..." calc = Morse(elements, epsilon, alpha, rmin) atoms = SimpleCubic('Ar', size=(10, 10, 10), latticeconstant=5.0) n = 0 while n < 100: i = np.random.randint(len(atoms) - 1) if atoms[i].number != atomic_numbers['Ru']: atoms[i].number = atomic_numbers['Ru'] n += 1 atoms.set_calculator(calc) # Set initial momentum MaxwellBoltzmannDistribution(atoms, 300 * units.kB) # Run dynamics dyn = VelocityVerlet(atoms, 1.0 * units.fs, logfile='test-energy.dat', loginterval=10) dyn.run(10) etot = (atoms.get_potential_energy() + atoms.get_kinetic_energy()) / len(atoms) print "%-9s %-9s %-9s" % ("Epot", "Ekin", "Sum") for i in range(25): if i: dyn.run(100) epot = atoms.get_potential_energy() / len(atoms) ekin = atoms.get_kinetic_energy() / len(atoms) print "%9.5f %9.5f %9.5f" % (epot, ekin, epot + ekin) ReportTest("Step %i." % (i, ), epot + ekin, etot, 1e-3, silent=True)
def TestEnergyConservation(): print "Running TestEnergyConservation..." calc = Morse(elements, epsilon, alpha, rmin) atoms = SimpleCubic('Ar', size=(10,10,10), latticeconstant=5.0) n = 0 while n < 100: i = np.random.randint(len(atoms)-1) if atoms[i].number != atomic_numbers['Ru']: atoms[i].number = atomic_numbers['Ru'] n += 1 atoms.set_calculator(calc) # Set initial momentum MaxwellBoltzmannDistribution(atoms, 300*units.kB) # Run dynamics dyn = VelocityVerlet(atoms, 1.0 * units.fs, logfile='test-energy.dat', loginterval=10) dyn.run(10) etot = (atoms.get_potential_energy() + atoms.get_kinetic_energy())/len(atoms) print "%-9s %-9s %-9s" % ("Epot", "Ekin", "Sum") for i in range(25): if i: dyn.run(100) epot = atoms.get_potential_energy()/len(atoms) ekin = atoms.get_kinetic_energy()/len(atoms) print "%9.5f %9.5f %9.5f" % (epot, ekin, epot+ekin) ReportTest("Step %i." % (i,), epot+ekin, etot, 1e-3, silent=True)
def test_calculator(): # create calculator #modelname = 'ex_model_Ar_P_MLJ_C' modelname = 'ex_model_Ar_P_Morse_07C' calc = KIMCalculator(modelname) # create a SC cyrstal argon = SimpleCubic(directions=[[1,0,0], [0,1,0], [0,0,1]], size=(2,2,2), symbol='Ar', pbc=(1,1,0), latticeconstant=3.0) # attach calculator to atoms argon.set_calculator(calc) # compute energy and forces print_values(argon, 'SC argon, pbc=(1,1,0)') # change pbc, and then compute energy and forces argon.set_pbc([0,0,0]) print_values(argon, 'SC argon, pbc=(0,0,0)') # create a FCC crystal argon2 = FaceCenteredCubic(directions=[[1,0,0], [0,1,0], [0,0,1]], size=(2,2,2), symbol='Ar', pbc=(1,1,0), latticeconstant=3.0) # attach the SAME calculator to the new atoms argon2.set_calculator(calc) # compute energy and forces print_values(argon2, 'FCC argon, pbc=(1,1,0)')
def MakeSystem(size, element, perturbation): lc = data.reference_states[data.atomic_numbers[element]]['a'] / 2.0**(1.0 / 3.0) atoms = MonteCarloAtoms( SimpleCubic(directions=((1, 0, 0), (0, 1, 0), (0, 0, 1)), size=size, symbol=element, latticeconstant=lc, pbc=True)) rs = atoms.get_scaled_positions() atoms.set_scaled_positions(0.5 * (rs + rs * rs)) r = atoms.get_positions() dr = perturbation * random.standard_normal(r.shape) atoms.set_positions(r + dr) return atoms
( "dia-Si-C", B3( [ "Si", "C" ], latticeconstant=4.3596, size=[sx,sx,sx]) ) ] ), ( BrennerScr, Erhart_PRB_71_035211_SiC__Scr, [ ( "dia-C", Diamond("C", size=[sx,sx,sx]) ), ( "dia-Si", Diamond("Si", size=[sx,sx,sx]) ), ( "dia-Si-C", B3( [ "Si", "C" ], latticeconstant=4.3596, size=[sx,sx,sx]) ) ] ), ( Brenner, Henriksson_PRB_79_114107_FeC, [ dict( name='dia-C', struct=Diamond('C', size=[sx,sx,sx]) ), dict( name='bcc-Fe', struct=BodyCenteredCubic('Fe', size=[sx,sx,sx]) ), dict( name='fcc-Fe', struct=FaceCenteredCubic('Fe', size=[sx,sx,sx], latticeconstant=3.6) ), dict( name='sc-Fe', struct=SimpleCubic('Fe', size=[sx,sx,sx], latticeconstant=2.4) ), dict( name='B1-Fe-C', struct=B1( [ 'Fe', 'C' ], size=[sx,sx,sx], latticeconstant=3.9) ), dict( name='B3-Fe-C', struct=B3( [ 'Fe', 'C' ], size=[sx,sx,sx], latticeconstant=4.0) ), ] ), ( Kumagai, Kumagai_CompMaterSci_39_457_Si, [ ( "dia-Si", Diamond("Si", size=[sx,sx,sx]) ) ] ), ( KumagaiScr, Kumagai_CompMaterSci_39_457_Si__Scr, [ ( "dia-Si", Diamond("Si", size=[sx,sx,sx]) ) ] ), ( Tersoff, Tersoff_PRB_39_5566_Si_C, [ ( "dia-C", Diamond("C", size=[sx,sx,sx]) ), ( "dia-Si", Diamond("Si", size=[sx,sx,sx]) ) ] ), ( TersoffScr, Tersoff_PRB_39_5566_Si_C__Scr, [ ( "dia-C", Diamond("C", size=[sx,sx,sx]) ), ( "dia-Si", Diamond("Si", size=[sx,sx,sx]) ) ] ),
AtomicAdjacency( shape='gaussian', length_scale='covalent_radius_pyykko', zoom=1.5 ), AtomicAdjacency(shape='compactbell3,2'), ] def test_ase_one(): atoms = molecule('H2') graph = Graph.from_ase(atoms) assert(len(graph.nodes) == 2) assert(len(graph.edges) == 1) @pytest.mark.parametrize('atoms', [ SimpleCubic(latticeconstant=2, size=(2, 1, 1), symbol='Cu', pbc=(1, 0, 0)), SimpleCubic(latticeconstant=2, size=(1, 2, 1), symbol='Cu', pbc=(0, 1, 0)), SimpleCubic(latticeconstant=2, size=(1, 1, 2), symbol='Cu', pbc=(0, 0, 1)), ]) @pytest.mark.parametrize('adj', adjacencies) def test_ase_pbc1(atoms, adj): graph_pbc = Graph.from_ase(atoms, use_pbc=True, adjacency=adj) graph_nopbc = Graph.from_ase(atoms, use_pbc=False, adjacency=adj) assert(len(graph_pbc.edges) == len(graph_nopbc.edges)) @pytest.mark.parametrize('atoms', [ SimpleCubic(latticeconstant=2, size=(3, 1, 1), symbol='Cu', pbc=(1, 0, 0)), SimpleCubic(latticeconstant=2, size=(4, 1, 1), symbol='Cu', pbc=(1, 0, 0)), SimpleCubic(latticeconstant=2, size=(7, 1, 1), symbol='Cu', pbc=(1, 0, 0)), SimpleCubic(latticeconstant=2, size=(1, 3, 1), symbol='Cu', pbc=(0, 1, 0)),
import time np.random.seed(42) #set_verbose(2) # Define constants and calculator elements = np.array([atomic_numbers['Ru'], atomic_numbers['Ar']]) epsilon = np.array([[5.720, 0.092], [0.092, 0.008]]) alpha = np.array([[1.475, 2.719], [2.719, 1.472]]) rmin = np.array([[2.110, 2.563], [2.563, 4.185]]) calc = Morse(elements, epsilon, alpha, rmin) # Define atoms atoms = SimpleCubic('Ar', size=(15, 15, 15), latticeconstant=50.0) n = 0 while n < 100: i = np.random.randint(len(atoms) - 1) if atoms[i].number != atomic_numbers['Ru']: atoms[i].number = atomic_numbers['Ru'] n += 1 atoms.set_calculator(calc) # Set initial momentum MaxwellBoltzmannDistribution(atoms, 1000 * units.kB) # Run dynamics startcpu, startwall = time.clock(), time.time() dyn = VelocityVerlet(atoms,
def build_emitter_from_scratch(element, basis, z_axis, filename="emitter.txt", x_axis="auto", y_axis="auto", emitter_radius=100, emitter_side_height=50, vacuum_radius=25, alloy={}): """ Build an emitter (set of nodes, TAPSim style) based on an element, basis, orientation, and dimensions. """ IDS = {element: "10"} if x_axis == "auto" and y_axis == "auto": if 0.99 < np.dot(z_axis, (1, 0, 0)) < 1.01: x_axis = tuple(np.cross(z_axis, (1, 0, 0))) else: x_axis = tuple(np.cross(z_axis, (0, 1, 0))) y_axis = tuple(np.cross(z_axis, x_axis)) R = emitter_radius + vacuum_radius if basis.lower() == "bcc": lattice = BodyCenteredCubic( size=(1, 1, 1), directions=[x_axis, y_axis, z_axis], symbol=element ) pts = lattice.get_positions() supercell_dimensions = ( int(math.ceil((2*R)/max([pt[0] for pt in pts])))+1, int(math.ceil((2*R)/max([pt[1] for pt in pts])))+1, int(math.ceil((emitter_side_height+R)/max([pt[2] for pt in pts])))+1 ) lattice = BodyCenteredCubic( size=supercell_dimensions, directions=[x_axis, y_axis, z_axis], symbol=element ) elif basis.lower() == "fcc": lattice = FaceCenteredCubic( size=(1, 1, 1), directions=[x_axis, y_axis, z_axis], symbol=element ) pts = lattice.get_positions() supercell_dimensions = ( int(math.ceil((2*R)/max([pt[0] for pt in pts])))+1, int(math.ceil((2*R)/max([pt[1] for pt in pts])))+1, int(math.ceil((emitter_side_height+R)/max([pt[2] for pt in pts])))+1 ) lattice = FaceCenteredCubic( size=supercell_dimensions, directions=[x_axis, y_axis, z_axis], symbol=element ) elif basis.lower() == "sc": lattice = SimpleCubic( size=(1, 1, 1), directions=[x_axis, y_axis, z_axis], symbol=element ) pts = lattice.get_positions() supercell_dimensions = ( int(math.ceil((2*R)/max([pt[0] for pt in pts])))+1, int(math.ceil((2*R)/max([pt[1] for pt in pts])))+1, int(math.ceil((emitter_side_height+R)/max([pt[2] for pt in pts])))+1 ) lattice = SimpleCubic( size=supercell_dimensions, directions=[x_axis, y_axis, z_axis], symbol=element ) pts = lattice.get_positions() cx = np.mean([pt[0] for pt in pts]) cy = np.mean([pt[1] for pt in pts]) min_z = min([pt[2] for pt in pts]) emitter_points, vacuum_points, bottom_points = [], [], [] number = 0 for pt in pts: pt = [pt[0], pt[1], pt[2]-min_z] if (pt[2] < 1e-5 and (pt[0]-cx)**2+(pt[1]-cy)**2<R**2): pt = [pt[0], pt[1], 0.0] pt = [i*1e-10 for i in pt] pt.append(2) # bottom ID number += 1 bottom_points.append(pt) elif (pt[2]<emitter_side_height and (pt[0]-cx)**2+(pt[1]-cy)**2\ <emitter_radius**2): pt = [i*1e-10 for i in pt] pt.append(IDS[element]) # emitter ID number += 1 emitter_points.append(pt) elif (pt[0]-cx)**2+(pt[1]-cy)**2+(pt[2]-emitter_side_height)**2\ <emitter_radius**2: pt = [i*1e-10 for i in pt] pt.append(IDS[element]) # emitter ID number += 1 emitter_points.append(pt) elif (pt[2]<emitter_side_height and (pt[0]-cx)**2+(pt[1]-cy)**2<R**2): pt = [i*1e-10 for i in pt] pt.append(0) # vacuum ID number += 1 vacuum_points.append(pt) elif (pt[0]-cx)**2+(pt[1]-cy)**2+(pt[2]-emitter_side_height)**2<R**2: pt = [i*1e-10 for i in pt] pt.append(0) # vacuum ID number += 1 vacuum_points.append(pt) alloy_id = 20 all_substitution_indices = [] for elt in alloy: substitution_indices = [] conc = alloy[elt] num_atoms = len(emitter_points) num_substitution_atoms = math.floor(conc*num_atoms) j = 0 while j < num_substitution_atoms: x = randint(0, num_atoms-1) if x not in all_substitution_indices: substitution_indices.append(x) all_substitution_indices.append(x) j += 1 for i in substitution_indices: emitter_points[i][3] = alloy_id IDS[elt] = str(alloy_id) alloy_id += 10 with open(filename, "w") as e: n_nodes = number e.write("ASCII {} 0 0\n".format(n_nodes)) for pt in emitter_points + vacuum_points + bottom_points: # It's required that the coordinates be # separated by a tab character (^I), not # by regular spaces. e.write(" ".join([str(i) for i in pt])) e.write("\n") comment = ["#"] comment += [" {}={}".format(IDS[elt], elt) for elt in IDS] e.write("{}\n".format(" ".join(comment)))
k0 = ase.units.GPa tests = [ (Harmonic, dict(k=1.0, r0=1.0, cutoff=1.3, shift=True), [ dict(name="fcc", struct=FaceCenteredCubic("He", size=[sx, sx, sx], latticeconstant=sqrt(2)), C11=sqrt(2) / GPa, C12=1. / sqrt(2) / GPa, C44=1. / sqrt(2) / GPa) ]), (DoubleHarmonic, dict(k1=1.0, r1=1.0, k2=1.0, r2=sqrt(2), cutoff=1.6), [ dict(name="sc", struct=SimpleCubic("He", size=[sx, sx, sx], latticeconstant=1.0), C11=3. / GPa, C12=1. / GPa, C44=1. / GPa) ]), ( Brenner, Brenner_PRB_42_9458_C_I, [ ( "dia-C", Diamond("C", size=[sx, sx, sx]), # Ec a0 C11 C12 C44 B Cp None, None, None,