Skip to content

Commit

Permalink
Ion ioncell relax input refactoring (#247)
Browse files Browse the repository at this point in the history
* Added ion_ioncell reference input json files.
Added comparison of the reference input json files.

* Refactored ion_ioncell_relax_input factory function.
  • Loading branch information
davidwaroquiers authored Jun 27, 2022
1 parent 6299326 commit 2ca0177
Show file tree
Hide file tree
Showing 4 changed files with 438 additions and 23 deletions.
30 changes: 7 additions & 23 deletions abipy/abio/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,33 +315,17 @@ def ion_ioncell_relax_input(structure, pseudos,
charge: Electronic charge added to the unit cell.
scf_algorithm: Algorithm used for the solution of the SCF cycle.
"""
structure = Structure.as_structure(structure)
multi = MultiDataset(structure, pseudos, ndtset=2)

# Set the cutoff energies.
multi.set_vars(_find_ecut_pawecutdg(ecut, pawecutdg, multi.pseudos, accuracy))

kppa = _DEFAULTS.get("kppa") if kppa is None else kppa

shift_mode = ShiftMode.from_object(shift_mode)
shifts = _get_shifts(shift_mode, structure)
ksampling = aobj.KSampling.automatic_density(structure, kppa, chksymbreak=0, shifts=shifts)
electrons = aobj.Electrons(spin_mode=spin_mode, smearing=smearing, algorithm=scf_algorithm,
charge=charge, nband=nband, fband=None)

if spin_mode == "polarized":
spinat_dict = multi[0].set_autospinat()
multi[1].set_vars(spinat_dict)

if electrons.nband is None:
electrons.nband = _find_scf_nband(structure, multi.pseudos, electrons, multi[0].get('spinat', None))
# Scf options
inp = scf_input(structure=structure, pseudos=pseudos, kppa=kppa,
ecut=ecut, pawecutdg=pawecutdg, nband=nband,
accuracy=accuracy, spin_mode=spin_mode, smearing=smearing,
charge=charge, scf_algorithm=scf_algorithm, shift_mode=shift_mode)
# Relaxation-specific options
multi = MultiDataset.replicate_input(inp, ndtset=2)

ion_relax = aobj.RelaxationMethod.atoms_only(atoms_constraints=None)
ioncell_relax = aobj.RelaxationMethod.atoms_and_cell(atoms_constraints=None)

multi.set_vars(electrons.to_abivars())
multi.set_vars(ksampling.to_abivars())

multi[0].set_vars(ion_relax.to_abivars())
multi[0].set_vars(_stopping_criterion("relax", accuracy))

Expand Down
9 changes: 9 additions & 0 deletions abipy/abio/tests/test_factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ def test_ion_ioncell_relax_input(self):
self.assertIn('ion_relax', ion_inp.runlevel)
self.assertIn('relax', ion_inp.runlevel)
self.assertIn('ground_state', ion_inp.runlevel)

if write_inputs_to_json:
with open('ion_ioncell_relax_ion_input.json', mode='w') as fp:
json.dump(ion_inp.as_dict(), fp, indent=2)
with open('ion_ioncell_relax_ioncell_input.json', mode='w') as fp:
json.dump(ioncell_inp.as_dict(), fp, indent=2)

self.assert_input_equality('ion_ioncell_relax_ion_input.json', ion_inp)
self.assert_input_equality('ion_ioncell_relax_ioncell_input.json', ioncell_inp)
flow = Flow.temporary_flow()
flow.register_work(RelaxWork(ion_inp, ioncell_inp))
assert flow.build_and_pickle_dump(abivalidate=True) == 0
Expand Down
203 changes: 203 additions & 0 deletions abipy/test_files/ion_ioncell_relax_ion_input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
{
"structure": {
"@module": "abipy.core.structure",
"@class": "Structure",
"charge": 0.0,
"lattice": {
"matrix": [
[
3.3488982567096763,
0.0,
1.9334873100000005
],
[
1.1162994189032256,
3.1573715557642927,
1.9334873100000005
],
[
0.0,
0.0,
3.86697462
]
],
"a": 3.86697462,
"b": 3.86697462,
"c": 3.86697462,
"alpha": 59.99999999999999,
"beta": 59.99999999999999,
"gamma": 59.99999999999999,
"volume": 40.88829179346891
},
"sites": [
{
"species": [
{
"element": "Si",
"occu": 1.0
}
],
"abc": [
0.0,
0.0,
0.0
],
"xyz": [
0.0,
0.0,
0.0
],
"label": "Si",
"properties": {}
},
{
"species": [
{
"element": "Si",
"occu": 1.0
}
],
"abc": [
0.25,
0.25,
0.25
],
"xyz": [
1.1162994189032256,
0.7893428889410732,
1.9334873100000003
],
"label": "Si",
"properties": {}
}
]
},
"pseudos": [
{
"basename": "14si.pspnc",
"type": "NcAbinitPseudo",
"symbol": "Si",
"Z": 14,
"Z_val": 4.0,
"l_max": 2,
"md5": "3916b143991b1cfa1542b130be320e5e",
"filepath": "/home/davidwaroquiers/PycharmProjects/abipy_dw/abipy/data/pseudos/14si.pspnc",
"@module": "pymatgen.io.abinit.pseudos",
"@class": "NcAbinitPseudo"
}
],
"comment": null,
"decorators": [],
"abi_args": [
[
"ecut",
2
],
[
"pawecutdg",
null
],
[
"spinat",
[
[
0.0,
0.0,
0.6
],
[
0.0,
0.0,
0.6
]
]
],
[
"nsppol",
2
],
[
"nspinor",
1
],
[
"nspden",
2
],
[
"nband",
16
],
[
"fband",
null
],
[
"charge",
0.0
],
[
"occopt",
3
],
[
"tsmear",
0.0036749322175655
],
[
"ngkpt",
[
2,
2,
2
]
],
[
"shiftk",
[
[
0.5,
0.5,
0.5
]
]
],
[
"nshiftk",
1
],
[
"kptopt",
1
],
[
"chksymbreak",
0
],
[
"ionmov",
3
],
[
"optcell",
0
],
[
"ntime",
80
],
[
"tolmxf",
null
],
[
"tolrff",
0.02
]
],
"tags": [],
"enforce_znucl": null,
"enforce_typat": null,
"@module": "abipy.abio.inputs",
"@class": "AbinitInput"
}
Loading

0 comments on commit 2ca0177

Please sign in to comment.