Esempio n. 1
0
def loadPattern(xyz, laz):
    text = open(laz).read()
    from mccomponents.sample.diffraction.parsers.laz import parse
    peaks = parse(text).peaks

    # load structure
    from sampleassembly.crystal.ioutils import xyzfile2unitcell
    structure = xyzfile2unitcell(xyz)

    # diffraction pattern
    return DiffractionPattern(structure, peaks)
Esempio n. 2
0
def loadPattern(xyz, laz):
    text = open(laz).read()
    from mccomponents.sample.diffraction.parsers.laz import parse
    peaks = parse(text).peaks
        
    # load structure
    from sampleassembly.crystal.ioutils import xyzfile2unitcell
    structure = xyzfile2unitcell(xyz)
    
    # diffraction pattern
    return DiffractionPattern(structure, peaks)
Esempio n. 3
0
 def onXYZfile(self, xyzfile):
     from sampleassembly.crystal.ioutils import xyzfile2unitcell
     try:
         self.element.unitcell = xyzfile2unitcell(xyzfile)
     except:
         import traceback
         tb = traceback.format_exc()
         marker = '*' * 60
         msg = "Unable to parse xyz file %s. traceback:\n%s\n%s\n%s" % (
             xyzfile, marker, tb, marker)
         raise RuntimeError(msg)
     return
Esempio n. 4
0
    def test1(self):
        # load peaks
        laz = os.path.join(aluminum_dir, 'powderdiffr', 'Al.laz')
        text = open(laz).read()
        from mccomponents.sample.diffraction.parsers.laz import parse
        peaks = parse(text).peaks

        # load structure
        from sampleassembly.crystal.ioutils import xyzfile2unitcell
        xyz = os.path.join(aluminum_dir, 'crystal', 'Al.xyz')
        structure = xyzfile2unitcell(xyz)

        # diffraction pattern
        from mccomponents.sample.diffraction.powder import total_scattering_cross_section, DiffractionPattern
        dp = DiffractionPattern(structure, peaks)

        # compute
        for Ei in [10, 100, 1000, 10000]:
            print Ei, total_scattering_cross_section(Ei, dp)
        return
Esempio n. 5
0
 def test1(self):
     # load peaks
     laz = os.path.join(aluminum_dir, 'powderdiffr', 'Al.laz')
     text = open(laz).read()
     from mccomponents.sample.diffraction.parsers.laz import parse
     peaks = parse(text).peaks
     
     # load structure
     from sampleassembly.crystal.ioutils import xyzfile2unitcell
     xyz = os.path.join(aluminum_dir, 'crystal', 'Al.xyz')
     structure = xyzfile2unitcell(xyz)
     
     # diffraction pattern
     from mccomponents.sample.diffraction.powder import total_scattering_cross_section, DiffractionPattern
     dp = DiffractionPattern(structure, peaks)
     
     # compute
     for Ei in [10, 100, 1000, 10000]:
         print Ei, total_scattering_cross_section(Ei, dp)
     return
Esempio n. 6
0
File: IDF.py Progetto: mcvine/phonon
def from_data_dir(
    datadir=None,
    disp=None,
    N=int(1e6),
    Q_bins=np.arange(0, 11, 0.1),
    E_bins=np.arange(0, 50, 0.5),
    doshist=None,
    T=300.,
    Ei=100.,
    max_det_angle=135.,
    include_multiphonon=True,
):
    if disp is None:
        from mccomponents.sample.phonon import periodicdispersion_fromidf
        dispersion = periodicdispersion_fromidf(datadir)
        from mccomponents.sample import scattererEngine
        disp = scattererEngine(dispersion)
    #
    poscar = os.path.join(datadir, 'POSCAR')
    from mcvine.phonon import from_phonopy
    from_phonopy.make_crystal_xyz('structure.xyz', poscar)
    from sampleassembly.crystal.ioutils import xyzfile2unitcell
    uc = xyzfile2unitcell('structure.xyz')
    # generate Q points
    max_Q = Q_bins[-1]
    Qmag_p3 = np.random.rand(N) * max_Q**3
    Qmag = Qmag_p3**(1. / 3)
    cos_theta = np.random.rand(N) * 2 - 1  # -1 -- 1
    phi = np.random.rand(N) * 2 * np.pi
    sin_theta = np.sqrt(1 - cos_theta * cos_theta)
    sin_phi = np.sin(phi)
    cos_phi = np.cos(phi)
    Qx = Qmag * sin_theta * cos_phi
    Qy = Qmag * sin_theta * sin_phi
    Qz = Qmag * cos_theta
    Qpoints = np.array([Qx, Qy, Qz]).T
    # in reciprocal units
    hkls = np.dot(Qpoints, uc.lattice.base.T) / (2 * np.pi)
    #
    omega, pols = _getEsAndPols(disp, Qpoints)
    from phonopy.interface import vasp
    atoms = vasp.read_vasp(poscar)
    masses = atoms.get_masses()
    average_mass = np.mean(masses)
    from ._calc import calcIQE, apply_corrections
    Qbb, Ebb, I = calcIQE(uc, omega, pols, Qpoints, Q_bins, E_bins)
    # additional corrections
    IQEhist = apply_corrections(I, Qbb, Ebb, N, average_mass, uc, doshist, T,
                                Ei, max_det_angle)
    if include_multiphonon:
        from ._calc import multiphononSQE
        mphIQE = multiphononSQE(T=T,
                                doshist=doshist,
                                mass=average_mass,
                                Q_bins=Q_bins,
                                E_bins=E_bins)
        symbols = [a.element for a in uc]
        from ..atomic_scattering import AtomicScattering
        total_xs = sum(AtomicScattering(s).sigma() for s in symbols)
        return IQEhist, mphIQE * (total_xs / 4 / np.pi, 0)
    return IQEhist