Skip to content

Commit

Permalink
Docs improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
hexane360 committed Apr 6, 2024
1 parent efdc4b7 commit b16454a
Show file tree
Hide file tree
Showing 6 changed files with 174 additions and 54 deletions.
3 changes: 2 additions & 1 deletion atomlib/atomcell.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,11 +329,12 @@ def with_columns(self: HasAtomCellT,

@_fwd_atoms_get
def get_column(self, name: str, *, frame: t.Optional[CoordinateFrame] = None) -> polars.Series:
"""Get the specified column from `self`, raising [`polars.ColumnNotFoundError`][polars.ColumnNotFoundError] if it's not present."""
"""Get the specified column from `self`, raising [`polars.ColumnNotFoundError`][polars.exceptions.ColumnNotFoundError] if it's not present."""
...

@_fwd_atoms_get
def get_columns(self, *, frame: t.Optional[CoordinateFrame] = None) -> t.List[polars.Series]:
"""Get the specified columns from `self`, raising [`polars.ColumnNotFoundError`][polars.exceptions.ColumnNotFoundError] if it's not present."""
...

@_fwd_atoms_get
Expand Down
36 changes: 26 additions & 10 deletions atomlib/atoms.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
This module defines [`Atoms`][atomlib.atoms.Atoms], which holds a collection of atoms
with no cell or periodicity. [`Atoms`][atomlib.atoms.Atoms] is essentially a wrapper
around [`polars.DataFrame`][polars.DataFrame].
around a [`polars.DataFrame`][polars.DataFrame].
[polars.DataFrame]: https://docs.pola.rs/py-polars/html/reference/dataframe/index.html
[polars.Series]: https://docs.pola.rs/py-polars/html/reference/series/index.html
"""

from __future__ import annotations
Expand Down Expand Up @@ -268,16 +271,17 @@ def insert_column(self, index: int, column: polars.Series) -> polars.DataFrame:

@_fwd_frame(polars.DataFrame.get_column)
def get_column(self, name: str) -> polars.Series:
"""Get the specified column from `self`, raising [`polars.ColumnNotFoundError`][polars.ColumnNotFoundError] if it's not present."""
"""Get the specified column from `self`, raising [`polars.ColumnNotFoundError`][polars.exceptions.ColumnNotFoundError] if it's not present."""
...

@_fwd_frame(polars.DataFrame.get_columns)
def get_columns(self) -> t.List[polars.Series]:
"""Get the specified columns from `self`, raising [`polars.ColumnNotFoundError`][polars.exceptions.ColumnNotFoundError] if it's not present."""
...

@_fwd_frame(polars.DataFrame.get_column_index)
def get_column_index(self, name: str) -> int:
"""Get the index of a column by name, raising [`polars.ColumnNotFoundError`][polars.ColumnNotFoundError] if it's not present."""
"""Get the index of a column by name, raising [`polars.ColumnNotFoundError`][polars.exceptions.ColumnNotFoundError] if it's not present."""
...

@_fwd_frame(polars.DataFrame.group_by)
Expand Down Expand Up @@ -666,11 +670,19 @@ def velocities(self, selection: t.Optional[AtomSelection] = None) -> t.Optional[
return df.get_column('velocity').to_numpy().astype(numpy.float64)

def types(self) -> t.Optional[polars.Series]:
"""Returns a [`Series`][polars.Series] of atom types (dtype [`polars.Int32`][polars.Int32])."""
"""
Returns a [`Series`][polars.Series] of atom types (dtype [`polars.Int32`][polars.Int32]).
[polars.Series]: https://docs.pola.rs/py-polars/html/reference/series/index.html
"""
return self.try_get_column('type')

def masses(self) -> t.Optional[polars.Series]:
"""Returns a [`Series`][polars.Series] of atom masses (dtype [`polars.Float32`][polars.Float32])."""
"""
Returns a [`Series`][polars.Series] of atom masses (dtype [`polars.Float32`][polars.Float32]).
[polars.Series]: https://docs.pola.rs/py-polars/html/reference/series/index.html
"""
return self.try_get_column('mass')

@t.overload
Expand Down Expand Up @@ -756,7 +768,7 @@ def pos(self,

def with_index(self: HasAtomsT, index: t.Optional[AtomValues] = None) -> HasAtomsT:
"""
Returns `self` with a row index added in column 'i' (dtype polars.Int64).
Returns `self` with a row index added in column 'i' (dtype [`polars.Int64`][polars.Int64]).
If `index` is not specified, defaults to an existing index or a new index.
"""
if index is None and 'i' in self.columns:
Expand All @@ -767,7 +779,7 @@ def with_index(self: HasAtomsT, index: t.Optional[AtomValues] = None) -> HasAtom

def with_wobble(self: HasAtomsT, wobble: t.Optional[AtomValues] = None) -> HasAtomsT:
"""
Return `self` with the given displacements in column 'wobble' (dtype polars.Float64).
Return `self` with the given displacements in column 'wobble' (dtype [`polars.Float64`][polars.Float64]).
If `wobble` is not specified, defaults to the already-existing wobbles or 0.
"""
if wobble is None and 'wobble' in self.columns:
Expand Down Expand Up @@ -819,7 +831,7 @@ def with_type(self: HasAtomsT, types: t.Optional[AtomValues] = None) -> HasAtoms
When auto-assigning, each symbol is given a unique value, case-sensitive.
Values are assigned from lowest atomic number to highest.
For instance: ["Ag+", "Na", "H", "Ag"] => [3, 11, 1, 2]
For instance: `["Ag+", "Na", "H", "Ag"]` => `[3, 11, 1, 2]`
"""
if types is not None:
return self.with_columns(type=_values_to_expr(self, types, polars.Int32))
Expand Down Expand Up @@ -921,20 +933,24 @@ def with_velocity(self: HasAtomsT, pts: t.Optional[ArrayLike] = None,
class Atoms(AtomsIOMixin, HasAtoms):
"""
A collection of atoms, absent any implied coordinate system.
Implemented as a wrapper around a Polars DataFrame.
Implemented as a wrapper around a [`polars.DataFrame`][polars.DataFrame].
Must contain the following columns:
- coords: array of [x, y, z] positions, float
- elem: atomic number, int
- symbol: atomic symbol (may contain charges)
In addition, it commonly contains the following columns:
- i: Initial atom number
- wobble: Isotropic Debye-Waller mean-squared deviation (<u^2> = B*3/8pi^2, dimensions of [Length^2])
- frac_occupancy: Fractional occupancy, [0., 1.]
- mass: Atomic mass, in g/mol (approx. Da)
- vel: array of [x, y, z] velocities, float, dimensions of length/time
- velocity: array of [x, y, z] velocities, float, dimensions of length/time
- type: Numeric atom type, as used by programs like LAMMPS
[polars.DataFrame]: https://docs.pola.rs/py-polars/html/reference/dataframe/index.html
"""

def __init__(self, data: t.Optional[IntoAtoms] = None, columns: t.Optional[t.Sequence[str]] = None,
Expand Down
Loading

0 comments on commit b16454a

Please sign in to comment.