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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
use crate::{model_type::ModelInfo, Transformation};
use std::cmp::Ordering;
use na::Point3;
#[derive(Debug, Clone)]
pub struct Atom<T: ModelInfo> {
element_symbol: String,
element_id: u32,
xyz: Point3<f64>,
fractional_xyz: Option<Point3<f64>>,
atom_id: u32,
format_type: T,
}
impl<T> Atom<T>
where
T: ModelInfo,
{
pub fn new(element_symbol: String, element_id: u32, xyz: Point3<f64>, atom_id: u32) -> Self {
Self {
element_symbol,
element_id,
xyz,
fractional_xyz: None,
atom_id,
format_type: T::default(),
}
}
pub fn element_symbol(&self) -> &str {
self.element_symbol.as_ref()
}
pub fn set_element_symbol(&mut self, element_symbol: String) {
self.element_symbol = element_symbol;
}
pub fn element_id(&self) -> u32 {
self.element_id
}
pub fn set_element_id(&mut self, element_id: u32) {
self.element_id = element_id;
}
pub fn xyz(&self) -> &Point3<f64> {
&self.xyz
}
pub fn set_xyz(&mut self, xyz: Point3<f64>) {
self.xyz = xyz;
}
pub fn atom_id(&self) -> u32 {
self.atom_id
}
pub fn set_atom_id(&mut self, atom_id: u32) {
self.atom_id = atom_id;
}
pub fn fractional_xyz(&self) -> Option<&Point3<f64>> {
self.fractional_xyz.as_ref()
}
pub fn set_fractional_xyz(&mut self, fractional_xyz: Option<Point3<f64>>) {
self.fractional_xyz = fractional_xyz;
}
}
impl<T> Transformation for Atom<T>
where
T: ModelInfo,
{
fn rotate(&mut self, rotate_quatd: &na::UnitQuaternion<f64>) {
self.set_xyz(rotate_quatd.transform_point(self.xyz()))
}
fn translate(&mut self, translate_matrix: &na::Translation<f64, 3>) {
self.set_xyz(translate_matrix.transform_point(self.xyz()))
}
}
impl<T> Ord for Atom<T>
where
T: ModelInfo,
{
fn cmp(&self, other: &Self) -> Ordering {
self.atom_id.cmp(&other.atom_id)
}
}
impl<T> PartialOrd for Atom<T>
where
T: ModelInfo,
{
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl<T> PartialEq for Atom<T>
where
T: ModelInfo,
{
fn eq(&self, other: &Self) -> bool {
self.atom_id == other.atom_id
}
}
impl<T> Eq for Atom<T> where T: ModelInfo {}