Skip to content

vasp

Schemas for VASP.

logger module-attribute

logger = getLogger(__name__)

summarize_vasp_opt_run

summarize_vasp_opt_run(
    optimizer: Optimizer,
    trajectory: Trajectory | list[Atoms] | None = None,
    directory: str | Path | None = None,
    move_magmoms: bool = True,
    run_bader: bool = _DEFAULT_SETTING,
    run_chargemol: bool = _DEFAULT_SETTING,
    check_convergence: bool = _DEFAULT_SETTING,
    report_mp_corrections: bool = False,
    additional_fields: dict[str, Any] | None = None,
    store: Store | None = _DEFAULT_SETTING,
) -> VaspASEOptSchema

Merges the vasp_summarize_run with an summarize_opt_run, meant to be used for an ASE-based VASP relaxation.

Parameters:

  • optimizer (Optimizer) –

    The ASE optimizer object

  • trajectory (Trajectory | list[Atoms] | None, default: None ) –

    ASE Trajectory object or list[Atoms] from reading a trajectory file. If None, the trajectory must be found in dyn.traj_atoms.

  • directory (str | Path | None, default: None ) –

    Path to VASP outputs. A value of None specifies the calculator directory.

  • move_magmoms (bool, default: True ) –

    Whether to move the final magmoms of the original Atoms object to the initial magmoms of the returned Atoms object.

  • run_bader (bool, default: _DEFAULT_SETTING ) –

    Whether a Bader analysis should be performed. Will not run if bader executable is not in PATH even if bader is set to True. Defaults to VASP_BADER in settings.

  • run_chargemol (bool, default: _DEFAULT_SETTING ) –

    Whether a Chargemol analysis should be performed. Will not run if chargemol executable is not in PATH even if chargmeol is set to True. Defaults to VASP_CHARGEMOL in settings.

  • check_convergence (bool, default: _DEFAULT_SETTING ) –

    Whether to throw an error if convergence is not reached. Defaults to True in settings.

  • report_mp_corrections (bool, default: False ) –

    Whether to apply the MP corrections to the task document. Defaults to False.

  • additional_fields (dict[str, Any] | None, default: None ) –

    Additional fields to add to the task document.

  • store (Store | None, default: _DEFAULT_SETTING ) –

    Maggma Store object to store the results in. Defaults to SETTINGS.STORE,

Source code in quacc/schemas/vasp.py
def summarize_vasp_opt_run(
    optimizer: Optimizer,
    trajectory: Trajectory | list[Atoms] | None = None,
    directory: str | Path | None = None,
    move_magmoms: bool = True,
    run_bader: bool = _DEFAULT_SETTING,
    run_chargemol: bool = _DEFAULT_SETTING,
    check_convergence: bool = _DEFAULT_SETTING,
    report_mp_corrections: bool = False,
    additional_fields: dict[str, Any] | None = None,
    store: Store | None = _DEFAULT_SETTING,
) -> VaspASEOptSchema:
    """
    Merges the `vasp_summarize_run` with an `summarize_opt_run`, meant to
    be used for an ASE-based VASP relaxation.

    Parameters
    ----------
    optimizer
        The ASE optimizer object
    trajectory
        ASE Trajectory object or list[Atoms] from reading a trajectory file. If
        None, the trajectory must be found in dyn.traj_atoms.
    directory
        Path to VASP outputs. A value of None specifies the calculator directory.
    move_magmoms
        Whether to move the final magmoms of the original Atoms object to the
        initial magmoms of the returned Atoms object.
    run_bader
        Whether a Bader analysis should be performed. Will not run if bader
        executable is not in PATH even if bader is set to True. Defaults to
        VASP_BADER in settings.
    run_chargemol
        Whether a Chargemol analysis should be performed. Will not run if chargemol
        executable is not in PATH even if chargmeol is set to True. Defaults to
        VASP_CHARGEMOL in settings.
    check_convergence
        Whether to throw an error if convergence is not reached. Defaults to True in
        settings.
    report_mp_corrections
        Whether to apply the MP corrections to the task document. Defaults to False.
    additional_fields
        Additional fields to add to the task document.
    store
        Maggma Store object to store the results in. Defaults to `SETTINGS.STORE`,
    """
    store = SETTINGS.STORE if store == _DEFAULT_SETTING else store

    final_atoms = get_final_atoms_from_dynamics(optimizer)
    directory = Path(directory or final_atoms.calc.directory)
    opt_run_summary = summarize_opt_run(
        optimizer,
        trajectory=trajectory,
        check_convergence=check_convergence,
        move_magmoms=move_magmoms,
        additional_fields=additional_fields,
        store=None,
    )
    vasp_summary = vasp_summarize_run(
        final_atoms,
        directory=directory,
        move_magmoms=move_magmoms,
        run_bader=run_bader,
        run_chargemol=run_chargemol,
        check_convergence=check_convergence,
        report_mp_corrections=report_mp_corrections,
        additional_fields=additional_fields,
        store=None,
    )
    unsorted_task_doc = recursive_dict_merge(vasp_summary, opt_run_summary)
    return finalize_dict(
        unsorted_task_doc, directory, gzip_file=SETTINGS.GZIP_FILES, store=store
    )

vasp_summarize_run

vasp_summarize_run(
    final_atoms: Atoms,
    directory: str | Path | None = None,
    move_magmoms: bool = True,
    run_bader: bool = _DEFAULT_SETTING,
    run_chargemol: bool = _DEFAULT_SETTING,
    check_convergence: bool = _DEFAULT_SETTING,
    report_mp_corrections: bool = False,
    additional_fields: dict[str, Any] | None = None,
    store: Store | None = _DEFAULT_SETTING,
) -> VaspSchema

Get tabulated results from a VASP run and store them in a database-friendly format.

Parameters:

  • final_atoms (Atoms) –

    ASE Atoms object following a calculation.

  • directory (str | Path | None, default: None ) –

    Path to VASP outputs. A value of None specifies the calculator directory.

  • move_magmoms (bool, default: True ) –

    Whether to move the final magmoms of the original Atoms object to the initial magmoms of the returned Atoms object.

  • run_bader (bool, default: _DEFAULT_SETTING ) –

    Whether a Bader analysis should be performed. Will not run if bader executable is not in PATH even if bader is set to True. Defaults to VASP_BADER in settings.

  • run_chargemol (bool, default: _DEFAULT_SETTING ) –

    Whether a Chargemol analysis should be performed. Will not run if chargemol executable is not in PATH even if chargmeol is set to True. Defaults to VASP_CHARGEMOL in settings.

  • check_convergence (bool, default: _DEFAULT_SETTING ) –

    Whether to throw an error if convergence is not reached. Defaults to True in settings.

  • report_mp_corrections (bool, default: False ) –

    Whether to apply the MP corrections to the task document. Defaults to False.

  • additional_fields (dict[str, Any] | None, default: None ) –

    Additional fields to add to the task document.

  • store (Store | None, default: _DEFAULT_SETTING ) –

    Maggma Store object to store the results in. Defaults to SETTINGS.STORE,

Returns:

  • VaspSchema

    Dictionary representation of the task document

Source code in quacc/schemas/vasp.py
def vasp_summarize_run(
    final_atoms: Atoms,
    directory: str | Path | None = None,
    move_magmoms: bool = True,
    run_bader: bool = _DEFAULT_SETTING,
    run_chargemol: bool = _DEFAULT_SETTING,
    check_convergence: bool = _DEFAULT_SETTING,
    report_mp_corrections: bool = False,
    additional_fields: dict[str, Any] | None = None,
    store: Store | None = _DEFAULT_SETTING,
) -> VaspSchema:
    """
    Get tabulated results from a VASP run and store them in a database-friendly format.

    Parameters
    ----------
    final_atoms
        ASE Atoms object following a calculation.
    directory
        Path to VASP outputs. A value of None specifies the calculator directory.
    move_magmoms
        Whether to move the final magmoms of the original Atoms object to the
        initial magmoms of the returned Atoms object.
    run_bader
        Whether a Bader analysis should be performed. Will not run if bader
        executable is not in PATH even if bader is set to True. Defaults to
        VASP_BADER in settings.
    run_chargemol
        Whether a Chargemol analysis should be performed. Will not run if chargemol
        executable is not in PATH even if chargmeol is set to True. Defaults to
        VASP_CHARGEMOL in settings.
    check_convergence
        Whether to throw an error if convergence is not reached. Defaults to True in
        settings.
    report_mp_corrections
        Whether to apply the MP corrections to the task document. Defaults to False.
    additional_fields
        Additional fields to add to the task document.
    store
        Maggma Store object to store the results in. Defaults to `SETTINGS.STORE`,

    Returns
    -------
    VaspSchema
        Dictionary representation of the task document
    """
    run_bader = SETTINGS.VASP_BADER if run_bader == _DEFAULT_SETTING else run_bader
    run_chargemol = (
        SETTINGS.VASP_CHARGEMOL if run_chargemol == _DEFAULT_SETTING else run_chargemol
    )
    check_convergence = (
        SETTINGS.CHECK_CONVERGENCE
        if check_convergence == _DEFAULT_SETTING
        else check_convergence
    )
    directory = Path(directory or final_atoms.calc.directory)
    store = SETTINGS.STORE if store == _DEFAULT_SETTING else store
    additional_fields = additional_fields or {}

    # Fetch all tabulated results from VASP outputs files. Fortunately, emmet
    # already has a handy function for this
    vasp_task_model = TaskDoc.from_directory(directory)

    # Get MP corrections
    if report_mp_corrections:
        mp_compat = MaterialsProject2020Compatibility()
        try:
            corrected_entry = mp_compat.process_entry(
                vasp_task_model.structure_entry, on_error="raise"
            )
            vasp_task_model.entry = corrected_entry
        except CompatibilityError as err:
            logger.warning(err)

    # Convert the VASP task model to a dictionary
    vasp_task_doc = vasp_task_model.model_dump()

    # Check for calculation convergence
    if check_convergence and vasp_task_doc["state"] != "successful":
        raise RuntimeError(
            f"VASP calculation did not converge. Will not store task data. Refer to {directory}"
        )

    initial_atoms = read(zpath(directory / "POSCAR"))
    base_task_doc = summarize_run(
        final_atoms, initial_atoms, move_magmoms=move_magmoms, store=None
    )

    if nsteps := len([f for f in os.listdir(directory) if f.startswith("step")]):
        intermediate_vasp_task_docs = {
            "steps": {
                n: TaskDoc.from_directory(Path(directory, f"step{n}")).model_dump()
                for n in range(nsteps)
            }
        }
    else:
        intermediate_vasp_task_docs = {}

    # Get Bader analysis
    if run_bader:
        try:
            bader_results = _bader_runner(directory)
        except Exception:
            bader_results = None
            logging.warning("Bader analysis could not be performed.", exc_info=True)

        if bader_results:
            vasp_task_doc["bader"] = bader_results

    # Get the Chargemol analysis
    if run_chargemol:
        try:
            chargemol_results = _chargemol_runner(directory)
        except Exception:
            chargemol_results = None
            logging.warning("Chargemol analysis could not be performed.", exc_info=True)

        if chargemol_results:
            vasp_task_doc["chargemol"] = chargemol_results

    # Make task document
    unsorted_task_doc = (
        intermediate_vasp_task_docs | vasp_task_doc | base_task_doc | additional_fields
    )
    return finalize_dict(
        unsorted_task_doc, directory, gzip_file=SETTINGS.GZIP_FILES, store=store
    )