From 54d0ad1b62faec36a6bac72a0ff4ecf727886a2e Mon Sep 17 00:00:00 2001 From: Benjamin Morgan Date: Thu, 9 Nov 2023 12:44:56 +0000 Subject: [PATCH 1/4] Update build.yml Updated coveralls github action --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8befbc7..d94880f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -33,9 +33,9 @@ jobs: run: | pytest --cov-config=.coveragerc --cov=vasppy --cov-report lcov - name: Coveralls GitHub Action - uses: coverallsapp/github-action@1.1.3 + uses: coverallsapp/github-action@2.2.3 with: - path-to-lcov: ./coverage.lcov + file: ./coverage.lcov github-token: ${{ secrets.GITHUB_TOKEN }} - name: Static type checking run: | From 76726d809f74de44051ac26e6793c4f0426d2a0f Mon Sep 17 00:00:00 2001 From: Benjamin Morgan Date: Thu, 9 Nov 2023 12:47:39 +0000 Subject: [PATCH 2/4] Update build.yml --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d94880f..a34bb00 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -33,7 +33,7 @@ jobs: run: | pytest --cov-config=.coveragerc --cov=vasppy --cov-report lcov - name: Coveralls GitHub Action - uses: coverallsapp/github-action@2.2.3 + uses: coverallsapp/github-action@v2 with: file: ./coverage.lcov github-token: ${{ secrets.GITHUB_TOKEN }} From 0c8570f49071b9f718005d905d4622dc7644102b Mon Sep 17 00:00:00 2001 From: Benjamin Morgan Date: Thu, 9 Nov 2023 12:54:37 +0000 Subject: [PATCH 3/4] Implements sqrt(2) x sqrt(2) supercell construction script (#27) * orthorhombic cells * Ruff fix * Ruff fix * Ruff fix * Fixing mypy error * Fixing mypy error * Fixing mypy error * Fixing mypy error * Added sqrt(2) x sqrt(2) supercell generator script * Ignoring pymatgen type hints until setuptools is fixed * Type fix --- vasppy/doscar.py | 2 +- vasppy/poscar.py | 10 +++++-- vasppy/scripts/proc_poscar.py | 8 +++++- vasppy/scripts/r2r2_expansion.py | 48 ++++++++++++++++++++++++++++++++ vasppy/xdatcar.py | 13 ++++++++- 5 files changed, 75 insertions(+), 6 deletions(-) create mode 100755 vasppy/scripts/r2r2_expansion.py diff --git a/vasppy/doscar.py b/vasppy/doscar.py index 9412d1a..570b0cf 100644 --- a/vasppy/doscar.py +++ b/vasppy/doscar.py @@ -274,7 +274,7 @@ def plot_pdos( fig, ax = plt.subplots(1, 1, figsize=(8.0, 3.0)) else: fig = None - assert(isinstance(ax, Axes)) + assert isinstance(ax, Axes) if not colors: colors = mcd.TABLEAU_COLORS assert isinstance(colors, Iterable) diff --git a/vasppy/poscar.py b/vasppy/poscar.py index 5be609d..cb59880 100644 --- a/vasppy/poscar.py +++ b/vasppy/poscar.py @@ -5,7 +5,7 @@ from vasppy import cell from vasppy.units import angstrom_to_bohr from pymatgen.core import Lattice as pmg_Lattice # type: ignore -from pymatgen.core import Structure as pmg_Structure +from pymatgen.core import Structure as pmg_Structure # type: ignore from pymatgen.io.cif import CifWriter # type: ignore from collections import Counter @@ -175,7 +175,7 @@ def output(self, coordinate_type="Direct", opts=None): if opts is None: opts = {} if not opts.get("coordinates_only"): - self.output_header(coordinate_type=coordinate_type) + self.output_header(coordinate_type=coordinate_type, opts=opts) self.output_coordinates_only(coordinate_type=coordinate_type, opts=opts) def output_header(self, coordinate_type="Direct", opts=None): @@ -183,7 +183,11 @@ def output_header(self, coordinate_type="Direct", opts=None): opts = {} print(self.title) print(self.scaling) - for row in self.cell.matrix: + if opts.get("orthorhombic"): + matrix = self.cell.matrix * np.eye(3) + else: + matrix = self.cell.matrix + for row in matrix: print("".join([" {: .10f}".format(element) for element in row])) print(" ".join(self.atoms)) print(" ".join([str(n) for n in self.atom_numbers])) diff --git a/vasppy/scripts/proc_poscar.py b/vasppy/scripts/proc_poscar.py index 5ec2f1d..f6be2c8 100755 --- a/vasppy/scripts/proc_poscar.py +++ b/vasppy/scripts/proc_poscar.py @@ -3,7 +3,6 @@ from vasppy.poscar import Poscar import argparse - def parse_command_line_arguments(): # command line arguments parser = argparse.ArgumentParser(description="Manipulates VASP POSCAR files") @@ -49,6 +48,12 @@ def parse_command_line_arguments(): action="store_true", help="label coordinates with atom number", ) + parser.add_argument( + "-o", + "--orthorhombic", + action="store_true", + help="force orthorhombic cell matrix (set off-diagonal elements to zero)", + ) parser.add_argument( "--scale", action="store_true", @@ -96,6 +101,7 @@ def main(): "numbered": args.number_atoms, "coordinates_only": args.coordinates_only, "selective": args.selective, + "orthorhombic": args.orthorhombic, } poscar.output(coordinate_type=coordinate_type, opts=output_opts) diff --git a/vasppy/scripts/r2r2_expansion.py b/vasppy/scripts/r2r2_expansion.py new file mode 100755 index 0000000..163bb25 --- /dev/null +++ b/vasppy/scripts/r2r2_expansion.py @@ -0,0 +1,48 @@ +#! /usr/bin/env python3 + +from vasppy.poscar import Poscar +import argparse +import numpy as np +from typing import Literal + +def parse_command_line_arguments(): + # command line arguments + parser = argparse.ArgumentParser(description="Generate a sqrt(2) x sqrt(2) supercell from a VASP POSCAR") + parser.add_argument("poscar", help="filename of the VASP POSCAR to be processed") + parser.add_argument( + "-a", + "--axis", + choices=['x', 'y', 'z'], + type=str, + help="normal vector for sqrt(2) x sqrt(2) expansion", + required=True, + ) + args = parser.parse_args() + return args + +def sqrt2_by_sqrt2_expansion( + poscar: Poscar, + axis: Literal['x', 'y', 'z'] + ) -> Poscar: + axis_vectors = {'x': [1, 0, 0], + 'y': [0, 1, 0], + 'z': [0, 0, 1]} + poscar.cell.rotate(axis=axis_vectors[axis], theta=np.pi/4) + poscar = poscar.replicate(2, 2, 1) + cc = poscar.cartesian_coordinates() + poscar.cell.matrix = np.diag(poscar.cell.matrix.diagonal()) + poscar.coordinates = cc.dot(np.linalg.inv(poscar.cell.matrix)) + return poscar + +def main(): + args = parse_command_line_arguments() + poscar = Poscar.from_file(args.poscar) + sqrt2_by_sqrt2_expansion( + poscar = poscar, + axis = args.axis + ).output() + +if __name__ == '__main__': + main() + + diff --git a/vasppy/xdatcar.py b/vasppy/xdatcar.py index 4d53cb6..cdb055e 100644 --- a/vasppy/xdatcar.py +++ b/vasppy/xdatcar.py @@ -5,6 +5,8 @@ class Xdatcar: + """Class for parsing and working with VASP XDATCAR files.""" + lines_offset = 9 def __init__(self): @@ -20,7 +22,16 @@ def __init__(self): self.poscar = [] self.poscar.append(Poscar()) - def read_from(self, filename): + def read_from(self, filename: str) -> None: + """Read XDATCAR data from a VASP XDATCAR file. + + Args: + filename (str): The XDATCAR file to read. + + Returns: + None + + """ self.poscar[0].read_from(filename) with open(filename) as f: lines = f.read() From 351a9dabdd2ed912ed38b02aa191a705ce52250b Mon Sep 17 00:00:00 2001 From: Benjamin Date: Thu, 9 Nov 2023 12:58:18 +0000 Subject: [PATCH 4/4] Added r2r2 expansion script to list of scripts --- setup.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 3eaccb1..b08ef00 100644 --- a/setup.py +++ b/setup.py @@ -27,7 +27,8 @@ 'vasp_grid', 'xdatcar_to_disp', 'xdatcar_to_poscart', - 'xdatcar_to_rdf'] + 'xdatcar_to_rdf', + 'r2r2_expansion'] setup( name='vasppy',