Structure analysis
The amorphgen.analysis module provides ensemble structural analysis for
amorphous structure files: pair distribution functions, coordination
numbers, bond angles, ring statistics, Voronoi metrics, energy ranking,
and validation against literature reference ranges.
The CLI entry point is amorphgen --analyse <FILE_OR_DIR>; the Python
API is the StructureAnalyser class.
StructureAnalyser
- class amorphgen.analysis.StructureAnalyser(source, cutoff='auto')[source]
Bases:
objectAnalyse amorphous structures: density, coordination, distances, angles, RDF, S(q), rings, Voronoi, energy ranking.
- Parameters:
- __init__(source, cutoff='auto')[source]
- Parameters:
source (str, list of str, or list of Atoms) – Path to a structure file, a directory of structure files, a list of file paths, or a list of ASE Atoms objects.
cutoff (float, dict, or str) – Neighbour cutoff for CN, bond distances, and angles. - float: single cutoff (A) for all pairs - dict: pair-specific, e.g. {“Si-O”: 2.2, “O-O”: 2.8} - “auto”: from bonding radii (fast, default) - “auto-rdf”: from RDF first minimum (more accurate)
- density()[source]
Compute density (g/cm3) for each structure.
- Returns:
{“values”: list[float], “mean”: float, “std”: float}
- Return type:
- rdf(pair=None, rmax=None, nbins=200, sigma=0.0)[source]
Compute the radial distribution function g(r).
- Parameters:
pair (str, optional) – Pair to analyse, e.g. “Si-O”. If None, total RDF.
rmax (float, optional) – Maximum radius in A. Auto-detected from cell if None.
nbins (int) – Number of histogram bins (default 200).
sigma (float) – Gaussian smearing width in A (default 0.0 = no smearing). Use 0.02-0.05 for comparison with experiment.
- Returns:
{“r”: list[float], “g_r”: list[float]}
- Return type:
- structure_factor(pair=None, qmax=15.0, nq=300, rmax=None)[source]
Compute the structure factor S(q) from g(r) via Fourier transform.
- Parameters:
- Returns:
{“q”: list[float], “s_q”: list[float]}
- Return type:
- averaged_rdf(pair=None, rmax=None, nbins=200)[source]
Compute RDF per structure with mean and standard deviation.
- Parameters:
- Returns:
{“r”: list, “g_r_mean”: list, “g_r_std”: list, “n_structures”: int}
- Return type:
- ring_statistics(bond_pair=None, cutoff=None, max_ring=12)[source]
Compute ring size statistics for network-forming structures.
- Parameters:
- Returns:
- {“ring_sizes”: list, “counts”: list, “fractions”: list,
”bond_pair”: tuple, “total_rings”: int}
- Return type:
- energy_ranking()[source]
Rank structures by potential energy per atom.
Reads energy from atoms.info or attached calculator.
- Returns:
- {“energies_per_atom”: dict, “ranking”: list, “best”: int,
”worst”: int, “best_energy”: float, “worst_energy”: float, “spread”: float}. Returns “warning” key if no energy data.
- Return type:
- per_structure_summary()[source]
Analyse each structure individually and produce a comparison table.
- Return type:
str — formatted table (also printed).
- plot(**kwargs)[source]
Generate and save analysis plots (RDF, CN distribution, bond angles).
- Parameters:
output_dir (str) – Directory for output files (default “.”).
prefix (str) – Filename prefix (default “analysis”).
rdf_pairs (list of str, optional) – Pairs to plot, e.g. [“Si-O”, “O-O”]. If None, all pairs.
rmax (float, optional) – Maximum radius for RDF. Auto-detected if None.
save_csv (bool) – Also save raw data as CSV files (default True).
Reference-validation helpers
For comparing computed metrics against literature ranges (used by
amorphgen --analyse --reference REF.yaml):
Validate computed structural metrics against literature reference ranges.
A reference YAML lists expected ranges for density, bond distances, mean coordination numbers, and bond angle means. Each metric is compared to the analyser’s computed value and labelled “match” / “concern” / “fail” so the user can defend an ensemble against published data.
- amorphgen.analysis.validate.validate_against_reference(analyser, reference)[source]
Compare analyser output to a reference dict (loaded from YAML).
- Parameters:
analyser (StructureAnalyser)
reference (dict) – Parsed YAML with optional keys:
density,bond_distances,coordination,bond_angles(see examples/reference_*.yaml).
- Returns:
{"system": str, "sources": list[str], "rows": list[tuple]}where each row is (descriptor, computed, expected_lo, expected_hi, units, verdict).- Return type:
Energy ranking helpers
For parsing random_gen.log and ranking generated structures by total
energy (used by amorphgen --rank-from-log LOG):
Energy ranking for multiple structures.
- amorphgen.analysis.energy.compute_energy_ranking(atoms_list)[source]
Rank structures by potential energy.
Reads energy from atoms.info or calculator.
- amorphgen.analysis.energy.rank_from_log(logfile)[source]
Parse a random-gen log file and rank structures by total energy.
The relax loop in batch_random() prints final energy on the last optimizer step row. This function reads those rows directly, so energy ranking works for VASP/CIF outputs that don’t store energy.
Submodule reference
StructureAnalyser delegates to focused submodules; advanced users can
import these directly:
Submodule |
Provides |
|---|---|
|
Pair distribution function g(r), partial RDFs |
|
Coordination numbers, bond distances, bond angles |
|
Ring statistics (King’s shortest-path) |
|
Voronoi cell volumes and connectivity |
|
Total-energy parsing and ranking |
|
Bond-cutoff selection from g(r) first minimum |
|
Publication-quality matplotlib helpers |
|
Reference-YAML validation |