4from ovito.io
import import_file
5from ovito.vis
import Viewport
6from scipy.spatial.transform
import Rotation
9A= np.array([[0.5,0.5,0.0],
12lattice=gb.Lattice3D(A)
15lv1 = lattice.latticeVector(np.array([1.0,2.0,2.0]))
18print(
"integer coordinates of lv1 = ", lv1.integerCoordinates())
19cartesianCoordinates= lv1.cartesian()
20print(
"cartesian coordinates of lv1 = ", cartesianCoordinates)
23lv2 = gb.LatticeVector3D(lv1.cartesian(),lattice)
27print(
"Are lv1 and lv2 identical: ", lv1.integerCoordinates()==lv2.integerCoordinates())
30lv2.integerCoordinates(np.array([1,2,3],dtype=np.int64))
31print(
"Integer coordinates of lv2 changed to = ", lv2.integerCoordinates())
32print(
"Cartesian coordinates of lv2 = ", lv2.cartesian())
36print(
"Integer coordinates of lv3 = ", lv3.integerCoordinates())
37print(
"Cartesian coordinates of lv3 = ", lv3.cartesian())
41rlv1= gb.ReciprocalLatticeVector3D(np.array([1,5,6],dtype=np.int64),lattice)
42rlv2= gb.ReciprocalLatticeVector3D(np.array([2.,2.,4.],dtype=np.float64),lattice)
46print(
"Integer coorindates of the resulting lattice direction = ", ld.integerCoordinates())
47print(
"Is ld perpendicular to rlv1 and rlv2?", (ld.dot(rlv1)==0
and ld.dot(rlv2)==0))
50bv1= gb.LatticeVector3D(np.array([1,-1,0]),lattice)
51bv2= gb.LatticeVector3D(np.array([1,1,-2]),lattice)
52bv3= gb.LatticeVector3D(np.array([1,1,1]),lattice)
56config= lattice.box([bv1,bv2,bv3],
"config.txt")
59misorientationAxis = lattice.reciprocalLatticeDirection(np.array([1.0,1.0,1.0]))
60print(
"Rotation axis = ", misorientationAxis.cartesian())
61rotations= lattice.generateCoincidentLattices(misorientationAxis)
63for i, rotation
in enumerate(rotations):
64 rot = Rotation.from_matrix(rotation)
65 angle = rot.magnitude() / 2
66 axis = rot.as_rotvec()
67 if np.allclose(axis, 0):
69 axis=np.array([1,0,0])
72 half_rotvec = axis / np.linalg.norm(axis) * angle
73 positiveR = Rotation.from_rotvec(half_rotvec).as_matrix()
74 negativeR = Rotation.from_rotvec(-half_rotvec).as_matrix()
77 lattice1 = gb.Lattice3D(A,positiveR)
78 lattice2 = gb.Lattice3D(A,negativeR)
81 bicrystal = gb.BiCrystal3D(lattice1,lattice2,
False)
82 print(f
"Matrix {i}: angle - {np.degrees(2*angle):.2f} degrees, sigma = {bicrystal.sigma}")
83 if (bicrystal.sigma<100):
86 bcslv1 = csl.latticeDirection(misorientationAxis.cartesian()).latticeVector()
89 bcslv2 = csl.latticeDirection(bcslv1.cross()).cartesian()).latticeVector()
91 bcslv3 = csl.latticeDirection(bcslv1.cross(bcslv2).cartesian()).latticeVector()
92 config = bicrystal.box([bcslv1,bcslv2,bcslv3],1,1,
"bc"+str(i))
93 except Exception
as e:
94 print(f
"Caught an exception: {e}")
97 pipeline = import_file(
"/Users/Nikhil/Documents/Academic/Software/oILAB/build/src/config.txt")
98 pipeline.add_to_scene()
100 vp.type = Viewport.Type.Perspective