Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use phase class2 #205

Merged
merged 36 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
1fc6a87
New Feature: Add Simulation classes using Phase Class
CSSFrancis Apr 12, 2024
8282721
New Feature: Add intensity to reciprocal lattice vector
CSSFrancis Apr 12, 2024
bfe0505
Testing: Add tests for adding intensity of reciprocal_lattive_vector.py
CSSFrancis Apr 12, 2024
ac97ee6
New Feature: Added zerobeam to reciprocal lattice vector
CSSFrancis Apr 12, 2024
b0b67fa
New Feature: Moved Shape factor calculation to shape_factor_models.py
CSSFrancis Apr 12, 2024
6ec15b8
Testing: Added testing for simulation_generator.
CSSFrancis Apr 12, 2024
f3bd483
Testing: Testing the zero Beam is most intense.
CSSFrancis Apr 12, 2024
d7c86ec
Min Version: Bump orix min version
CSSFrancis Apr 17, 2024
ef03b39
Packaging: Include function and classes in init file
CSSFrancis Apr 17, 2024
d1839a5
Testing: Clean up tests due to changed function name
CSSFrancis Apr 17, 2024
3567308
Testing: Add coverage for simulation classes
CSSFrancis Apr 17, 2024
66f0133
Documentation: Fixed Broken documentation
CSSFrancis Apr 17, 2024
3d9c662
Refactor: Fixes per @viljarjf
CSSFrancis Apr 21, 2024
99327ad
Refactor: Clean up intensity in rlv class
CSSFrancis Apr 25, 2024
2ad4567
Refactor: Remove calculate structure factor
CSSFrancis Apr 25, 2024
273ffcc
Refactor: Changes from @hakonanes
CSSFrancis May 3, 2024
f32bfda
Refactor: Improve Documentation
CSSFrancis May 3, 2024
a8c68a3
Testing: Test simulation continuity
CSSFrancis May 3, 2024
3a27a7b
Documentation: Add intensity parameter
CSSFrancis May 3, 2024
9bf9404
Manifest: Add numpy old file
CSSFrancis May 3, 2024
9c216f8
Refactor: Refactor DiffractingVector code
CSSFrancis May 5, 2024
2ada567
Refactor: Refactor Rotation implementation
CSSFrancis May 5, 2024
b598a5a
BugFix: Fix HKL computation
CSSFrancis May 5, 2024
e0815d5
Refactor: Fix MANIFEST.in
CSSFrancis May 5, 2024
dff72bb
Plotting: Add interactive plotting
CSSFrancis May 6, 2024
8b92dce
Testing: no cover interactive plotting
CSSFrancis May 6, 2024
f3d9b95
Documentation: Add docstrings for interactive plotting
CSSFrancis May 6, 2024
82b3333
Documentation: Remove lattice rotation
CSSFrancis May 6, 2024
c39e357
Bugfix: Fix polar conversion
CSSFrancis May 7, 2024
05b3736
Bugfix: Fix Rotation with RLV
CSSFrancis May 8, 2024
bfbd299
Revert "Bugfix: Fix Rotation with RLV"
CSSFrancis May 8, 2024
96a48ec
Testing: Improve testing
CSSFrancis May 8, 2024
1f2150d
Refactor: Improve based on @hakonanes and @viljarjf's suggestions
CSSFrancis May 8, 2024
efde31d
Refactor: Tests including zero-vector
CSSFrancis May 8, 2024
da45a32
Refactor: Remove changes from RLV
CSSFrancis May 8, 2024
0e97f22
Refactor: suggestions for @hakonanes
CSSFrancis May 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
- os: ubuntu-latest
python-version: 3.8
OLDEST_SUPPORTED_VERSION: true
DEPENDENCIES: diffpy.structure==3.0.2 matplotlib==3.5 numpy==1.17.3 orix==0.9.0 scipy==1.8 tqdm==4.9
DEPENDENCIES: diffpy.structure==3.0.2 matplotlib==3.5 numpy==1.17.3 orix==0.11.0 scipy==1.8 tqdm==4.9
LABEL: -oldest
steps:
- uses: actions/checkout@v4
Expand Down
46 changes: 43 additions & 3 deletions diffsims/crystallography/reciprocal_lattice_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

from collections import defaultdict
from copy import deepcopy
from typing import Tuple
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line can be dropped.


from diffpy.structure.symmetryutilities import expandPosition
from diffpy.structure import Structure
Expand Down Expand Up @@ -122,10 +123,11 @@ def __init__(self, phase, xyz=None, hkl=None, hkil=None):

self._theta = np.full(self.shape, np.nan)
self._structure_factor = np.full(self.shape, np.nan, dtype="complex128")
self._intensity = np.full(self.shape, np.nan)

def __getitem__(self, key):
miller_new = self.to_miller().__getitem__(key)
rlv_new = self.from_miller(miller_new)
new_data = self.data[key]
rlv_new = self.__class__(self.phase, xyz=new_data)

if np.isnan(self.structure_factor).all():
rlv_new._structure_factor = np.full(
Expand All @@ -139,6 +141,18 @@ def __getitem__(self, key):
else:
rlv_new._theta = self.theta[key]

if np.isnan(self.intensity).all():
rlv_new._intensity = np.full(rlv_new.shape, np.nan)
else:
slic = self.intensity[key]
if not hasattr(slic, "__len__"):
slic = np.array(
[
slic,
]
)
rlv_new._intensity = slic

return rlv_new

def __repr__(self):
Expand Down Expand Up @@ -502,6 +516,28 @@ def scattering_parameter(self):

return 0.5 * self.gspacing

@property
def intensity(self):
return self._intensity

@intensity.setter
def intensity(self, value):
if not hasattr(value, "__len__"):
value = np.array(
[
value,
]
* self.size
)
if len(value) != self.size:
raise ValueError("Length of intensity array must match number of vectors")
self._intensity = np.array(value)

def rotate_from_matrix(self, rotation_matrix):
hakonanes marked this conversation as resolved.
Show resolved Hide resolved
return ReciprocalLatticeVector(
phase=self.phase, xyz=np.matmul(rotation_matrix.T, self.data.T).T
hakonanes marked this conversation as resolved.
Show resolved Hide resolved
)

@property
def structure_factor(self):
r"""Kinematical structure factors :math:`F`.
Expand Down Expand Up @@ -1070,7 +1106,7 @@ def from_highest_hkl(cls, phase, hkl):
return cls(phase, hkl=idx).unique()

@classmethod
def from_min_dspacing(cls, phase, min_dspacing=0.7):
def from_min_dspacing(cls, phase, min_dspacing=0.7, include_zero_beam=False):
hakonanes marked this conversation as resolved.
Show resolved Hide resolved
"""Create a set of unique reciprocal lattice vectors with a
a direct space interplanar spacing greater than a lower
threshold.
Expand All @@ -1083,6 +1119,8 @@ def from_min_dspacing(cls, phase, min_dspacing=0.7):
Smallest interplanar spacing to consider. Default is 0.7,
in the unit used to define the lattice parameters in
``phase``, which is assumed to be Ångström.
include_zero_beam: bool
If ``True``, include the zero beam in the set of vectors.
hakonanes marked this conversation as resolved.
Show resolved Hide resolved

Examples
--------
Expand Down Expand Up @@ -1128,6 +1166,8 @@ def from_min_dspacing(cls, phase, min_dspacing=0.7):
dspacing = 1 / phase.structure.lattice.rnorm(hkl)
idx = dspacing >= min_dspacing
hkl = hkl[idx]
if include_zero_beam:
hkl = np.vstack((hkl, np.zeros(3, dtype=int)))
return cls(phase, hkl=hkl).unique()

@classmethod
Expand Down
2 changes: 2 additions & 0 deletions diffsims/generators/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@
rotation_list_generators,
sphere_mesh_generators,
zap_map_generator,
simulation_generator,
)

__all__ = [
"diffraction_generator",
"library_generator",
"rotation_list_generators",
"sphere_mesh_generators",
"simulation_generator",
"zap_map_generator",
]
Loading