added crystal repr(); fixed typos; extended help

This commit is contained in:
Philip Eisenlohr 2021-08-08 17:56:54 -04:00
parent b1dab5f398
commit 5292f9b414
2 changed files with 22 additions and 14 deletions

View File

@ -26,7 +26,7 @@ lattice_symmetries = {
class Crystal(): class Crystal():
"""Lattice.""" """Crystal lattice."""
def __init__(self,*, def __init__(self,*,
family = None, family = None,
@ -41,7 +41,7 @@ class Crystal():
---------- ----------
family : {'triclinic', 'monoclinic', 'orthorhombic', 'tetragonal', 'hexagonal', 'cubic'}, optional. family : {'triclinic', 'monoclinic', 'orthorhombic', 'tetragonal', 'hexagonal', 'cubic'}, optional.
Name of the crystal family. Name of the crystal family.
Will be infered if 'lattice' is given. Will be inferred if 'lattice' is given.
lattice : {'aP', 'mP', 'mS', 'oP', 'oS', 'oI', 'oF', 'tP', 'tI', 'hP', 'cP', 'cI', 'cF'}, optional. lattice : {'aP', 'mP', 'mS', 'oP', 'oS', 'oI', 'oF', 'tP', 'tI', 'hP', 'cP', 'cI', 'cF'}, optional.
Name of the Bravais lattice in Pearson notation. Name of the Bravais lattice in Pearson notation.
a : float, optional a : float, optional
@ -110,14 +110,23 @@ class Crystal():
self.alpha = self.beta = self.gamma = None self.alpha = self.beta = self.gamma = None
def __repr__(self):
"""Represent."""
return '\n'.join([f'Crystal family {self.family}']
+ ([] if self.lattice is None else [f'Bravais lattice {self.lattice}']+
list(map(lambda x:f'{x[0]}:{x[1]:.5g}',
zip(['a','b','c','alpha','beta','gamma',],
self.parameters))))
)
def __eq__(self,other): def __eq__(self,other):
""" """
Equal to other. Equal to other.
Parameters Parameters
---------- ----------
other : Lattice other : Crystal
Lattice to check for equality. Crystal to check for equality.
""" """
return self.lattice == other.lattice and \ return self.lattice == other.lattice and \
@ -325,7 +334,7 @@ class Crystal():
def kinematics(self,mode): def kinematics(self,mode):
""" """
Return kinematic sytems. Return crystal kinematics systems.
Parameters Parameters
---------- ----------
@ -335,7 +344,7 @@ class Crystal():
Returns Returns
------- -------
direction_plane : dictionary direction_plane : dictionary
Direction and plane of deformation mode. Directions and planes of deformation mode families.
""" """
_kinematics = { _kinematics = {
@ -531,7 +540,7 @@ class Crystal():
Returns Returns
------- -------
operations : (string, damask.Rotation) operations : (string, damask.Rotation)
Rotations characterizing the orientation relationship. Resulting lattice and rotations characterizing the orientation relationship.
References References
---------- ----------

View File

@ -108,7 +108,7 @@ class Orientation(Rotation,Crystal):
An array of 3 x 5 random orientations reduced to the fundamental zone of tetragonal symmetry: An array of 3 x 5 random orientations reduced to the fundamental zone of tetragonal symmetry:
>>> import damask >>> import damask
>>> o=damask.Orientation.from_random(shape=(3,5),lattice='tetragonal').reduced >>> o=damask.Orientation.from_random(shape=(3,5),family='tetragonal').reduced
""" """
@ -138,9 +138,8 @@ class Orientation(Rotation,Crystal):
def __repr__(self): def __repr__(self):
"""Represent.""" """Represent."""
return '\n'.join(([] if self.lattice is None else [f'Bravais lattice {self.lattice}']) return '\n'.join([Crystal.__repr__(self),
+ ([f'Crystal family {self.family}']) Rotation.__repr__(self)])
+ [super().__repr__()])
def __copy__(self,rotation=None): def __copy__(self,rotation=None):
@ -862,7 +861,7 @@ class Orientation(Rotation,Crystal):
---------- ----------
N_slip|N_twin : iterable of int N_slip|N_twin : iterable of int
Number of deformation systems per family of the deformation system. Number of deformation systems per family of the deformation system.
Use '*'. to select all. Use '*' to select all.
Returns Returns
------- -------
@ -887,8 +886,8 @@ class Orientation(Rotation,Crystal):
if (N_slip is not None) ^ (N_twin is None): if (N_slip is not None) ^ (N_twin is None):
raise KeyError('Specify either "N_slip" or "N_twin"') raise KeyError('Specify either "N_slip" or "N_twin"')
kinematics = self.kinematics('slip' if N_twin is None else 'twin') kinematics,active = (self.kinematics('slip'),N_slip) if N_twin is None else \
active = N_slip if N_twin is None else N_twin (self.kinematics('twin'),N_twin)
if active == '*': active = [len(a) for a in kinematics['direction']] if active == '*': active = [len(a) for a in kinematics['direction']]
d = self.to_frame(uvw=np.vstack([kinematics['direction'][i][:n] for i,n in enumerate(active)])) d = self.to_frame(uvw=np.vstack([kinematics['direction'][i][:n] for i,n in enumerate(active)]))