pub struct Atom<T: ModelInfo> { /* private fields */ }
Expand description

Struct that defines an atom.

Implementations§

Creates a new Atom.

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(),
        )
    }

Sets the element symbol of this Atom<Format>.

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(),
        )
    }

Sets the element id of this Atom<Format>.

Returns a reference to the xyz of this Atom<Format>.

Examples found in repository?
src/atom/mod.rs (line 324)
323
324
325
326
327
328
329
    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()))
    }
More examples
Hide additional 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(),
        )
    }

Sets the xyz of this Atom<Format>.

Examples found in repository?
src/atom/mod.rs (line 324)
323
324
325
326
327
328
329
    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()))
    }

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
    }

Sets the atom id of this Atom<Format>.

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more

Display trait for Atom<MsiModel>

Formats the value using the given formatter. Read more
Converts to this type from the input type.
This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. Read more
Should always be Self
The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Checks if self is actually part of its subset T (and can be converted to it).
Use with care! Same as self.to_subset but without any property checks. Always succeeds.
The inclusion map: converts self to the equivalent element of its superset.
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.