Metadata-Version: 2.1
Name: magneticScattering
Version: 0.1.0
Summary: Simulates x-ray magnetic scattering
Author: Andreas Apseros
License: Copyright (c) 2024, Apseros
        
        Redistribution and use in source and binary forms, with or without
        modification, are permitted provided that the following conditions are met:
        
        1. Redistributions of source code must retain the above copyright notice, this
        list of conditions and the following disclaimer.
        
        2. Redistributions in binary form must reproduce the above copyright notice,
        this list of conditions and the following disclaimer in the documentation
        and/or other materials provided with the distribution.
        
        3. Neither the name of the copyright holder nor the names of its contributors
        may be used to endorse or promote products derived from this software without
        specific prior written permission.
        
        THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
        AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
        ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
        LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
        CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
        SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
        INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
        CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
        ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
        POSSIBILITY OF SUCH DAMAGE.
        
Project-URL: Homepage, https://github.com/apseros/magneticScattering
Project-URL: Issues, https://github.com/apseros/magneticScattering/issues
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: BSD License
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: OS Independent
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE.txt
Requires-Dist: numpy
Requires-Dist: matplotlib

# Magnetic Diffraction

Simple code for computing the magnetic diffraction pattern of a magnetic structure. 

To use: Define the structure, beam and geometry of the experiment, then compute scattering by calling the `Scatter` 
class. The magnetic structure is defined using the `Sample` class, the incident beam is defined using the `Beam` class 
and the geometry is defined using the `Geometry` class.

## Sample

The `Sample` is initialized with the following parameters: 

```python
Sample(sample_length, scattering_factors, magnetic_configuration)
```

`sample_length`: real size of the sample in meters. Scalar if x, y dimensions are equal or vector otherwise.

`scattering_factors`: scattering factors list with [f0, f1, f2] representing charge, XMCD and XMLD respectively.

`structure`: the magnetic configuration for scattering ([see section below](#structure)).

## Beam

The `Beam` is initialized with the following parameters:

```python
Beam(wavelength, beam_fwhm, polarization)
```

`wavelength`: wavelength of incident radiation in meters.

`beam_fwhm`: size of beam or full width at half maximum of the beam. Can be a scalar or a 2 component vector.

`polarization`: 4 component polarization in the form of a Stokes vector ([see section below](#stokes-vectors)).

## Geometry

The `Geometry` is initialized with the following parameters:

```python
Geometry(angle, detector_distance)
```

`angle`: The angle between the beam and the sample plane in degrees.

`detector_distance`: The distance between the sample and the detector in meters.

## Scatter
To compute the scattering pattern call the `Scatter` class with the following parameters:
```python
Scatter(Sample, Beam, Geometry)
```
The intensity of the scattering can be obtained from `Scatter.intensity` or plotted directly using functions in the 
plotting.py folder, some examples are:

```python
plotting.plot_structure(Sample, quiver=True)        # plot the components magnetic structure
plotting.plot_intensity(Scatter, log=True)          # plot the intensity of the scattering
plotting.plot_diff(Scatter_a, Scatter_b, log=True)  # plot the difference between two scattering patterns
```

## Stokes Parameters

The Stokes parameters are four components that define the polarization state of light. For convenience they are combined
to form a vector; it is actually a pseudovector and does not have any physical interpretation. They are defined as
follows:

`S_0`: Intensity of the light.

`S_1`: Component of intensity of light that is linearly polarized. Positive values for horizontal polarization, negative
values for vertical polarization.

`S_2`: Component of intensity of light that is linearly polarized along the diagonals. Positive values for +45 degree
polarization, negative values for -45 degree polarization.

`S_3`: Component of intensity of light that is circularly polarized. Positive values for right-handed polarization,
negative values for left-handed polarization.

## Structure

The magnetic vector field is a two-dimensional field, with three components. It is therefore defined as a `numpy` array
of shape `(3, nx, ny)`. To create this array from its scalar components, `(mx, my, mz)` one can use:

```python
structure = np.array([mx, my, mz])
```

`mx`, `my`, `mz` must all be of the same size and should be two dimensional, of size `(nx, ny)`, same as the pixel_size.

Structures can be made or imported using the `structures` header. Some examples are:

`strucutres.vortex(nx, ny)` and `structures.skyrmion(nx, ny)`.

## Geometry

The geometry here is such that the beam travels in the positive z dimension when `angle_d = 0` and along the negative y
dimension when `angle_d = 90`.

The sample plane is the x-y plane, thus the `mx` and `my` components are in-plane and `mz` is out of plane. 

# Theory of Magnetic Diffraction

Theory from "Soft X-ray resonant magnetic scattering of magnetic nanostructures"
, https://doi.org/10.1016/j.crhy.2007.06.004
