fn read(&self, filename: String) -> ReadFunction {
        // the voxel origin in cube files is (0.5, 0.5, 0.5)
        let mut voxel_origin = [0.5f64; 3];

        println!("Reading {} as cube format:", filename);
        // find the start and end points of the density as well as the total file size
        let (start, grid_pts) = {
            // open the file in a buffer reader
            let mut reader = BufReader::open(filename.clone())?;

            let mut buffer = String::new();
            let mut pos = 0;
            // first two lines are comments
            for _ in 0..2 {
                let size = match reader.read_line(&mut buffer) {
                    Some(line) => {
                        let (_, size) = line?;
                        size
                    }
                    None => 0,
                };
                pos += size;
            }
            // lets start trying to match
            let natoms = match reader.read_line(&mut buffer) {
                Some(line) => {
                    let (text, size) = line?;
                    pos += size;
                    let split = text
                        .trim()
                        .split_whitespace()
                        .map(|x| x.parse::<f64>())
                        .collect::<Vec<Result<f64, std::num::ParseFloatError>>>(
                        );
                    if split.len() == 5 && split[4] != Ok(1.) {
                        panic!(
                            "Error(Unsuppoerted): Multiple values per voxel."
                        );
                    }
                    let natoms = match split[0] {
                        Ok(x) => x as isize,
                        Err(_) => panic!("Error: Cannot read {} as cube file.",
                                         filename),
                    };
                    for i in 0..3 {
                        voxel_origin[i] += match split[i + 1] {
                            Ok(x) => x,
                            Err(_) => {
                                panic!("Error: Cannot read {} as cube file.",
                                       filename)
                            }
                        };
                    }
                    natoms
                }
                None => panic!("Error: Cannot read {} as cube file.", filename),
            };
            if natoms < 0 {
                panic!("Error(Unsuppoerted): Multiple values per voxel.");
            }
            let mut grid_pts = [0usize; 3];
            for gp in &mut grid_pts {
                *gp = match reader.read_line(&mut buffer) {
                    Some(line) => {
                        let (text, size) = line?;
                        pos += size;
                        match text.trim().split_whitespace().next() {
                            Some(x) => match x.parse::<usize>() {
                                Ok(x) => x,
                                Err(_) => panic!(
                                    "Error: Cannot read {} as cube file.",
                                    filename
                                ),
                            },
                            None => {
                                panic!("Error: Cannot read {} as cube file.",
                                       filename)
                            }
                        }
                    }
                    None => {
                        panic!("Error: Cannot read {} as cube file.", filename)
                    }
                }
            }
            for _ in 0..natoms.abs() {
                match reader.read_line(&mut buffer) {
                    Some(line) => {
                        let (_, size) = line?;
                        pos += size;
                    }
                    None => {
                        panic!("Error: Cannot read {} as cube file.", filename)
                    }
                }
            }
            (pos, grid_pts)
        };
        // Now we know where everything is so let's work out what to do
        // Start by making vector of start and end points of the densities
        let mut file = File::open(filename)?;
        let total = file.metadata()?.len();
        // assign Vectos with the capacity of what it is to hold
        let mut xyz_b = Vec::with_capacity(start);
        let mut density_b = Vec::with_capacity(total as usize - start);
        // read the xyz information into xyz_b
        let _ = <File as Read>::by_ref(&mut file).take(start as u64)
                                                 .read_to_end(&mut xyz_b)?;
        // read the total charge density into density_b
        let _ = <File as Read>::by_ref(&mut file).take(total - start as u64)
                                                 .read_to_end(&mut density_b)?;
        // convert the bytes we have read into a String and an Atoms struct
        let xyz = String::from_utf8(xyz_b).unwrap();
        let atoms = self.to_atoms(xyz);
        // convert out of Bohr
        let density = String::from_utf8(density_b).unwrap()
                                                  .split_whitespace()
                                                  .map(|x| {
                                                      x.parse::<f64>().unwrap()
                                                      / VOLUME_UNITS
                                                  })
                                                  .collect::<Vec<f64>>();
        println!("File read successfully.");
        Ok((voxel_origin, grid_pts, atoms, vec![density]))
    }
/// reads a cube file from filename.
reads a cube file from filename.
reads a cube file from filename .
fn read(&self, filename: String) -> ReadFunction {
        // the voxel origin in cube files is (0.5, 0.5, 0.5)
        let mut voxel_origin = [0.5f64; 3];
        println!("Reading {} as cube format:", filename);
        // find the start and end points of the density as well as the total file size
        let (start, grid_pts) = {
            // open the file in a buffer reader
            let mut reader = BufReader::open(filename.clone())?;
            let mut buffer = String::new();
            let mut pos = 0;
            // first two lines are comments
            for _ in 0..2 {
                let size = match reader.read_line(&mut buffer) {
                    Some(line) => {
                        let (_, size) = line?;
                        size
                    }
                    None => 0,
                };
                pos += size;
            }
            // lets start trying to match
            let natoms = match reader.read_line(&mut buffer) {
                Some(line) => {
                    let (text, size) = line?;
                    pos += size;
                    let split = text
                        .trim()
                        .split_whitespace()
                        .map(|x| x.parse::<f64>())
                        .collect::<Vec<Result<f64, std::num::ParseFloatError>>>(
                        );
                    if split.len() == 5 && split[4] != Ok(1.) {
                        panic!(
                            "Error(Unsuppoerted): Multiple values per voxel."
                        );
                    }
                    let natoms = match split[0] {
                        Ok(x) => x as isize,
                        Err(_) => panic!("Error: Cannot read {} as cube file.",
                                         filename),
                    };
                    for i in 0..3 {
                        voxel_origin[i] += match split[i + 1] {
                            Ok(x) => x,
                            Err(_) => {
                                panic!("Error: Cannot read {} as cube file.",
                                       filename)
                            }
                        };
                    }
                    natoms
                }
                None => panic!("Error: Cannot read {} as cube file.", filename),
            };
            if natoms < 0 {
                panic!("Error(Unsuppoerted): Multiple values per voxel.");
            }
            let mut grid_pts = [0usize; 3];
            for gp in &mut grid_pts {
                *gp = match reader.read_line(&mut buffer) {
                    Some(line) => {
                        let (text, size) = line?;
                        pos += size;
                        match text.trim().split_whitespace().next() {
                            Some(x) => match x.parse::<usize>() {
                                Ok(x) => x,
                                Err(_) => panic!(
                                    "Error: Cannot read {} as cube file.",
                                    filename
                                ),
                            },
                            None => {
                                panic!("Error: Cannot read {} as cube file.",
                                       filename)
                            }
                        }
                    }
                    None => {
                        panic!("Error: Cannot read {} as cube file.", filename)
                    }
                }
            }
            for _ in 0..natoms.abs() {
                match reader.read_line(&mut buffer) {
                    Some(line) => {
                        let (_, size) = line?;
                        pos += size;
                    }
                    None => {
                        panic!("Error: Cannot read {} as cube file.", filename)
                    }
                }
            }
            (pos, grid_pts)
        };
        // Now we know where everything is so let's work out what to do
        // Start by making vector of start and end points of the densities
        let mut file = File::open(filename)?;
        let total = file.metadata()?.len();
        // assign Vectos with the capacity of what it is to hold
        let mut xyz_b = Vec::with_capacity(start);
        let mut density_b = Vec::with_capacity(total as usize - start);
        // read the xyz information into xyz_b
        let _ = <File as Read>::by_ref(&mut file).take(start as u64)
                                                 .read_to_end(&mut xyz_b)?;
        // read the total charge density into density_b
        let _ = <File as Read>::by_ref(&mut file).take(total - start as u64)
                                                 .read_to_end(&mut density_b)?;
        // convert the bytes we have read into a String and an Atoms struct
        let xyz = String::from_utf8(xyz_b).unwrap();
        let atoms = self.to_atoms(xyz);
        // convert out of Bohr
        let density = String::from_utf8(density_b).unwrap()
                                                  .split_whitespace()
                                                  .map(|x| {
                                                      x.parse::<f64>().unwrap()
                                                      / VOLUME_UNITS
                                                  })
                                                  .collect::<Vec<f64>>();
        println!("File read successfully.");
        Ok((voxel_origin, grid_pts, atoms, vec![density]))
    }
fn read ( & self , filename : String ) -> ReadFunction { // the voxel origin in cube files is (0.5, 0.5, 0.5) let mut voxel_origin = [ 0.5f64 ; 3 ] ; println ! ( " " filename ) ; // find the start and end points of the density as well as the total file size let ( start , grid_pts ) = { // open the file in a buffer reader let mut reader = BufReader :: open ( filename . clone ( ) ) ? ; let mut buffer = String :: new ( ) ; let mut pos = 0 ; // first two lines are comments for _ in 0 .. 2 { let size = match reader . read_line ( & mut buffer ) { Some ( line ) => { let ( _ , size ) = line ? ; size } None => 0 , } ; pos += size ; } // lets start trying to match let natoms = match reader . read_line ( & mut buffer ) { Some ( line ) => { let ( text , size ) = line ? ; pos += size ; let split = text . trim ( ) . split_whitespace ( ) . map ( | x | x . parse :: < f64 > ( ) ) . collect :: < Vec < Result < f64 , std :: num :: ParseFloatError > > > ( ) ; if split . len ( ) == 5 && split [ 4 ] != Ok ( 1. ) { panic ! ( " " ) ; } let natoms = match split [ 0 ] { Ok ( x ) => x as isize , Err ( _ ) => panic ! ( " " filename ) , } ; for i in 0 .. 3 { voxel_origin [ i ] += match split [ i + 1 ] { Ok ( x ) => x , Err ( _ ) => { panic ! ( " " filename ) } } ; } natoms } None => panic ! ( " " filename ) , } ; if natoms < 0 { panic ! ( " " ) ; } let mut grid_pts = [ 0usize ; 3 ] ; for gp in & mut grid_pts { * gp = match reader . read_line ( & mut buffer ) { Some ( line ) => { let ( text , size ) = line ? ; pos += size ; match text . trim ( ) . split_whitespace ( ) . next ( ) { Some ( x ) => match x . parse :: < usize > ( ) { Ok ( x ) => x , Err ( _ ) => panic ! ( " " filename ) , } , None => { panic ! ( " " filename ) } } } None => { panic ! ( " " filename ) } } } for _ in 0 .. natoms . abs ( ) { match reader . read_line ( & mut buffer ) { Some ( line ) => { let ( _ , size ) = line ? ; pos += size ; } None => { panic ! ( " " filename ) } } } ( pos , grid_pts ) } ; // Now we know where everything is so let's work out what to do // Start by making vector of start and end points of the densities let mut file = File :: open ( filename ) ? ; let total = file . metadata ( ) ? . len ( ) ; // assign Vectos with the capacity of what it is to hold let mut xyz_b = Vec :: with_capacity ( start ) ; let mut density_b = Vec :: with_capacity ( total as usize - start ) ; // read the xyz information into xyz_b let _ = < File as Read > :: by_ref ( & mut file ) . take ( start as u64 ) . read_to_end ( & mut xyz_b ) ? ; // read the total charge density into density_b let _ = < File as Read > :: by_ref ( & mut file ) . take ( total - start as u64 ) . read_to_end ( & mut density_b ) ? ; // convert the bytes we have read into a String and an Atoms struct let xyz = String :: from_utf8 ( xyz_b ) . unwrap ( ) ; let atoms = self . to_atoms ( xyz ) ; // convert out of Bohr let density = String :: from_utf8 ( density_b ) . unwrap ( ) . split_whitespace ( ) . map ( | x | { x . parse :: < f64 > ( ) . unwrap ( ) / VOLUME_UNITS } ) . collect :: < Vec < f64 > > ( ) ; println ! ( " " ) ; Ok ( ( voxel_origin , grid_pts , atoms , vec ! [ density ] ) ) }
reads a cube file from filename.
reads a cube file from filename .
&self
filename
String
&self
filename
String