Skip to content

Commit

Permalink
Merge branch 'main' of github.com:bjmorgan/vasppy
Browse files Browse the repository at this point in the history
  • Loading branch information
bjmorgan committed Jun 14, 2024
2 parents 2578a81 + 351a9da commit fcd95e7
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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@v2
with:
path-to-lcov: ./coverage.lcov
file: ./coverage.lcov
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Static type checking
run: |
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
'vasp_grid',
'xdatcar_to_disp',
'xdatcar_to_poscart',
'xdatcar_to_rdf']
'xdatcar_to_rdf',
'r2r2_expansion']

setup(
name='vasppy',
Expand Down
2 changes: 1 addition & 1 deletion vasppy/doscar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 7 additions & 3 deletions vasppy/poscar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -175,15 +175,19 @@ 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):
if opts is 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]))
Expand Down
8 changes: 7 additions & 1 deletion vasppy/scripts/proc_poscar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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)

Expand Down
48 changes: 48 additions & 0 deletions vasppy/scripts/r2r2_expansion.py
Original file line number Diff line number Diff line change
@@ -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()


13 changes: 12 additions & 1 deletion vasppy/xdatcar.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@


class Xdatcar:
"""Class for parsing and working with VASP XDATCAR files."""

lines_offset = 9

def __init__(self):
Expand All @@ -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()
Expand Down

0 comments on commit fcd95e7

Please sign in to comment.