File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments