Struct castep_model_core::atom::AtomCollectionBuilder
source · pub struct AtomCollectionBuilder<T, S>where
T: ModelInfo,
S: BuildState,{ /* private fields */ }Implementations§
source§impl<T: ModelInfo, S: BuildState> AtomCollectionBuilder<T, S>
impl<T: ModelInfo, S: BuildState> AtomCollectionBuilder<T, S>
sourcepub fn new(size: usize) -> AtomCollectionBuilder<T, No>
pub fn new(size: usize) -> AtomCollectionBuilder<T, No>
Examples found in repository?
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
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()
}More examples
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
fn parse_atoms(&self) -> AtomCollection<MsiModel> {
let mut element_symbols: Vec<String> = Vec::with_capacity(self.num_atom);
let mut atomic_numbers: Vec<u8> = Vec::with_capacity(self.num_atom);
let mut xyz_coords: Vec<Point3<f64>> = Vec::with_capacity(self.num_atom);
let mut atom_ids: Vec<u32> = Vec::with_capacity(self.num_atom);
let frac_xyz: Vec<Option<Point3<f64>>> =
(0..self.num_atom).into_iter().map(|_| None).collect();
self.atoms.iter().for_each(|atom_fields| {
let (_, atom_attrs) = many0(Self::take_attribute)(atom_fields).unwrap();
atom_attrs.iter().for_each(|item| {
if let Ok((_, acl)) = parse_acl(item) {
let (num, symbol) = acl;
atomic_numbers.push(num);
element_symbols.push(symbol.into());
} else if let Ok((_, xyz)) = parse_xyz(item) {
xyz_coords.push(xyz);
} else if let Ok((_, id)) = parse_id(item) {
atom_ids.push(id);
} else {
}
})
});
let builder = AtomCollectionBuilder::<MsiModel, No>::new(self.num_atom);
builder
.with_atom_ids(&atom_ids)
.unwrap()
.with_element_symbols(&element_symbols)
.unwrap()
.with_atomic_nums(&atomic_numbers)
.unwrap()
.with_xyz_coords(&xyz_coords)
.unwrap()
.with_fractional_xyz(&frac_xyz)
.unwrap()
.finish()
.unwrap()
.build()
}sourcepub fn with_element_symbols(
self,
element_symbols: &[String]
) -> Result<Self, AtomCollectionBuildingError>
pub fn with_element_symbols(
self,
element_symbols: &[String]
) -> Result<Self, AtomCollectionBuildingError>
Supply the element_symbols for an AtomCollection.
Errors
This function will return an error if the element_ids has a different vector size
with the builder’s given size.
Examples found in repository?
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
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()
}More examples
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
fn parse_atoms(&self) -> AtomCollection<MsiModel> {
let mut element_symbols: Vec<String> = Vec::with_capacity(self.num_atom);
let mut atomic_numbers: Vec<u8> = Vec::with_capacity(self.num_atom);
let mut xyz_coords: Vec<Point3<f64>> = Vec::with_capacity(self.num_atom);
let mut atom_ids: Vec<u32> = Vec::with_capacity(self.num_atom);
let frac_xyz: Vec<Option<Point3<f64>>> =
(0..self.num_atom).into_iter().map(|_| None).collect();
self.atoms.iter().for_each(|atom_fields| {
let (_, atom_attrs) = many0(Self::take_attribute)(atom_fields).unwrap();
atom_attrs.iter().for_each(|item| {
if let Ok((_, acl)) = parse_acl(item) {
let (num, symbol) = acl;
atomic_numbers.push(num);
element_symbols.push(symbol.into());
} else if let Ok((_, xyz)) = parse_xyz(item) {
xyz_coords.push(xyz);
} else if let Ok((_, id)) = parse_id(item) {
atom_ids.push(id);
} else {
}
})
});
let builder = AtomCollectionBuilder::<MsiModel, No>::new(self.num_atom);
builder
.with_atom_ids(&atom_ids)
.unwrap()
.with_element_symbols(&element_symbols)
.unwrap()
.with_atomic_nums(&atomic_numbers)
.unwrap()
.with_xyz_coords(&xyz_coords)
.unwrap()
.with_fractional_xyz(&frac_xyz)
.unwrap()
.finish()
.unwrap()
.build()
}sourcepub fn with_atomic_nums(
self,
atomic_nums: &[u8]
) -> Result<Self, AtomCollectionBuildingError>
pub fn with_atomic_nums(
self,
atomic_nums: &[u8]
) -> Result<Self, AtomCollectionBuildingError>
Supply the atomic_nums for an AtomCollection.
Errors
This function will return an error if the element_ids has a different vector size
with the builder’s given size.
Examples found in repository?
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
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()
}More examples
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
fn parse_atoms(&self) -> AtomCollection<MsiModel> {
let mut element_symbols: Vec<String> = Vec::with_capacity(self.num_atom);
let mut atomic_numbers: Vec<u8> = Vec::with_capacity(self.num_atom);
let mut xyz_coords: Vec<Point3<f64>> = Vec::with_capacity(self.num_atom);
let mut atom_ids: Vec<u32> = Vec::with_capacity(self.num_atom);
let frac_xyz: Vec<Option<Point3<f64>>> =
(0..self.num_atom).into_iter().map(|_| None).collect();
self.atoms.iter().for_each(|atom_fields| {
let (_, atom_attrs) = many0(Self::take_attribute)(atom_fields).unwrap();
atom_attrs.iter().for_each(|item| {
if let Ok((_, acl)) = parse_acl(item) {
let (num, symbol) = acl;
atomic_numbers.push(num);
element_symbols.push(symbol.into());
} else if let Ok((_, xyz)) = parse_xyz(item) {
xyz_coords.push(xyz);
} else if let Ok((_, id)) = parse_id(item) {
atom_ids.push(id);
} else {
}
})
});
let builder = AtomCollectionBuilder::<MsiModel, No>::new(self.num_atom);
builder
.with_atom_ids(&atom_ids)
.unwrap()
.with_element_symbols(&element_symbols)
.unwrap()
.with_atomic_nums(&atomic_numbers)
.unwrap()
.with_xyz_coords(&xyz_coords)
.unwrap()
.with_fractional_xyz(&frac_xyz)
.unwrap()
.finish()
.unwrap()
.build()
}sourcepub fn with_xyz_coords(
self,
xyz_coords: &[Point3<f64>]
) -> Result<Self, AtomCollectionBuildingError>
pub fn with_xyz_coords(
self,
xyz_coords: &[Point3<f64>]
) -> Result<Self, AtomCollectionBuildingError>
Supply the xyz_coords for an AtomCollection.
Errors
This function will return an error if the xyz_coords has a different vector size
with the builder’s given size.
Examples found in repository?
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
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()
}More examples
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
fn parse_atoms(&self) -> AtomCollection<MsiModel> {
let mut element_symbols: Vec<String> = Vec::with_capacity(self.num_atom);
let mut atomic_numbers: Vec<u8> = Vec::with_capacity(self.num_atom);
let mut xyz_coords: Vec<Point3<f64>> = Vec::with_capacity(self.num_atom);
let mut atom_ids: Vec<u32> = Vec::with_capacity(self.num_atom);
let frac_xyz: Vec<Option<Point3<f64>>> =
(0..self.num_atom).into_iter().map(|_| None).collect();
self.atoms.iter().for_each(|atom_fields| {
let (_, atom_attrs) = many0(Self::take_attribute)(atom_fields).unwrap();
atom_attrs.iter().for_each(|item| {
if let Ok((_, acl)) = parse_acl(item) {
let (num, symbol) = acl;
atomic_numbers.push(num);
element_symbols.push(symbol.into());
} else if let Ok((_, xyz)) = parse_xyz(item) {
xyz_coords.push(xyz);
} else if let Ok((_, id)) = parse_id(item) {
atom_ids.push(id);
} else {
}
})
});
let builder = AtomCollectionBuilder::<MsiModel, No>::new(self.num_atom);
builder
.with_atom_ids(&atom_ids)
.unwrap()
.with_element_symbols(&element_symbols)
.unwrap()
.with_atomic_nums(&atomic_numbers)
.unwrap()
.with_xyz_coords(&xyz_coords)
.unwrap()
.with_fractional_xyz(&frac_xyz)
.unwrap()
.finish()
.unwrap()
.build()
}sourcepub fn with_fractional_xyz(
self,
fractional_xyz: &[Option<Point3<f64>>]
) -> Result<Self, AtomCollectionBuildingError>
pub fn with_fractional_xyz(
self,
fractional_xyz: &[Option<Point3<f64>>]
) -> Result<Self, AtomCollectionBuildingError>
Supply the fractional_xyz for an AtomCollection.
Errors
This function will return an error if the fractional_xyz has a different vector size
with the builder’s given size.
Examples found in repository?
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
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()
}More examples
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
fn parse_atoms(&self) -> AtomCollection<MsiModel> {
let mut element_symbols: Vec<String> = Vec::with_capacity(self.num_atom);
let mut atomic_numbers: Vec<u8> = Vec::with_capacity(self.num_atom);
let mut xyz_coords: Vec<Point3<f64>> = Vec::with_capacity(self.num_atom);
let mut atom_ids: Vec<u32> = Vec::with_capacity(self.num_atom);
let frac_xyz: Vec<Option<Point3<f64>>> =
(0..self.num_atom).into_iter().map(|_| None).collect();
self.atoms.iter().for_each(|atom_fields| {
let (_, atom_attrs) = many0(Self::take_attribute)(atom_fields).unwrap();
atom_attrs.iter().for_each(|item| {
if let Ok((_, acl)) = parse_acl(item) {
let (num, symbol) = acl;
atomic_numbers.push(num);
element_symbols.push(symbol.into());
} else if let Ok((_, xyz)) = parse_xyz(item) {
xyz_coords.push(xyz);
} else if let Ok((_, id)) = parse_id(item) {
atom_ids.push(id);
} else {
}
})
});
let builder = AtomCollectionBuilder::<MsiModel, No>::new(self.num_atom);
builder
.with_atom_ids(&atom_ids)
.unwrap()
.with_element_symbols(&element_symbols)
.unwrap()
.with_atomic_nums(&atomic_numbers)
.unwrap()
.with_xyz_coords(&xyz_coords)
.unwrap()
.with_fractional_xyz(&frac_xyz)
.unwrap()
.finish()
.unwrap()
.build()
}sourcepub fn with_atom_ids(
self,
atom_ids: &[u32]
) -> Result<Self, AtomCollectionBuildingError>
pub fn with_atom_ids(
self,
atom_ids: &[u32]
) -> Result<Self, AtomCollectionBuildingError>
Supply the atom_ids for an AtomCollection.
Errors
This function will return an error if the atom_ids has a different vector size
with the builder’s given size.
Examples found in repository?
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
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()
}More examples
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
fn parse_atoms(&self) -> AtomCollection<MsiModel> {
let mut element_symbols: Vec<String> = Vec::with_capacity(self.num_atom);
let mut atomic_numbers: Vec<u8> = Vec::with_capacity(self.num_atom);
let mut xyz_coords: Vec<Point3<f64>> = Vec::with_capacity(self.num_atom);
let mut atom_ids: Vec<u32> = Vec::with_capacity(self.num_atom);
let frac_xyz: Vec<Option<Point3<f64>>> =
(0..self.num_atom).into_iter().map(|_| None).collect();
self.atoms.iter().for_each(|atom_fields| {
let (_, atom_attrs) = many0(Self::take_attribute)(atom_fields).unwrap();
atom_attrs.iter().for_each(|item| {
if let Ok((_, acl)) = parse_acl(item) {
let (num, symbol) = acl;
atomic_numbers.push(num);
element_symbols.push(symbol.into());
} else if let Ok((_, xyz)) = parse_xyz(item) {
xyz_coords.push(xyz);
} else if let Ok((_, id)) = parse_id(item) {
atom_ids.push(id);
} else {
}
})
});
let builder = AtomCollectionBuilder::<MsiModel, No>::new(self.num_atom);
builder
.with_atom_ids(&atom_ids)
.unwrap()
.with_element_symbols(&element_symbols)
.unwrap()
.with_atomic_nums(&atomic_numbers)
.unwrap()
.with_xyz_coords(&xyz_coords)
.unwrap()
.with_fractional_xyz(&frac_xyz)
.unwrap()
.finish()
.unwrap()
.build()
}sourcepub fn finish(
self
) -> Result<AtomCollectionBuilder<T, Ready>, AtomCollectionBuildingError>
pub fn finish(
self
) -> Result<AtomCollectionBuilder<T, Ready>, AtomCollectionBuildingError>
Examples found in repository?
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
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()
}More examples
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
fn parse_atoms(&self) -> AtomCollection<MsiModel> {
let mut element_symbols: Vec<String> = Vec::with_capacity(self.num_atom);
let mut atomic_numbers: Vec<u8> = Vec::with_capacity(self.num_atom);
let mut xyz_coords: Vec<Point3<f64>> = Vec::with_capacity(self.num_atom);
let mut atom_ids: Vec<u32> = Vec::with_capacity(self.num_atom);
let frac_xyz: Vec<Option<Point3<f64>>> =
(0..self.num_atom).into_iter().map(|_| None).collect();
self.atoms.iter().for_each(|atom_fields| {
let (_, atom_attrs) = many0(Self::take_attribute)(atom_fields).unwrap();
atom_attrs.iter().for_each(|item| {
if let Ok((_, acl)) = parse_acl(item) {
let (num, symbol) = acl;
atomic_numbers.push(num);
element_symbols.push(symbol.into());
} else if let Ok((_, xyz)) = parse_xyz(item) {
xyz_coords.push(xyz);
} else if let Ok((_, id)) = parse_id(item) {
atom_ids.push(id);
} else {
}
})
});
let builder = AtomCollectionBuilder::<MsiModel, No>::new(self.num_atom);
builder
.with_atom_ids(&atom_ids)
.unwrap()
.with_element_symbols(&element_symbols)
.unwrap()
.with_atomic_nums(&atomic_numbers)
.unwrap()
.with_xyz_coords(&xyz_coords)
.unwrap()
.with_fractional_xyz(&frac_xyz)
.unwrap()
.finish()
.unwrap()
.build()
}source§impl<T: ModelInfo> AtomCollectionBuilder<T, Ready>
impl<T: ModelInfo> AtomCollectionBuilder<T, Ready>
sourcepub fn build(self) -> AtomCollection<T>
pub fn build(self) -> AtomCollection<T>
Examples found in repository?
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
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()
}More examples
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
fn parse_atoms(&self) -> AtomCollection<MsiModel> {
let mut element_symbols: Vec<String> = Vec::with_capacity(self.num_atom);
let mut atomic_numbers: Vec<u8> = Vec::with_capacity(self.num_atom);
let mut xyz_coords: Vec<Point3<f64>> = Vec::with_capacity(self.num_atom);
let mut atom_ids: Vec<u32> = Vec::with_capacity(self.num_atom);
let frac_xyz: Vec<Option<Point3<f64>>> =
(0..self.num_atom).into_iter().map(|_| None).collect();
self.atoms.iter().for_each(|atom_fields| {
let (_, atom_attrs) = many0(Self::take_attribute)(atom_fields).unwrap();
atom_attrs.iter().for_each(|item| {
if let Ok((_, acl)) = parse_acl(item) {
let (num, symbol) = acl;
atomic_numbers.push(num);
element_symbols.push(symbol.into());
} else if let Ok((_, xyz)) = parse_xyz(item) {
xyz_coords.push(xyz);
} else if let Ok((_, id)) = parse_id(item) {
atom_ids.push(id);
} else {
}
})
});
let builder = AtomCollectionBuilder::<MsiModel, No>::new(self.num_atom);
builder
.with_atom_ids(&atom_ids)
.unwrap()
.with_element_symbols(&element_symbols)
.unwrap()
.with_atomic_nums(&atomic_numbers)
.unwrap()
.with_xyz_coords(&xyz_coords)
.unwrap()
.with_fractional_xyz(&frac_xyz)
.unwrap()
.finish()
.unwrap()
.build()
}Auto Trait Implementations§
impl<T, S> RefUnwindSafe for AtomCollectionBuilder<T, S>where
S: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, S> Send for AtomCollectionBuilder<T, S>where
S: Send,
T: Send,
impl<T, S> Sync for AtomCollectionBuilder<T, S>where
S: Sync,
T: Sync,
impl<T, S> Unpin for AtomCollectionBuilder<T, S>where
S: Unpin,
T: Unpin,
impl<T, S> UnwindSafe for AtomCollectionBuilder<T, S>where
S: UnwindSafe,
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>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
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
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.