Skip to content

Commit

Permalink
drop backticks from doc str + err msg
Browse files Browse the repository at this point in the history
  • Loading branch information
janosh committed Aug 8, 2024
1 parent ee1a65b commit a3164dd
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 36 deletions.
64 changes: 32 additions & 32 deletions src/pymatgen/core/trajectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def __init__(
coords_are_displacement: bool = False,
base_positions: list[list[Vector3D]] | np.ndarray | None = None,
) -> None:
"""In below, `N` denotes the number of sites in the structure, and `M` denotes the
"""In below, N denotes the number of sites in the structure, and M denotes the
number of frames in the trajectory.
Args:
Expand All @@ -73,40 +73,40 @@ def __init__(
spin_multiplicity: int or float. Spin multiplicity of the system. This is only
used for Molecule-based trajectories.
lattice: shape (3, 3) or (M, 3, 3). Lattice of the structures in the
trajectory; should be used together with `constant_lattice`.
If `constant_lattice=True`, this should be a single lattice that is
trajectory; should be used together with constant_lattice.
If constant_lattice=True, this should be a single lattice that is
common for all structures in the trajectory (e.g. in an NVT run).
If `constant_lattice=False`, this should be a list of lattices,
If constant_lattice=False, this should be a list of lattices,
each for one structure in the trajectory (e.g. in an NPT run or a
relaxation that allows changing the cell size). This is only used for
Structure-based trajectories.
site_properties: Properties associated with the sites. This should be a
list of `M` dicts for a single dict. If a list of dicts, each provides
list of M dicts for a single dict. If a list of dicts, each provides
the site properties for a frame. Each value in a dict should be a
sequence of length `N`, giving the properties of the `N` sites.
For example, for a trajectory with `M=2` and `N=4`, the
`site_properties` can be: [{"magmom":[5,5,5,5]}, {"magmom":[5,5,5,5]}].
sequence of length N, giving the properties of the N sites.
For example, for a trajectory with M=2 and N=4, the
site_properties can be: [{"magmom":[5,5,5,5]}, {"magmom":[5,5,5,5]}].
If a single dict, the site properties in the dict apply to all frames
in the trajectory. For example, for a trajectory with `M=2` and `N=4`,
in the trajectory. For example, for a trajectory with M=2 and N=4,
{"magmom":[2,2,2,2]} means that, through the entire trajectory,
the magmom are kept constant at 2 for all four atoms.
frame_properties: Properties associated with the structure (e.g. total
energy). This should be a sequence of `M` dicts, with each dict
energy). This should be a sequence of M dicts, with each dict
providing the properties for a frame. For example, for a trajectory with
`M=2`, the `frame_properties` can be [{'energy':1.0}, {'energy':2.0}].
M=2, the frame_properties can be [{'energy':1.0}, {'energy':2.0}].
constant_lattice: Whether the lattice changes during the simulation.
Should be used together with `lattice`. See usage there. This is only
Should be used together with lattice. See usage there. This is only
used for Structure-based trajectories.
time_step: Time step of MD simulation in femto-seconds. Should be `None`
time_step: Time step of MD simulation in femto-seconds. Should be None
for a trajectory representing a geometry optimization.
coords_are_displacement: Whether `coords` are given in displacements
(True) or positions (False). Note, if this is `True`, `coords`
coords_are_displacement: Whether coords are given in displacements
(True) or positions (False). Note, if this is True, coords
of a frame (say i) should be relative to the previous frame (i.e.
i-1), but not relative to the `base_position`.
i-1), but not relative to the base_position.
base_positions: shape (N, 3). The starting positions of all atoms in the
trajectory. Used to reconstruct positions when converting from
displacements to positions. Only needs to be specified if
`coords_are_displacement=True`. Defaults to the first index of
coords_are_displacement=True. Defaults to the first index of
coords when coords_are_displacement=False.
"""
coords = np.asarray(coords)
Expand All @@ -116,7 +116,7 @@ def __init__(

if len(species) != coords.shape[1]:
raise ValueError(
f"`species` (N={len(species)}) and `coords` "
f"species (N={len(species)}) and coords "
f"(N={coords.shape[1]}) must have the same number of sites!"
)

Expand All @@ -128,7 +128,7 @@ def __init__(
# First, sanity check that the necessary inputs have been provided
if lattice is None:
if charge is None:
raise ValueError("`charge` must be provided for a Molecule-based Trajectory!")
raise ValueError("charge must be provided for a Molecule-based Trajectory!")

self.charge = int(charge)
if spin_multiplicity is None:
Expand All @@ -143,19 +143,19 @@ def __init__(
lattice = np.asarray(lattice)

if lattice.shape[-2:] != (3, 3):
raise ValueError(f"`lattice` must have shape (3, 3) or (M, 3, 3), found {lattice.shape}!")
raise ValueError(f"lattice must have shape (3, 3) or (M, 3, 3), found {lattice.shape}!")

if not constant_lattice and lattice.shape == (3, 3):
self.lattice = np.tile(lattice, (len(coords), 1, 1))
warnings.warn(
"Get `constant_lattice=False`, but only get a single `lattice`. "
"Use this single `lattice` as the lattice for all frames."
"Get constant_lattice=False, but only get a single lattice. "
"Use this single lattice as the lattice for all frames."
)
else:
self.lattice = lattice

if len(lattice.shape) == 3 and (lattice.shape[0] != len(coords)):
raise ValueError(f"`lattice` must have shape (M, 3, 3)! found M={len(coords)}, {lattice.shape=}!")
raise ValueError(f"lattice must have shape (M, 3, 3)! found M={len(coords)}, {lattice.shape=}!")

self.constant_lattice = constant_lattice

Expand Down Expand Up @@ -192,7 +192,7 @@ def __len__(self) -> int:
def __getitem__(self, frames: ValidIndex) -> Molecule | Structure | Self:
"""Get a subset of the trajectory.
The output depends on the type of the input `frames`. If an int is given, return
The output depends on the type of the input frames. If an int is given, return
a pymatgen Molecule or Structure at the specified frame. If a list or a slice, return a new
trajectory with a subset of frames.
Expand Down Expand Up @@ -290,7 +290,7 @@ def get_structure(self, idx: int) -> Structure:
"""
struct = self[idx]
if isinstance(struct, Molecule):
raise TypeError("Cannot return `Structure` for `Molecule`-based `Trajectory`! Use `get_molecule` instead!")
raise TypeError("Cannot return Structure for Molecule-based Trajectory! Use get_molecule instead!")

return struct

Expand All @@ -305,17 +305,17 @@ def get_molecule(self, idx: int) -> Molecule:
"""
mol = self[idx]
if isinstance(mol, Structure):
raise TypeError("Cannot return `Molecule` for `Structure`-based `Trajectory`! Use `get_structure` instead!")
raise TypeError("Cannot return Molecule for Structure-based Trajectory! Use get_structure instead!")

return mol

def to_positions(self) -> None:
"""Convert displacements between consecutive frames into positions.
`base_positions` and `coords` should both be in fractional coords or
base_positions and coords should both be in fractional coords or
absolute coords.
This is the opposite operation of `to_displacements()`.
This is the opposite operation of to_displacements().
"""
if not self.coords_are_displacement:
return
Expand All @@ -327,11 +327,11 @@ def to_positions(self) -> None:
def to_displacements(self) -> None:
"""Convert positions of trajectory into displacements between consecutive frames.
`base_positions` and `coords` should both be in fractional coords. Does
base_positions and coords should both be in fractional coords. Does
not work for absolute coords because the atoms are to be wrapped into the
simulation box.
This is the opposite operation of `to_positions()`.
This is the opposite operation of to_positions().
"""
if self.coords_are_displacement:
return
Expand Down Expand Up @@ -367,7 +367,7 @@ def extend(self, trajectory: Self) -> None:
self.lattice is not None # is structures
and trajectory.lattice is None # is molecules
):
raise ValueError("Cannot combine `Molecule`- and `Structure`-based `Trajectory`. objects.")
raise ValueError("Cannot combine Molecule- and Structure-based Trajectory. objects.")

if self.time_step != trajectory.time_step:
raise ValueError(
Expand Down Expand Up @@ -430,7 +430,7 @@ def write_Xdatcar(
significant_figures: Significant figures in the output file.
"""
if self.lattice is None:
raise TypeError("`write_Xdatcar` can only be used with `Structure`-based `Trajectory` objects!")
raise TypeError("write_Xdatcar can only be used with Structure-based Trajectory objects!")

# Ensure trajectory is in position form
self.to_positions()
Expand Down
8 changes: 4 additions & 4 deletions tests/core/test_trajectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,13 +526,13 @@ def test_incorrect_dims(self):
]
wrong_dim_coords = [[1.5, -0, 0, 1], [1.9, -1.2, 0, 1]]

with pytest.raises(ValueError, match=re.escape("`lattice` must have shape (M, 3, 3)!")):
with pytest.raises(ValueError, match=re.escape("lattice must have shape (M, 3, 3)!")):
Trajectory(species=species, coords=coords, lattice=short_lattice)
with pytest.raises(ValueError, match=re.escape("lattice` must have shape (3, 3) or (M, 3, 3)")):
with pytest.raises(ValueError, match=re.escape("lattice must have shape (3, 3) or (M, 3, 3)")):
Trajectory(species=species, coords=coords, lattice=unphysical_lattice)
with pytest.raises(ValueError, match="must have the same number of sites!"):
Trajectory(species=species, coords=extra_coords, lattice=const_lattice)
with pytest.raises(ValueError, match=re.escape("`coords` must have shape (M, N, 3)")):
with pytest.raises(ValueError, match=re.escape("coords must have shape (M, N, 3)")):
Trajectory(species=species, coords=unphysical_coords, lattice=const_lattice)
with pytest.raises(ValueError, match="`coords` must have 3 dimensions!"):
with pytest.raises(ValueError, match="coords must have 3 dimensions!"):
Trajectory(species=species, coords=wrong_dim_coords, lattice=const_lattice)

0 comments on commit a3164dd

Please sign in to comment.