-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into rework_raman
- Loading branch information
Showing
7 changed files
with
144 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#! /usr/bin/env python3 | ||
|
||
from pathlib import Path | ||
|
||
import typer | ||
from ase.io import read | ||
from rich import print as echo | ||
import numpy as np | ||
|
||
|
||
def guess_format(file: Path): | ||
if "geometry.in" in file.name: | ||
return "aims" | ||
elif "poscar" in file.name.lower(): | ||
return "vasp" | ||
else: | ||
return None | ||
|
||
|
||
app = typer.Typer(pretty_exceptions_show_locals=False) | ||
|
||
|
||
@app.command() | ||
def main( | ||
file1: Path, | ||
file2: Path, | ||
format: str = None, | ||
): | ||
"""Compare two structures, find supercell matrices etc.""" | ||
echo(f"Match structures in {file1} and {file2}") | ||
echo(f"... read '{file1}'") | ||
atoms1 = read(file1, format=guess_format(file1)) | ||
echo(atoms1) | ||
echo(f"... read '{file2}'") | ||
atoms2 = read(file2, format=guess_format(file2)) | ||
echo(atoms2) | ||
|
||
echo("MATCH LATTICES") | ||
echo() | ||
|
||
cell1 = np.array(atoms1.cell) | ||
cell2 = np.array(atoms2.cell) | ||
smatrix = np.linalg.inv(cell1).T @ cell2 | ||
echo("... supercell matrix:") | ||
echo(smatrix) | ||
|
||
echo("... round to integers:") | ||
echo(smatrix.round().astype(int)) | ||
|
||
echo("... for TDEP `generate_structure`") | ||
echo(" ".join([f"{m:d}" for m in smatrix.round().astype(int).T.flatten()])) | ||
|
||
|
||
if __name__ == "__main__": | ||
app() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#! /usr/bin/env python3 | ||
|
||
from pathlib import Path | ||
|
||
import typer | ||
from ase.io import read | ||
from rich import print as echo | ||
import numpy as np | ||
|
||
|
||
def guess_format(file: Path): | ||
if "geometry.in" in file.name: | ||
return "aims" | ||
elif "poscar" in file.name.lower(): | ||
return "vasp" | ||
else: | ||
return None | ||
|
||
|
||
app = typer.Typer(pretty_exceptions_show_locals=False) | ||
|
||
|
||
@app.command() | ||
def main( | ||
file1: Path, | ||
file2: Path, | ||
scale_atoms: bool = True, | ||
tolerance_volume: float = 0.1, | ||
format: str = None, | ||
outfile: str = None, | ||
): | ||
"""Match lattice vectors of structure in FILE2 to that in FILE1.""" | ||
echo(f"Match lattices of structures in {file1} and {file2}") | ||
echo(f"... read '{file1}'") | ||
atoms1 = read(file1, format=guess_format(file1)) | ||
echo(atoms1) | ||
echo(f"... read '{file2}'") | ||
atoms2 = read(file2, format=guess_format(file2)) | ||
echo(atoms2) | ||
|
||
echo("MATCH LATTICES") | ||
echo() | ||
|
||
cell1 = np.array(atoms1.cell) | ||
cell2 = np.array(atoms2.cell) | ||
smatrix = np.linalg.inv(cell1).T @ cell2 | ||
echo("... supercell matrix:") | ||
echo(smatrix) | ||
echo() | ||
|
||
volume_change = np.linalg.det(smatrix - np.eye(3)) | ||
|
||
echo(f"... volume change: {volume_change}") | ||
|
||
if abs(volume_change) > tolerance_volume: | ||
raise ValueError("DETERMINANT OF cell changes by more than tolerance!") | ||
|
||
atoms2.set_cell(atoms1.cell, scale_atoms=scale_atoms) | ||
|
||
if outfile is None: | ||
outfile = file2.name + ".matched" | ||
|
||
echo(f'... write to "{outfile}"') | ||
atoms2.write(outfile, format=format) | ||
|
||
|
||
if __name__ == "__main__": | ||
app() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters