Beispiel #1
0
def test1_magmom():

    atoms = BodyCenteredCubic(directions=[[1,0,0],
                                          [0,1,0],
                                          [0,0,1]],
                              size=(1,1,1),
                              symbol='Fe')

    for atom in atoms:
        atom.magmom = 2

    with jasp('Fe-magmom',
          xc='PBE',
          encut=300,
          kpts=(4,4,4),
          ispin=2,
          atoms=atoms) as calc:
        calc.prepare_input_files()
        atoms.get_potential_energy()

    with jasp('Fe-magmom') as calc:
        atoms.get_potential_energy()
        
    counter = 0
    with open('Fe-magmom/INCAR') as f:
        for line in f:
            if 'MAGMOM' in line:
                counter += 1

    assert counter == 1
    def EfccEbccCalculator(self, EMT, PARAMETERS):
        # Return 0 is used when the method is not desired to be used
        # return 0
        """ This method uses the given EMT calculator to calculate and return the difference in energy between a system 
            of atoms placed in the BCC and FCC structure. """
        # The atoms objects are created using the input size and element and the energy calculator
        # is set to the EMT calculator
        # The Lattice Constant for the BCC lattice is here given so that the volume pr atom of the system is
        # held fixed for the FCC and BCC lattice, that is Vol_pr_atom_BCC = Vol_pr_atom_FCC.
        atoms1 = FaceCenteredCubic(size=(self.Size, self.Size, self.Size),
                                   symbol=self.Element)
        atoms1.set_calculator(EMT)
        # The Lattice constant which produces the same volume pr atom for an BCC crystal is calculated
        LCBcc = 1. / (2.**(1. / 3.)) * beta * PARAMETERS[
            self.Element][1] * Bohr * numpy.sqrt(2)
        atoms2 = BodyCenteredCubic(size=(self.Size, self.Size, self.Size),
                                   symbol=self.Element,
                                   latticeconstant=LCBcc)
        atoms2.set_calculator(EMT)

        # The energy difference pr atom is calculated and returned
        return atoms2.get_potential_energy() / len(
            atoms2) - atoms1.get_potential_energy() / len(atoms1)
Beispiel #3
0
from vasp import Vasp
from ase.lattice.cubic import BodyCenteredCubic
atoms = BodyCenteredCubic(directions=[[1, 0, 0],
                                      [0, 1, 0],
                                      [0, 0, 1]],
                                      size=(1, 1, 1),
                                      symbol='Fe')
NUPDOWNS = [0.0, 2.0, 4.0, 5.0, 6.0, 8.0]
energies = []
for B in NUPDOWNS:
    calc = Vasp('bulk/Fe-bcc-fixedmagmom-{0:1.2f}'.format(B),
                xc='PBE',
                encut=300,
                kpts=[4, 4, 4],
                ispin=2,
                nupdown=B,
                atoms=atoms)
    energies.append(atoms.get_potential_energy())
if None in energies:
    calc.abort()
import matplotlib.pyplot as plt
plt.plot(NUPDOWNS, energies)
plt.xlabel('Total Magnetic Moment')
plt.ylabel('Energy (eV)')
plt.savefig('images/Fe-fixedmagmom.png')
Beispiel #4
0
from jasp import *
from ase.lattice.cubic import BodyCenteredCubic

atoms = BodyCenteredCubic(directions=[[1, 0, 0], [0, 1, 0], [0, 0, 1]], size=(1, 1, 1), symbol="Fe")
# set magnetic moments on each atom
for atom in atoms:
    atom.magmom = 2.5
with jasp(
    "bulk/Fe-bcc-sp-1",
    xc="PBE",
    encut=300,
    kpts=(4, 4, 4),
    ispin=2,
    lorbit=11,  # you need this for individual magnetic moments
    atoms=atoms,
) as calc:
    try:
        e = atoms.get_potential_energy()
        B = atoms.get_magnetic_moment()
        magmoms = atoms.get_magnetic_moments()
    except (VaspSubmitted, VaspQueued):
        pass
print "Total magnetic moment is {0:1.2f} Bohr-magnetons".format(B)
print "Individual moments are {0} Bohr-magnetons".format(magmoms)
Beispiel #5
0
def calc_bulk_dissolution(args):
    """Calculate the bulk dissolution energy for hydrogen
    in a tetrahedral position in bcc iron.
    Args:
      args(list): determine applied strain to unit cell.
    """
    POT_DIR = os.path.join(app.root_path, 'potentials')
    eam_pot = os.path.join(POT_DIR, 'PotBH.xml')
    r_scale = 1.00894848312
    pot = Potential(
        'IP EAM_ErcolAd do_rescale_r=T r_scale={0}'.format(r_scale),
        param_filename=eam_pot)
    alat = 2.83

    gb = BodyCenteredCubic(directions=[[1, 0, 0], [0, 1, 0], [0, 0, 1]],
                           size=(6, 6, 6),
                           symbol='Fe',
                           pbc=(1, 1, 1),
                           latticeconstant=alat)
    cell = gb.get_cell()
    print 'Fe Cell', cell

    e1 = np.array([1, 0, 0])
    e2 = np.array([0, 1, 0])
    e3 = np.array([0, 0, 1])

    if args.hydrostatic != 0.0:
        strain_tensor = np.eye(3) + args.hydrostatic * np.eye(3)
        cell = cell * strain_tensor
        gb.set_cell(cell, scale_atoms=True)
        print 'Hydrostatic strain', args.hydrostatic
        print 'strain tensor', strain_tensor
        print gb.get_cell()
    elif args.stretch != 0.0:
        strain_tensor = np.tensordot(e2, e2, axes=0)
        strain_tensor = np.eye(3) + args.stretch * strain_tensor
        cell = strain_tensor * cell
        print 'Stretch strain'
        print 'Cell:', cell
        gb.set_cell(cell, scale_atoms=True)
    elif args.shear != 0.0:
        strain_tensor = np.tensordot(e1, e2, axes=0)
        strain_tensor = np.eye(3) + args.shear * strain_tensor
        cell = strain_tensor.dot(cell)
        print 'Shear Strain', strain_tensor
        print 'Cell:', cell
        gb.set_cell(cell, scale_atoms=True)
        gb.write('sheared.xyz')
    else:
        print 'No strain applied.'

    tetra_pos = alat * np.array([0.25, 0.0, 0.5])
    h2 = aseAtoms('H2', positions=[[0, 0, 0], [0, 0, 0.7]])
    h2 = Atoms(h2)

    gb = Atoms(gb)
    gb_h = gb.copy()
    gb_h.add_atoms(tetra_pos, 1)

    #caclulators
    gb.set_calculator(pot)
    h2.set_calculator(pot)
    gb_h.set_calculator(pot)
    gb_h.write('hydrogen_bcc.xyz')

    #Calc Hydrogen molecule energy
    opt = BFGS(h2)
    opt.run(fmax=0.0001)
    E_h2 = h2.get_potential_energy()
    h2.write('h2mol.xyz')

    #strain_mask  = [1,1,1,0,0,0]
    strain_mask = [0, 0, 0, 0, 0, 0]
    ucf = UnitCellFilter(gb_h, strain_mask)

    #opt = BFGS(gb_h)
    opt = FIRE(ucf)
    opt.run(fmax=0.0001)
    E_gb = gb.get_potential_energy()
    E_gbh = gb_h.get_potential_energy()
    E_dis = E_gbh - E_gb - 0.5 * E_h2

    print 'E_gb', E_gb
    print 'E_gbh', E_gbh
    print 'H2 Formation Energy', E_h2
    print 'Dissolution Energy', E_dis
Beispiel #6
0
from jasp import *
from ase.lattice.cubic import BodyCenteredCubic
atoms = BodyCenteredCubic(directions=[[1, 0, 0], [0, 1, 0], [0, 0, 1]],
                          size=(1, 1, 1),
                          symbol='Fe')
# set magnetic moments on each atom
for atom in atoms:
    atom.magmom = 2.5
with jasp(
        'bulk/Fe-bcc-sp-1',
        xc='PBE',
        encut=300,
        kpts=(4, 4, 4),
        ispin=2,
        lorbit=11,  # you need this for individual magnetic moments
        atoms=atoms) as calc:
    try:
        e = atoms.get_potential_energy()
        B = atoms.get_magnetic_moment()
        magmoms = atoms.get_magnetic_moments()
    except (VaspSubmitted, VaspQueued):
        pass
print 'Total magnetic moment is {0:1.2f} Bohr-magnetons'.format(B)
print 'Individual moments are {0} Bohr-magnetons'.format(magmoms)
Beispiel #7
0
from vasp import Vasp
from ase.lattice.cubic import BodyCenteredCubic
atoms = BodyCenteredCubic(directions=[[1, 0, 0],
                                      [0, 1, 0],
                                      [0, 0, 1]],
                                      size=(1, 1, 1),
                                      symbol='Fe')
calc = Vasp('bulk/Fe-bcc-fixedmagmom-{0:1.2f}'.format(0.0),
            xc='PBE',
            encut=300,
            kpts=[4, 4, 4],
            ispin=2,
            nupdown=0,
            atoms=atoms)
print(atoms.get_potential_energy())
Beispiel #8
0
from jasp import *
from ase.lattice.cubic import BodyCenteredCubic
atoms = BodyCenteredCubic(symbol='Fe')
for atom in atoms:
    atom.magmom = 3.0
with jasp('bulk/Fe-bulk',
          xc='PBE',
          kpts=(6, 6, 6),
          encut=350,
          ispin=2,
          isif=3,
          nsw=30,
          ibrion=1,
          atoms=atoms) as calc:
    print atoms.get_potential_energy()
    print atoms.get_stress()
Beispiel #9
0
# NB: order of types must match order in control file
tb_pot = Potential('IP LMTO_TBE',
                   param_str="""
    <params>
      <LMTO_TBE_params n_types="3" control_file="ctrl.fe">
        <per_type_data type="1" atomic_num="26"/>
        <per_type_data type="2" atomic_num="6"/>
        <per_type_data type="3" atomic_num="1"/>
      </LMTO_TBE_params>
    </params>""")

print tb_pot

# compute energies and forces for a range of lattice constants
if True:
    a = np.linspace(2.5, 3.0, 5)
    e = []
    f = []
    configs = []
    for aa in a:
        atoms = BodyCenteredCubic(symbol='Fe', latticeconstant=aa)
        atoms *= [n, n, n]
        atoms.set_calculator(tb_pot)
        e.append(atoms.get_potential_energy())
        f.append(atoms.get_forces()[0, 0])
        configs.append(atoms.copy())
# print lattice constants, energies and forces
    print 'a = ', list(a)
    print 'e = ', list(e)
    print 'f = ', list(f)
Beispiel #10
0
  or_axis = [1,1,0]
  bp      = [-1,1,12]

##########################################
##First calculate surface energetics:   ##
##########################################
  bulk = BodyCenteredCubic(directions = [[1,0,0],[0,1,0], [0,0,1]],
                           size = (1,1,1), symbol='Fe', pbc=(1,1,1),
                           latticeconstant = 2.85)

  eam_pot = './Fe_Mendelev.xml'
  gb_frac = GBFracture()
  surf_cell = gb_frac.build_surface(bp = sym_tilt_110[0][1])
  pot     = Potential('IP EAM_ErcolAd', param_filename=eam_pot)
  bulk.set_calculator(pot)
  ener_per_atom = bulk.get_potential_energy()/len(bulk)
  surf_cell.set_calculator(pot)
  surf_ener = surf_cell.get_potential_energy()
  cell  = surf_cell.get_cell()
  A     = cell[0][0]*cell[1][1]
  gamma = (surf_ener- len(surf_cell)*ener_per_atom)/A

  print '2*gamma ev/A2', gamma
  print '2*gamma J/m2',  gamma/(units.J/units.m**2)
  j_dict = {'or_axis':or_axis, 'bp':bp, 'gamma':gamma}
  with open('gbfrac.json','w') as f:
    json.dump(j_dict, f)
  out = AtomsWriter('{0}'.format('{0}_surf.xyz'.format(gbid)))
  out.write(Atoms(surf_cell))
  out.close()
  frac_cell = gb_frac.build_tilt_sym_frac()
Beispiel #11
0
gb = Atoms(gb)
gb_h = gb.copy()
gb_h.add_atoms(tetra_pos, 1)

#caclulators
gb.set_calculator(pot)
h2.set_calculator(pot)
gb_h.set_calculator(pot)
gb_h.write('hydrogen_bcc.xyz')

#Calc Hydrogen molecule energy
opt = BFGS(h2)
opt.run(fmax=0.0001)
E_h2 = h2.get_potential_energy()

strain_mask = [1, 1, 1, 0, 0, 0]
ucf = UnitCellFilter(gb_h, strain_mask)

#opt = BFGS(gb_h)
opt = FIRE(ucf)
opt.run(fmax=0.0001)
E_gb = gb.get_potential_energy()
E_gbh = gb_h.get_potential_energy()
E_dis = E_gbh - E_gb - 0.5 * E_h2

print 'E_gb', E_gb
print 'E_gbh', E_gbh
print 'H2 Formation Energy', E_h2
print 'Dissolution Energy', E_dis
Beispiel #12
0
def gamma_surf(h_pos=np.array([1.41, 1.500, 22.48])):
    """
    :method:`gamma_surf` generates a set of directories with the upper
    half unit cell displaced along a certain distance
    along a particular lattice vector. Hydrogens can be added by
    setting vector in h_pos.

    TODO:
      h_pos should be a list of vectors and atom type for this to be more general.
    """

    vasp_exe = '/projects/SiO2_Fracture/iron/vasp.bgq'
    crack_geom = {
        'cleavage_plane': (1, 1, 0),
        'crack_front': (1, -1, 0),
        'crack_direction': (0, 0, 1)
    }

    crack_direction = crack_geom['crack_direction']
    crack_front = crack_geom['crack_front']
    cleavage_plane = crack_geom['cleavage_plane']
    fe_unit = BodyCenteredCubic(
        directions=[crack_direction, crack_front, cleavage_plane],
        size=(1, 1, 1),
        symbol='Fe',
        pbc=(1, 1, 1),
        latticeconstant=2.83)
    nunits = 8
    fe_bulk = BodyCenteredCubic(
        directions=[crack_direction, crack_front, cleavage_plane],
        size=(2, 2, nunits),
        symbol='Fe',
        pbc=(1, 1, 1),
        latticeconstant=2.83)
    fe_unit = Atoms(fe_unit)
    fe_bulk = Atoms(fe_bulk)

    ycut = 5.0 + float(nunits) / 2.0 * fe_unit.lattice[2, 2]
    fe_bulk.center(vacuum=5.0, axis=2)
    print 'lattice', fe_bulk.lattice[1, 1]
    print 'ycut', ycut

    a1 = fe_unit.lattice[0, 0]
    a2 = fe_unit.lattice[1, 1]

    POT_DIR = os.environ['POTDIR']
    eam_pot = os.path.join(POT_DIR, 'PotBH.xml')
    r_scale = 1.00894848312
    #eam_pot = os.path.join(POT_DIR, 'iron_mish.xml')
    #r_scale = 1.0129007626
    pot = Potential(
        'IP EAM_ErcolAd do_rescale_r=T r_scale={0}'.format(r_scale),
        param_filename=eam_pot)
    fe_bulk.set_calculator(pot)
    print 'Bulk Energy', fe_bulk.get_potential_energy()
    refen = fe_bulk.get_potential_energy()
    A = fe_bulk.get_volume() / fe_bulk.lattice[2, 2]

    vasp_args = dict(
        xc='PBE',
        amix=0.01,
        amin=0.001,
        bmix=0.001,
        amix_mag=0.01,
        bmix_mag=0.001,
        kpts=[8, 8, 1],
        kpar=32,
        lreal='auto',
        ibrion=2,
        nsw=40,
        nelmdl=-15,
        ispin=2,
        nelm=100,
        algo='VeryFast',
        npar=8,
        lplane=False,
        lwave=False,
        lcharg=False,
        istart=0,
        voskown=1,
        ismear=1,
        sigma=0.1,
        isym=2)  # possibly try iwavpr=12, should be faster if it works

    dir_name = 'b111shiftsym'
    #dir_name  = 'b001shiftsym'
    f = open('_patdon123{0}H1.dat'.format(dir_name), 'w')
    WRITEVASP = True
    a0 = 2.83
    for inum, ashift in enumerate(np.arange(0, 1.10, 0.10)):
        try:
            os.mkdir('{0}{1}'.format(dir_name, ashift))
        except:
            pass
        print 'Directory already exists'

        os.chdir('{0}{1}'.format(dir_name, ashift))
        fe_shift = fe_bulk.copy()
        fe_shift.set_calculator(pot)
        for at in fe_shift:
            if at.position[2] > ycut:
                #[00-1](110)
                #  at.position += ashift*np.array([-a1,0,0])
                #[1-11](110)
                at.position += 0.5 * ashift * np.array([a1, a2, 0])
    #  print >> fil1, ashift, (units.m**2/units.J)*(fe_shift.get_potential_energy()-refen)/A
        line = []
        for at in fe_shift:
            line.append(FixedLine(at.index, (0, 0, 1)))
    #Now add Hydrogen
    # fe_shift.add_atoms(np.array([0.53*a0, 0.53*a0, 21.0+a0/2]),1)
    # at relaxed position:
        fe_shift.add_atoms(h_pos, 1)
        fix_atoms_mask = [at.number == 1 for at in fe_shift]
        fixedatoms = FixAtoms(mask=fix_atoms_mask)
        fe_shift.set_constraint(line + [fixedatoms])
        opt = LBFGS(fe_shift)
        opt.run(fmax=0.1, steps=1000)
        if inum == 0:
            print 'Setting Reference Energy'
            refen = fe_shift.get_potential_energy()
        print >> f, ashift, (units.m**2 / units.J) * (
            fe_shift.get_potential_energy() - refen) / A
        fe_shift.write('feb{0}.xyz'.format(ashift))
        if WRITEVASP:
            vasp = Vasp(**vasp_args)
            vasp.initialize(fe_shift)
            write_vasp('POSCAR',
                       vasp.atoms_sorted,
                       symbol_count=vasp.symbol_count,
                       vasp5=True)
            vasp.write_incar(fe_shift)
            vasp.write_potcar()
            vasp.write_kpoints()
        os.chdir('../')
    f.close()
Beispiel #13
0
fmax = 1e-3  # maximum force following relaxtion [eV/A]
N = 3  # number of unit cells in each direction
remove_index = 0  # which atom to remove

if not hasattr(model, 'bulk_reference_216'):
    # set up the a
    bulk = BodyCenteredCubic(symbol='W', latticeconstant=a0)

    # specify that we will use model.calculator to compute forces, energies and stresses
    bulk.set_calculator(model.calculator)

    # use one of the routines from utilities module to relax the initial
    # unit cell and atomic positions
    bulk = relax_atoms_cell(bulk, tol=fmax, traj_file=None)
    bulk *= (N, N, N)
    bulk_energy = bulk.get_potential_energy()
else:
    bulk = model.bulk_reference_216
    bulk_energy = bulk.get_potential_energy()


def vacancy_energy(bulk, remove_index=0):
    Nat = bulk.get_number_of_atoms()
    vac = bulk.copy()
    vac.set_calculator(bulk.get_calculator())

    nl = NeighborList([a0 * sqrt(3.0) / 4 * 0.6] * len(bulk),
                      self_interaction=False,
                      bothways=True)
    nl.update(bulk)
    indices, offsets = nl.get_neighbors(remove_index)