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

Add feature for multiple lattice parameters/phases in polycrystal_from_odf #16

Merged
merged 2 commits into from
Sep 17, 2024
Merged
Changes from 1 commit
Commits
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
27 changes: 19 additions & 8 deletions xrd_simulator/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -117,11 +118,11 @@ 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
unit_cell (:obj:`list of lists` 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.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we add a sentence to each of these arguments which specify that "When unit_cell is an iterable with several instances of unit cell parameters, the polycrystal represents a multi-phase material."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is updated.

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
sgname (:obj:`list of strings`): Name of space group , e.g ['P3221',] for quartz, SiO2, for instance
path_to_cif_file (:obj:`list of strings`): [Path to CIF file,]. Defaults to None, in which case no structure
factors are computed.
maximum_sampling_bin_seperation (:obj:`float`): Discretization steplength of orientation
space using spherical coordinates over the unit quarternions in units of radians.
Expand All @@ -131,6 +132,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`)
Copy link
Collaborator

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.

Copy link
Contributor Author

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.

Expand Down Expand Up @@ -168,10 +171,18 @@ 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)

Copy link
Collaborator

Choose a reason for hiding this comment

The 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.

phases = [Phase(uc, sg, cf) for uc, sg, cf in zip(unit_cell, sgname, path_to_cif_file)]
if len(phases) == 1:
# Sample is uniformly single phase
element_phase_map = np.zeros((mesh.number_of_elements,)).astype(int)
elif 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)

# Sample spatial texture
orientation = _sample_ODF(
Expand Down
Loading