-
Notifications
You must be signed in to change notification settings - Fork 8
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
Add feature for multiple lattice parameters/phases in polycrystal_from_odf #16
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
docs/source/examples/example_polycrystal_from_odf_2phases.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import numpy as np | ||
from xrd_simulator.templates import polycrystal_from_odf | ||
|
||
|
||
# uniform orientation distribution function. | ||
def ODF(x, q): return 1. / (np.pi**2) | ||
|
||
|
||
number_of_crystals = 500 | ||
bounding_height = 50.0 | ||
bounding_radius = 25.0 | ||
unit_cell = [[3.579, 3.579, 3.579, 90., 90., 90.0], | ||
[5.46745, 5.46745, 5.46745, 90., 90., 90.0]] | ||
sgname = ['F432', 'F432'] | ||
max_bin = np.radians(10.0) | ||
path_to_cif_file = None | ||
|
||
def strain_tensor(x): return np.array([[0, 0, 0.02 * x[2] / bounding_height], | ||
[0, 0, 0], | ||
[0, 0, 0]]) # Linear strain gradient along rotation axis. | ||
|
||
|
||
polycrystal = polycrystal_from_odf(ODF, | ||
number_of_crystals, | ||
bounding_height, | ||
bounding_radius, | ||
unit_cell, | ||
sgname, | ||
path_to_cif_file, | ||
max_bin, | ||
strain_tensor) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,6 +94,7 @@ def polycrystal_from_odf( | |
path_to_cif_file=None, | ||
maximum_sampling_bin_seperation=np.radians(5.0), | ||
strain_tensor=lambda x: np.zeros((3, 3)), | ||
phase_fractions=None | ||
): | ||
"""Fill a cylinder with crystals from a given orientation density function. | ||
|
||
|
@@ -117,12 +118,19 @@ def polycrystal_from_odf( | |
microns. | ||
sample_bounding_cylinder_radius (:obj:`float`): Radius of sample cylinder in units of | ||
microns. | ||
unit_cell (:obj:`list` of :obj:`float`): Crystal unit cell representation of the form | ||
[a,b,c,alpha,beta,gamma], where alpha,beta and gamma are in units of degrees while | ||
a,b and c are in units of anstrom. | ||
sgname (:obj:`string`): Name of space group , e.g 'P3221' for quartz, SiO2, for instance | ||
path_to_cif_file (:obj:`string`): Path to CIF file. Defaults to None, in which case no structure | ||
factors are computed. | ||
unit_cell (:obj:`list of lists` of :obj:`float`): Crystal unit cell representation of the form | ||
[a,b,c,alpha,beta,gamma] or [[a,b,c,alpha,beta,gamma],], where alpha,beta and gamma are | ||
in units of degrees while a,b and c are in units of anstrom. When the unit_cell is just a | ||
list (first example), the input represents single-phase material. When the unit_cell is an | ||
iterable list (second example), the input represents multi-phase material. | ||
sgname (:obj:`list of strings`): Name of space group , e.g 'P3221' or ['P3221',] for quartz, | ||
SiO2, for instance. When the input is just a string, it represents space group for | ||
single-phase material. When the input is a list of string (second example), it represents | ||
space groups for multi-phase material. | ||
path_to_cif_file (:obj:`list of strings`): Path to CIF file or [Path to CIF file,]. | ||
Defaults to None, in which case no structure factors are computed. When the input is a | ||
single file path (first example), the input is for single-phase material. When the | ||
input is a list of file paths (second example), the input is for multi-phase material. | ||
maximum_sampling_bin_seperation (:obj:`float`): Discretization steplength of orientation | ||
space using spherical coordinates over the unit quarternions in units of radians. | ||
A smaller steplength gives more accurate sampling of the input | ||
|
@@ -131,6 +139,8 @@ def polycrystal_from_odf( | |
strain_tensor(x) -> :obj:`numpy array` of shape ``(3,3)`` where input variable ``x`` is | ||
a :obj:`numpy array` of shape ``(3,)`` representing a spatial coordinate in the | ||
cylinder (x,y,z). | ||
phase_fraction (:obj: `list` of :obj:`float`): Phase fraction represented as probability, summing up to 1. | ||
Default None; will take even distribution of crystals. | ||
|
||
Returns: | ||
(:obj:`xrd_simulator.polycrystal.Polycrystal`) | ||
|
@@ -168,10 +178,29 @@ def polycrystal_from_odf( | |
) | ||
|
||
mesh = TetraMesh._build_tetramesh(cylinder) | ||
|
||
# Sample is uniformly single phase | ||
phases = [Phase(unit_cell, sgname, path_to_cif_file)] | ||
element_phase_map = np.zeros((mesh.number_of_elements,)).astype(int) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks solid to me. :=) Altough, we need to make the unit tests pass / add one for the case of multi phase. |
||
if all(isinstance(x, list) for x in unit_cell) \ | ||
and isinstance(sgname, list): | ||
# Multi Phase Material | ||
if not isinstance(path_to_cif_file, list): | ||
if path_to_cif_file is None: | ||
path_to_cif_file = [None]* len(unit_cell) | ||
else: | ||
print("Single cif file input. Please enter list of corresponding cif files.") | ||
exit | ||
phases = [Phase(uc, sg, cf) for uc, sg, cf in zip(unit_cell, sgname, path_to_cif_file)] | ||
if phase_fractions is None: | ||
# Sample is uniformly distributed phases | ||
element_phase_map = np.random.randint(len(phases), size=(mesh.number_of_elements,)) | ||
else : | ||
# Sample is distributed by phase fraction | ||
probabilities = np.array(phase_fractions) | ||
element_phase_map = np.random.choice(len(phases), size=(mesh.number_of_elements,), p=probabilities) | ||
else: | ||
# Single Phase Material | ||
phases = [Phase(unit_cell, sgname, path_to_cif_file)] | ||
# Sample is uniformly single phase | ||
element_phase_map = np.zeros((mesh.number_of_elements,)).astype(int) | ||
|
||
# Sample spatial texture | ||
orientation = _sample_ODF( | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also neeed to edit the example file. c.f docs/source/examples/example_polycrystal_from_odf.py
This example is included into the docs so it now needs to reflect the changes. I suggest to make it a simple 2-phase material example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a 2 phase example, albeit with trivial input values.