API Reference¶
Transforms¶
mixture
¶
Structure generation for amorphous solid and liquid mixtures.
Provides :func:mix_number and :func:mix_cell for building
multicomponent mixtures using Packmol packing with crystal structure
prototypes retrieved from the Materials Project.
mix_number(recipe: dict[str, int], density: float | None = None, tolerance: float = 2.0, rattle: float = 0.5, scale: float = 1.0, shuffle: bool = False, seed: int = 1, timeout: int = 30, log: bool = False, mp_api_key: str | None = MP_API_KEY, retry: int = 1000, retry_scale: float = 1.5) -> Atoms
¶
Build a mixture structure by specifying formula unit counts.
Retrieves primitive crystal structures from Materials Project for each component, then uses Packmol to pack the specified number of formula units into a cubic simulation cell. The cell size is estimated from the sum of solid-state primitive cell volumes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
recipe
|
dict[str, int]
|
Mapping of chemical formula strings to the desired number
of formula units (e.g., |
required |
density
|
float | None
|
Target mass density in amu/ų. If provided, the cell is rescaled after packing. Defaults to None (use solid-state volume). |
None
|
tolerance
|
float
|
Minimum distance between packed molecules in Å. Defaults to 2.0. |
2.0
|
rattle
|
float
|
Standard deviation of Gaussian noise added to atomic positions in Å. Defaults to 0.5. |
0.5
|
scale
|
float
|
Multiplicative factor for the estimated cubic cell edge. Defaults to 1.0. |
1.0
|
shuffle
|
bool
|
If True, randomly permute atomic species numbers. Defaults to False. |
False
|
seed
|
int
|
Random seed for Packmol and numpy. Defaults to 1. |
1
|
timeout
|
int
|
Packmol timeout in seconds. Defaults to 30. |
30
|
log
|
bool
|
If True, print diagnostic information. Defaults to False. |
False
|
mp_api_key
|
str | None
|
Materials Project API key. Defaults to the
|
MP_API_KEY
|
retry
|
int
|
Number of Packmol attempts before enlarging the box. Defaults to 1000. |
1000
|
retry_scale
|
float
|
Factor by which to enlarge the box after |
1.5
|
Returns:
| Type | Description |
|---|---|
Atoms
|
Sorted ASE Atoms object with periodic boundary conditions. |
Source code in muse/transforms/mixture.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | |
mix_cell(recipe: dict[str, float], cell: Cell, tolerance: float = 2.0, rattle: float = 0.5, scale: float = 1.0, shuffle: bool = True, seed: int = 1, log: bool = False, mp_api_key: str | None = MP_API_KEY, retry_scale: float = 1.5) -> Atoms
¶
Build a mixture structure to fill a given simulation cell.
Similar to :func:mix_number, but instead of specifying absolute
formula unit counts, the recipe specifies molar fractions and the
total number of atoms is determined by the target cell volume.
The function scales the number of molecules to fill the provided cell based on the ratio of cell volume to the total solid-state volume of the components.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
recipe
|
dict[str, float]
|
Mapping of chemical formula strings to molar ratios
(e.g., |
required |
cell
|
Cell
|
Target ASE Cell object defining the simulation box shape. |
required |
tolerance
|
float
|
Minimum distance between packed molecules in Å. Defaults to 2.0. |
2.0
|
rattle
|
float
|
Standard deviation of Gaussian noise added to atomic positions in Å. Defaults to 0.5. |
0.5
|
scale
|
float
|
Multiplicative factor for cell dimensions during packing. Defaults to 1.0. |
1.0
|
shuffle
|
bool
|
If True, randomly permute atomic species numbers. Defaults to True. |
True
|
seed
|
int
|
Random seed for Packmol and numpy. Defaults to 1. |
1
|
log
|
bool
|
If True, print diagnostic information. Defaults to False. |
False
|
mp_api_key
|
str | None
|
Materials Project API key. Defaults to the
|
MP_API_KEY
|
retry_scale
|
float
|
Factor by which to enlarge the box after 1000 Packmol failures. Defaults to 1.5. |
1.5
|
Returns:
| Type | Description |
|---|---|
Atoms
|
Sorted ASE Atoms object with periodic boundary conditions |
Atoms
|
matching the target cell. |
Source code in muse/transforms/mixture.py
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 | |
Calculations¶
density
¶
Calculator for density-related properties via NPT molecular dynamics.
DensityCalc(calculator: Calculator, optimizer: Optimizer | str = 'FIRE', steps: int = 500, interval: int = 1, fmax: float = 0.1, mask: list | np.ndarray | None = None, rtol: float = 0.0001, atol: float = 0.0001, out_stem: str | Path = '.')
¶
Bases: PropCalc
Relax and run NPT simulations to compute the equilibrium density.
This calculator performs a three-stage molecular dynamics workflow:
- 0 K relaxation — Minimize forces with the chosen optimizer.
- NVT equilibration — Thermalize at the target temperature with fixed volume until energy converges.
- NPT production — Allow both temperature and pressure to equilibrate, then compute density from the final volume.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
calculator
|
Calculator
|
ASE calculator to use for energy/force evaluation. |
required |
optimizer
|
Optimizer | str
|
ASE optimizer class or name string. Defaults to |
'FIRE'
|
steps
|
int
|
Number of MD steps per convergence window. Defaults to 500. |
500
|
interval
|
int
|
Trajectory save interval in steps. Defaults to 1. |
1
|
fmax
|
float
|
Maximum force for structural relaxation (eV/Å). Defaults to 0.1. |
0.1
|
mask
|
list | ndarray | None
|
3×3 mask array controlling which cell degrees of freedom are relaxed in the NPT barostat. Defaults to None (all free). |
None
|
rtol
|
float
|
Relative tolerance for energy convergence between windows. Defaults to 1e-4. |
0.0001
|
atol
|
float
|
Absolute tolerance for stress convergence (eV/ų). Defaults to 1e-4. |
0.0001
|
out_stem
|
str | Path
|
Path stem for saving trajectory and observer files.
Defaults to |
'.'
|
Source code in muse/calcs/density.py
calc(atoms: Atoms, temperature: float, externalstress: float | np.ndarray, timestep: float = 2.0 * units.fs, ttime: float = 25.0 * units.fs, pfactor: float = (75 * units.fs) ** 2 * units.GPa, annealing: float = 1.0, momentum: float = 0.9) -> dict
¶
Relax the structure and run NPT simulations to compute the density.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
atoms
|
Atoms
|
Structure to relax and equilibrate. |
required |
temperature
|
float
|
Temperature of the simulation in Kelvin. |
required |
externalstress
|
float | ndarray
|
External pressure in eV/ų (scalar for isotropic, or Voigt 6-vector). |
required |
timestep
|
float
|
MD timestep in ASE internal units. Defaults to 2.0 fs. |
2.0 * fs
|
ttime
|
float
|
Thermostat characteristic timescale in ASE internal units. Defaults to 25.0 fs. |
25.0 * fs
|
pfactor
|
float
|
Barostat constant in ASE internal units. Defaults to (75 fs)² × 1 GPa. |
(75 * fs) ** 2 * GPa
|
annealing
|
float
|
Temperature scaling factor for NVT initialization. Values > 1 start hotter to aid equilibration. Defaults to 1.0. |
1.0
|
momentum
|
float
|
Exponential moving average factor for energy convergence tracking between NVT/NPT windows. Defaults to 0.9. |
0.9
|
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary with keys:
- |
Source code in muse/calcs/density.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 | |
utils
¶
Trajectory observation utilities for MD simulations.
Provides :class:TrajectoryObserver, a callback hook that records
energies, forces, stresses, positions, and cell parameters during
ASE relaxations and molecular dynamics runs.
TrajectoryObserver(atoms: Atoms)
¶
Trajectory observer that records simulation data at each step.
Attach this observer to an ASE optimizer or dynamics object to capture per-step energies, forces, stresses, positions, and cell matrices. Data can be serialized to a pickle file for post-processing.
This class is adapted from
matcalc <https://github.com/materialsvirtuallab/matcalc>_.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
atoms
|
Atoms
|
The ASE Atoms object to observe. |
required |
Source code in muse/calcs/utils.py
__call__() -> None
¶
Record the current state of the Atoms object.
Captures potential energy, forces, stress tensor (including ideal gas contribution when available), positions, and cell matrix.
Source code in muse/calcs/utils.py
save(filename: str | Path) -> None
¶
Save the recorded trajectory data to a pickle file.
The output dictionary contains
energy: List of potential energies (eV).forces: List of force arrays (eV/Å).stresses: List of stress tensors (eV/ų Voigt).atom_positions: List of position arrays (Å).cell: List of cell matrices (Å).atomic_number: Array of atomic numbers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str | Path
|
Path to the output pickle file. |
required |
Source code in muse/calcs/utils.py
Plotting¶
density
¶
Binary density–composition diagram with Redlich–Kister curve fitting.
BinaryDXDiagram(fig: Figure, *args: Any, facecolor=None, frameon: bool = True, sharex: Axes | None = None, sharey: Axes | None = None, label: str = '', xscale: float | None = None, yscale: float | None = None, box_aspect: float | None = None, **kwargs)
¶
Bases: Axes
Custom Matplotlib Axes for binary density–composition (D–x) diagrams.
Processes MD trajectories at various compositions to compute density and molar volume, then plots the results with an optional Redlich–Kister polynomial fit for the excess property.
Source code in muse/plots/density.py
process(trajectories: Sequence[Sequence[Atoms]], phases: Sequence[str | Formula]) -> None
¶
Process MD trajectories to extract density and volume statistics.
Computes mass density (g/cm³) and molar volume (ų/formula unit) for each trajectory, storing the results sorted by composition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trajectories
|
Sequence[Sequence[Atoms]]
|
List of MD trajectories, each a sequence of Atoms. |
required |
phases
|
Sequence[str | Formula]
|
Two-element list of phase formulas defining the binary system. |
required |
Source code in muse/plots/density.py
from_trajectories(trajectories: Sequence[Sequence[Atoms]], phases: Sequence[str | Formula], temperature: float | None = None, label: str | None = None, rk: int = 2, **kwargs) -> None
¶
Plot a binary density–composition diagram from MD trajectories.
Computes densities from the trajectories, plots them with error bars, and overlays a Redlich–Kister polynomial fit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trajectories
|
Sequence[Sequence[Atoms]]
|
List of MD trajectories at different compositions. |
required |
phases
|
Sequence[str | Formula]
|
Two-element list of phase formulas defining the binary system. |
required |
temperature
|
float | None
|
Temperature in Kelvin for the Redlich–Kister fit. Defaults to 1000 K. |
None
|
label
|
str | None
|
Label prefix for the legend entries. |
None
|
rk
|
int
|
Number of Redlich–Kister terms to use in the fit. Defaults to 2. |
2
|
**kwargs
|
Additional keyword arguments passed to |
{}
|
Source code in muse/plots/density.py
plot_volume(label: str | None = None, **kwargs)
¶
Plot molar volume on a secondary y-axis.
Must be called after from_trajectories or process so that
self.x and self.y are populated.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str | None
|
Legend label for the volume curve. |
None
|
**kwargs
|
Additional keyword arguments passed to |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Axes |
The secondary y-axis Axes. |
Source code in muse/plots/density.py
pd
¶
Binary Gibbs energy–composition (G–x) diagram with Redlich–Kister curve fitting.
BinaryGXDiagram(fig: Figure, *args: Any, facecolor=None, frameon: bool = True, sharex: Axes | None = None, sharey: Axes | None = None, label: str = '', xscale: float | None = None, yscale: float | None = None, box_aspect: float | None = None, **kwargs)
¶
Bases: Axes
Custom Matplotlib Axes for binary Gibbs energy–composition (G–x) diagrams.
Computes mixing enthalpy ΔH and ideal entropy of mixing ΔS from MD trajectories, then fits ΔH with a Redlich–Kister polynomial.
Source code in muse/plots/pd.py
from_trajectories(trajectories: Sequence[Sequence[Atoms]], phases: Sequence[str | Formula], temperature: float | None = None, label: str | None = None, rk: int = 2, **kwargs) -> None
¶
Plot a binary G–x diagram from MD trajectories.
Computes mixing enthalpy ΔH = E(x) - [E(0) + x*(E(1) - E(0))] and ideal entropy of mixing, then fits ΔH with a Redlich–Kister polynomial expansion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trajectories
|
Sequence[Sequence[Atoms]]
|
List of MD trajectories at different compositions. |
required |
phases
|
Sequence[str | Formula]
|
Two-element list of phase formulas defining the binary system. |
required |
temperature
|
float | None
|
Temperature in Kelvin for the Redlich–Kister fit. Defaults to 1000 K if not provided. |
None
|
label
|
str | None
|
Label prefix for the legend entries. |
None
|
rk
|
int
|
Number of Redlich–Kister terms. Defaults to 2. |
2
|
**kwargs
|
Additional keyword arguments passed to |
{}
|
Source code in muse/plots/pd.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | |
volume
¶
Binary mixing volume diagram with Redlich–Kister curve fitting.
MixingVolumeDiagram(fig: Figure, *args: Any, facecolor=None, frameon: bool = True, sharex: Axes | None = None, sharey: Axes | None = None, label: str = '', xscale: float | None = None, yscale: float | None = None, box_aspect: float | None = None, **kwargs)
¶
Bases: Axes
Custom Matplotlib Axes for binary excess mixing volume diagrams.
Computes the deviation of molar volume from ideal mixing (Vegard's law) and fits the excess volume with a Redlich–Kister polynomial.
Source code in muse/plots/volume.py
process(trajectories: Sequence[Sequence[Atoms]], phases: Sequence[str | Formula]) -> None
¶
Process MD trajectories to extract density, volume, and excess volume.
Computes mass density (g/cm³), molar volume (ų/formula unit), and volume deviation from ideal (Vegard's law) mixing for each trajectory, storing results sorted by composition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trajectories
|
Sequence[Sequence[Atoms]]
|
List of MD trajectories, each a sequence of Atoms. |
required |
phases
|
Sequence[str | Formula]
|
Two-element list of phase formulas defining the binary system. |
required |
Source code in muse/plots/volume.py
from_trajectories(trajectories: Sequence[Sequence[Atoms]], phases: Sequence[str | Formula], temperature: float | None = None, label: str | None = None, rk: int = 2, **kwargs) -> None
¶
Plot a binary excess volume diagram from MD trajectories.
Computes the volume deviation from ideal mixing, plots it with error bars, and overlays a Redlich–Kister polynomial fit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trajectories
|
Sequence[Sequence[Atoms]]
|
List of MD trajectories at different compositions. |
required |
phases
|
Sequence[str | Formula]
|
Two-element list of phase formulas defining the binary system. |
required |
temperature
|
float | None
|
Temperature in Kelvin for the Redlich–Kister fit. Defaults to 1000 K if not provided. |
None
|
label
|
str | None
|
Label prefix for the legend entries. |
None
|
rk
|
int
|
Number of Redlich–Kister terms. Defaults to 2. |
2
|
**kwargs
|
Additional keyword arguments passed to |
{}
|
Source code in muse/plots/volume.py
I/O¶
mptrj
¶
Convert pymatgen trajectory data to extended XYZ format.
Supports writing energies, forces, stresses, charges, magnetic moments, and dipoles from Materials Project trajectory (MPtrj) data.
pmgtraj_to_extxyz(pmgtraj: Trajectory, fname: str | Path) -> None
¶
Convert a pymatgen Trajectory to an extended XYZ file.
Writes each frame of the trajectory in the extended XYZ format, including lattice vectors, per-atom properties (species, positions, forces, charges, magnetic moments, dipoles), and frame-level properties (energies, stresses).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pmgtraj
|
Trajectory
|
A pymatgen Trajectory object, typically from MPtrj data. |
required |
fname
|
str | Path
|
Output file path for the extended XYZ file. |
required |
Source code in muse/io/mptrj.py
Jobs¶
slurm
¶
SLURM job submission utilities.
submit_job(cmd: str, time: str, partition: str, nodes: int, ntasks_per_node: int, job_name: str, account: str | None = None, **kwargs: str | None) -> subprocess.CompletedProcess
¶
Submit a SLURM batch job using sbatch --wrap.
Constructs and executes an sbatch command with the given
resource parameters, wrapping the provided command string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cmd
|
str
|
The command to run inside the SLURM job. |
required |
time
|
str
|
Wall time limit (e.g., |
required |
partition
|
str
|
SLURM partition/QOS name. |
required |
nodes
|
int
|
Number of nodes to request. |
required |
ntasks_per_node
|
int
|
Number of tasks per node. |
required |
job_name
|
str
|
Name for the SLURM job. |
required |
account
|
str | None
|
SLURM account/project for billing. Defaults to None. |
None
|
**kwargs
|
str | None
|
Additional sbatch options. Supported keys:
- |
{}
|
Returns:
| Type | Description |
|---|---|
CompletedProcess
|
The completed process result from |
Raises:
| Type | Description |
|---|---|
CalledProcessError
|
If sbatch returns a non-zero exit code. |