Beispiel #1
0
def exafs_first_shell(S02, energy_shift, absorber, 
        ignore_elements, edge, neighbor_cutoff, trajectory):
        feff_options = {
                'RMAX':str(neighbor_cutoff),
                'HOLE':'%i %.4f' % (feff_edge_number(edge), S02),
                'CORRECTIONS':'%.4f %.4f' % (energy_shift, 0.0),
        }

        #generate the bulk reference state 
        atoms = bulk(absorber, orthorhombic=True, cubic=True)
        atoms = atoms.repeat((4,4,4))
        center = numpy.argmin(numpy.sum((atoms.get_scaled_positions() -
            numpy.array( (.5,.5,.5) ))**2.0, axis=1))
        #do the bulk reference scattering calculation and get the path
        #data from feff
        path = run_feff(atoms, center, feff_options, get_path=True)[2]

        k = None
        chi_total = None

        counter = -1
        interactions = 0
        nl = None

        for step, atoms in enumerate(trajectory):
            if COMM_WORLD.rank == 0:
                print 'step %i/%i' % (step+1, len(trajectory))
            atoms = atoms.copy()
            if ignore_elements:
                ignore_indicies = [atom.index for atom in atoms 
                                   if atom.symbol in ignore_elements]
                del atoms[ignore_indicies]
            if nl == None:
                nl = NeighborList(len(atoms)*[neighbor_cutoff], skin=0.3, 
                        self_interaction=False)
            nl.update(atoms)

            for i in xrange(len(atoms)):
                if atoms[i].symbol != absorber:
                    continue
                indicies, offsets = nl.get_neighbors(i)
                for j, offset in zip(indicies, offsets):
                    counter += 1
                    if counter % COMM_WORLD.size != COMM_WORLD.rank: 
                        continue

                    r = atoms.get_distance(i,j,True)
                    if r >= neighbor_cutoff: continue
                    interactions += 1
                    k, chi = chi_path(path, r, 0.0, energy_shift, S02, 1)

                    if chi_total != None:
                        chi_total += chi
                    else:
                        chi_total = chi
        chi_total = COMM_WORLD.allreduce(chi_total)
        chi_total /= atoms.get_chemical_symbols().count(absorber)
        chi_total /= len(trajectory)
        chi_total *= 2
        return k, chi_total
Beispiel #2
0
def exafs_reference_path(z, feff_options):
    atoms = bulk(z, orthorhombic=True, cubic=True)
    atoms = atoms.repeat((4,4,4))
    center = numpy.argmin(numpy.sum((atoms.get_scaled_positions() -
        numpy.array( (.5,.5,.5) ))**2.0, axis=1))
    #do the bulk reference scattering calculation and get the path
    #data from feff
    path = run_feff(atoms, center, feff_options, get_path=True)[2]
    return path
Beispiel #3
0
def exafs_reference_path(z, feff_options):
    atoms = bulk(z, orthorhombic=True, cubic=True)
    atoms = atoms.repeat((4, 4, 4))
    center = numpy.argmin(
        numpy.sum((atoms.get_scaled_positions() - numpy.array(
            (.5, .5, .5)))**2.0,
                  axis=1))
    #do the bulk reference scattering calculation and get the path
    #data from feff
    path = run_feff(atoms, center, feff_options, get_path=True)[2]
    return path
Beispiel #4
0
def exafs_multiple_scattering(S02, energy_shift, absorber, ignore_elements,
                              edge, rmax, trajectory):
    feff_options = {
        'RMAX': str(rmax),
        'HOLE': '%i %.4f' % (feff_edge_number(edge), S02),
        'CORRECTIONS': '%.4f %.4f' % (energy_shift, 0.0),
        'NLEG': '4',
    }

    k = None
    chi_total = None
    counter = -1
    for step, atoms in enumerate(trajectory):
        if COMM_WORLD.rank == 0:
            time_stamp = strftime("%F %T")
            print '[%s] step %i/%i' % (time_stamp, step + 1, len(trajectory))
        atoms = atoms.copy()
        if ignore_elements:
            ignore_indicies = [
                atom.index for atom in atoms if atom.symbol in ignore_elements
            ]
            del atoms[ignore_indicies]

        for i in xrange(len(atoms)):
            counter += 1
            if counter % COMM_WORLD.size != COMM_WORLD.rank:
                continue

            if atoms[i].symbol != absorber:
                continue

            k, chi = run_feff(atoms, i, feff_options)
            if k == None and chi == None:
                continue

            if chi_total != None:
                chi_total += chi
            else:
                chi_total = chi

    #in case too many ranks
    k = COMM_WORLD.bcast(k)
    if chi_total == None:
        chi_total = numpy.zeros(len(k))

    chi_total = COMM_WORLD.allreduce(chi_total)
    chi_total /= atoms.get_chemical_symbols().count(absorber)
    chi_total /= len(trajectory)

    return k, chi_total
Beispiel #5
0
def exafs_multiple_scattering(S02, energy_shift, absorber,
    ignore_elements, edge, rmax, trajectory):
    feff_options = {
            'RMAX':str(rmax),
            'HOLE':'%i %.4f' % (feff_edge_number(edge), S02),
            'CORRECTIONS':'%.4f %.4f' % (energy_shift, 0.0),
            'NLEG':'4',
    }

    k = None
    chi_total = None
    counter = -1
    for step, atoms in enumerate(trajectory):
        if COMM_WORLD.rank == 0:
            time_stamp = strftime("%F %T")
            print '[%s] step %i/%i' % (time_stamp, step+1, len(trajectory))
        atoms = atoms.copy()
        if ignore_elements:
            ignore_indicies = [atom.index for atom in atoms
                               if atom.symbol in ignore_elements]
            del atoms[ignore_indicies]

        for i in xrange(len(atoms)):
            counter += 1
            if counter % COMM_WORLD.size != COMM_WORLD.rank:
                continue

            if atoms[i].symbol != absorber:
                continue

            k, chi = run_feff(atoms, i, feff_options)
            if k is None and chi is None:
                continue

            if chi_total is not None:
                chi_total += chi
            else:
                chi_total = chi

    #in case too many ranks
    k = COMM_WORLD.bcast(k)
    if chi_total is None:
        chi_total = numpy.zeros(len(k))

    chi_total = COMM_WORLD.allreduce(chi_total)
    chi_total /= atoms.get_chemical_symbols().count(absorber)
    chi_total /= len(trajectory)

    return k, chi_total
Beispiel #6
0
def exafs_multiple_scattering(S02, energy_shift, absorber, ignore_elements, edge, rmax, trajectory):
    feff_options = {
        "RMAX": str(rmax),
        "HOLE": "%i %.4f" % (feff_edge_number(edge), S02),
        "CORRECTIONS": "%.4f %.4f" % (energy_shift, 0.0),
        "NLEG": "4",
    }

    k = None
    chi_total = None
    counter = -1
    for step, atoms in enumerate(trajectory):
        if COMM_WORLD.rank == 0:
            print "step %i/%i" % (step + 1, len(trajectory))
        atoms = atoms.copy()
        if ignore_elements:
            ignore_indicies = [atom.index for atom in atoms if atom.symbol in ignore_elements]
            del atoms[ignore_indicies]

        for i in xrange(len(atoms)):
            counter += 1
            if counter % COMM_WORLD.size != COMM_WORLD.rank:
                continue

            if atoms[i].symbol != absorber:
                continue

            k, chi = run_feff(atoms, i, feff_options)
            if k == None and chi == None:
                continue

            if chi_total != None:
                chi_total += chi
            else:
                chi_total = chi

    chi_total = COMM_WORLD.allreduce(chi_total)
    chi_total /= atoms.get_chemical_symbols().count(absorber)
    chi_total /= len(trajectory)

    return k, chi_total