|
20 | 20 | import ase.io
|
21 | 21 | import chemiscope
|
22 | 22 | import ipi
|
| 23 | +import numpy as np |
| 24 | +from ipi.utils.mathtools import ( |
| 25 | + get_rotation_quadrature_lebedev, |
| 26 | + get_rotation_quadrature_legendre, |
| 27 | +) |
23 | 28 |
|
24 | 29 |
|
25 | 30 | # import matplotlib.pyplot as plt
|
26 | 31 | # import numpy as np
|
27 | 32 |
|
| 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 | +) |
28 | 90 |
|
29 | 91 | # %%
|
30 | 92 | # Show the problem
|
|
0 commit comments