#!/usr/bin/env python3

################################################################################
##                                                                            ##
##  This file is part of NCrystal (see https://mctools.github.io/ncrystal/)   ##
##                                                                            ##
##  Copyright 2015-2021 NCrystal developers                                   ##
##                                                                            ##
##  Licensed under the Apache License, Version 2.0 (the "License");           ##
##  you may not use this file except in compliance with the License.          ##
##  You may obtain a copy of the License at                                   ##
##                                                                            ##
##      http://www.apache.org/licenses/LICENSE-2.0                            ##
##                                                                            ##
##  Unless required by applicable law or agreed to in writing, software       ##
##  distributed under the License is distributed on an "AS IS" BASIS,         ##
##  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  ##
##  See the License for the specific language governing permissions and       ##
##  limitations under the License.                                            ##
##                                                                            ##
################################################################################

import NCrystal

#Create and use polycrystalline aluminium:

pc = NCrystal.createScatter( "Al_sg225.ncmat;dcutoff=0.5;temp=25C" )
wavelength = 2.5
xsect = pc.xsect(wl=wavelength)

for i in range(20):
    scatter_angle,delta_ekin = pc.genscat(wl=wavelength)
    print( "polycrystal random angle/delta-e at %g Aa is %g degrees and %g meV"%(wavelength,
                                                                                 scatter_angle*57.2957795131,
                                                                                 delta_ekin*1e3) )
#Create and use single-crystal germanium

sc = NCrystal.createScatter("""Ge_sg227.ncmat;dcutoff=0.5;mos=40arcsec;
                               dir1=@crys_hkl:5,1,1@lab:0,0,1;
                               dir2=@crys_hkl:0,-1,1@lab:0,1,0""")

wavelength = 1.540
ekin = NCrystal.wl2ekin(wavelength)

xsect = sc.xsect( wl=wavelength, direction = ( 0.0, 1.0, 1.0 ) )
print( "singlecrystal Ge x-sect at  %g Aa is %g barn (orientation 1)"%(wavelength,xsect) )

xsect = sc.xsect( wl=wavelength, direction = ( 1.0, 1.0, 0.0 ) )
print( "singlecrystal Ge x-sect at  %g Aa is %g barn (orientation 2)"%(wavelength,xsect) )
