Skip to content

Commit 2ec3820

Browse files
committed
Doc cleanup.
1 parent 0991719 commit 2ec3820

19 files changed

Lines changed: 693 additions & 1372 deletions

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ exclude_lines = [
238238

239239
[tool.pyright]
240240
reportMissingImports = false
241+
reportMissingModuleSource = false
241242
reportPossiblyUnboundVariable = true
242243
reportUnboundVariable = true
243244
exclude = ["tests"]

src/matcalc/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from ._stability import EnergeticsCalc
2525
from ._surface import SurfaceCalc
2626
from .config import SIMULATION_BACKEND, clear_cache
27-
from .utils import UNIVERSAL_CALCULATORS, PESCalculator
27+
from .utils import UNIVERSAL_CALCULATOR_NAMES, UNIVERSAL_CALCULATORS, PESCalculator
2828

2929
# Provide an alias for loading calculators quickly.
3030
load_up = PESCalculator.load_universal

src/matcalc/_adsorption.py

Lines changed: 57 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -27,32 +27,10 @@
2727

2828
class AdsorptionCalc(PropCalc):
2929
"""
30-
Calculator for adsorption energies on surfaces.
31-
Combines bulk relaxation, slab generation and relaxation, adsorbate
32-
relaxation, and adsorption energy calculations.
33-
Uses :class:`RelaxCalc` for structure relaxations.
34-
Parameters allow control over which parts are relaxed and how.
35-
36-
:param calculator: An ASE calculator object used to perform energy and force
37-
calculations. If string is provided, the corresponding universal calculator is loaded.
38-
:type calculator: Calculator | str
39-
:param relax_adsorbate: Whether to relax the adsorbate structure. If note relaxed,
40-
a single point or the adsorbate energy provided downstream is used. Default is True.
41-
:type relax_adsorbate: bool, optional
42-
:param relax_slab: Whether to relax each clean slab structure (cell fixed). Default is True.
43-
:type relax_slab: bool, optional
44-
:param relax_bulk: Whether to relax the bulk structure used to generate slabs, including its cell. Default is True.
45-
:type relax_bulk: bool, optional
46-
:param fmax: Force tolerance in eV/Å for relaxation. Default is 0.1.
47-
:type fmax: float, optional
48-
:param optimizer: The ASE optimizer to use in RelaxCalc. Can be a string (e.g. "BFGS") or
49-
an :class:`Optimizer` instance. Default is "BFGS".
50-
:type optimizer: str | Optimizer, optional
51-
:param max_steps: Maximum number of optimization steps for relaxation. Default is 500.
52-
:type max_steps: int, optional
53-
:param relax_calc_kwargs: Additional keyword arguments passed to the
54-
:class:`RelaxCalc` constructor for both bulk and slabs. Default is None.
55-
:type relax_calc_kwargs: dict | None, optional
30+
Adsorption energies on surfaces via bulk, slab, adsorbate, and adslab relaxations.
31+
32+
Uses ``RelaxCalc`` for geometry optimizations. Attributes mirror constructor arguments
33+
plus optional cached bulk state after ``calc_bulk`` / ``calc_adslabs``.
5634
"""
5735

5836
def __init__(
@@ -68,27 +46,15 @@ def __init__(
6846
relax_calc_kwargs: dict[str, Any] | None = None,
6947
) -> None:
7048
"""
71-
Initialize the AdsorptionCalc.
72-
73-
:param calculator: An ASE calculator object used to perform energy and force
74-
calculations. If string is provided, the corresponding universal calculator is loaded.
75-
:type calculator: Calculator | str
76-
:param relax_adsorbate: Whether to relax the adsorbate structure. Default is True.
77-
:type relax_adsorbate: bool, optional
78-
:param relax_slab: Whether to relax each slab structure (cell fixed). Default is True.
79-
:type relax_slab: bool, optional
80-
:param relax_bulk: Whether to relax the bulk structure, including its cell. Default is True.
81-
:type relax_bulk: bool, optional
82-
:param fmax: Force tolerance in eV/Å for relaxation. Default is 0.1.
83-
:type fmax: float, optional
84-
:param optimizer: The ASE optimizer to use. Can be a string (e.g. "BFGS") or
85-
an :class:`Optimizer` instance. Default is "BFGS".
86-
:type optimizer: str | Optimizer, optional
87-
:param max_steps: Maximum number of optimization steps for relaxation. Default is 500.
88-
:type max_steps: int, optional
89-
:param relax_calc_kwargs: Additional keyword arguments passed to the
90-
:class:`RelaxCalc` constructor for both bulk and slabs. Default is None.
91-
:type relax_calc_kwargs: dict | None, optional
49+
Args:
50+
calculator: ASE calculator or universal model name string.
51+
relax_adsorbate: Relax isolated adsorbate in a box when True.
52+
relax_slab: Relax clean slab (fixed cell) when True.
53+
relax_bulk: Relax bulk with cell when True.
54+
fmax: Force tolerance (eV/Å).
55+
optimizer: ASE optimizer name or class.
56+
max_steps: Max relaxation steps.
57+
relax_calc_kwargs: Optional kwargs for ``RelaxCalc``.
9258
"""
9359
self.calculator = calculator # type: ignore[assignment]
9460
self.relax_adsorbate = relax_adsorbate
@@ -109,15 +75,12 @@ def calc_bulk(
10975
bulk_energy: float | None = None,
11076
) -> dict[str, Any]:
11177
"""
112-
Prepare the bulk structure for slab generation, optionally relaxing it.
113-
114-
:param bulk: The bulk structure to be calculated.
115-
:type bulk: Structure | Atoms
116-
:param bulk_energy: Optional pre-calculated energy of the bulk. If not provided,
117-
the bulk will be relaxed and its energy calculated.
118-
:type bulk_energy: float | None, optional
119-
:return: A dictionary containing the bulk energy and final structure.
120-
:rtype: dict[str, Any]
78+
Args:
79+
bulk: Bulk pymatgen structure or ASE atoms.
80+
bulk_energy: If ``relax_bulk`` is False and this is set, used as energy; else relaxed.
81+
82+
Returns:
83+
Dict with ``final_structure`` and ``energy`` (when available).
12184
"""
12285
initial_bulk = to_pmg_structure(bulk)
12386

@@ -147,12 +110,12 @@ def calc_adsorbate(
147110
adsorbate_energy: float | None = None,
148111
) -> dict[str, Any]:
149112
"""
150-
Calculate the energy of the adsorbate, optionally relaxing it.
113+
Args:
114+
adsorbate: Adsorbate as molecule or atoms.
115+
adsorbate_energy: Optional fixed energy; otherwise from calculator on final geometry.
151116
152-
:param adsorbate: The adsorbate structure to be calculated.
153-
:type adsorbate: Molecule | Atoms
154-
:return: A dictionary containing the adsorbate energy and final structure.
155-
:rtype: dict[str, Any]
117+
Returns:
118+
Dict with ``adsorbate_energy``, ``adsorbate``, ``final_adsorbate``.
156119
"""
157120
initial_adsorbate = to_pmg_molecule(adsorbate)
158121

@@ -196,15 +159,12 @@ def calc_slab(
196159
slab_energy: float | None = None,
197160
) -> dict[str, Any]:
198161
"""
199-
Calculate the energy of the slab, optionally relaxing it.
200-
201-
:param slab: The slab structure to be calculated.
202-
:type slab: Structure | Atoms
203-
:param slab_energy: Optional pre-calculated energy of the slab. If not provided,
204-
the slab will be relaxed and its energy calculated.
205-
:type slab_energy: float | None, optional
206-
:return: A dictionary containing the slab energy and final structure.
207-
:rtype: dict[str, Any]
162+
Args:
163+
slab: Slab structure or atoms.
164+
slab_energy: Optional total slab energy; if None, taken from calculator.
165+
166+
Returns:
167+
Dict with ``slab``, ``slab_energy``, ``slab_energy_per_atom``, ``final_slab``.
208168
"""
209169
if self.relax_slab:
210170
relaxer = RelaxCalc(
@@ -257,53 +217,28 @@ def calc_adslabs( # noqa: C901
257217
**kwargs: dict[str, Any],
258218
) -> list[dict[str, Any]] | dict[Any, Any]:
259219
"""
260-
Calculate adsorption energies for adsorbates on slabs generated from a bulk structure.
261-
:param adsorbate: The adsorbate structure to be placed on the slab.
262-
:type adsorbate: Molecule | Atoms
263-
:param bulk: The bulk structure from which slabs will be generated. Be careful
264-
to provide conventional cells if that is your intention for miller indices.
265-
:type bulk: Structure | Atoms
266-
:param miller_index: The Miller index defining the slab orientation.
267-
:type miller_index: tuple[int, int, int]
268-
:param adsorbate_energy: Optional pre-calculated energy of the adsorbate. If not provided,
269-
the adsorbate will be relaxed and its energy calculated.
270-
:type adsorbate_energy: float | None, optional
271-
:param min_slab_size: Minimum thickness of the slab in Å. Default is 10.0.
272-
:type min_slab_size: float, optional
273-
:param min_vacuum_size: Minimum size of the vacuum layer in Å. Default is 20.0.
274-
:type min_vacuum_size: float, optional
275-
:param min_area_extent: Minimum in-plane dimensions of the slab in Å. If provided,
276-
the slab will be expanded to at least these dimensions in the a and perpendicular
277-
to a directions by projecting the b lattice vector onto a. Default is None.
278-
:type min_area_extent: tuple[float, float] | None, optional
279-
:param inplane_supercell: Tuple defining the in-plane supercell size. Default is (1, 1).
280-
:type inplane_supercell: tuple[int, int], optional
281-
:param slab_gen_kwargs: Additional keyword arguments passed to the SlabGenerator. Default is None.
282-
:type slab_gen_kwargs: dict[str, Any] | None, optional
283-
:param get_slabs_kwargs: Additional keyword arguments passed to the get_slabs method of
284-
SlabGenerator. Default is None.
285-
:type get_slabs_kwargs: dict[str, Any] | None, optional
286-
:param adsorption_sites: Either a string specifying which adsorption sites to consider
287-
(e.g., "all", "ontop", "bridge", "hollow"), or a dictionary specifying custom adsorption sites
288-
with site names as keys and lists of fractional coordinates as values.
289-
Default is "all".
290-
:type adsorption_sites: dict[str:tuple[float, float]] | str, optional
291-
:param height: Height above the surface to place the adsorbate in Å. Default is 0.9.
292-
:type height: float, optional
293-
:param mi_vec: Optional in-plane vector defining the slab orientation. If None, it is
294-
automatically determined. Default is None.
295-
:type mi_vec: tuple[float, float] | None, optional
296-
:param fixed_height: Height below which slab atoms are fixed during relaxation in Å.
297-
Default is 5 Å.
298-
:type fixed_height: float, optional
299-
:param find_adsorption_sites_args: Additional keyword arguments passed to the
300-
find_adsorption_sites method of AdsorbateSiteFinder. Default is None.
301-
:type find_adsorption_sites_args: dict[str, Any] | None, optional
302-
:param dry_run: If True, only generates the adslab structures without performing calculations.
303-
Default is False.
304-
:type dry_run: bool, optional
305-
:return: A list of dictionaries containing results for each adslab, or just the structures if dry_run is True.
306-
:rtype: list[dict[str, Any]] | dict[Any, Any].
220+
Args:
221+
adsorbate: Adsorbate species.
222+
bulk: Bulk structure (use conventional cell if needed for Miller indices).
223+
miller_index: Surface orientation.
224+
adsorbate_energy: Optional fixed adsorbate energy.
225+
slab_energy: Optional fixed clean-slab energy for all slabs.
226+
min_slab_size: Minimum slab thickness (Å).
227+
min_vacuum_size: Vacuum thickness (Å).
228+
min_area_extent: Minimum in-plane extent (Å); may expand ``inplane_supercell``.
229+
inplane_supercell: In-plane supercell factors.
230+
slab_gen_kwargs: Kwargs for ``SlabGenerator``.
231+
get_slabs_kwargs: Kwargs for ``SlabGenerator.get_slabs``.
232+
adsorption_sites: ``"all"``, site name string, or custom fractional-coordinate dict.
233+
height: Adsorbate height above surface (Å).
234+
mi_vec: Optional in-plane vector for ``AdsorbateSiteFinder``.
235+
fixed_height: Fix slab atoms below this height (Å) during relaxation.
236+
find_adsorption_sites_args: Kwargs for ``find_adsorption_sites``.
237+
dry_run: If True, return adslab dicts without ``calc_many``.
238+
**kwargs: Forwarded to ``calc_many``.
239+
240+
Returns:
241+
List of per-configuration results, or raw adslab dicts if ``dry_run``.
307242
"""
308243
adslab_dict = {}
309244
bulk = to_pmg_structure(bulk)
@@ -406,13 +341,12 @@ def calc(
406341
structure: dict[str, Any], # type: ignore[override]
407342
) -> dict[str, Any]:
408343
"""
409-
Calculate the adsorption energy for a given adslab structure.
344+
Args:
345+
structure: Dict with ``adslab``, ``slab``, ``adsorbate``; optional ``slab_energy`` /
346+
``adsorbate_energy``.
410347
411-
:param structure: A dictionary containing 'adslab', 'slab', and 'adsorbate' structures,
412-
and optionally 'slab_energy' and/or 'adsorbate_energy'.
413-
:type structure: dict[str, Any]
414-
:return: A dictionary containing the adsorption energy and related information.
415-
:rtype: dict[str, Any]
348+
Returns:
349+
Dict including ``adsorption_energy`` and merged slab/adsorbate fields.
416350
"""
417351
result_dict = structure.copy()
418352

src/matcalc/_base.py

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def calculator(self) -> Calculator:
4040
and controlled access to the underlying calculator.
4141
4242
Returns:
43-
Calculator: The internal `Calculator` instance.
43+
The internal ASE calculator instance.
4444
"""
4545
return self._pes_calculator
4646

@@ -51,16 +51,8 @@ def calculator(self, val: str | Calculator) -> None:
5151
loads the universal PESCalculator using the given value. Otherwise, it sets
5252
the provided Calculator instance.
5353
54-
Parameters:
55-
val (str | Calculator): The new value to assign to the calculator property.
56-
It can either be a string representing a PESCalculator configuration or an
57-
existing Calculator object.
58-
59-
Returns:
60-
None
61-
62-
Exceptions:
63-
None
54+
Args:
55+
val: Universal model name string or an existing ASE calculator instance.
6456
"""
6557
self._pes_calculator = PESCalculator.load_universal(val) if isinstance(val, str) else val
6658

@@ -116,25 +108,16 @@ def calc_many(
116108
`None` for those structures, without raising exceptions.
117109
118110
Args:
119-
structures (Sequence[Structure | dict[str, Any] | Atoms]): A sequence of structures
120-
to be processed. Each structure can be represented as `Structure`, a dictionary
121-
containing structure-related data, or `Atoms`.
122-
n_jobs (None | int, optional): The number of jobs to use for parallel processing. If
123-
`None`, the default parallelism settings of the `Parallel` utility will be used.
124-
Defaults to `None`.
125-
allow_errors (bool, optional): If `True`, exceptions encountered during the
126-
calculation of a structure will be caught, and `None` will be returned for that
127-
structure. If `False`, the exception is raised. Defaults to `False`.
128-
**kwargs (Any): Additional keyword arguments to pass to the `Parallel` utility.
111+
structures: Sequence of structures or structure dicts.
112+
n_jobs: ``joblib`` worker count; ``None`` uses joblib defaults.
113+
allow_errors: If True, failed structures yield ``None`` instead of raising.
114+
**kwargs: Forwarded to ``joblib.Parallel``.
129115
130-
Returns:
131-
Generator[dict | None, None, None]: A generator that yields the results of the
132-
calculations for the input structures. If an exception occurs and `allow_errors`
133-
is `True`, `None` will be yielded for the corresponding structure.
116+
Yields:
117+
Result dict from ``calc``, or ``None`` when ``allow_errors`` and a structure fails.
134118
135119
Raises:
136-
Exception: If any error occurs during the calculation of a structure and
137-
`allow_errors` is `False`, the exception will be raised.
120+
Exception: Any error from ``calc`` when ``allow_errors`` is False.
138121
"""
139122
parallel = Parallel(n_jobs=n_jobs, return_as="generator", **kwargs)
140123

@@ -177,7 +160,7 @@ def calc(self, structure: Structure | Atoms | dict[str, Any]) -> dict[str, Any]:
177160
by an elasticity calculation.
178161
179162
Returns:
180-
dict[str, Any]: In the form {"prop_name": value}.
163+
Merged dict from all steps (final keys depend on the chain).
181164
"""
182165
results = structure # type:ignore[assignment]
183166
for prop_calc in self.prop_calcs:

src/matcalc/_cli.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,7 @@
1717

1818

1919
def calculate_property(args: Any) -> None:
20-
"""
21-
Implements calculate property.
22-
23-
:param args:
24-
:return:
25-
"""
20+
"""Run the selected PropCalc on input structure files (from parsed CLI args)."""
2621
calculator = mtc.load_fp(args.model)
2722
mod = mtc.__dict__[args.property](calculator)
2823
results = []
@@ -39,12 +34,7 @@ def calculate_property(args: Any) -> None:
3934

4035

4136
def clear_cache(args: Any) -> None:
42-
"""
43-
Clear the benchmark cache.
44-
45-
:param args:
46-
:return:
47-
"""
37+
"""Clear the MatCalc benchmark cache (from parsed CLI args)."""
4838
mtc.clear_cache(confirm=args.yes)
4939

5040

@@ -74,7 +64,7 @@ def main() -> None:
7464
"--model",
7565
dest="model",
7666
type=str,
77-
choices=mtc.UNIVERSAL_CALCULATORS,
67+
choices=mtc.UNIVERSAL_CALCULATOR_NAMES,
7868
default="TensorNet",
7969
help="Universal MLIP to use.",
8070
)

0 commit comments

Comments
 (0)