Bader charge analysis
For the source code, see bader.
Example: H2O
Prepare the inputs and visualize the WorkGraph
[1]:
from ase.build import molecule
from aiida import load_profile
from workgraph_collections.ase.espresso.bader import BaderWorkgraph
from aiida_pythonjob.config import config
# allow pickle
config["allow_pickle"] = True
load_profile()
atoms = molecule('H2O', vacuum=3.0)
atoms.pbc = True
metadata = {
"options": {
'prepend_text' : """eval "$(conda shell.posix hook)"
conda activate aiida
export OMP_NUM_THREADS=1
""",
}
}
pseudopotentials = {"H": "H.pbe-kjpaw_psl.1.0.0.UPF",
"O": "O.pbe-n-kjpaw_psl.1.0.0.UPF"}
pseudo_dir = "/home/xing/data/ase/espresso_pseudo/kjpaw"
# pseudo_dir = "/home/wang_x3/datas/pseudos/psl"
scf_input_data = {
"control": {"calculation": "scf",
},
"system": {"ecutwfc": 30, "ecutrho": 240,
"occupations": "smearing",
"degauss": 0.01,
"smearing": "cold"
},
}
inputs = {
"scf": {
"input_data": scf_input_data,
"kpts": [1, 1, 1],
"metadata": metadata
},
"pp_valence": {
"metadata": metadata
},
"pp_all": {
"metadata": metadata
},
"bader": {
"metadata": metadata
}
}
#------------------------- Set the inputs -------------------------
wg = BaderWorkgraph.build_graph(atoms=atoms,
pw_command="mpirun -np 1 pw.x",
pp_command="mpirun -np 1 pp.x",
bader_command="bader",
computer="localhost",
pseudopotentials=pseudopotentials,
pseudo_dir=pseudo_dir,
inputs=inputs)
wg.to_html()
[1]:
Run the WorkGraph
[2]:
#------------------------- Submit the calculation -------------------
wg.run()
09/04/2025 07:17:28 AM <564861> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [179998|WorkGraphEngine|continue_workgraph]: tasks ready to run: pw_calculator
REPORT:aiida.orm.nodes.process.workflow.workchain.WorkChainNode:[179998|WorkGraphEngine|continue_workgraph]: tasks ready to run: pw_calculator
09/04/2025 07:17:29 AM <564861> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [179998|WorkGraphEngine|on_wait]: Process status: Waiting for child processes: 180002
REPORT:aiida.orm.nodes.process.workflow.workchain.WorkChainNode:[179998|WorkGraphEngine|on_wait]: Process status: Waiting for child processes: 180002
09/04/2025 07:17:46 AM <564861> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [179998|WorkGraphEngine|update_task_state]: Task: pw_calculator, type: PYTHONJOB, finished.
REPORT:aiida.orm.nodes.process.workflow.workchain.WorkChainNode:[179998|WorkGraphEngine|update_task_state]: Task: pw_calculator, type: PYTHONJOB, finished.
09/04/2025 07:17:49 AM <564861> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [179998|WorkGraphEngine|continue_workgraph]: tasks ready to run: pp_calculator,pp_calculator1
REPORT:aiida.orm.nodes.process.workflow.workchain.WorkChainNode:[179998|WorkGraphEngine|continue_workgraph]: tasks ready to run: pp_calculator,pp_calculator1
09/04/2025 07:17:51 AM <564861> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [179998|WorkGraphEngine|on_wait]: Process status: Waiting for child processes: 180018, 180024
REPORT:aiida.orm.nodes.process.workflow.workchain.WorkChainNode:[179998|WorkGraphEngine|on_wait]: Process status: Waiting for child processes: 180018, 180024
09/04/2025 07:18:04 AM <564861> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [179998|WorkGraphEngine|update_task_state]: Task: pp_calculator, type: PYTHONJOB, finished.
REPORT:aiida.orm.nodes.process.workflow.workchain.WorkChainNode:[179998|WorkGraphEngine|update_task_state]: Task: pp_calculator, type: PYTHONJOB, finished.
09/04/2025 07:18:07 AM <564861> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [179998|WorkGraphEngine|continue_workgraph]: tasks ready to run:
REPORT:aiida.orm.nodes.process.workflow.workchain.WorkChainNode:[179998|WorkGraphEngine|continue_workgraph]: tasks ready to run:
09/04/2025 07:18:07 AM <564861> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [179998|WorkGraphEngine|on_wait]: Process status: Waiting for child processes: 180024
REPORT:aiida.orm.nodes.process.workflow.workchain.WorkChainNode:[179998|WorkGraphEngine|on_wait]: Process status: Waiting for child processes: 180024
09/04/2025 07:18:12 AM <564861> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [179998|WorkGraphEngine|update_task_state]: Task: pp_calculator1, type: PYTHONJOB, finished.
REPORT:aiida.orm.nodes.process.workflow.workchain.WorkChainNode:[179998|WorkGraphEngine|update_task_state]: Task: pp_calculator1, type: PYTHONJOB, finished.
09/04/2025 07:18:15 AM <564861> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [179998|WorkGraphEngine|continue_workgraph]: tasks ready to run: bader_calculator
REPORT:aiida.orm.nodes.process.workflow.workchain.WorkChainNode:[179998|WorkGraphEngine|continue_workgraph]: tasks ready to run: bader_calculator
09/04/2025 07:18:16 AM <564861> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [179998|WorkGraphEngine|on_wait]: Process status: Waiting for child processes: 180036
REPORT:aiida.orm.nodes.process.workflow.workchain.WorkChainNode:[179998|WorkGraphEngine|on_wait]: Process status: Waiting for child processes: 180036
09/04/2025 07:18:27 AM <564861> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [179998|WorkGraphEngine|update_task_state]: Task: bader_calculator, type: PYTHONJOB, finished.
REPORT:aiida.orm.nodes.process.workflow.workchain.WorkChainNode:[179998|WorkGraphEngine|update_task_state]: Task: bader_calculator, type: PYTHONJOB, finished.
09/04/2025 07:18:29 AM <564861> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [179998|WorkGraphEngine|continue_workgraph]: tasks ready to run:
REPORT:aiida.orm.nodes.process.workflow.workchain.WorkChainNode:[179998|WorkGraphEngine|continue_workgraph]: tasks ready to run:
09/04/2025 07:18:30 AM <564861> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [179998|WorkGraphEngine|finalize]: Finalize workgraph.
REPORT:aiida.orm.nodes.process.workflow.workchain.WorkChainNode:[179998|WorkGraphEngine|finalize]: Finalize workgraph.
[6]:
#------------------------- Print the output -------------------------
charges = wg.outputs.result.value.value
print("Bader charges:")
print("Index Symbol Charge")
for i, charge in enumerate(charges):
print(f"{i:5d} {atoms.get_chemical_symbols()[i]:5s} {charge:5.3f}")
Bader charges:
Index Symbol Charge
0 O 7.148
1 H 0.426
2 H 0.426