Skip to content

Commit 34101bc

Browse files
committed
pre-commit Black
1 parent 8ef27a8 commit 34101bc

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""This module defines class StructureDF.
2+
3+
A local structure or cluster of atoms is represented in a DataFrame
4+
format.
5+
"""
6+
7+
import pandas as pd
8+
from pymatgen.core import Structure
9+
10+
# -------------------------
11+
12+
13+
class StructureDF(pd.DataFrame):
14+
"""Define a structure or cluster of atoms in a pandas DataFrame
15+
format. Each row corresponds to an atom, and columns represent
16+
atomic properties: species, xyz coordinates, and (optionally)
17+
coordination shells, specifying the central atom (0) and its
18+
neighboring atoms (1, 2, ...).
19+
20+
Parameters
21+
----------
22+
structure : pymatgen.core.Structure, optional
23+
A Structure object from pymatgen.core to initialize the DataFrame.
24+
filename : str, optional
25+
Path to a file to read the structure (or cluster) from.
26+
Accepted file formats include cif and xyz.
27+
"""
28+
29+
def __init__(self, structure=None, site_index=None, filename=None):
30+
# load from Structure object if provided
31+
if isinstance(structure, Structure):
32+
self._from_structure(structure, site_index)
33+
return
34+
# load from file if a filename is provided (without a Structure)
35+
elif filename is not None:
36+
self._from_file(filename, site_index)
37+
return
38+
else:
39+
raise ValueError("Either structure or filename must be provided.")

0 commit comments

Comments
 (0)