Skip to content

ase

Schemas for storing ASE-based data.

summarize_opt_run

summarize_opt_run(
    dyn: Optimizer,
    trajectory: Trajectory | list[Atoms] | None = None,
    check_convergence: bool = _DEFAULT_SETTING,
    charge_and_multiplicity: tuple[int, int] | None = None,
    move_magmoms: bool = False,
    additional_fields: dict[str, Any] | None = None,
    store: Store | None = _DEFAULT_SETTING,
) -> OptSchema

Get tabulated results from an ASE Atoms trajectory and store them in a database- friendly format. This is meant to be compatible with all calculator types.

Parameters:

  • dyn (Optimizer) –

    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.

  • check_convergence (bool, default: _DEFAULT_SETTING ) –

    Whether to check the convergence of the calculation. Defaults to True in settings.

  • charge_and_multiplicity (tuple[int, int] | None, default: None ) –

    Charge and spin multiplicity of the Atoms object, only used for Molecule metadata.

  • move_magmoms (bool, default: False ) –

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

  • 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:

  • OptSchema

    Dictionary representation of the task document

Source code in quacc/schemas/ase.py
def summarize_opt_run(
    dyn: Optimizer,
    trajectory: Trajectory | list[Atoms] | None = None,
    check_convergence: bool = _DEFAULT_SETTING,
    charge_and_multiplicity: tuple[int, int] | None = None,
    move_magmoms: bool = False,
    additional_fields: dict[str, Any] | None = None,
    store: Store | None = _DEFAULT_SETTING,
) -> OptSchema:
    """
    Get tabulated results from an ASE Atoms trajectory and store them in a database-
    friendly format. This is meant to be compatible with all calculator types.

    Parameters
    ----------
    dyn
        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.
    check_convergence
        Whether to check the convergence of the calculation. Defaults to True in
        settings.
    charge_and_multiplicity
        Charge and spin multiplicity of the Atoms object, only used for Molecule
        metadata.
    move_magmoms
        Whether to move the final magmoms of the original Atoms object to the
        initial magmoms of the returned Atoms object.
    additional_fields
        Additional fields to add to the task document.
    store
        Maggma Store object to store the results in. Defaults to `SETTINGS.STORE`.

    Returns
    -------
    OptSchema
        Dictionary representation of the task document
    """
    check_convergence = (
        SETTINGS.CHECK_CONVERGENCE
        if check_convergence == _DEFAULT_SETTING
        else check_convergence
    )
    store = SETTINGS.STORE if store == _DEFAULT_SETTING else store
    additional_fields = additional_fields or {}

    # Get trajectory
    if not trajectory:
        trajectory = (
            dyn.traj_atoms
            if hasattr(dyn, "traj_atoms")
            else read(dyn.trajectory.filename, index=":")
        )

    initial_atoms = trajectory[0]
    final_atoms = get_final_atoms_from_dynamics(dyn)
    directory = final_atoms.calc.directory

    # Check convergence
    is_converged = dyn.converged()
    if check_convergence and not is_converged:
        msg = f"Optimization did not converge. Refer to {directory}"
        raise RuntimeError(msg)

    # Base task doc
    base_task_doc = summarize_run(
        final_atoms,
        initial_atoms,
        charge_and_multiplicity=charge_and_multiplicity,
        move_magmoms=move_magmoms,
        store=None,
    )

    # Clean up the opt parameters
    parameters_opt = dyn.todict() | {"fmax": getattr(dyn, "fmax", None)}
    parameters_opt.pop("logfile", None)
    parameters_opt.pop("restart", None)

    opt_fields = {
        "parameters_opt": parameters_opt,
        "converged": is_converged,
        "nsteps": dyn.get_number_of_steps(),
        "trajectory": trajectory,
        "trajectory_results": [atoms.calc.results for atoms in trajectory],
    }

    # Create a dictionary of the inputs/outputs
    unsorted_task_doc = base_task_doc | opt_fields | additional_fields

    return finalize_dict(
        unsorted_task_doc, directory, gzip_file=SETTINGS.GZIP_FILES, store=store
    )

summarize_run

summarize_run(
    final_atoms: Atoms,
    input_atoms: Atoms,
    charge_and_multiplicity: tuple[int, int] | None = None,
    move_magmoms: bool = False,
    additional_fields: dict[str, Any] | None = None,
    store: Store | None = _DEFAULT_SETTING,
) -> RunSchema

Get tabulated results from an Atoms object and calculator and store them in a database-friendly format. This is meant to be compatible with all calculator types.

Parameters:

  • final_atoms (Atoms) –

    ASE Atoms following a calculation. A calculator must be attached.

  • input_atoms (Atoms) –

    Input ASE Atoms object to store.

  • charge_and_multiplicity (tuple[int, int] | None, default: None ) –

    Charge and spin multiplicity of the Atoms object, only used for Molecule metadata.

  • move_magmoms (bool, default: False ) –

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

  • 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:

  • RunSchema

    Dictionary representation of the task document

Source code in quacc/schemas/ase.py
def summarize_run(
    final_atoms: Atoms,
    input_atoms: Atoms,
    charge_and_multiplicity: tuple[int, int] | None = None,
    move_magmoms: bool = False,
    additional_fields: dict[str, Any] | None = None,
    store: Store | None = _DEFAULT_SETTING,
) -> RunSchema:
    """
    Get tabulated results from an Atoms object and calculator and store them in a
    database-friendly format. This is meant to be compatible with all calculator types.

    Parameters
    ----------
    final_atoms
        ASE Atoms following a calculation. A calculator must be attached.
    input_atoms
        Input ASE Atoms object to store.
    charge_and_multiplicity
        Charge and spin multiplicity of the Atoms object, only used for Molecule
        metadata.
    move_magmoms
        Whether to move the final magmoms of the original Atoms object to the
        initial magmoms of the returned Atoms object.
    additional_fields
        Additional fields to add to the task document.
    store
        Maggma Store object to store the results in. Defaults to `SETTINGS.STORE`

    Returns
    -------
    RunSchema
        Dictionary representation of the task document
    """
    additional_fields = additional_fields or {}
    store = SETTINGS.STORE if store == _DEFAULT_SETTING else store

    if not final_atoms.calc:
        msg = "ASE Atoms object has no attached calculator."
        raise ValueError(msg)
    if not final_atoms.calc.results:
        msg = "ASE Atoms object's calculator has no results."
        raise ValueError(msg)

    directory = final_atoms.calc.directory
    uri = get_uri(directory)

    if input_atoms:
        input_atoms_metadata = atoms_to_metadata(
            input_atoms,
            charge_and_multiplicity=charge_and_multiplicity,
            store_pmg=False,
        )
    else:
        input_atoms_metadata = {}

    inputs = {
        "parameters": final_atoms.calc.parameters,
        "nid": uri.split(":")[0],
        "dir_name": directory,
        "input_atoms": input_atoms_metadata,
        "quacc_version": __version__,
    }
    results = {"results": final_atoms.calc.results}

    atoms_to_store = prep_next_run(final_atoms, move_magmoms=move_magmoms)

    if final_atoms:
        final_atoms_metadata = atoms_to_metadata(
            atoms_to_store, charge_and_multiplicity=charge_and_multiplicity
        )
    else:
        final_atoms_metadata = {}

    unsorted_task_doc = final_atoms_metadata | inputs | results | additional_fields

    return finalize_dict(
        unsorted_task_doc, directory, gzip_file=SETTINGS.GZIP_FILES, store=store
    )

summarize_vib_and_thermo

summarize_vib_and_thermo(
    vib: Vibrations,
    igt: IdealGasThermo,
    temperature: float = 298.15,
    pressure: float = 1.0,
    charge_and_multiplicity: tuple[int, int] | None = None,
    additional_fields: dict[str, Any] | None = None,
    store: Store | None = _DEFAULT_SETTING,
) -> VibThermoSchema

Get tabulated results from an ASE Vibrations run and ASE IdealGasThermo object and store them in a database-friendly format.

Parameters:

  • vib (Vibrations) –

    ASE Vibrations object.

  • igt (IdealGasThermo) –

    ASE IdealGasThermo object.

  • temperature (float, default: 298.15 ) –

    Temperature in Kelvins.

  • pressure (float, default: 1.0 ) –

    Pressure in bar.

  • charge_and_multiplicity (tuple[int, int] | None, default: None ) –

    Charge and spin multiplicity of the Atoms object, only used for Molecule metadata.

  • 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:

  • VibThermoSchema

    A dictionary that merges the VibSchema and ThermoSchema.

Source code in quacc/schemas/ase.py
def summarize_vib_and_thermo(
    vib: Vibrations,
    igt: IdealGasThermo,
    temperature: float = 298.15,
    pressure: float = 1.0,
    charge_and_multiplicity: tuple[int, int] | None = None,
    additional_fields: dict[str, Any] | None = None,
    store: Store | None = _DEFAULT_SETTING,
) -> VibThermoSchema:
    """
    Get tabulated results from an ASE Vibrations run and ASE IdealGasThermo object and
    store them in a database-friendly format.

    Parameters
    ----------
    vib
        ASE Vibrations object.
    igt
        ASE IdealGasThermo object.
    temperature
        Temperature in Kelvins.
    pressure
        Pressure in bar.
    charge_and_multiplicity
        Charge and spin multiplicity of the Atoms object, only used for Molecule
        metadata.
    additional_fields
        Additional fields to add to the task document.
    store
        Maggma Store object to store the results in. Defaults to  `SETTINGS.STORE`.

    Returns
    -------
    VibThermoSchema
        A dictionary that merges the `VibSchema` and `ThermoSchema`.
    """
    store = SETTINGS.STORE if store == _DEFAULT_SETTING else store

    vib_task_doc = _summarize_vib_run(
        vib, charge_and_multiplicity=charge_and_multiplicity
    )
    thermo_task_doc = _summarize_ideal_gas_thermo(
        igt,
        temperature=temperature,
        pressure=pressure,
        charge_and_multiplicity=charge_and_multiplicity,
    )

    unsorted_task_doc = recursive_dict_merge(
        vib_task_doc, thermo_task_doc, additional_fields
    )

    return finalize_dict(
        unsorted_task_doc,
        vib.atoms.calc.directory if isinstance(vib, Vibrations) else None,
        gzip_file=SETTINGS.GZIP_FILES,
        store=store,
    )