|
3 | 3 | from sphinx_parser.potential import get_paw_from_structure |
4 | 4 |
|
5 | 5 |
|
6 | | -def calc_static( |
7 | | - structure, |
8 | | - eCut=25, |
9 | | - xc=1, |
10 | | - spinPolarized=False, |
11 | | - maxSteps=30, |
12 | | - ekt=0.2, |
13 | | - k_point_coords=[0.5, 0.5, 0.5], |
| 6 | +def set_base_parameters( |
| 7 | + structure: "ase.Atoms", |
| 8 | + eCut: float = 25, |
| 9 | + xc: int = 1, |
| 10 | + maxSteps: int = 30, |
| 11 | + ekt: float = 0.2, |
| 12 | + k_point_coords: list = [0.5, 0.5, 0.5], |
14 | 13 | ): |
| 14 | + """ |
| 15 | + Set the base parameters for the sphinx input file |
| 16 | +
|
| 17 | + Args: |
| 18 | + structure (ase.Atoms): ASE Atoms object |
| 19 | + eCut (float, optional): Energy cutoff. Defaults to 25. |
| 20 | + xc (int, optional): Exchange-correlation functional. Defaults to 1. |
| 21 | + maxSteps (int, optional): Maximum number of steps. Defaults to 30. |
| 22 | + ekt (float, optional): Temperature. Defaults to 0.2. |
| 23 | + k_point_coords (list, optional): K-point coordinates. Defaults to [0.5, 0.5, 0.5]. |
| 24 | +
|
| 25 | + Returns: |
| 26 | + dict: Sphinx input dictionary |
| 27 | + """ |
15 | 28 | struct_group, spin_lst = get_structure_group(structure) |
| 29 | + spinPolarized = spin_lst is not None |
16 | 30 | main_group = sphinx.main.create( |
17 | 31 | scfDiag=sphinx.main.scfDiag.create( |
18 | 32 | maxSteps=maxSteps, blockCCG=sphinx.main.scfDiag.blockCCG.create() |
@@ -40,3 +54,64 @@ def calc_static( |
40 | 54 | initialGuess=initial_guess_group, |
41 | 55 | ) |
42 | 56 | return input_sx |
| 57 | + |
| 58 | + |
| 59 | +def apply_minimization(sphinx_input, mode="linQN", dEnergy=1.0e-6, maxSteps=50): |
| 60 | + """ |
| 61 | + Apply minimization to the sphinx input file |
| 62 | +
|
| 63 | + Args: |
| 64 | + sphinx_input (dict): Sphinx input dictionary |
| 65 | + mode (str, optional): Minimization mode. Defaults to "linQN". |
| 66 | + dEnergy (float, optional): Energy tolerance. Defaults to 1.0e-6. |
| 67 | + maxSteps (int, optional): Maximum number of steps. Defaults to 50. |
| 68 | +
|
| 69 | + Returns: |
| 70 | + dict: Sphinx input dictionary |
| 71 | + """ |
| 72 | + input_sx = sphinx_input.copy() |
| 73 | + if "main" not in input_sx or "scfDiag" not in input_sx["main"]: |
| 74 | + raise ValueError("main group not found - run set_base_parameters first") |
| 75 | + if mode == "linQN": |
| 76 | + input_sx["main"] = sphinx.main.create( |
| 77 | + linQN=sphinx.main.linQN.create( |
| 78 | + dEnergy=dEnergy, |
| 79 | + maxSteps=maxSteps, |
| 80 | + bornOppenheimer=sphinx.main.linQN.bornOppenheimer.create( |
| 81 | + scfDiag=input_sx["main"]["scfDiag"] |
| 82 | + ), |
| 83 | + ) |
| 84 | + ) |
| 85 | + elif mode == "QN": |
| 86 | + input_sx["main"] = sphinx.main.create( |
| 87 | + QN=sphinx.main.QN.create( |
| 88 | + dEnergy=dEnergy, |
| 89 | + maxSteps=maxSteps, |
| 90 | + bornOppenheimer=sphinx.main.QN.bornOppenheimer.create( |
| 91 | + scfDiag=input_sx["main"]["scfDiag"] |
| 92 | + ), |
| 93 | + ) |
| 94 | + ) |
| 95 | + elif mode == "ricQN": |
| 96 | + input_sx["main"] = sphinx.main.create( |
| 97 | + ricQN=sphinx.main.ricQN.create( |
| 98 | + dEnergy=dEnergy, |
| 99 | + maxSteps=maxSteps, |
| 100 | + bornOppenheimer=sphinx.main.ricQN.bornOppenheimer.create( |
| 101 | + scfDiag=input_sx["main"]["scfDiag"] |
| 102 | + ), |
| 103 | + ) |
| 104 | + ) |
| 105 | + elif mode == "ricTS": |
| 106 | + input_sx["main"] = sphinx.main.create( |
| 107 | + ricTS=sphinx.main.ricTS.create( |
| 108 | + dEnergy=dEnergy, |
| 109 | + maxSteps=maxSteps, |
| 110 | + bornOppenheimer=sphinx.main.ricTS.bornOppenheimer.create( |
| 111 | + scfDiag=input_sx["main"]["scfDiag"] |
| 112 | + ), |
| 113 | + ) |
| 114 | + ) |
| 115 | + else: |
| 116 | + raise ValueError("mode not recognized") |
| 117 | + return input_sx |
0 commit comments