Skip to content

Commit b553546

Browse files
Merge pull request #21 from shry-project/devel-clean
Clean up the code
2 parents 5f42bcb + 33035ac commit b553546

10 files changed

Lines changed: 543 additions & 459 deletions

File tree

examples/PbSnTe.cif

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,6 @@ _atom_site_fract_x
227227
_atom_site_fract_y
228228
_atom_site_fract_z
229229
_atom_site_occupancy
230-
Pb1 Pb2+ 4 a 0.0 0.0 0.0 0.75000
231-
Sn1 Sn2+ 4 a 0.0 0.0 0.0 0.25000
232-
Te1 Te2- 4 b 0.5 0.5 0.5 1.00000
230+
Pb1 Pb 4 a 0.0 0.0 0.0 0.75000
231+
Sn1 Sn 4 a 0.0 0.0 0.0 0.25000
232+
Te1 Te 4 b 0.5 0.5 0.5 1.00000

examples/README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,47 @@
33
What each script does, summarized per example. All required CIF inputs are bundled in this directory.
44

55
## Example 1: Basic enumeration and CIF output
6-
- File: [examples/example1.py](examples/example1.py)
6+
- File: [example1.py](example1.py)
77
- What it does: Load `SmFe7Ti.cif`, use `Substitutor` to generate all symmetry-inequivalent structures, and write CIFs with their multiplicity (weight).
88
- Key point: Uses `Substitutor.quantities(("cifwriter", "weight"))` and saves to `output/` as `cif_i{index}w{weight}.cif`.
99

1010
## Example 2: Comparison with enumlib
11-
- File: [examples/example2.py](examples/example2.py)
11+
- File: [example2.py](example2.py)
1212
- What it does: Expand `PbSnTe.cif` to a 2×2×2 supercell and compare enumeration results between Pymatgen's `EnumlibAdaptor` and SHRY.
1313
- Comparison modes:
1414
- SHRY default (group equivalent sites).
1515
- SHRY with `groupby=lambda x: x.species` (group by species, similar to enumlib behavior).
1616
- Output: Prints the number of structures from each approach to stdout.
1717

1818
## Example 3: LabeledStructure and label-based substitutions
19-
- File: [examples/example3.py](examples/example3.py)
19+
- File: [example3.py](example3.py)
2020
- What it does: Load `SmFe12.cif` as a `LabeledStructure`, replace labels `Fe1``Fe3Ti`, `Fe2``Fe7Ti`, `Fe3``Ti`, then expand to a non-diagonal supercell `((2,0,1),(0,1,0),(1,0,1))`. Generates all structures, writes CIFs and weights to `output/`, and prints configuration letters (e.g., `aba...`).
2121
- Key point: Keeps `_atom_site_label`, so substitutions remain label-consistent even after supercell expansion.
2222

2323
## Example 4a: Caching pattern generation and saving it
24-
- File: [examples/example4a.py](examples/example4a.py)
24+
- File: [example4a.py](example4a.py)
2525
- What it does: Load `SmFe12.cif` as a `LabeledStructure`, replace `Fe1``Fe7Ti`, run `Substitutor(cache=True)`, write CIFs, and pickle the internal `pattern_makers` to `pg.pkl`.
2626
- Benefit: Reuse the cached pattern makers to skip expensive recomputation for symmetry-equivalent systems later.
2727

2828
## Example 4b: Reusing cache and applying to different compositions
29-
- File: [examples/example4b.py](examples/example4b.py)
29+
- File: [example4b.py](example4b.py)
3030
- What it does: Load `pg.pkl` from Example 4a. Starting from `SmFe12.cif`, evaluate two substitution cases (`Fe``Fe3Ti` and `Fe``FeTi3`) in sequence. Attach the loaded `pattern_makers` to a `Substitutor`, generate CIFs for `run1` and `run2`, then overwrite `pg.pkl` with the updated cache.
3131
- Key point: When symmetry is the same, you can rapidly iterate different substitution patterns using the cached pattern makers.
3232

3333
## Example 5: Generating ASE Atoms
34-
- File: [examples/example5.py](examples/example5.py)
34+
- File: [example5.py](example5.py)
3535
- What it does: Expand `PbSnTe.cif` to 2×2×2, enumerate all structures with `Substitutor`, and obtain them as ASE `Atoms` objects.
3636
- Output: Prints the number of structures to stdout and shows one sample `Atoms` instance; useful as a bridge to downstream ASE workflows.
3737

3838
## Example 6: Ranking by Ewald energy
39-
- File: [examples/example6.py](examples/example6.py)
39+
- File: [example6.py](example6.py)
4040
- What it does: Enumerates substitutions, guesses oxidation states, computes Ewald energies, and writes the 100 lowest-energy structures to output_ewald/.
4141
- Note: If oxidation states cannot be guessed, Ewald energies may be zero or skipped.
4242

4343
## Example 7: Highest symmetry structures (lowest weight)
44-
- File: [examples/example7.py](examples/example7.py)
44+
- File: [example7.py](example7.py)
4545
- What it does: Enumerates substitutions and writes the top-N structures with the smallest weight (highest symmetry) to output_symm_top/. Optionally writes all structures sorted by weight.
4646

4747
## Example 8: Merge multiple Wyckoff labels for shared concentration
48-
- File: [examples/example8.py](examples/example8.py)
48+
- File: [example8.py](example8.py)
4949
- What it does: Loads `SmFe12.cif`, relabels multiple Wyckoff labels (e.g., `Fe1` and `Fe2`) into a shared label (`Target`), then applies a single disordered composition (e.g., `Fe0.5Ti0.5`) across that pooled site set. This enables specifying a global substitution concentration across multiple Wyckoff positions.

examples/SmFe12.cif

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
data_SmFe12
1010

11-
loop_
1211
_chemical_formula_sum 'Fe12 Sm'
1312
_space_group_IT_number 139
1413
_symmetry_space_group_name_Hall '-I 4 2'

examples/SmFe7Ti.cif

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ data_SmFe12
77
# http://www.crystallography.net/
88
#
99

10-
11-
loop_
12-
_chemical_formula_sum 'Fe12 Sm'
10+
_chemical_formula_sum 'Fe10.5 Sm Ti1.5'
1311
_space_group_IT_number 139
1412
_symmetry_space_group_name_Hall '-I 4 2'
1513
_symmetry_space_group_name_H-M 'I 4/m m m'
@@ -21,8 +19,8 @@ _cell_length_a 8.59
2119
_cell_length_b 8.59
2220
_cell_length_c 4.804
2321
_cell_volume 354.478
24-
_cod_data_source_block 'Fe12 Sm1'
25-
_cod_original_formula_sum 'Fe12 Sm1'
22+
_cod_data_source_block 'Fe10.5 Sm1 Ti1.5'
23+
_cod_original_formula_sum 'Fe10.5 Sm1 Ti1.5'
2624
loop_
2725
_symmetry_equiv_pos_as_xyz
2826
x,y,z

examples/example6.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
helper = ScriptHelper(
2020
structure_file="PbSnTe.cif", # Replace with your CIF if desired
2121
from_species=("Sn",),
22-
to_species=("Sn0.5Sb0.5",),
22+
to_species=("Sn0.5Se0.5",),
2323
scaling_matrix=(2, 2, 1), # enlarge to break more symmetry and get multiple patterns
2424
)
2525

@@ -29,7 +29,16 @@
2929

3030
for i, structure in enumerate(helper.substitutor.structure_writers()):
3131
try:
32-
structure.add_oxidation_state_by_guess()
32+
# Ensure oxidation states are set explicitly for this system.
33+
structure.remove_oxidation_states()
34+
structure.add_oxidation_state_by_element(
35+
{
36+
"Pb": +2,
37+
"Sn": +2,
38+
"Se": +4,
39+
"Te": -2,
40+
}
41+
)
3342
energy = EwaldSummation(structure).total_energy
3443
except Exception as exc: # noqa: BLE001 - narrow for clarity in real workflows
3544
print(f"Skipping structure {i}: {exc}")

0 commit comments

Comments
 (0)