Struct castep_model_core::atom::Atom
source · pub struct Atom<T: ModelInfo> { /* private fields */ }Expand description
Struct that defines an atom.
Implementations§
source§impl<T> Atom<T>where
T: ModelInfo,
impl<T> Atom<T>where
T: ModelInfo,
sourcepub fn new(
element_symbol: String,
atomic_number: u8,
xyz: Point3<f64>,
atom_id: u32
) -> Self
pub fn new(
element_symbol: String,
atomic_number: u8,
xyz: Point3<f64>,
atom_id: u32
) -> Self
Creates a new Atom.
sourcepub fn element_symbol(&self) -> &str
pub fn element_symbol(&self) -> &str
Returns a reference to the element symbol of this Atom<Format>.
Examples found in repository?
src/model_type/msi.rs (line 47)
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
r#" ({item_id} Atom
(A C ACL "{elm_id} {elm}")
(A C Label "{elm}")
(A D XYZ ({x:.12} {y:.12} {z:.12}))
(A I Id {atom_id})
)
"#,
item_id = self.atom_id() + 1,
elm_id = self.element_id(),
elm = self.element_symbol(),
x = self.xyz().x,
y = self.xyz().y,
z = self.xyz().z,
atom_id = self.atom_id(),
)
}sourcepub fn set_element_symbol(&mut self, element_symbol: String)
pub fn set_element_symbol(&mut self, element_symbol: String)
Sets the element symbol of this Atom<Format>.
sourcepub fn element_id(&self) -> u8
pub fn element_id(&self) -> u8
Returns the element id of this Atom<Format>.
Examples found in repository?
src/model_type/msi.rs (line 46)
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
r#" ({item_id} Atom
(A C ACL "{elm_id} {elm}")
(A C Label "{elm}")
(A D XYZ ({x:.12} {y:.12} {z:.12}))
(A I Id {atom_id})
)
"#,
item_id = self.atom_id() + 1,
elm_id = self.element_id(),
elm = self.element_symbol(),
x = self.xyz().x,
y = self.xyz().y,
z = self.xyz().z,
atom_id = self.atom_id(),
)
}sourcepub fn set_element_id(&mut self, atomic_number: u8)
pub fn set_element_id(&mut self, atomic_number: u8)
Sets the element id of this Atom<Format>.
sourcepub fn xyz(&self) -> &Point3<f64>
pub fn xyz(&self) -> &Point3<f64>
Returns a reference to the xyz of this Atom<Format>.
Examples found in repository?
More examples
src/model_type/msi.rs (line 48)
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
r#" ({item_id} Atom
(A C ACL "{elm_id} {elm}")
(A C Label "{elm}")
(A D XYZ ({x:.12} {y:.12} {z:.12}))
(A I Id {atom_id})
)
"#,
item_id = self.atom_id() + 1,
elm_id = self.element_id(),
elm = self.element_symbol(),
x = self.xyz().x,
y = self.xyz().y,
z = self.xyz().z,
atom_id = self.atom_id(),
)
}sourcepub fn set_xyz(&mut self, xyz: Point3<f64>)
pub fn set_xyz(&mut self, xyz: Point3<f64>)
Sets the xyz of this Atom<Format>.
sourcepub fn atom_id(&self) -> u32
pub fn atom_id(&self) -> u32
Returns the atom id of this Atom<Format>.
Examples found in repository?
src/model_type/msi.rs (line 45)
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 133 134 135
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
r#" ({item_id} Atom
(A C ACL "{elm_id} {elm}")
(A C Label "{elm}")
(A D XYZ ({x:.12} {y:.12} {z:.12}))
(A I Id {atom_id})
)
"#,
item_id = self.atom_id() + 1,
elm_id = self.element_id(),
elm = self.element_symbol(),
x = self.xyz().x,
y = self.xyz().y,
z = self.xyz().z,
atom_id = self.atom_id(),
)
}
}
/// Display trait for `LatticeVectors<MsiModel>`
impl Display for LatticeVectors<MsiModel> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let vector_a = self.vectors().column(0);
let vector_b = self.vectors().column(1);
let vector_c = self.vectors().column(2);
let vector_a_line = format!(
" (A D A3 ({:.12} {:.12} {:.12}))\n",
vector_a.x, vector_a.y, vector_a.z
);
let vector_b_line = format!(
" (A D B3 ({:.12} {:.12} {:.12}))\n",
vector_b.x, vector_b.y, vector_b.z
);
let vector_c_line = format!(
" (A D C3 ({:.12} {:.12} {:.12}))",
vector_c.x, vector_c.y, vector_c.z
);
writeln!(f, "{vector_a_line}{vector_b_line}{vector_c_line}")
}
}
impl<T> From<T> for AtomCollection<MsiModel>
where
T: AsRef<AtomCollection<CellModel>>,
{
fn from(src: T) -> Self {
let builder = AtomCollectionBuilder::<MsiModel, No>::new(src.as_ref().size());
builder
.with_element_symbols(src.as_ref().element_symbols())
.unwrap()
.with_atomic_nums(src.as_ref().atomic_nums())
.unwrap()
.with_xyz_coords(src.as_ref().xyz_coords())
.unwrap()
.with_fractional_xyz(src.as_ref().fractional_xyz())
.unwrap()
.with_atom_ids(src.as_ref().atom_ids())
.unwrap()
.finish()
.unwrap()
.build()
}
}
impl<T> From<T> for LatticeModel<MsiModel>
where
T: AsRef<LatticeModel<CellModel>>,
{
fn from(cell_model: T) -> Self {
let new_lat_vec = LatticeVectors::new(
cell_model
.as_ref()
.lattice_vectors()
.unwrap()
.vectors()
.to_owned(),
);
// Convert the SoA to AoS for easier sorting.
let msi_atoms: AtomCollection<MsiModel> = cell_model.as_ref().atoms().into();
let mut msi_atom_array: Vec<Atom<MsiModel>> = msi_atoms.into();
msi_atom_array.sort_by_key(|a| a.atom_id());
// Convert AoS back to SoA.
let msi_atom_collection: AtomCollection<MsiModel> = msi_atom_array.into();
let mut msi_model = Self::new(Some(new_lat_vec), msi_atom_collection, Settings::default());
let y_axis: Vector3<f64> = Vector::y();
let b_vec = cell_model
.as_ref()
.lattice_vectors()
.unwrap()
.vectors()
.column(1);
let b_to_y_angle = b_vec.angle(&y_axis);
if b_to_y_angle != 0.0 {
let rot_axis = b_vec.cross(&y_axis).normalize();
let rot_quatd: UnitQuaternion<f64> = UnitQuaternion::new(rot_axis * b_to_y_angle);
msi_model.rotate(&rot_quatd);
}
msi_model
}sourcepub fn set_atom_id(&mut self, atom_id: u32)
pub fn set_atom_id(&mut self, atom_id: u32)
Sets the atom id of this Atom<Format>.
pub fn fractional_xyz(&self) -> Option<&Point3<f64>>
pub fn set_fractional_xyz(&mut self, fractional_xyz: Option<Point3<f64>>)
Trait Implementations§
source§impl<T> Ord for Atom<T>where
T: ModelInfo,
impl<T> Ord for Atom<T>where
T: ModelInfo,
source§impl<T> PartialEq<Atom<T>> for Atom<T>where
T: ModelInfo,
impl<T> PartialEq<Atom<T>> for Atom<T>where
T: ModelInfo,
source§impl<T> PartialOrd<Atom<T>> for Atom<T>where
T: ModelInfo,
impl<T> PartialOrd<Atom<T>> for Atom<T>where
T: ModelInfo,
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self and other) and is used by the <=
operator. Read moresource§impl<T> Transformation for Atom<T>where
T: ModelInfo,
impl<T> Transformation for Atom<T>where
T: ModelInfo,
fn rotate(&mut self, rotate_quatd: &UnitQuaternion<f64>)
fn translate(&mut self, translate_matrix: &Translation<f64, 3>)
impl<T> Eq for Atom<T>where
T: ModelInfo,
Auto Trait Implementations§
impl<T> RefUnwindSafe for Atom<T>where
T: RefUnwindSafe,
impl<T> Send for Atom<T>where
T: Send,
impl<T> Sync for Atom<T>where
T: Sync,
impl<T> Unpin for Atom<T>where
T: Unpin,
impl<T> UnwindSafe for Atom<T>where
T: UnwindSafe,
Blanket Implementations§
§impl<T> Pointable for T
impl<T> Pointable for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.