コード例 #1
0
ファイル: gb_frac.py プロジェクト: Montmorency/fracture
def del_atoms(x=None):
  rcut = 2.0
  #x = Atoms('crack.xyz')
  if x == None:
    x = Atoms('1109337334_frac.xyz')
  else:
    pass
  x.set_cutoff(3.0)
  x.calc_connect()
  x.calc_dists()
  rem=[]
  r = farray(0.0)
  u = fzeros(3)
  print len(x)
  for i in frange(x.n):
    for n in frange(x.n_neighbours(i)):
      j = x.neighbour(i, n, distance=3.0, diff=u)
      if x.distance_min_image(i, j) < rcut and j!=i:
        rem.append(sorted([j,i]))
    if i%10000==0: print i
  rem = list(set([a[0] for a in rem]))
  if len(rem) > 0:
    print rem
    x.remove_atoms(rem)
  else:
    print 'No duplicate atoms in list.'
  x.write('crack_nodup.xyz')
  return x
コード例 #2
0
ファイル: calc_elast_dipole.py プロジェクト: obaica/imeall
def calc_elast_dipole_dft(input_file, vasp_calc=True):
    """Reads OUTCAR file in the same directory with one shot forces
    induced by removal of defect. Reads defect position
    from .xyz file (which contains the defect) defined by `input_file`
    calculates and returns the elastic dipole tensor of the defect.

    Args:
      input_file(str): name of input .xyz file containing defect cell.

    Returns:
      Elastic Dipole Tensor 3x3 numpy array.
    """

    elastic = ElasticDipole()
    ats_def = Atoms(input_file)
    defect = find_h_atom(ats_def)
    if vasp_calc:
        import ase.io.vasp as vasp
        ats_pos = vasp.read_vasp()
        ats = vasp.read_vasp_out()
        ats = Atoms(ats)
    else:
        pass

    print 'Defect index', defect.index, 'Position', defect.position, 'Type: ', defect.number
    f = ats.get_forces()
    ats.add_property('force', f.T)
    ats.write('force.xyz')
    return elastic.compute_vacancy_dipole(defect,
                                          ats_pos.copy(),
                                          forces=ats.get_forces())
コード例 #3
0
ファイル: run_dyn.py プロジェクト: ecnuitaa/imeall
    def delete_atoms(self, grain=None, rcut=2.0):
        """
        Delete atoms below a certain distance threshold.

        Args:
          grain(:class:`quippy.Atoms`): Atoms object of the grain.
          rcut(float): Atom deletion criterion.

        Returns:
          :class:`quippy.Atoms` object with atoms nearer than deletion criterion removed.
        """
        io = ImeallIO()
        if grain == None:
            x = Atoms('{0}.xyz'.format(os.path.join(self.grain_dir,
                                                    self.gbid)))
        else:
            x = Atoms(grain)
        x.set_cutoff(2.4)
        x.calc_connect()
        x.calc_dists()
        rem = []
        u = fzeros(3)
        for i in frange(x.n):
            for n in frange(x.n_neighbours(i)):
                j = x.neighbour(i, n, distance=3.0, diff=u)
                if x.distance_min_image(i, j) < rcut and j != i:
                    rem.append(sorted([j, i]))
        rem = list(set([a[0] for a in rem]))
        if len(rem) > 0:
            x.remove_atoms(rem)
        else:
            print 'No duplicate atoms in list.'
        if grain == None:
            self.name = '{0}_d{1}'.format(self.gbid, str(rcut))
            self.subgrain_dir = io.make_dir(self.calc_dir, self.name)
            self.struct_file = gbid + '_' + 'n' + str(
                len(rem)) + 'd' + str(rcut)
            x.write('{0}.xyz'.format(
                os.path.join(self.subgrain_dir, self.struct_file)))
            return len(rem)
        else:
            return x
コード例 #4
0
def decorate_interface():
    ats = Atoms('interface.xyz')
    dataset = spglib.get_symmetry_dataset(ats, symprec=1e-5)

    with open('unique_lattice_sites.json', 'w') as f:
        json.dump([
            list(ats[site_num].position)
            for site_num in np.unique(dataset['equivalent_atoms'])
        ], f)

    unique_atoms = []
    for at in ats:
        unique_atoms.append(at.position)
    voronoi = Voronoi(limits=tuple(np.diag(ats.cell)),
                      periodic=(True, True, False))
    cntr = voronoi.compute_voronoi(unique_atoms)
    ints_list = []
    for site_num in np.unique(dataset['equivalent_atoms']):
        for vert in voronoi.get_vertices(site_num, cntr):
            ints_list.append(vert.tolist())

    for unique in ints_list:
        ats.add_atoms(unique, 1)
    for i in range(len(ats)):
        ats.id[i] = i
    #remove voronoi duplicates
    print 'Fe_H atoms', len(ats)
    ats.wrap()
    del_ats = aseAtoms()
    for at in ats:
        del_ats.append(at)
    geometry.get_duplicate_atoms(del_ats, cutoff=0.2, delete=True)
    ats = del_ats.copy()
    print 'Fe_H atoms remove duplicates', len(ats)
    #select unique hydrogens
    #for i in range(len(ats)):
    #  ats.id[i] = i
    ints_list = [at.position for at in ats if at.number == 1]
    with open('unique_h_sites.json', 'w') as f:
        json.dump([list(u) for u in ints_list], f)
    ats.write('hydrogenated_grain.xyz')
コード例 #5
0
ファイル: make_edge.py プロジェクト: ecnuitaa/imeall
at = gbr.delete_atoms(grain=at, rcut=1.5)
at.info['OrigHeight'] = at.positions[:, 1].max() - at.positions[:, 1].min()
r_scale = 1.00894848312
rem = []
for atom in at:
    if atom.position[0] <= 0.00 and atom.position[1] <= 100.0:
        rem.append(atom.index + 1)
print 'Removing ', len(rem), ' atoms.'
if len(rem) > 0:
    at.remove_atoms(rem)
else:
    print 'No atoms displaced from unitcell'
pot = Potential('IP EAM_ErcolAd do_rescale_r=T r_scale={0}'.format(r_scale),
                param_filename=eam_pot)
at.set_calculator(pot)
at.write('unrelaxed.xyz')
print 'Running Relaxation'
opt = FIRE(at)
opt.run(fmax=0.1)

print 'Calculating connectivity and Nye Tensor'

ref_slab = Atoms('ref_slab.xyz')
ref_slab.set_cutoff(3.0)
ref_slab.calc_connect()

at.set_cutoff(3.0)
at.calc_connect()
alpha = calc_nye_tensor(at, ref_slab, 3, 3, at.n)
at.add_property('screw', alpha[2, 2, :])
at.add_property('edgex', alpha[2, 0, :])
コード例 #6
0
ファイル: defect.py プロジェクト: Montmorency/fracture
                               check_force_error=False)
       dynamics.set_qm_update_func(update_qm_region)
       dynamics.attach(pass_print_context(defect, dynamics))
       dynamics.attach(traj_writer, print_interval, defect)
    else:
      print 'No dyn_type chosen', 1/0
    
    trajectory = AtomsWriter('{0}.traj.xyz'.format(input_file))
    print 'Running Crack Simulation'
    dynamics.run(nsteps)
#Write cooked i.e. thermalized ceel to file.
    defect.set_cutoff(3.0)
    defect.calc_connect()
    new_core = pp_nye_tensor(defect, dis_type=dis_type)
    defect.info['core']= new_core
    defect.write('{0}_therm.xyz'.format(input_file))
    print 'Crack Simulation Finished'

  if calc_nye or calc_virial:
#ats = AtomsReader('{0}_traj.xyz'.format(input_file))
    ats = AtomsReader('{0}.xyz'.format(input_file))
    hyb = np.zeros(ats[0].n)
#calc_nye tensor for each configuration in the trajectory:
    print len(hyb)
    print ats[0].params
    print len(ats)
    traj_burg = AtomsWriter('{0}_burg.xyz'.format(input_file))
    for i, at in enumerate(ats[::sampling]):
      try:
        del at.properties['edgex']
        del at.properties['edgey']
コード例 #7
0
ファイル: defect.py プロジェクト: Montmorency/fracture
                                    check_force_error=False)
            dynamics.set_qm_update_func(update_qm_region)
            dynamics.attach(pass_print_context(defect, dynamics))
            dynamics.attach(traj_writer, print_interval, defect)
        else:
            print 'No dyn_type chosen', 1 / 0

        trajectory = AtomsWriter('{0}.traj.xyz'.format(input_file))
        print 'Running Crack Simulation'
        dynamics.run(nsteps)
        #Write cooked i.e. thermalized ceel to file.
        defect.set_cutoff(3.0)
        defect.calc_connect()
        new_core = pp_nye_tensor(defect, dis_type=dis_type)
        defect.info['core'] = new_core
        defect.write('{0}_therm.xyz'.format(input_file))
        print 'Crack Simulation Finished'

    if calc_nye or calc_virial:
        #ats = AtomsReader('{0}_traj.xyz'.format(input_file))
        ats = AtomsReader('{0}.xyz'.format(input_file))
        hyb = np.zeros(ats[0].n)
        #calc_nye tensor for each configuration in the trajectory:
        print len(hyb)
        print ats[0].params
        print len(ats)
        traj_burg = AtomsWriter('{0}_burg.xyz'.format(input_file))
        for i, at in enumerate(ats[::sampling]):
            try:
                del at.properties['edgex']
                del at.properties['edgey']
コード例 #8
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
コード例 #9
0
        sc = SumCalculator(pot, cc)

        atoms.set_constraint(FixAtoms(mask=fix_line_mask))
        atoms.set_calculator(sc)
        LBFGS(atoms, use_armijo=False).run(fmax=0.2)

        fix_line = [FixedLine(i, np.array([0, 1, 0])) for i in fix_line_idx]
        atoms.set_array('fix_line_mask', fix_line_mask)

        atoms.set_constraint(fix_line + springs)
        atoms.set_calculator(pot)
        opt = vanillaLBFGS(atoms)

    else:
        print("Method not understood")
        return

    opt.attach(trajectory_write, interval=5)
    opt.run(fmax=fmax)
    return


if __name__ == '__main__':

    pot = Potential('IP TS', param_filename="../ts_params.xml")
    in_file = sys.argv[1]
    out_file = os.path.splitext(in_file)[0] + '_relaxed.xyz'
    atoms = Atoms(in_file)
    minim_precon(atoms)
    atoms.write(out_file)
コード例 #10
0
ファイル: redecorate.py プロジェクト: obaica/imeall
from quippy import Atoms
from imeall.calc_inter_ener import get_interface_bounds

with open('unique_h_sites.json','r') as f:
    h_sites = json.load(f)
print 'There are ', len(h_sites), 'H interstitials'

ats = Atoms('output.xyz')
gb_min, gb_max, z_width, at_min = get_interface_bounds(ats)
h_ats = ats.copy()

for h_site in h_sites:
    h_site_tmp = list(h_site)
    #remove vacuum restore min position
    h_site_tmp[2] += gb_min - 1.0 + at_min
    h_ats.add_atoms(h_site_tmp, 1)

h_int_ats = Atoms('interface.xyz')
for h_site in h_sites:
    h_site_tmp = list(h_site)
    h_int_ats.add_atoms(h_site_tmp, 1)

for i in range(0,len(h_ats)):
    h_ats.id[i] = i

for i in range(0, len(h_int_ats)):
    h_int_ats.id[i] = i

h_ats.write('decorated.xyz')
h_int_ats.write('int_decorated.xyz')
コード例 #11
0
ファイル: hyd_single.py プロジェクト: Montmorency/fracture
ats = Atoms('crack.xyz')
if DOUBLE_CELL:
  ats = ats*(1,1,2)

ats.info['adsorbate_info']=None

with open('crack_info.pckl','r') as f:
  crack_dict= pickle.load(f)
print 'G: {}, H_d: {}, sim_T {}'.format(crack_dict['initial_G']*(units.m**2/units.J),
                                        crack_dict['H_d'], crack_dict['sim_T']/units.kB)
h_list  = hydrify.hydrogenate_gb(ats, mode='CrackTip', d_H=crack_dict['H_d'][0], tetrahedral=True, crackpos_fix=ats.params['CrackPos'])
for h in h_list:
  ats.add_atoms(h,1)

#ats.wrap()
ats.write('crackH.xyz')
ats = None
ats = Atoms('crackH.xyz')
ats.set_cutoff(2.4)
ats.calc_connect()
ats.calc_dists()
filter_mask = (ats.get_atomic_numbers()==1)
h_atoms     = ats.select(filter_mask, orig_index=True)
rem=[]
u = np.zeros(3)
for i in h_atoms.orig_index:
  print 'hindex', i
  print 'nneighbs', ats.n_neighbours(i)
  for n in range(ats.n_neighbours(i)):
    j = ats.neighbour(i, n+1, distance=2.4, diff=u)
    print 'neighb index', j
コード例 #12
0
ファイル: plot_h_energy.py プロジェクト: obaica/imeall
    r'\[\s+([\-0-9\.]+)\s+([\-0-9\.]+)\s+([\-0-9\.]+)\s?\s?\]\s+([\-0-9\.]+)\s+([\-0-9\.]+)',
    re.S)

with open(args.input_file) as f:
    lines = h_line_re.findall(f.read())

interstitials = []
for line in lines:
    site = map(float, [line[0], line[1], line[2]])
    energy = float(line[4])
    interstitials.append(Particle(site, 'H', energy))

interstitials.sort(key=lambda x: x.energy)
for int_ in interstitials:
    print int_.site, int_.energy

ats = Atoms('output.xyz')
num_fe = len(ats)
for int_ in interstitials:
    ats.add_atoms(np.array(int_.site), 1)

for i in range(len(ats)):
    ats.id[i] = i

ats.add_property('locen', 0.0)

for i, at in enumerate(interstitials):
    ats.properties['locen'][i + num_fe] = at.energy

ats.write('h_energetics.xyz')