pub struct Neighbours { /* private fields */ }Expand description
Owned neighbour list.
The handle is freed on drop. It is Send and not Sync.
let (xyz, edge) = seams::diamond8();
let mut system = seams::System::new()?;
system.set_ortho(&xyz, edge, edge, edge)?;
let list = system.neighbours(&seams::NeighbourOptions::default())?;
assert!(list.pairs().all(|pair| pair.atom != pair.neighbour));
assert!(list.degrees()?.iter().all(|degree| *degree == 4));Implementations§
Source§impl Neighbours
impl Neighbours
Sourcepub fn nnz(&self) -> Result<usize, Error>
pub fn nnz(&self) -> Result<usize, Error>
Number of neighbour pairs, omitting self.
let (xyz, edge) = seams::diamond8();
let mut system = seams::System::new()?;
system.set_ortho(&xyz, edge, edge, edge)?;
let list = system.knn(&seams::KnnOptions { k: 4, mutual: true, ..Default::default() })?;
assert!(list.nnz()? > 0);Examples found in repository?
examples/lang_tasks.rs (line 28)
25fn census(path: &str) -> Result<String, Error> {
26 let mut frame = System::new()?;
27 frame.read(path, 1, -1)?;
28 let pairs = frame.neighbours(&NeighbourOptions::default())?.nnz()?;
29 let rings = frame
30 .rings(&RingOptions {
31 max_size: 6,
32 ..RingOptions::default()
33 })?
34 .histogram(6)?;
35 let chill = frame.chill_plus(&ChillOptions::default())?;
36 Ok(format!(
37 "pairs {pairs} rings {} chill {}",
38 joined(&rings),
39 joined(&chill.counts)
40 ))
41}More examples
examples/binding_overhead.rs (line 71)
17fn main() {
18 let mut frames: HashMap<String, System> = HashMap::new();
19 let mut loaded: HashMap<String, bool> = HashMap::new();
20 let mut sink = 0.0_f64;
21 let stdin = std::io::stdin();
22 let mut out = std::io::stdout();
23 for line in stdin.lock().lines() {
24 let line = line.unwrap_or_default();
25 if line.is_empty() {
26 continue;
27 }
28 if line.starts_with("quit") {
29 break;
30 }
31 let mut parts = line.split_whitespace();
32 let threads: i32 = parts.next().and_then(|s| s.parse().ok()).unwrap_or(0);
33 let op = parts.next().unwrap_or("").to_string();
34 let path = parts.next().unwrap_or("").to_string();
35 if threads < 1 || path.is_empty() {
36 eprintln!("error command");
37 std::process::exit(1);
38 }
39 if let Err(err) = retune(threads) {
40 eprintln!("error {err}");
41 std::process::exit(1);
42 }
43 let sys = frames.entry(path.clone()).or_insert_with(|| {
44 System::new().unwrap_or_else(|err| {
45 eprintln!("error {err}");
46 std::process::exit(1);
47 })
48 });
49 let ready = loaded.get(&path).copied().unwrap_or(false);
50 if op != "read" && !ready {
51 if let Err(err) = sys.read(&path, 1, -1) {
52 eprintln!("error {err}");
53 std::process::exit(1);
54 }
55 loaded.insert(path.clone(), true);
56 }
57 let t0 = Instant::now();
58 let result = match op.as_str() {
59 "read" => sys.read(&path, 1, -1).map(|_| {
60 loaded.insert(path.clone(), true);
61 sink += f64::from(sys.count());
62 }),
63 "knn" => sys
64 .knn(&seams::KnnOptions {
65 k: 4,
66 cutoff: 3.5,
67 mutual: true,
68 ..seams::KnnOptions::default()
69 })
70 .and_then(|nb| {
71 sink += nb.nnz()? as f64;
72 Ok(())
73 }),
74 "steinhardt" => sys
75 .steinhardt(&seams::SteinhardtOptions {
76 cutoff: 3.5,
77 order: 6,
78 average: true,
79 ..seams::SteinhardtOptions::default()
80 })
81 .map(|q| {
82 let extra = q.average.as_ref().map(|v| v[0]).unwrap_or(0.0);
83 sink += q.local[0] + extra;
84 }),
85 "chill" => sys
86 .chill(&seams::ChillOptions {
87 cutoff: 3.5,
88 ..seams::ChillOptions::default()
89 })
90 .map(|ice| {
91 sink += f64::from(ice.counts[1]);
92 }),
93 "rings" => sys
94 .rings(&seams::RingOptions {
95 cutoff: 3.5,
96 max_size: 6,
97 ..seams::RingOptions::default()
98 })
99 .map(|rings| {
100 sink += f64::from(rings.size());
101 }),
102 _ => {
103 eprintln!("error {op}");
104 std::process::exit(1);
105 }
106 };
107 let ms = t0.elapsed().as_secs_f64() * 1e3;
108 if let Err(err) = result {
109 eprintln!("error {err}");
110 std::process::exit(1);
111 }
112 writeln!(out, "{ms:.9}").ok();
113 out.flush().ok();
114 }
115 eprintln!("sink {sink:.6}");
116}Sourcepub fn degrees(&self) -> Result<Vec<i32>, Error>
pub fn degrees(&self) -> Result<Vec<i32>, Error>
Degree of each atom. The self entry is not counted.
let (xyz, edge) = seams::diamond8();
let mut system = seams::System::new()?;
system.set_ortho(&xyz, edge, edge, edge)?;
let list = system.neighbours(&seams::NeighbourOptions::default())?;
assert_eq!(list.degrees()?.len(), 8);Sourcepub fn pairs(&self) -> NeighbourPairs<'_> ⓘ
pub fn pairs(&self) -> NeighbourPairs<'_> ⓘ
Directed pairs. Self is omitted.
let (xyz, edge) = seams::diamond8();
let mut system = seams::System::new()?;
system.set_ortho(&xyz, edge, edge, edge)?;
let list = system.neighbours(&seams::NeighbourOptions::default())?;
assert_eq!(list.pairs().count(), list.nnz()?);Trait Implementations§
Source§impl Drop for Neighbours
impl Drop for Neighbours
impl Send for Neighbours
Auto Trait Implementations§
impl !Sync for Neighbours
impl Forget for Neighbours
impl Freeze for Neighbours
impl Move for Neighbours
impl RefUnwindSafe for Neighbours
impl Unpin for Neighbours
impl UnsafeUnpin for Neighbours
impl UnwindSafe for Neighbours
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more