/// Reads a POSCAR from an open file.
Reads a POSCAR from an open file.
Reads a POSCAR from an open file .
fn load_txt(f: &mut dyn BufRead) -> FailResult<Poscar>
{
    use vasp_poscar::failure::ResultExt;
    let poscar = imp::Poscar::from_reader(f).compat()?;
    let comment = poscar.comment().to_string();
    let lattice = Lattice::from(&poscar.scaled_lattice_vectors());
    let coords = match poscar.scaled_positions() {
        imp::Coords::Cart(p) => CoordsKind::Carts(p.to_vec().envee()),
        imp::Coords::Frac(p) => CoordsKind::Fracs(p.to_vec().envee()),
    };
    let group_elems = {
        // we need symbols, but prior to VASP 5 they were not even part of
        // the format, so some programs don't write them where they belong.
        // Sometimes they are used as the title comment (by phonopy, ASE...).
        let group_symbols = match poscar.group_symbols() {
            Some(iter) => iter.map(|s| s.to_string()).collect(),
            None => {
                let words = poscar.comment().split_whitespace();
                let symbols = words.map(|s| s.to_string()).collect::<Vec<_>>();
                ensure!(
                    symbols.len() == poscar.group_counts().len(),
                    "Symbols must be given either in the standard location or the POSCAR comment."
                );
                // pray for the best.  If they're not the group symbols, it is at least
                // unlikely that the next step will erroneously "succeed"
                symbols
            },
        };
        group_symbols.into_iter()
            .map(|sym| Element::from_symbol(&sym))
            .collect::<Result<Vec<Element>, _>>()?
    };
    let elements = zip_eq!(poscar.group_counts(), group_elems)
        .flat_map(|(c, elem)| std::iter::repeat(elem).take(c))
        .collect::<Vec<_>>();
    assert_eq!(elements.len(), coords.len());
    let coords = Coords::new(lattice, coords);
    Ok(Poscar { comment, coords, elements })
}
fn load_txt ( f : & mut dyn BufRead ) -> FailResult < Poscar > { use vasp_poscar :: failure :: ResultExt ; let poscar = imp :: Poscar :: from_reader ( f ) . compat ( ) ? ; let comment = poscar . comment ( ) . to_string ( ) ; let lattice = Lattice :: from ( & poscar . scaled_lattice_vectors ( ) ) ; let coords = match poscar . scaled_positions ( ) { imp :: Coords :: Cart ( p ) => CoordsKind :: Carts ( p . to_vec ( ) . envee ( ) ) , imp :: Coords :: Frac ( p ) => CoordsKind :: Fracs ( p . to_vec ( ) . envee ( ) ) , } ; let group_elems = { // we need symbols, but prior to VASP 5 they were not even part of // the format, so some programs don't write them where they belong. // Sometimes they are used as the title comment (by phonopy, ASE...). let group_symbols = match poscar . group_symbols ( ) { Some ( iter ) => iter . map ( | s | s . to_string ( ) ) . collect ( ) , None => { let words = poscar . comment ( ) . split_whitespace ( ) ; let symbols = words . map ( | s | s . to_string ( ) ) . collect :: < Vec < _ > > ( ) ; ensure ! ( symbols len ( ) poscar group_counts ( ) len ( ) " " ) ; // pray for the best.  If they're not the group symbols, it is at least // unlikely that the next step will erroneously "succeed" symbols } , } ; group_symbols . into_iter ( ) . map ( | sym | Element :: from_symbol ( & sym ) ) . collect :: < Result < Vec < Element > , _ > > ( ) ? } ; let elements = zip_eq ! ( poscar group_counts ( ) group_elems ) . flat_map ( | ( c , elem ) | std :: iter :: repeat ( elem ) . take ( c ) ) . collect :: < Vec < _ > > ( ) ; assert_eq ! ( elements len ( ) coords len ( ) ) ; let coords = Coords :: new ( lattice , coords ) ; Ok ( Poscar { comment , coords , elements } ) }
Reads a POSCAR from an open file.
Reads a POSCAR from an open file .
f
&mut dyn BufRead