pub struct CellDocument {
pub lattice: Lattice,
pub positions: Positions,
pub kpoints: KpointsParams,
pub spectral: SpectralParams,
pub optics_magres: OpticsMagresParams,
pub symmetry: SymmetryParams,
pub constraints: ConstraintsParams,
pub external_fields: ExternalFieldParams,
pub species: SpeciesParams,
pub phonon: PhononParams,
pub phonon_fine: PhononFineParams,
pub dynamics: DynamicsParams,
}Expand description
Complete representation of a CASTEP .cell file.
This is the primary type for working with CASTEP cell files. It contains all structural information, calculation parameters, and optional blocks that can appear in a cell file.
§Required Fields
All other fields are optional and correspond to specific CASTEP features.
§Construction
Use the builder pattern (via bon) for ergonomic construction:
use castep_cell_io::CellDocument;
let doc = CellDocument::builder()
.lattice(todo!()) // LatticeCart - automatically wrapped in Lattice::Cart
.positions(todo!()) // PositionsFrac/PositionsAbs - automatically wrapped
.build();§Parsing and Serialization
Implements FromCellFile for parsing and ToCellFile for serialization:
use castep_cell_io::CellDocument;
use castep_cell_fmt::{ToCellFile, format::to_string_many_spaced};
// Parse from string
let input = std::fs::read_to_string("input.cell")?;
let doc = castep_cell_fmt::parse::<CellDocument>(&input)?;
// Serialize back to CASTEP format
let cells = doc.to_cell_file();
let output = to_string_many_spaced(&cells);§Optional Blocks (via Cell Document Groups)
The document organizes optional blocks into logical sub-groups,
mirroring the ParamDocument pattern:
- K-points:
kpoints— SCF k-point sampling - Spectral:
spectral— BS_ and SPECTRAL_ k-point paths - Optics/Magres:
optics_magres— optics and magnetic resonance k-points - Symmetry:
symmetry— symmetry operations and generation - Constraints:
constraints— ionic and cell constraints - External fields:
external_fields— electric field and pressure - Species:
species— masses, pseudopotentials, Hubbard U - Phonon:
phonon— coarse phonon k-point settings - Phonon fine:
phonon_fine— fine phonon k-point settings - Dynamics:
dynamics— ionic velocities for MD
Fields§
§lattice: LatticeLattice vectors defining the simulation cell.
Required field. Defines the periodic boundary conditions.
positions: PositionsAtomic positions within the cell.
Required field. Can be fractional or absolute coordinates.
kpoints: KpointsParamsSCF k-point sampling parameters.
Contains KPOINTS_LIST, KPOINTS_MP_GRID, KPOINTS_MP_SPACING, and KPOINTS_MP_OFFSET.
spectral: SpectralParamsSpectral/BS k-point parameters.
Contains BS_ and SPECTRAL_ prefixed k-point types for band structure calculations.
optics_magres: OpticsMagresParamsOptics and magnetic resonance k-point lists.
Contains OPTICS_KPOINTS_LIST and MAGRES_KPOINTS_LIST.
symmetry: SymmetryParamsSymmetry parameters.
Contains SYMMETRY_OPS, SYMMETRY_GENERATE, and SYMMETRY_TOL.
constraints: ConstraintsParamsMovement constraints for ions and cell.
Contains FIX_COM, IONIC_CONSTRAINTS, NONLINEAR_CONSTRAINTS, FIX_ALL_IONS, FIX_ALL_CELL, CELL_CONSTRAINTS, and FIX_VOL.
external_fields: ExternalFieldParamsExternal field parameters.
Contains EXTERNAL_EFIELD and EXTERNAL_PRESSURE.
species: SpeciesParamsSpecies properties.
Contains SPECIES_MASS, SPECIES_POT, SPECIES_LCAO_STATES, SPECIES_Q, HUBBARD_U, and SEDC_CUSTOM_PARAMS.
phonon: PhononParamsPhonon (coarse) k-point parameters.
Contains phonon k-point lists, paths, MP grids, and related settings.
phonon_fine: PhononFineParamsPhonon fine k-point parameters.
Contains fine phonon k-point paths, lists, and MP grids.
dynamics: DynamicsParamsMolecular dynamics dynamics parameters.
Contains IONIC_VELOCITIES for MD restart.
Implementations§
Source§impl CellDocument
impl CellDocument
Sourcepub fn builder() -> CellDocumentBuilder
pub fn builder() -> CellDocumentBuilder
Create an instance of CellDocument using the builder syntax
Trait Implementations§
Source§impl Clone for CellDocument
impl Clone for CellDocument
Source§fn clone(&self) -> CellDocument
fn clone(&self) -> CellDocument
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for CellDocument
impl Debug for CellDocument
Source§impl FromCellFile for CellDocument
impl FromCellFile for CellDocument
Source§fn from_cell_file(cells: &[Cell<'_>]) -> CResult<Self>
fn from_cell_file(cells: &[Cell<'_>]) -> CResult<Self>
Parse a CellDocument from a slice of parsed Cell tokens.
This method is called by [castep_cell_fmt::parse] after tokenizing the input text.
It extracts all recognized blocks and keywords from the token stream.
§Required Blocks
%BLOCK LATTICE_CART— must be present- Either
%BLOCK POSITIONS_FRACor%BLOCK POSITIONS_ABS— must have exactly one
§Errors
Returns Error if:
- Required blocks are missing
- Block content is malformed
- Multiple position blocks are present
- Any block fails to parse according to its schema
§Example
use castep_cell_io::CellDocument;
let input = r#"
%BLOCK LATTICE_CART
10.0 0.0 0.0
0.0 10.0 0.0
0.0 0.0 10.0
%ENDBLOCK LATTICE_CART
%BLOCK POSITIONS_FRAC
Si 0.0 0.0 0.0
Si 0.25 0.25 0.25
%ENDBLOCK POSITIONS_FRAC
"#;
let doc = castep_cell_fmt::parse::<CellDocument>(input)?;Source§impl ToCellFile for CellDocument
impl ToCellFile for CellDocument
Source§fn to_cell_file(&self) -> Vec<Cell<'_>>
fn to_cell_file(&self) -> Vec<Cell<'_>>
Serialize this document to a vector of Cell tokens.
Converts the structured document back to the token representation used by
castep_cell_fmt. The tokens can then be formatted to text with
castep_cell_fmt::format.
§Block Order
Blocks are emitted in a standard order:
- Lattice and positions (required)
- K-point sampling blocks
- Constraints and flags
- External fields
- Species properties
- Phonon calculation blocks
- Dynamics (ionic velocities)
Optional blocks that are None are omitted from the output.
§Example
use castep_cell_io::CellDocument;
use castep_cell_fmt::{ToCellFile, format::to_string_many_spaced};
// Assuming you have a CellDocument instance
let doc = todo!(); // Your CellDocument instance
let cells = doc.to_cell_file();
let output = to_string_many_spaced(&cells);Auto Trait Implementations§
impl Freeze for CellDocument
impl RefUnwindSafe for CellDocument
impl Send for CellDocument
impl Sync for CellDocument
impl Unpin for CellDocument
impl UnsafeUnpin for CellDocument
impl UnwindSafe for CellDocument
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);