Skip to content

Commit

Permalink
Merge pull request #2 from Ionizing/dev
Browse files Browse the repository at this point in the history
POSCAR option and failure on OUTCARs contain "Primitive cell"
  • Loading branch information
Ionizing committed Mar 4, 2021
2 parents 1031e40 + e884576 commit 56f9f4f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
20 changes: 18 additions & 2 deletions src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,21 @@ impl IonicIterationsFormat {

impl fmt::Display for IonicIterationsFormat {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let nions = self._data[0].forces.len();
let dynamics =
if let Ok(poscar) = Poscar::from_path("POSCAR") {
info!("POSCAR was read. Filtering relaxed ions... {}",
"Note: the force info listed below doesn't contain fixed atoms");
let dynamics = poscar.into_raw().dynamics.unwrap_or(vec![[true; 3]; nions]);
assert_eq!(nions, dynamics.len(), "Inconsistent ion numbers from POSCAR and OUTCAR");
dynamics
} else { vec![[true; 3]; nions] }
.into_iter()
.map(|v| {
[v[0] as i32 as f64, v[1] as i32 as f64, v[2] as i32 as f64]
})
.collect::<Vec<_>>();

let mut ce: f64 = 0.0;

// Prepare Header
Expand Down Expand Up @@ -145,8 +160,9 @@ impl fmt::Display for IonicIterationsFormat {
if self.print_log10de { line += &format!(" {:4.1}", de.abs().log10()); }

let fsize = it.forces.iter()
.map(|f| (f[0]*f[0] + f[1]*f[1] + f[2]*f[2]).sqrt())
.collect::<Vec<_>>();
.zip(dynamics.iter())
.map(|(f, d)| (f[0]*f[0]*d[0] + f[1]*f[1]*d[1] + f[2]*f[2]*d[2]).sqrt())
.collect::<Vec<_>>();

if self.print_favg {
line += &format!(" {:6.3}", fsize.iter().sum::<f64>() / it.forces.len() as f64);
Expand Down
17 changes: 12 additions & 5 deletions src/outcar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,11 +358,10 @@ impl Outcar {
}

fn parse_opt_cells(context: &str) -> Vec<Mat33<f64>> {
let skip_cnt: usize = if context.find(" old parameters").is_some() {
2
} else {
1
};
let skip_cnt: usize = 1 +
context.find(" old parameters").is_some() as usize +
context.find("Primitive cell").is_some() as usize;

Regex::new(r"direct lattice vectors")
.unwrap()
.find_iter(context)
Expand Down Expand Up @@ -854,6 +853,14 @@ mod tests{
4.001368000 0.000000000 0.000000000 0.249914529 0.000000000 0.000000000
0.000000000 4.001368000 0.000000000 0.000000000 0.249914529 0.000000000
0.000000000 0.000000000 4.215744000 0.000000000 0.000000000 0.237206054
--
Primitive cell
volume of cell : 47993.5183
direct lattice vectors reciprocal lattice vectors
4.001368000 0.000000000 0.000000000 0.249914529 0.000000000 0.000000000
0.000000000 4.001368000 0.000000000 0.000000000 0.249914529 0.000000000
0.000000000 0.000000000 4.215744000 0.000000000 0.000000000 0.237206054
--
direct lattice vectors reciprocal lattice vectors
6.000000000 0.000000000 0.000000000 0.166666667 0.000000000 0.000000000
Expand Down

0 comments on commit 56f9f4f

Please sign in to comment.