pub fn new(arguments: ArgMatches) -> Self {
        // Collect file
        let file = match arguments.value_of("file") {
            Some(f) => String::from(f),
            None => String::new(),
        };

        // Collect write charge info
        let output = match arguments.value_of("output") {
            Some("atoms") => {
                let atoms = match arguments.values_of("index") {
                    Some(vec) => {
                        vec.map(|s| match s.parse::<usize>() {
                            Ok(u) => match u.checked_sub(1) {
                                Some(u) => u as isize,
                                None => {
                                    panic!("Counting for index starts at 1.")
                                }
                            },
                            Err(_) => {
                                panic!("Unable to parse index, ({}) to usize.",
                                       s)
                            }
                        })
                        .collect::<Vec<isize>>()
                    }
                    None => Vec::with_capacity(0),
                };
                WriteType::Atom(atoms)
            }
            Some("volumes") => {
                let volumes = match arguments.values_of("index") {
                    Some(vec) => {
                        vec.map(|s| match s.parse::<usize>() {
                            Ok(u) => match u.checked_sub(1) {
                                Some(u) => u as isize,
                                None => {
                                    panic!("Counting for index starts at 1.")
                                }
                            },
                            Err(_) => {
                                panic!("Unable to parse index, ({}) to usize.",
                                       s)
                            }
                        })
                        .collect::<Vec<isize>>()
                    }
                    None => Vec::with_capacity(0),
                };
                WriteType::Volume(volumes)
            }
            _ => WriteType::None,
        };

        // Collect file type
        let file_type = arguments.value_of("file type").map(String::from);
        let file_type = match file_type {
            Some(ftype) => {
                if ftype.eq("cube") {
                    FileType::Cube
                } else {
                    FileType::Vasp
                }
            }
            None => {
                if file.to_lowercase().contains("cube") {
                    FileType::Cube
                } else if file.to_lowercase().contains("car") {
                    FileType::Vasp
                } else {
                    println!("Error: File-type cannot be infered, attempting to read as VASP");
                    FileType::Vasp
                }
            }
        };
        // Collect weight tolerance
        let weight_tolerance = match arguments.value_of("weight tolerance") {
            Some(x) => match x.parse::<f64>() {
                Ok(x) => x.max(1E-13),
                Err(e) => {
                    panic!("Couldn't parse weight tolerance into float:\n{}", e)
                }
            },
            _ => 1E-8,
        };
        // Collect maxima tolerance
        let maxima_tolerance = match arguments.value_of("maxima tolerance") {
            Some(x) => match x.parse::<f64>() {
                Ok(x) => x,
                Err(e) => {
                    panic!("Couldn't parse maxima tolerance into float:\n{}", e)
                }
            },
            _ => 1E-6,
        };
        // Collect threads
        // safe to unwrap as threads has a default value of 0
        let threads = {
            match arguments.value_of("threads").unwrap().parse::<usize>() {
                Ok(0) => num_cpus::get().min(12),
                Ok(x) => x,
                Err(e) => panic!("Couldn't parse threads into integer:\n{}", e),
            }
        };
        // Collect vacuum tolerance
        let vacuum_tolerance = match arguments.value_of("vacuum tolerance") {
            Some(s) => {
                if s.eq("auto") {
                    Some(1E-6)
                } else {
                    match s.parse::<f64>() {
                        Ok(x) => Some(x),
                        Err(e) => panic!(
                            "Couldn't parse vacuum tolerance into float:\n{}",
                            e
                        ),
                    }
                }
            }
            None => None,
        };
        // Collect reference files
        let references: Vec<_> = if arguments.is_present("all electron") {
            if let FileType::Vasp = file_type {
                vec!["AECCAR0", "AECCAR2"]
            } else {
                panic!("Error: Cannot use AECCAR flag for non VASP file-types.")
            }
        } else {
            match arguments.values_of("reference") {
                Some(x) => x.collect(),
                None => Vec::with_capacity(0),
            }
        };
        let reference = match references.len() {
            2 => Reference::Two(String::from(references[0]),
                                String::from(references[1])),
            1 => Reference::One(String::from(references[0])),
            _ => Reference::None,
        };
        let spin = arguments.value_of("spin").map(String::from);
        let verbosity = match arguments.occurrences_of("verbosity") {
            0 => Verbosity::Atoms,
            1 => Verbosity::Bader,
            _ => Verbosity::Full,
        };
        Self { file,
               file_type,
               weight_tolerance,
               maxima_tolerance,
               output,
               reference,
               spin,
               threads,
               vacuum_tolerance,
               verbosity }
    }
/// Initialises the structure from the command-line arguments.
Initialises the structure from the command-line arguments.
Initialises the structure from the command - line arguments .
pub fn new(arguments: ArgMatches) -> Self {
        // Collect file
        let file = match arguments.value_of("file") {
            Some(f) => String::from(f),
            None => String::new(),
        };
        // Collect write charge info
        let output = match arguments.value_of("output") {
            Some("atoms") => {
                let atoms = match arguments.values_of("index") {
                    Some(vec) => {
                        vec.map(|s| match s.parse::<usize>() {
                            Ok(u) => match u.checked_sub(1) {
                                Some(u) => u as isize,
                                None => {
                                    panic!("Counting for index starts at 1.")
                                }
                            },
                            Err(_) => {
                                panic!("Unable to parse index, ({}) to usize.",
                                       s)
                            }
                        })
                        .collect::<Vec<isize>>()
                    }
                    None => Vec::with_capacity(0),
                };
                WriteType::Atom(atoms)
            }
            Some("volumes") => {
                let volumes = match arguments.values_of("index") {
                    Some(vec) => {
                        vec.map(|s| match s.parse::<usize>() {
                            Ok(u) => match u.checked_sub(1) {
                                Some(u) => u as isize,
                                None => {
                                    panic!("Counting for index starts at 1.")
                                }
                            },
                            Err(_) => {
                                panic!("Unable to parse index, ({}) to usize.",
                                       s)
                            }
                        })
                        .collect::<Vec<isize>>()
                    }
                    None => Vec::with_capacity(0),
                };
                WriteType::Volume(volumes)
            }
            _ => WriteType::None,
        };
        // Collect file type
        let file_type = arguments.value_of("file type").map(String::from);
        let file_type = match file_type {
            Some(ftype) => {
                if ftype.eq("cube") {
                    FileType::Cube
                } else {
                    FileType::Vasp
                }
            }
            None => {
                if file.to_lowercase().contains("cube") {
                    FileType::Cube
                } else if file.to_lowercase().contains("car") {
                    FileType::Vasp
                } else {
                    println!("Error: File-type cannot be infered, attempting to read as VASP");
                    FileType::Vasp
                }
            }
        };
        // Collect weight tolerance
        let weight_tolerance = match arguments.value_of("weight tolerance") {
            Some(x) => match x.parse::<f64>() {
                Ok(x) => x.max(1E-13),
                Err(e) => {
                    panic!("Couldn't parse weight tolerance into float:\n{}", e)
                }
            },
            _ => 1E-8,
        };
        // Collect maxima tolerance
        let maxima_tolerance = match arguments.value_of("maxima tolerance") {
            Some(x) => match x.parse::<f64>() {
                Ok(x) => x,
                Err(e) => {
                    panic!("Couldn't parse maxima tolerance into float:\n{}", e)
                }
            },
            _ => 1E-6,
        };
        // Collect threads
        // safe to unwrap as threads has a default value of 0
        let threads = {
            match arguments.value_of("threads").unwrap().parse::<usize>() {
                Ok(0) => num_cpus::get().min(12),
                Ok(x) => x,
                Err(e) => panic!("Couldn't parse threads into integer:\n{}", e),
            }
        };
        // Collect vacuum tolerance
        let vacuum_tolerance = match arguments.value_of("vacuum tolerance") {
            Some(s) => {
                if s.eq("auto") {
                    Some(1E-6)
                } else {
                    match s.parse::<f64>() {
                        Ok(x) => Some(x),
                        Err(e) => panic!(
                            "Couldn't parse vacuum tolerance into float:\n{}",
                            e
                        ),
                    }
                }
            }
            None => None,
        };
        // Collect reference files
        let references: Vec<_> = if arguments.is_present("all electron") {
            if let FileType::Vasp = file_type {
                vec!["AECCAR0", "AECCAR2"]
            } else {
                panic!("Error: Cannot use AECCAR flag for non VASP file-types.")
            }
        } else {
            match arguments.values_of("reference") {
                Some(x) => x.collect(),
                None => Vec::with_capacity(0),
            }
        };
        let reference = match references.len() {
            2 => Reference::Two(String::from(references[0]),
                                String::from(references[1])),
            1 => Reference::One(String::from(references[0])),
            _ => Reference::None,
        };
        let spin = arguments.value_of("spin").map(String::from);
        let verbosity = match arguments.occurrences_of("verbosity") {
            0 => Verbosity::Atoms,
            1 => Verbosity::Bader,
            _ => Verbosity::Full,
        };
        Self { file,
               file_type,
               weight_tolerance,
               maxima_tolerance,
               output,
               reference,
               spin,
               threads,
               vacuum_tolerance,
               verbosity }
    }
pub fn new ( arguments : ArgMatches ) -> Self { // Collect file let file = match arguments . value_of ( " " ) { Some ( f ) => String :: from ( f ) , None => String :: new ( ) , } ; // Collect write charge info let output = match arguments . value_of ( " " ) { Some ( " " ) => { let atoms = match arguments . values_of ( " " ) { Some ( vec ) => { vec . map ( | s | match s . parse :: < usize > ( ) { Ok ( u ) => match u . checked_sub ( 1 ) { Some ( u ) => u as isize , None => { panic ! ( " " ) } } , Err ( _ ) => { panic ! ( " " s ) } } ) . collect :: < Vec < isize > > ( ) } None => Vec :: with_capacity ( 0 ) , } ; WriteType :: Atom ( atoms ) } Some ( " " ) => { let volumes = match arguments . values_of ( " " ) { Some ( vec ) => { vec . map ( | s | match s . parse :: < usize > ( ) { Ok ( u ) => match u . checked_sub ( 1 ) { Some ( u ) => u as isize , None => { panic ! ( " " ) } } , Err ( _ ) => { panic ! ( " " s ) } } ) . collect :: < Vec < isize > > ( ) } None => Vec :: with_capacity ( 0 ) , } ; WriteType :: Volume ( volumes ) } _ => WriteType :: None , } ; // Collect file type let file_type = arguments . value_of ( " " ) . map ( String :: from ) ; let file_type = match file_type { Some ( ftype ) => { if ftype . eq ( " " ) { FileType :: Cube } else { FileType :: Vasp } } None => { if file . to_lowercase ( ) . contains ( " " ) { FileType :: Cube } else if file . to_lowercase ( ) . contains ( " " ) { FileType :: Vasp } else { println ! ( " " ) ; FileType :: Vasp } } } ; // Collect weight tolerance let weight_tolerance = match arguments . value_of ( " " ) { Some ( x ) => match x . parse :: < f64 > ( ) { Ok ( x ) => x . max ( 1E-13 ) , Err ( e ) => { panic ! ( " \n " e ) } } , _ => 1E-8 , } ; // Collect maxima tolerance let maxima_tolerance = match arguments . value_of ( " " ) { Some ( x ) => match x . parse :: < f64 > ( ) { Ok ( x ) => x , Err ( e ) => { panic ! ( " \n " e ) } } , _ => 1E-6 , } ; // Collect threads // safe to unwrap as threads has a default value of 0 let threads = { match arguments . value_of ( " " ) . unwrap ( ) . parse :: < usize > ( ) { Ok ( 0 ) => num_cpus :: get ( ) . min ( 12 ) , Ok ( x ) => x , Err ( e ) => panic ! ( " \n " e ) , } } ; // Collect vacuum tolerance let vacuum_tolerance = match arguments . value_of ( " " ) { Some ( s ) => { if s . eq ( " " ) { Some ( 1E-6 ) } else { match s . parse :: < f64 > ( ) { Ok ( x ) => Some ( x ) , Err ( e ) => panic ! ( " \n " e ) , } } } None => None , } ; // Collect reference files let references : Vec < _ > = if arguments . is_present ( " " ) { if let FileType :: Vasp = file_type { vec ! [ " " " " ] } else { panic ! ( " " ) } } else { match arguments . values_of ( " " ) { Some ( x ) => x . collect ( ) , None => Vec :: with_capacity ( 0 ) , } } ; let reference = match references . len ( ) { 2 => Reference :: Two ( String :: from ( references [ 0 ] ) , String :: from ( references [ 1 ] ) ) , 1 => Reference :: One ( String :: from ( references [ 0 ] ) ) , _ => Reference :: None , } ; let spin = arguments . value_of ( " " ) . map ( String :: from ) ; let verbosity = match arguments . occurrences_of ( " " ) { 0 => Verbosity :: Atoms , 1 => Verbosity :: Bader , _ => Verbosity :: Full , } ; Self { file , file_type , weight_tolerance , maxima_tolerance , output , reference , spin , threads , vacuum_tolerance , verbosity } }
Initialises the structure from the command-line arguments.
Initialises the structure from the command - line arguments .
arguments
ArgMatches
arguments
ArgMatches