Skip to content

Commit

Permalink
Merge branch 'main' into rework_raman
Browse files Browse the repository at this point in the history
  • Loading branch information
flokno committed Aug 27, 2024
2 parents 1816a1b + dbaee0b commit 2da6470
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 4 deletions.
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ include =

[options.entry_points]
console_scripts =
ase_compare_structures = tdeptools.scripts.ase_compare_structures:app
ase_geometry_info = tdeptools.scripts.ase_geometry_info:app
ase_geometry_refine = tdeptools.scripts.ase_geometry_refine:app
ase_get_distance_table = tdeptools.scripts.ase_get_distance_table:app
ase_join_pw_ph = tdeptools.scripts.ase_join_pw_ph:app
ase_match_lattices = tdeptools.scripts.ase_match_lattices:app
ase_strain_sample = tdeptools.scripts.ase_strain_sample:app
ase_suggest_kpoints = tdeptools.scripts.ase_suggest_kpoints:app
tdep_compute_raman_intensities = tdeptools.scripts.tdep_compute_raman_intensities:app
Expand Down
55 changes: 55 additions & 0 deletions tdeptools/scripts/ase_compare_structures.py
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()
4 changes: 2 additions & 2 deletions tdeptools/scripts/ase_geometry_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def inform(atoms, symprec=default_symprec, max_atoms=20, verbose=False):
for key, val in atoms.cell.bandpath().special_points.items():
echo(f" {key}: {val}")

if symprec is not None:
if symprec is not None and all(atoms.pbc):
echo()
echo("Report symmetry information from spglib:")
sds = get_symmetry_dataset(atoms, symprec=symprec)
Expand All @@ -106,7 +106,7 @@ def inform(atoms, symprec=default_symprec, max_atoms=20, verbose=False):
echo(f" {vec}")

# Info
for (key, val) in atoms.info.items():
for key, val in atoms.info.items():
echo(f" {key:10s}: {val}")


Expand Down
68 changes: 68 additions & 0 deletions tdeptools/scripts/ase_match_lattices.py
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()
6 changes: 6 additions & 0 deletions tdeptools/scripts/tdep_create_next_iteration.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def main(
create_sample_folder: bool = True,
file_geometry: str = "geometry.in",
files_control: List[Path] = None,
files_aux: List[Path] = None,
predictions: bool = False,
file_predictions: Path = "predictions.nc",
format: str = "aims",
Expand Down Expand Up @@ -115,6 +116,11 @@ def main(
for file in files_control:
shutil.copy(file, folder_new)

if files_aux is not None:
echo(f".. copy aux files: {files_aux}")
for file in files_aux:
shutil.copy(file, folder_new)

if create_sample_folder:
files = sorted(folder_new.glob("contcar_conf*"))
create_sample_folders(
Expand Down
11 changes: 10 additions & 1 deletion tdeptools/scripts/tdep_displace_atoms.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
def main(
file: Path,
file_unitcell: Path = None,
nmax: int = None,
plusminus: bool = True,
displacement: float = typer.Option(default_displacement, help="displacement in Å"),
format: str = "vasp",
Expand Down Expand Up @@ -60,8 +61,16 @@ def main(
else:
signs = (1,)

natoms = len(atoms)

if nmax is None:
nmax = natoms

echo(f"... number of atoms: {natoms}")
echo(f"... number of displacements: {nmax}")

counter = 0
for nn in list_match:
for nn in list_match[:nmax]:
for ii in range(3):
for ss in signs:
counter += 1
Expand Down
2 changes: 1 addition & 1 deletion tdeptools/scripts/tdep_relax_cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def _array_to_str(array, decimals=6):
return f"[ {rep} ]"


app = typer.Typer()
app = typer.Typer(pretty_exceptions_show_locals=False)


@app.command()
Expand Down

0 comments on commit 2da6470

Please sign in to comment.