elastic-ase 0.0.1__py3-none-any.whl
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.
- elastic_ase/__init__.py +32 -0
- elastic_ase/_spglib.py +21 -0
- elastic_ase/analysis.py +130 -0
- elastic_ase/auto.py +233 -0
- elastic_ase/average.py +82 -0
- elastic_ase/calculator.py +906 -0
- elastic_ase/cli.py +260 -0
- elastic_ase/codes.py +153 -0
- elastic_ase/deformations.py +20 -0
- elastic_ase/orientation.py +108 -0
- elastic_ase/plotting.py +35 -0
- elastic_ase/properties.py +53 -0
- elastic_ase/report.py +69 -0
- elastic_ase/results.py +51 -0
- elastic_ase/rundir.py +148 -0
- elastic_ase/solvers.py +31 -0
- elastic_ase/symmetry.py +152 -0
- elastic_ase/systems.py +322 -0
- elastic_ase-0.0.1.dist-info/METADATA +364 -0
- elastic_ase-0.0.1.dist-info/RECORD +24 -0
- elastic_ase-0.0.1.dist-info/WHEEL +5 -0
- elastic_ase-0.0.1.dist-info/entry_points.txt +2 -0
- elastic_ase-0.0.1.dist-info/licenses/LICENSE +10 -0
- elastic_ase-0.0.1.dist-info/top_level.txt +1 -0
elastic_ase/__init__.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
__version__ = "0.0.1"
|
|
2
|
+
|
|
3
|
+
from elastic_ase.calculator import ElasticASE
|
|
4
|
+
from elastic_ase.properties import derived_properties
|
|
5
|
+
from elastic_ase.results import ElasticResults
|
|
6
|
+
|
|
7
|
+
from elastic_ase.symmetry import check_symmetry, classify, SymmetryReport
|
|
8
|
+
from elastic_ase.deformations import get_deformation_specs
|
|
9
|
+
from elastic_ase.solvers import solve_stiffness, check_mechanical_stability
|
|
10
|
+
from elastic_ase.average import calculate_polycrystalline_averages
|
|
11
|
+
from elastic_ase.systems import SYSTEMS, CrystalSystem
|
|
12
|
+
from elastic_ase import auto
|
|
13
|
+
|
|
14
|
+
# Same class under a descriptive name: ec = ElasticConstants(atoms)
|
|
15
|
+
ElasticConstants = ElasticASE
|
|
16
|
+
|
|
17
|
+
__all__ = [
|
|
18
|
+
"ElasticASE",
|
|
19
|
+
"ElasticConstants",
|
|
20
|
+
"ElasticResults",
|
|
21
|
+
"derived_properties",
|
|
22
|
+
"check_symmetry",
|
|
23
|
+
"classify",
|
|
24
|
+
"SymmetryReport",
|
|
25
|
+
"get_deformation_specs",
|
|
26
|
+
"solve_stiffness",
|
|
27
|
+
"check_mechanical_stability",
|
|
28
|
+
"calculate_polycrystalline_averages",
|
|
29
|
+
"SYSTEMS",
|
|
30
|
+
"CrystalSystem",
|
|
31
|
+
"auto",
|
|
32
|
+
]
|
elastic_ase/_spglib.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""Calls into spglib that behave the same on spglib 2.4 to 3.x.
|
|
2
|
+
|
|
3
|
+
Silences the deprecation warning ("Set OLD_ERROR_HANDLING to false ...")
|
|
4
|
+
on spglib >= 2.7 and handles failures uniformly across versions.
|
|
5
|
+
"""
|
|
6
|
+
import warnings
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def call(name, *args, **kwargs):
|
|
10
|
+
"""Return ``spglib.<name>(*args, **kwargs)``, or ``None`` if spglib fails."""
|
|
11
|
+
import spglib
|
|
12
|
+
|
|
13
|
+
error = getattr(getattr(spglib, "error", None), "SpglibError", None) or getattr(spglib, "SpglibError", None)
|
|
14
|
+
with warnings.catch_warnings():
|
|
15
|
+
warnings.filterwarnings("ignore", message=".*OLD_ERROR_HANDLING.*", category=DeprecationWarning)
|
|
16
|
+
try:
|
|
17
|
+
return getattr(spglib, name)(*args, **kwargs)
|
|
18
|
+
except Exception as exc:
|
|
19
|
+
if error is not None and isinstance(exc, error):
|
|
20
|
+
return None
|
|
21
|
+
raise
|
elastic_ase/analysis.py
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"""From energies to elastic constants: pure functions (no files, no printing).
|
|
2
|
+
|
|
3
|
+
For every deformation the energy per volume is fitted with (E - E0)/V0 = a d^2 + b d + c; the
|
|
4
|
+
curvatures a are solved for the independent constants of the table (see the theory page of
|
|
5
|
+
the documentation).
|
|
6
|
+
"""
|
|
7
|
+
import numpy as np
|
|
8
|
+
|
|
9
|
+
from elastic_ase import auto
|
|
10
|
+
from elastic_ase.average import calculate_polycrystalline_averages
|
|
11
|
+
from elastic_ase.properties import derived_properties
|
|
12
|
+
from elastic_ase.results import ElasticResults
|
|
13
|
+
from elastic_ase.rundir import GROUND_STATE, strained_key
|
|
14
|
+
from elastic_ase.solvers import check_mechanical_stability
|
|
15
|
+
|
|
16
|
+
EV_TO_GPA = 160.21766208
|
|
17
|
+
RESIDUAL_STRESS_TOL = 0.5 # GPa: warn above this residual stress of the reference cell
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def fit_curves(system, strains, energies, volume):
|
|
21
|
+
"""Quadratic fit of every energy-strain curve.
|
|
22
|
+
|
|
23
|
+
Returns (coefficients, r2_scores, fits, linear_terms): the curvature a (GPa) and R^2 per
|
|
24
|
+
deformation, the data and fitted polynomial per deformation (for plots), and the
|
|
25
|
+
(strain direction e, linear term b in GPa) pairs used for the residual stress.
|
|
26
|
+
"""
|
|
27
|
+
strains = np.asarray(strains, float)
|
|
28
|
+
e0 = energies[GROUND_STATE]
|
|
29
|
+
coefficients, r2_scores, fits, linear_terms = {}, {}, {}, []
|
|
30
|
+
for deformation in system.deformations:
|
|
31
|
+
name = deformation.folder
|
|
32
|
+
energy = np.array([e0 if s == 0.0 else energies[strained_key(name, float(s))] for s in strains])
|
|
33
|
+
y = (energy - e0) / volume
|
|
34
|
+
poly = np.polyfit(strains, y, 2)
|
|
35
|
+
coefficients[name] = float(poly[0] * EV_TO_GPA)
|
|
36
|
+
|
|
37
|
+
residual = y - np.polyval(poly, strains)
|
|
38
|
+
ss_tot = np.sum((y - y.mean()) ** 2)
|
|
39
|
+
r2_scores[name] = float(1.0 - np.sum(residual ** 2) / ss_tot) if ss_tot > 1e-15 else 1.0
|
|
40
|
+
fits[name] = {"strains": strains.tolist(), "y_GPa": (y * EV_TO_GPA).tolist(),
|
|
41
|
+
"coefficients_GPa": (poly * EV_TO_GPA).tolist(), "r2": r2_scores[name]}
|
|
42
|
+
|
|
43
|
+
# Linear term = sigma_0 . e. From a cubic fit when possible: in a quadratic fit the
|
|
44
|
+
# anharmonic cubic term leaks into it (about 0.3 GPa of fake pressure for Al at +-3 %).
|
|
45
|
+
b = np.polyfit(strains, y, 3)[2] if len(np.unique(strains)) >= 4 else poly[1]
|
|
46
|
+
linear_terms.append((np.array(deformation.strain, float), float(b * EV_TO_GPA)))
|
|
47
|
+
return coefficients, r2_scores, fits, linear_terms
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def residual_stress(system, linear_terms):
|
|
51
|
+
"""Residual stress of the reference cell from the linear terms of the fits.
|
|
52
|
+
|
|
53
|
+
b_j = sigma_0 . e_j for every deformation j; solving gives the parts of sigma_0 the
|
|
54
|
+
deformations determine. The pressure P = -tr(sigma_0)/3 is exact whenever (1,1,1,0,0,0) lies
|
|
55
|
+
in the span of the e_j (true for every named table), else None.
|
|
56
|
+
"""
|
|
57
|
+
e = np.array([t[0] for t in linear_terms])
|
|
58
|
+
b = np.array([t[1] for t in linear_terms])
|
|
59
|
+
sigma, *_ = np.linalg.lstsq(e, b, rcond=None)
|
|
60
|
+
hydro = np.array([1.0, 1.0, 1.0, 0.0, 0.0, 0.0])
|
|
61
|
+
coef, *_ = np.linalg.lstsq(e.T, hydro, rcond=None)
|
|
62
|
+
pressure = float(-hydro @ sigma / 3.0) if np.abs(e.T @ coef - hydro).max() < 1e-8 else None
|
|
63
|
+
along = np.abs(b) / np.linalg.norm(e, axis=1)
|
|
64
|
+
return {
|
|
65
|
+
"pressure_GPa": pressure, # positive = compressed reference cell
|
|
66
|
+
"max_along_deformation_GPa": float(along.max()),
|
|
67
|
+
"per_deformation_GPa": {d.folder: float(v) for d, v in zip(system.deformations, along)},
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def residual_stress_message(stress, tolerance=RESIDUAL_STRESS_TOL):
|
|
72
|
+
"""Warning text if the reference cell is noticeably stressed, else None."""
|
|
73
|
+
worst = stress["max_along_deformation_GPa"]
|
|
74
|
+
if worst <= tolerance:
|
|
75
|
+
return None
|
|
76
|
+
pressure = stress["pressure_GPa"]
|
|
77
|
+
text = f"pressure {pressure:+.2f} GPa" if pressure is not None else f"up to {worst:.2f} GPa"
|
|
78
|
+
return (f"The reference cell is not stress-free ({text}, from the linear terms of the "
|
|
79
|
+
"energy-strain fits). The elastic constants are biased by a similar amount: relax "
|
|
80
|
+
"the structure (cell and atoms) with the same calculator and settings first.")
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def standard_frame(stiffness, rotation, space_group_number, constants):
|
|
84
|
+
"""(C in the standard setting, independent constants of the space group there)."""
|
|
85
|
+
if rotation is None:
|
|
86
|
+
return stiffness.copy(), dict(constants)
|
|
87
|
+
c_standard = auto.to_standard(stiffness, rotation)
|
|
88
|
+
standard_constants = dict(constants)
|
|
89
|
+
if space_group_number > 0:
|
|
90
|
+
try:
|
|
91
|
+
_, standard_constants, _ = auto.standard_constants(c_standard, space_group_number)
|
|
92
|
+
except Exception:
|
|
93
|
+
standard_constants = dict(constants)
|
|
94
|
+
return c_standard, standard_constants
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def analyse(system, strains, energies, atoms, symmetry, standard_rotation=None,
|
|
98
|
+
space_group_number=0, frame="cartesian"):
|
|
99
|
+
"""ElasticResults from the energies of all runs (``energies[run name]`` in eV).
|
|
100
|
+
|
|
101
|
+
``atoms`` is the reference structure (its volume and masses are used), ``symmetry`` the
|
|
102
|
+
table name (for the stability description and the Kleinman parameter). Directional
|
|
103
|
+
properties (elastic-vis) are not computed here.
|
|
104
|
+
"""
|
|
105
|
+
coefficients, r2_scores, fits, linear_terms = fit_curves(system, strains, energies, atoms.get_volume())
|
|
106
|
+
constants, stiffness = system.solve(coefficients)
|
|
107
|
+
c_standard, standard_constants = standard_frame(stiffness, standard_rotation, space_group_number, constants)
|
|
108
|
+
|
|
109
|
+
# Stability and the Zener/Cauchy values read entries such as C12 and C44, which have their
|
|
110
|
+
# usual meaning only with the crystal axes along x, y, z: use the standard setting.
|
|
111
|
+
is_stable, criteria = check_mechanical_stability(c_standard, symmetry)
|
|
112
|
+
averages = calculate_polycrystalline_averages(c_standard)
|
|
113
|
+
return ElasticResults(
|
|
114
|
+
stiffness_matrix=c_standard if frame == "standard" else stiffness,
|
|
115
|
+
stiffness_cartesian=stiffness,
|
|
116
|
+
stiffness_standard=c_standard,
|
|
117
|
+
standard_constants=standard_constants,
|
|
118
|
+
standard_rotation=standard_rotation,
|
|
119
|
+
independent_constants=constants,
|
|
120
|
+
is_stable=is_stable,
|
|
121
|
+
stability_criteria=criteria,
|
|
122
|
+
polycrystalline_averages=averages,
|
|
123
|
+
directional_properties=None,
|
|
124
|
+
derived_properties=derived_properties(averages, atoms, c_standard, symmetry),
|
|
125
|
+
residual_stress=residual_stress(system, linear_terms),
|
|
126
|
+
coefficients=coefficients,
|
|
127
|
+
r2_scores=r2_scores,
|
|
128
|
+
energies=dict(energies),
|
|
129
|
+
fits=fits,
|
|
130
|
+
)
|
elastic_ase/auto.py
ADDED
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
"""Orientation-aware automatic mode: independent constants and deformations from the crystal.
|
|
2
|
+
|
|
3
|
+
Instead of assuming a standard orientation (c along z, unique axis along y, etc.),
|
|
4
|
+
the crystal's symmetry operations are derived via spglib from the primitive cell
|
|
5
|
+
in the user's own Cartesian frame:
|
|
6
|
+
|
|
7
|
+
1. The stiffness matrices invariant under every point group operation form a linear
|
|
8
|
+
subspace. Its reduced row-echelon basis over C11..C66 identifies the
|
|
9
|
+
independent constants in this exact orientation.
|
|
10
|
+
2. A minimal, well-conditioned set of deformations is selected greedily from simple
|
|
11
|
+
candidates, maximizing the smallest singular value (sigma_min).
|
|
12
|
+
3. The resulting stiffness tensor can be reported both in the user's frame and
|
|
13
|
+
transformed to the textbook standard crystallographic setting.
|
|
14
|
+
"""
|
|
15
|
+
from itertools import combinations
|
|
16
|
+
import numpy as np
|
|
17
|
+
|
|
18
|
+
from elastic_ase._spglib import call as spg_call
|
|
19
|
+
from elastic_ase.systems import CrystalSystem, Deformation
|
|
20
|
+
|
|
21
|
+
SYMPREC = 1e-3
|
|
22
|
+
_TOL = 1e-8
|
|
23
|
+
NOISE_TOL = 1e-6
|
|
24
|
+
|
|
25
|
+
# Voigt index -> Cartesian index pair
|
|
26
|
+
_VOIGT = [(0, 0), (1, 1), (2, 2), (1, 2), (0, 2), (0, 1)]
|
|
27
|
+
_UPPER = [(i, j) for i in range(6) for j in range(i, 6)]
|
|
28
|
+
_NAMES = [f"C{i + 1}{j + 1}" for i, j in _UPPER]
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def bond_matrix(rotation):
|
|
32
|
+
"""6x6 Bond matrix M with C' = M C M^T for a Cartesian rotation."""
|
|
33
|
+
r = np.asarray(rotation, float)
|
|
34
|
+
m = np.zeros((6, 6))
|
|
35
|
+
for a, (i, j) in enumerate(_VOIGT):
|
|
36
|
+
for b, (k, l) in enumerate(_VOIGT):
|
|
37
|
+
m[a, b] = r[i, k] * r[j, l] if b < 3 else r[i, k] * r[j, l] + r[i, l] * r[j, k]
|
|
38
|
+
return m
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _to_matrix(vector):
|
|
42
|
+
c = np.zeros((6, 6))
|
|
43
|
+
for value, (i, j) in zip(vector, _UPPER):
|
|
44
|
+
c[i, j] = c[j, i] = value
|
|
45
|
+
return c
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _to_vector(matrix):
|
|
49
|
+
return np.array([matrix[i, j] for i, j in _UPPER])
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def primitive_cell(atoms, symprec=SYMPREC):
|
|
53
|
+
"""spglib cell tuple (lattice, positions, numbers) of primitive cell, same orientation."""
|
|
54
|
+
cell = (np.asarray(atoms.get_cell(), float), atoms.get_scaled_positions(), atoms.numbers)
|
|
55
|
+
primitive = spg_call("standardize_cell", cell, to_primitive=True, no_idealize=True, symprec=symprec)
|
|
56
|
+
return primitive if primitive is not None else cell
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def crystal_rotations(atoms, symprec=SYMPREC):
|
|
60
|
+
"""Cartesian rotation matrices of the crystal's point group (from spglib)."""
|
|
61
|
+
cell = primitive_cell(atoms, symprec)
|
|
62
|
+
data = spg_call("get_symmetry", cell, symprec=symprec)
|
|
63
|
+
if not data:
|
|
64
|
+
raise ValueError(f"spglib could not determine symmetry (symprec={symprec})")
|
|
65
|
+
lattice = np.asarray(cell[0])
|
|
66
|
+
to_cart, from_cart = lattice.T, np.linalg.inv(lattice.T)
|
|
67
|
+
rotations = []
|
|
68
|
+
for w in data["rotations"]:
|
|
69
|
+
r = to_cart @ w @ from_cart
|
|
70
|
+
u, _, vt = np.linalg.svd(r)
|
|
71
|
+
r = u @ vt
|
|
72
|
+
if not any(np.allclose(r, other, atol=1e-6) for other in rotations):
|
|
73
|
+
rotations.append(r)
|
|
74
|
+
return rotations
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def standard_setting(atoms, symprec=SYMPREC):
|
|
78
|
+
"""(rotation, space_group_number) taking this crystal to its standard setting."""
|
|
79
|
+
dataset = spg_call("get_symmetry_dataset", primitive_cell(atoms, symprec), symprec=symprec)
|
|
80
|
+
if dataset is None:
|
|
81
|
+
raise ValueError(f"spglib could not determine symmetry (symprec={symprec})")
|
|
82
|
+
get = (lambda key: getattr(dataset, key)) if hasattr(dataset, "number") else dataset.__getitem__
|
|
83
|
+
rotation = np.array(get("std_rotation_matrix"), float)
|
|
84
|
+
u, _, vt = np.linalg.svd(rotation)
|
|
85
|
+
return u @ vt, int(get("number"))
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def to_standard(c, rotation):
|
|
89
|
+
"""Stiffness matrix C expressed in the standard crystallographic frame."""
|
|
90
|
+
m = bond_matrix(rotation)
|
|
91
|
+
return m @ np.asarray(c, float) @ m.T
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def invariant_basis(rotations):
|
|
95
|
+
"""{name: 6x6 matrix}: reduced row-echelon basis of symmetry-allowed stiffness matrices."""
|
|
96
|
+
eye = np.eye(len(_UPPER))
|
|
97
|
+
blocks = []
|
|
98
|
+
for r in rotations:
|
|
99
|
+
m = bond_matrix(r)
|
|
100
|
+
t = np.array([_to_vector(m @ _to_matrix(e) @ m.T) for e in eye]).T # 21x21
|
|
101
|
+
blocks.append(t - eye)
|
|
102
|
+
a = np.vstack(blocks) if blocks else np.zeros((1, len(_UPPER)))
|
|
103
|
+
_, s, vt = np.linalg.svd(a)
|
|
104
|
+
s = np.concatenate([s, np.zeros(vt.shape[0] - len(s))])
|
|
105
|
+
null = vt[s < 1e-6 * max(1.0, s.max())]
|
|
106
|
+
rows = _rref(null)
|
|
107
|
+
basis = {}
|
|
108
|
+
for row in rows:
|
|
109
|
+
pivot = int(np.argmax(np.abs(row) > _TOL))
|
|
110
|
+
row = np.where(np.abs(row) < 1e-10, 0.0, row)
|
|
111
|
+
basis[_NAMES[pivot]] = _to_matrix(row)
|
|
112
|
+
return basis
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def _rref(m):
|
|
116
|
+
m = np.array(m, float)
|
|
117
|
+
rows, cols = m.shape
|
|
118
|
+
lead = 0
|
|
119
|
+
for c in range(cols):
|
|
120
|
+
if lead >= rows:
|
|
121
|
+
break
|
|
122
|
+
p = lead + int(np.argmax(np.abs(m[lead:, c])))
|
|
123
|
+
if abs(m[p, c]) < _TOL:
|
|
124
|
+
continue
|
|
125
|
+
m[[lead, p]] = m[[p, lead]]
|
|
126
|
+
m[lead] /= m[lead, c]
|
|
127
|
+
for r in range(rows):
|
|
128
|
+
if r != lead:
|
|
129
|
+
m[r] -= m[r, c] * m[lead]
|
|
130
|
+
lead += 1
|
|
131
|
+
return m[:lead]
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def _candidates():
|
|
135
|
+
"""Candidate deformations in order of preference, with volume-conserving corrections."""
|
|
136
|
+
out = []
|
|
137
|
+
for i in range(6):
|
|
138
|
+
e = [0] * 6
|
|
139
|
+
e[i] = 1
|
|
140
|
+
correction = (i - 3, 4) if i >= 3 else None
|
|
141
|
+
out.append((e, correction))
|
|
142
|
+
for i, j in combinations(range(6), 2):
|
|
143
|
+
for sign in (1, -1):
|
|
144
|
+
e = [0] * 6
|
|
145
|
+
e[i], e[j] = 1, sign
|
|
146
|
+
correction = None
|
|
147
|
+
if sign < 0 and j < 3:
|
|
148
|
+
correction = (3 - i - j, 1)
|
|
149
|
+
out.append((e, correction))
|
|
150
|
+
return out
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def _folder_name(strain):
|
|
154
|
+
parts = []
|
|
155
|
+
for index, value in enumerate(strain):
|
|
156
|
+
if value:
|
|
157
|
+
label = f"e{index + 1}"
|
|
158
|
+
parts.append(label if not parts else ("+" if value > 0 else "-") + label)
|
|
159
|
+
return "".join(parts)
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def _energy_row(strain, basis_matrices):
|
|
163
|
+
e = np.asarray(strain, float)
|
|
164
|
+
return np.array([0.5 * e @ b @ e for b in basis_matrices])
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def _orthonormal(basis):
|
|
168
|
+
vectors = np.array([np.asarray(m).ravel() for m in basis.values()]).T
|
|
169
|
+
q, _ = np.linalg.qr(vectors)
|
|
170
|
+
return [q[:, j].reshape(6, 6) for j in range(q.shape[1])]
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
def choose_deformations(basis):
|
|
174
|
+
"""Minimal set of deformations determining stiffness matrix with optimal condition number."""
|
|
175
|
+
matrices = _orthonormal(basis)
|
|
176
|
+
n = len(matrices)
|
|
177
|
+
chosen, rows = [], []
|
|
178
|
+
pool = _candidates()
|
|
179
|
+
while len(rows) < n:
|
|
180
|
+
best = None
|
|
181
|
+
for strain, correction in pool:
|
|
182
|
+
if any(strain == c[0] for c in chosen):
|
|
183
|
+
continue
|
|
184
|
+
e = np.asarray(strain, float)
|
|
185
|
+
row = _energy_row(strain, matrices) / (e @ e)
|
|
186
|
+
if np.linalg.norm(row) < _TOL:
|
|
187
|
+
continue
|
|
188
|
+
s = np.linalg.svd(np.vstack(rows + [row]), compute_uv=False)
|
|
189
|
+
rank = int(np.sum(s > 1e-8))
|
|
190
|
+
score = (rank, s[rank - 1] if rank else 0.0)
|
|
191
|
+
if best is None or score[0] > best[0][0] or (
|
|
192
|
+
score[0] == best[0][0] and score[1] > best[0][1] * (1 + 1e-9)):
|
|
193
|
+
best = (score, strain, correction, row)
|
|
194
|
+
if best is None or best[0][0] <= len(rows):
|
|
195
|
+
raise ValueError("Could not find deformations that determine all constants")
|
|
196
|
+
chosen.append((best[1], best[2]))
|
|
197
|
+
rows.append(best[3])
|
|
198
|
+
return tuple(Deformation(_folder_name(s), tuple(s), c) for s, c in chosen)
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
def _layout(basis):
|
|
202
|
+
names = list(basis)
|
|
203
|
+
|
|
204
|
+
def layout(ns):
|
|
205
|
+
return sum(getattr(ns, name) * basis[name] for name in names).tolist()
|
|
206
|
+
return layout
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
def from_structure(atoms, symprec=SYMPREC):
|
|
210
|
+
"""Generates an orientation-adapted CrystalSystem for this crystal in its current Cartesian frame."""
|
|
211
|
+
sg = spg_call("get_spacegroup", (np.asarray(atoms.get_cell(), float), atoms.get_scaled_positions(), atoms.numbers), symprec=symprec) or "unknown"
|
|
212
|
+
basis = invariant_basis(crystal_rotations(atoms, symprec))
|
|
213
|
+
spec = CrystalSystem(
|
|
214
|
+
f"auto: {sg}",
|
|
215
|
+
tuple(basis),
|
|
216
|
+
_layout(basis),
|
|
217
|
+
choose_deformations(basis)
|
|
218
|
+
)
|
|
219
|
+
return spec, basis
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
def standard_constants(c_standard, spacegroup_number):
|
|
223
|
+
"""Named workflow and textbook constants for a stiffness matrix in the standard setting."""
|
|
224
|
+
from elastic_ase.symmetry import classify
|
|
225
|
+
from elastic_ase.systems import SYSTEMS
|
|
226
|
+
|
|
227
|
+
name = classify(spacegroup_number)[2]
|
|
228
|
+
table = SYSTEMS[name]
|
|
229
|
+
n = len(table.constants)
|
|
230
|
+
design = np.array([table.matrix(np.eye(n)[j]).ravel() for j in range(n)]).T
|
|
231
|
+
values, *_ = np.linalg.lstsq(design, np.asarray(c_standard).ravel(), rcond=None)
|
|
232
|
+
residual = float(np.abs(design @ values - np.asarray(c_standard).ravel()).max())
|
|
233
|
+
return name, dict(zip(table.constants, values)), residual
|
elastic_ase/average.py
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
|
|
3
|
+
def calculate_polycrystalline_averages(C):
|
|
4
|
+
"""
|
|
5
|
+
Compute Voigt, Reuss, and Hill polycrystalline elastic averages from 6x6 stiffness matrix C (in GPa).
|
|
6
|
+
"""
|
|
7
|
+
C11 = C[0, 0]
|
|
8
|
+
C22 = C[1, 1]
|
|
9
|
+
C33 = C[2, 2]
|
|
10
|
+
C44 = C[3, 3]
|
|
11
|
+
C55 = C[4, 4]
|
|
12
|
+
C66 = C[5, 5]
|
|
13
|
+
C12 = C[0, 1]
|
|
14
|
+
C13 = C[0, 2]
|
|
15
|
+
C23 = C[1, 2]
|
|
16
|
+
|
|
17
|
+
# Voigt averages
|
|
18
|
+
K_voigt = ((C11 + C22 + C33) + 2.0 * (C12 + C13 + C23)) / 9.0
|
|
19
|
+
G_voigt = ((C11 + C22 + C33) - (C12 + C13 + C23) + 3.0 * (C44 + C55 + C66)) / 15.0
|
|
20
|
+
|
|
21
|
+
try:
|
|
22
|
+
S = np.linalg.inv(C)
|
|
23
|
+
S11, S22, S33 = S[0, 0], S[1, 1], S[2, 2]
|
|
24
|
+
S44, S55, S66 = S[3, 3], S[4, 4], S[5, 5]
|
|
25
|
+
S12, S13, S23 = S[0, 1], S[0, 2], S[1, 2]
|
|
26
|
+
|
|
27
|
+
k_denom = (S11 + S22 + S33) + 2.0 * (S12 + S13 + S23)
|
|
28
|
+
g_denom = 4.0 * (S11 + S22 + S33) - 4.0 * (S12 + S13 + S23) + 3.0 * (S44 + S55 + S66)
|
|
29
|
+
|
|
30
|
+
if abs(k_denom) < 1e-15 or abs(g_denom) < 1e-15:
|
|
31
|
+
K_reuss = K_voigt
|
|
32
|
+
G_reuss = G_voigt
|
|
33
|
+
else:
|
|
34
|
+
K_reuss = 1.0 / k_denom
|
|
35
|
+
G_reuss = 15.0 / g_denom
|
|
36
|
+
except np.linalg.LinAlgError:
|
|
37
|
+
K_reuss = K_voigt
|
|
38
|
+
G_reuss = G_voigt
|
|
39
|
+
|
|
40
|
+
K_VRH = 0.5 * (K_voigt + K_reuss)
|
|
41
|
+
G_VRH = 0.5 * (G_voigt + G_reuss)
|
|
42
|
+
|
|
43
|
+
denom_E = G_VRH + 3.0 * K_VRH
|
|
44
|
+
E_VRH = (9.0 * K_VRH * G_VRH) / denom_E if abs(denom_E) > 1e-12 else 0.0
|
|
45
|
+
|
|
46
|
+
denom_nu = 6.0 * K_VRH + 2.0 * G_VRH
|
|
47
|
+
nu_VRH = (3.0 * K_VRH - 2.0 * G_VRH) / denom_nu if abs(denom_nu) > 1e-12 else 0.0
|
|
48
|
+
|
|
49
|
+
pugh = K_VRH / G_VRH if abs(G_VRH) > 1e-12 else 0.0
|
|
50
|
+
|
|
51
|
+
# Cauchy pressure and Zener anisotropy (for cubic/orthorhombic systems)
|
|
52
|
+
cauchy = C12 - C44
|
|
53
|
+
denom_A = C11 - C12
|
|
54
|
+
anisotropy = (2.0 * C44) / denom_A if abs(denom_A) > 1e-12 else 1.0
|
|
55
|
+
|
|
56
|
+
# Universal elastic anisotropy index A^U (Ranganathan & Ostoja-Starzewski, PRL 2008)
|
|
57
|
+
# A^U = 5 * (G_voigt / G_reuss) + (K_voigt / K_reuss) - 6 >= 0 (0 for isotropic)
|
|
58
|
+
if G_reuss > 1e-6 and K_reuss > 1e-6:
|
|
59
|
+
universal_anisotropy = max(0.0, float(5.0 * (G_voigt / G_reuss) + (K_voigt / K_reuss) - 6.0))
|
|
60
|
+
else:
|
|
61
|
+
universal_anisotropy = 0.0
|
|
62
|
+
|
|
63
|
+
# Chung-Buessem fractional anisotropy
|
|
64
|
+
cb_G = (G_voigt - G_reuss) / (G_voigt + G_reuss) if (G_voigt + G_reuss) > 1e-6 else 0.0
|
|
65
|
+
cb_K = (K_voigt - K_reuss) / (K_voigt + K_reuss) if (K_voigt + K_reuss) > 1e-6 else 0.0
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
"K_voigt": float(K_voigt),
|
|
69
|
+
"K_reuss": float(K_reuss),
|
|
70
|
+
"K_VRH": float(K_VRH),
|
|
71
|
+
"G_voigt": float(G_voigt),
|
|
72
|
+
"G_reuss": float(G_reuss),
|
|
73
|
+
"G_VRH": float(G_VRH),
|
|
74
|
+
"E_VRH": float(E_VRH),
|
|
75
|
+
"nu_VRH": float(nu_VRH),
|
|
76
|
+
"Pugh_ratio": float(pugh),
|
|
77
|
+
"Cauchy_pressure": float(cauchy),
|
|
78
|
+
"Zener_anisotropy": float(anisotropy),
|
|
79
|
+
"universal_anisotropy": float(universal_anisotropy),
|
|
80
|
+
"chung_buessem_G": float(cb_G),
|
|
81
|
+
"chung_buessem_K": float(cb_K)
|
|
82
|
+
}
|