-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathatom.py
More file actions
68 lines (55 loc) · 1.74 KB
/
Copy pathatom.py
File metadata and controls
68 lines (55 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"""
Atom representation for molecular crystals.
This module defines the Atom class which represents atomic species and coordinates
in molecular crystals.
"""
import numpy as np
from dataclasses import dataclass
@dataclass
class MolAtom:
"""
Represents an atom in a molecular crystal.
Attributes
----------
symbol : str
Chemical symbol of the atom (e.g., 'C', 'H', 'O').
frac_coords : np.ndarray
Fractional coordinates of the atom within the crystal lattice.
occupancy : float, default=1.0
Site occupancy of the atom (0.0 to 1.0).
"""
symbol: str
frac_coords: np.ndarray
occupancy: float = 1.0
def __post_init__(self):
"""Ensure frac_coords is a numpy array."""
self.frac_coords = np.array(self.frac_coords)
def __repr__(self):
"""String representation of the atom."""
return f"MolAtom(symbol='{self.symbol}', frac_coords={self.frac_coords.tolist()}, occupancy={self.occupancy})"
def to_cartesian(self, lattice: np.ndarray) -> np.ndarray:
"""
Convert fractional coordinates to cartesian coordinates.
Parameters
----------
lattice : np.ndarray
3x3 array representing the lattice vectors as rows.
Returns
-------
np.ndarray
Cartesian coordinates of the atom.
"""
return np.dot(self.frac_coords, lattice)
def copy(self) -> "MolAtom":
"""
Create a copy of the atom.
Returns
-------
MolAtom
A copy of the atom with the same properties.
"""
return MolAtom(
symbol=self.symbol,
frac_coords=self.frac_coords.copy(),
occupancy=self.occupancy,
)