picometer 0.3.1__tar.gz → 0.5.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {picometer-0.3.1 → picometer-0.5.0}/PKG-INFO +1 -1
- {picometer-0.3.1 → picometer-0.5.0}/picometer/atom.py +40 -0
- {picometer-0.3.1 → picometer-0.5.0}/picometer/instructions.py +33 -0
- {picometer-0.3.1 → picometer-0.5.0}/picometer/settings.py +3 -0
- picometer-0.5.0/picometer/settings.yaml +6 -0
- {picometer-0.3.1 → picometer-0.5.0}/pyproject.toml +1 -1
- picometer-0.3.1/picometer/settings.yaml +0 -3
- {picometer-0.3.1 → picometer-0.5.0}/LICENSE +0 -0
- {picometer-0.3.1 → picometer-0.5.0}/README.md +0 -0
- {picometer-0.3.1 → picometer-0.5.0}/picometer/__init__.py +0 -0
- {picometer-0.3.1 → picometer-0.5.0}/picometer/__main__.py +0 -0
- {picometer-0.3.1 → picometer-0.5.0}/picometer/logging.py +0 -0
- {picometer-0.3.1 → picometer-0.5.0}/picometer/models.py +0 -0
- {picometer-0.3.1 → picometer-0.5.0}/picometer/process.py +0 -0
- {picometer-0.3.1 → picometer-0.5.0}/picometer/shapes.py +0 -0
- {picometer-0.3.1 → picometer-0.5.0}/picometer/utility.py +0 -0
|
@@ -119,6 +119,20 @@ class AtomSet(Shape):
|
|
|
119
119
|
def cart_xyz(self) -> np.ndarray:
|
|
120
120
|
return self.orthogonalise(self.fract_xyz)
|
|
121
121
|
|
|
122
|
+
@property
|
|
123
|
+
def fract_uij(self) -> np.ndarray:
|
|
124
|
+
"""Return a 3D array i.e. stack of 3x3 fract. displacement tensors."""
|
|
125
|
+
t = self.table
|
|
126
|
+
default = pd.Series([np.nan] * len(t), index=t.index)
|
|
127
|
+
uij = np.zeros((len(t), 3, 3), dtype=np.float64)
|
|
128
|
+
uij[:, 0, 0] = t.get('U11', default).to_numpy(dtype=np.float64)
|
|
129
|
+
uij[:, 1, 1] = t.get('U22', default).to_numpy(dtype=np.float64)
|
|
130
|
+
uij[:, 2, 2] = t.get('U33', default).to_numpy(dtype=np.float64)
|
|
131
|
+
uij[:, 0, 1] = uij[:, 1, 0] = t.get('U12', default).to_numpy(dtype=np.float64)
|
|
132
|
+
uij[:, 0, 2] = uij[:, 2, 0] = t.get('U13', default).to_numpy(dtype=np.float64)
|
|
133
|
+
uij[:, 1, 2] = uij[:, 2, 1] = t.get('U23', default).to_numpy(dtype=np.float64)
|
|
134
|
+
return uij
|
|
135
|
+
|
|
122
136
|
def fractionalise(self, cart_xyz: np.ndarray) -> np.ndarray:
|
|
123
137
|
"""Multiply 3xN vector by crystallographic matrix to get fract coord"""
|
|
124
138
|
return np.linalg.inv(self.base.A_d.T) @ cart_xyz
|
|
@@ -158,8 +172,34 @@ class AtomSet(Shape):
|
|
|
158
172
|
data['fract_x'] = fract_xyz[:, 0]
|
|
159
173
|
data['fract_y'] = fract_xyz[:, 1]
|
|
160
174
|
data['fract_z'] = fract_xyz[:, 2]
|
|
175
|
+
if {'U11', 'U22', 'U33', 'U12', 'U13', 'U23'}.issubset(data.columns):
|
|
176
|
+
uij = self.fract_uij # shape: (n_atoms, 3, 3)
|
|
177
|
+
mask = ~np.isnan(uij).all(axis=(1, 2)) # atoms with defined Uij
|
|
178
|
+
if np.any(mask):
|
|
179
|
+
uij_rot = (s := symm_op.tf) @ uij[mask] @ s.T
|
|
180
|
+
data.loc[mask, 'U11'] = uij_rot[:, 0, 0]
|
|
181
|
+
data.loc[mask, 'U22'] = uij_rot[:, 1, 1]
|
|
182
|
+
data.loc[mask, 'U33'] = uij_rot[:, 2, 2]
|
|
183
|
+
data.loc[mask, 'U12'] = uij_rot[:, 0, 1]
|
|
184
|
+
data.loc[mask, 'U13'] = uij_rot[:, 0, 2]
|
|
185
|
+
data.loc[mask, 'U23'] = uij_rot[:, 1, 2]
|
|
161
186
|
return self.__class__(self.base, data)
|
|
162
187
|
|
|
188
|
+
@property
|
|
189
|
+
def u_cartesian_eigenvalues(self):
|
|
190
|
+
u_columns = ['U11', 'U12', 'U13', 'U22', 'U23', 'U33']
|
|
191
|
+
eigenvalues = np.full((len(self), 3), np.nan)
|
|
192
|
+
if not set(u_columns).issubset(self.table.keys()):
|
|
193
|
+
return eigenvalues
|
|
194
|
+
u_fract = self.fract_uij # Nx3n3 stack of abc-normalized U_cif tensors
|
|
195
|
+
a_mat = self.base.A_d.T # fractional to orthogonal cartesian metric
|
|
196
|
+
n_mat = np.diag([self.base.a_r, self.base.b_r, self.base.c_r])
|
|
197
|
+
u_star = (n_mat @ u_fract) @ n_mat # eq. 4b @ S0021889802008580
|
|
198
|
+
u_cart = (a_mat @ u_star) @ a_mat.T # eq. 3a @ S0021889802008580
|
|
199
|
+
mask = ~self.table[u_columns].isna().any(axis=1)
|
|
200
|
+
eigenvalues[mask, :] = np.linalg.eigh(u_cart[mask, :, :])[0]
|
|
201
|
+
return eigenvalues
|
|
202
|
+
|
|
163
203
|
@property
|
|
164
204
|
def centroid(self) -> np.ndarray:
|
|
165
205
|
"""A 3-vector with average atom position."""
|
|
@@ -15,6 +15,7 @@ from pathlib import Path
|
|
|
15
15
|
from typing import Any, Union, Protocol
|
|
16
16
|
|
|
17
17
|
from numpy import rad2deg
|
|
18
|
+
import numpy as np
|
|
18
19
|
import pandas as pd
|
|
19
20
|
import yaml
|
|
20
21
|
|
|
@@ -218,6 +219,32 @@ class LoadInstructionHandler(BaseInstructionHandler):
|
|
|
218
219
|
label = cif_path + (':' + block_name if block_name else '')
|
|
219
220
|
self.processor.model_states[label] = ModelState(atoms=atoms)
|
|
220
221
|
logger.info(f'Loaded model state {label}')
|
|
222
|
+
|
|
223
|
+
if self.processor.settings['complete_uiso_from_umatrix']:
|
|
224
|
+
if 'U11' in atoms.table.columns:
|
|
225
|
+
if 'Uiso' not in atoms.table.columns:
|
|
226
|
+
atoms.table['Uiso'] = pd.NA
|
|
227
|
+
u_equiv = atoms.table[['U11', 'U22', 'U33']].mean(axis=1)
|
|
228
|
+
mask = atoms.table['Uiso'].isna()
|
|
229
|
+
atoms.table.loc[mask, 'Uiso'] = u_equiv[mask]
|
|
230
|
+
|
|
231
|
+
if self.processor.settings['complete_umatrix_from_uiso']:
|
|
232
|
+
u_columns = ['U11', 'U12', 'U13', 'U22', 'U23', 'U33']
|
|
233
|
+
if 'Uiso' in atoms.table.columns:
|
|
234
|
+
for col in u_columns:
|
|
235
|
+
if col not in atoms.table.columns:
|
|
236
|
+
atoms.table[col] = pd.NA
|
|
237
|
+
mask1 = atoms.table['Uiso'].notna()
|
|
238
|
+
mask2 = atoms.table[['U11', 'U22', 'U33']].isna().all(axis=1)
|
|
239
|
+
# based on http://dx.doi.org/10.1107/S0021889802008580
|
|
240
|
+
n_mat = np.diag([atoms.base.a_r, atoms.base.b_r, atoms.base.c_r])
|
|
241
|
+
n_inv = np.linalg.inv(n_mat)
|
|
242
|
+
u_star = (m := np.linalg.inv(atoms.base.A_d.T)) @ m.T
|
|
243
|
+
u_cif = n_inv @ u_star @ n_inv.T
|
|
244
|
+
for atom_label in atoms.table.index[mask1 & mask2]:
|
|
245
|
+
u_atom = atoms.table.at[atom_label, 'Uiso'] * u_cif
|
|
246
|
+
atoms.table.loc[atom_label, u_columns] = u_atom[np.triu_indices(3)]
|
|
247
|
+
|
|
221
248
|
if not self.processor.settings['auto_write_unit_cell']:
|
|
222
249
|
return
|
|
223
250
|
et = self.processor.evaluation_table
|
|
@@ -326,12 +353,18 @@ class DisplacementInstructionHandler(SerialInstructionHandler):
|
|
|
326
353
|
|
|
327
354
|
def handle_one(self, instruction: Instruction, ms_key: str, ms: ModelState) -> None:
|
|
328
355
|
focus = ms.nodes.locate(self.processor.selection)
|
|
356
|
+
assert len(focus) > 0
|
|
329
357
|
for label, displacements in focus.table.iterrows():
|
|
330
358
|
for suffix in 'Uiso U11 U22 U33 U23 U13 U12'.split():
|
|
331
359
|
label_ = label + '_' + suffix
|
|
332
360
|
value = getattr(displacements, suffix, None)
|
|
333
361
|
if value is not None:
|
|
334
362
|
self.processor.evaluation_table.loc[ms_key, label_] = value
|
|
363
|
+
if self.processor.settings['displacement_get_cartesian_eigenvalues']:
|
|
364
|
+
for label, es in zip(focus.table.index, focus.u_cartesian_eigenvalues):
|
|
365
|
+
for e, suffix in zip(es, ['Uce1', 'Uce2', 'Uce3']):
|
|
366
|
+
label_ = label + '_' + suffix
|
|
367
|
+
self.processor.evaluation_table.loc[ms_key, label_] = e
|
|
335
368
|
logger.info(f'Noted displacement for current selection in model state {ms_key}')
|
|
336
369
|
|
|
337
370
|
|
|
@@ -19,6 +19,9 @@ class DefaultSettings:
|
|
|
19
19
|
"""Store default values of all settings. Use `AnyValue` if no default."""
|
|
20
20
|
auto_write_unit_cell: bool = True
|
|
21
21
|
clear_selection_after_use: bool = True
|
|
22
|
+
displacement_get_cartesian_eigenvalues: bool = False
|
|
23
|
+
complete_uiso_from_umatrix: bool = False
|
|
24
|
+
complete_umatrix_from_uiso: bool = False
|
|
22
25
|
|
|
23
26
|
@classmethod
|
|
24
27
|
def get_field(cls, key: str) -> Field:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|