Skip to content

Commit 29dd72a

Browse files
committed
Added a visualization of what the rotation averaging does
1 parent cb046bf commit 29dd72a

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

examples/o3-averaging/o3-averaging.py

+62
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,73 @@
2020
import ase.io
2121
import chemiscope
2222
import ipi
23+
import numpy as np
24+
from ipi.utils.mathtools import (
25+
get_rotation_quadrature_lebedev,
26+
get_rotation_quadrature_legendre,
27+
)
2328

2429

2530
# import matplotlib.pyplot as plt
2631
# import numpy as np
2732

33+
# %%
34+
# show rotations
35+
36+
# Gets quadrature grid (regular spacing in alpha,
37+
# lebedev grids for beta, gamma)
38+
quad_grid = get_rotation_quadrature_lebedev(3)
39+
quad = {
40+
"rotation_matrices": np.array([q[0] for q in quad_grid]),
41+
"weights": np.array([q[1] for q in quad_grid]),
42+
"angles": np.array([q[2] for q in quad_grid]),
43+
}
44+
45+
# Display the rotations of an atom with a "force" vector
46+
# The "reference atom" is marked as an O, and its copies as H
47+
vs = [
48+
np.asarray([[2, 0, 0], [2, 1, 0]]),
49+
np.asarray([[0, 2, 0], [0, 2, 1]]),
50+
np.asarray([[0, 0, 2], [1, 0, 2]]),
51+
]
52+
53+
frames = []
54+
for v in vs:
55+
rl = v @ quad["rotation_matrices"]
56+
ats = ase.Atoms("O" + ("H" * (len(rl) - 1)), positions=rl[:, 0])
57+
ats.arrays["forces"] = rl[:, 1] - rl[:, 0]
58+
ats.arrays["weight"] = quad["weights"]
59+
ats.arrays["alpha"] = quad["angles"][:, 0]
60+
ats.arrays["beta"] = quad["angles"][:, 1]
61+
ats.arrays["gamma"] = quad["angles"][:, 2]
62+
frames.append(ats)
63+
64+
# Display with chemiscope. Three frames for three
65+
# initial positions. You can also color by grid weight
66+
# and by Euler angles
67+
68+
chemiscope.show(
69+
frames=frames,
70+
mode="structure",
71+
shapes={"forces": chemiscope.ase_vectors_to_arrows(frames)},
72+
properties=chemiscope.extract_properties(frames),
73+
settings={
74+
"structure": [
75+
dict(
76+
bonds=False,
77+
atoms=True,
78+
shape="forces",
79+
environments={"activated": False},
80+
color={
81+
"property": "element",
82+
"transform": "linear",
83+
"palette": "viridis",
84+
},
85+
),
86+
]
87+
},
88+
environments=chemiscope.all_atomic_environments(frames),
89+
)
2890

2991
# %%
3092
# Show the problem

0 commit comments

Comments
 (0)