Skip to content

Commit 549a967

Browse files
committed
Add src/vasp_snake/cell.py
1 parent c1d3d8a commit 549a967

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

src/vasp_snake/cell.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from collections import Counter
2+
3+
from pymatgen.core.periodic_table import Element
4+
from pymatgen.io.vasp import Poscar
5+
6+
__all__ = ["get_cell", "get_volume", "count_elements"]
7+
8+
9+
def get_cell(filename):
10+
"""
11+
Get the cell from a VASP POSCAR file.
12+
"""
13+
poscar = Poscar.from_file(filename)
14+
return poscar.structure
15+
16+
17+
def get_volume(filename):
18+
"""
19+
Get the volume of the cell from a VASP POSCAR file.
20+
"""
21+
poscar = Poscar.from_file(filename)
22+
return poscar.structure.volume
23+
24+
25+
def count_elements(filename):
26+
"""
27+
Count the number of atoms for each element in a VASP POSCAR file.
28+
Returns a dict: {element_symbol: count, ...}
29+
"""
30+
poscar = Poscar.from_file(filename)
31+
atomic_numbers = poscar.structure.atomic_numbers
32+
# Convert atomic numbers to element symbols
33+
symbols = [Element.from_Z(z).symbol for z in atomic_numbers]
34+
counts = dict(Counter(symbols))
35+
return counts

0 commit comments

Comments
 (0)