Struct RawPoscar

Source
pub struct RawPoscar {
    pub comment: String,
    pub scale: ScaleLine,
    pub lattice_vectors: [[f64; 3]; 3],
    pub group_symbols: Option<Vec<String>>,
    pub group_counts: Vec<usize>,
    pub positions: Coords,
    pub velocities: Option<Coords>,
    pub dynamics: Option<Vec<[bool; 3]>>,
    /* private fields */
}
Expand description

Unencumbered struct form of a Poscar with public data members.

This is basically the Poscar type, minus all the type-protected invariants which ensure that it can be printed.

§General notes

Working with this type requires you to be familiar with the POSCAR format. Its fields map one-to-one with the sections of a POSCAR file. Please see the VASP documentation for help regarding its semantics.

Important: not mentioned on that page is the symbols line, which may appear right after the lattice vectors, before the counts. The number of symbols must match the number of counts. Example with a symbols line:

Cubic BN
   3.57
 0.0 0.5 0.5
 0.5 0.0 0.5
 0.5 0.5 0.0
   B N
   1 1
Direct
 0.00 0.00 0.00
 0.25 0.25 0.25

§Construction

§From data

A RawPoscar can be constructed using the Builder API.

use vasp_poscar::{Builder, ScaleLine, Coords};

let poscar =
    Builder::new()
    .comment("Cubic BN")
    .scale(ScaleLine::Factor(3.57))
    .lattice_vectors(&[
        [0.0, 0.5, 0.5],
        [0.5, 0.0, 0.5],
        [0.5, 0.5, 0.0],
    ])
    .group_symbols(vec!["B", "N"])
    .group_counts(vec![1, 1])
    .positions(Coords::Frac(vec![
        [0.00, 0.00, 0.00],
        [0.25, 0.25, 0.25],
    ]))
    .build_raw();

§From a file

You may parse the file into a Poscar first.

let poscar = Poscar::from_path("tests/POSCAR")?.into_raw();

§Manipulation

All fields are public, barring a single trivial private field used to prevent construction. You can freely access and manipulate the data fields as you see fit.

§Display

Because it may contain invalid data, a RawPoscar object cannot be printed. To write a RawPoscar to a file, use the validate method to obtain a Poscar first.

// suppose you have a RawPoscar
let raw = get_raw_poscar();

// validate() will "upgrade" it into a Poscar...
let poscar = raw.validate()?;
// ...which can be printed.
print!("{}", poscar);

Fields§

§comment: String§scale: ScaleLine§lattice_vectors: [[f64; 3]; 3]§group_symbols: Option<Vec<String>>§group_counts: Vec<usize>§positions: Coords§velocities: Option<Coords>§dynamics: Option<Vec<[bool; 3]>>

Implementations§

Source§

impl RawPoscar

Source

pub fn validate(self) -> Result<Poscar, ValidationError>

Convert into a Poscar object after checking its invariants.

To see what those invariants are, check the docs for ValidationError.

Trait Implementations§

Source§

impl Clone for RawPoscar

Source§

fn clone(&self) -> RawPoscar

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RawPoscar

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.