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
impl RawPoscar
Sourcepub fn validate(self) -> Result<Poscar, ValidationError>
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
.