Пример #1
0
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())
Пример #2
0
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, :])
at.add_property('edgey', alpha[2, 1, :])
at.write('e{0}.xyz'.format(name))
Пример #3
0
def NetCDFReader(source, frame=None, start=0, stop=None, step=1, format=None):

    opened = False
    if isinstance(source, str):
        opened = True
        source = netcdf_file(source)

    from quippy import Atoms

    DEG_TO_RAD = pi/180.0

    remap_names = {'coordinates': 'pos',
                   'velocities': 'velo',
                   'cell_lengths': None,
                   'cell_angles': None,
                   'cell_lattice': None,
                   'cell_rotated': None}

    prop_type_to_value = {PROPERTY_INT: 0,
                          PROPERTY_REAL: 0.0,
                          PROPERTY_STR: "",
                          PROPERTY_LOGICAL: False}

    prop_dim_to_ncols = {('frame','atom','spatial'): 3,
                         ('frame','atom','label'): 1,
                         ('frame', 'atom'): 1}

    if frame is not None:
        start = frame
        stop = frame+1
        step = 1
    else:
        if stop is None:
            stop = source.variables['cell_lengths'].shape[0]

    for frame in range(start, stop, step):
        cl = source.variables['cell_lengths'][frame]
        ca = source.variables['cell_angles'][frame]
        lattice = make_lattice(cl[0],cl[1],cl[2],ca[0]*DEG_TO_RAD,ca[1]*DEG_TO_RAD,ca[2]*DEG_TO_RAD)

        at = Atoms(n=netcdf_dimlen(source, 'atom'), lattice=lattice, properties={})

        for name, var in source.variables.iteritems():
            name = remap_names.get(name, name)

            if name is None:
                continue

            name = str(name) # in case it's a unicode string

            if 'frame' in var.dimensions:
                if 'atom' in var.dimensions:
                    # It's a property
                    value = var[frame]
                    if value.dtype.kind != 'S': value = value.T
                    at.add_property(name, value)
                else:
                    # It's a param
                    if var.dimensions == ('frame','string'):
                        # if it's a single string, join it and strip it
                        at.params[name] = ''.join(var[frame]).strip()
                    else:
                        if name == 'cutoff':
                            at.cutoff = var[frame]
                        elif name == 'cutoff_skin':
                            at.cutoff_skin = var[frame]
                        elif name == 'nneightol':
                            at.nneightol = var[frame]
                        elif name == 'pbc':
                            at.pbc = var[frame]
                        else:
                            at.params[name] = var[frame].T

        if 'cell_rotated' in source.variables:
            cell_rotated = source.variables['cell_rotated'][frame]
            orig_lattice = source.variables['cell_lattice'][frame]
            #if cell_rotated == 1:
            at.set_lattice(orig_lattice, True)

        yield at

    def close(self):
        if self.opened: source.close()
Пример #4
0
    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')