|
| 1 | +import cellconstructor as CC, cellconstructor.Phonons |
| 2 | +import sscha, sscha.Ensemble |
| 3 | +import sscha.SchaMinimizer, sscha.Relax |
| 4 | +import sscha.Utilities |
| 5 | + |
| 6 | +import ase, ase.calculators, ase.calculators.emt |
| 7 | +import numpy as np |
| 8 | +import os, sys |
| 9 | + |
| 10 | +import pytest |
| 11 | + |
| 12 | + |
| 13 | +def test_gold(use_julia=True, verbose=False): |
| 14 | + supercell=(2,2,2) |
| 15 | + |
| 16 | + # Change directory to the current script |
| 17 | + total_path = os.path.dirname(os.path.abspath(__file__)) |
| 18 | + os.chdir(total_path) |
| 19 | + |
| 20 | + cif_file="../test_release/Au_mp-81_primitive.cif" |
| 21 | + temperature = 300 |
| 22 | + |
| 23 | + # Load the structure |
| 24 | + struct = CC.Structure.Structure() |
| 25 | + struct.read_generic_file(cif_file) |
| 26 | + gold_dyn = CC.Phonons.compute_phonons_finite_displacements(struct, |
| 27 | + ase.calculators.emt.EMT(), supercell=supercell) |
| 28 | + |
| 29 | + # Setup a sscha |
| 30 | + gold_dyn.Symmetrize() |
| 31 | + gold_dyn.ForcePositiveDefinite() |
| 32 | + |
| 33 | + ensemble = sscha.Ensemble.Ensemble(gold_dyn, temperature) |
| 34 | + minim = sscha.SchaMinimizer.SSCHA_Minimizer(ensemble) |
| 35 | + minim.set_minimization_step(0.001) |
| 36 | + minim.meaningful_factor = 1e-5 |
| 37 | + minim.use_julia = use_julia |
| 38 | + |
| 39 | + relax = sscha.Relax.SSCHA(minim, |
| 40 | + ase_calculator=ase.calculators.emt.EMT(), |
| 41 | + N_configs = 50, |
| 42 | + max_pop = 3) |
| 43 | + relax.save_ensemble=False |
| 44 | + |
| 45 | + cfp=None |
| 46 | + if verbose: |
| 47 | + ioinfo = sscha.Utilities.IOInfo() |
| 48 | + ioinfo.SetupSaving("minim") |
| 49 | + cfp = ioinfo.CFP_SaveAll |
| 50 | + |
| 51 | + relax.setup_custom_functions( |
| 52 | + custom_function_post=cfp) |
| 53 | + |
| 54 | + relax.vc_relax(target_press=0) |
| 55 | + |
| 56 | + if verbose: |
| 57 | + relax.minim.dyn.save_qe("final_dyn") |
| 58 | + |
| 59 | +if __name__ == "__main__": |
| 60 | + use_julia=True |
| 61 | + if len(sys.argv) > 1: |
| 62 | + if sys.argv[1].lower() != "julia": |
| 63 | + use_julia=False |
| 64 | + |
| 65 | + test_gold(verbose=True, use_julia=use_julia) |
0 commit comments