pub struct Rings { /* private fields */ }Expand description
Owned primitive-ring set.
let (xyz, edge) = seams::diamond8();
let mut system = seams::System::new()?;
system.set_ortho(&xyz, edge, edge, edge)?;
let rings = system.rings(&seams::RingOptions::default())?;
assert!(rings.size() > 0);
assert!(!rings.vertices(0)?.is_empty());Implementations§
Source§impl Rings
impl Rings
Sourcepub fn from_csr(
offsets: &[i32],
columns: &[i32],
max_size: i32,
) -> Result<Self, Error>
pub fn from_csr( offsets: &[i32], columns: &[i32], max_size: i32, ) -> Result<Self, Error>
Find primitive rings in an explicit bond graph.
offsets contains one compressed sparse row offset per site plus a
final offset equal to columns.len(). The first offset is zero.
columns contains zero-based neighbour indices. Either direction
records a bond, and self-edges and duplicates are ignored.
max_size ranges from three to twelve.
let rings = seams::Rings::from_csr(&[0, 2, 3, 4, 4], &[1, 3, 2, 3], 4)?;
assert_eq!(rings.size(), 1);
assert_eq!(rings.vertices(0)?, [0, 1, 2, 3]);Sourcepub fn size(&self) -> i32
pub fn size(&self) -> i32
Number of primitive rings.
let (xyz, edge) = seams::diamond8();
let mut system = seams::System::new()?;
system.set_ortho(&xyz, edge, edge, edge)?;
let rings = system.rings(&seams::RingOptions::default())?;
assert_eq!(rings.iter().count(), rings.size() as usize);Examples found in repository?
examples/binding_overhead.rs (line 100)
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 vertices(&self, index: i32) -> Result<Vec<i32>, Error>
pub fn vertices(&self, index: i32) -> Result<Vec<i32>, Error>
Atom indices of one ring.
let (xyz, edge) = seams::diamond8();
let mut system = seams::System::new()?;
system.set_ortho(&xyz, edge, edge, edge)?;
let rings = system.rings(&seams::RingOptions::default())?;
assert!(!rings.vertices(0)?.is_empty());Sourcepub fn histogram(&self, up_to: i32) -> Result<Vec<i32>, Error>
pub fn histogram(&self, up_to: i32) -> Result<Vec<i32>, Error>
Histogram of ring size. counts[k] is the number of rings of size k.
let (xyz, edge) = seams::diamond8();
let mut system = seams::System::new()?;
system.set_ortho(&xyz, edge, edge, edge)?;
let rings = system.rings(&seams::RingOptions::default())?;
let hist = rings.histogram(6)?;
assert_eq!(hist.len(), 7);Examples found in repository?
examples/lang_tasks.rs (line 34)
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}Sourcepub fn fraction(&self, ring_size: i32) -> Result<f64, Error>
pub fn fraction(&self, ring_size: i32) -> Result<f64, Error>
Fraction of atoms that sit on a ring of one size. Zero counts every ring.
let (xyz, edge) = seams::diamond8();
let mut system = seams::System::new()?;
system.set_ortho(&xyz, edge, edge, edge)?;
let rings = system.rings(&seams::RingOptions::default())?;
assert!(rings.fraction(6)?.is_finite());Sourcepub fn iter(&self) -> RingIter<'_> ⓘ
pub fn iter(&self) -> RingIter<'_> ⓘ
Walk the rings. Each item is the vertex list of one ring.
let (xyz, edge) = seams::diamond8();
let mut system = seams::System::new()?;
system.set_ortho(&xyz, edge, edge, edge)?;
let rings = system.rings(&seams::RingOptions::default())?;
assert!(rings.iter().all(|ring| ring.is_ok()));Trait Implementations§
Auto Trait Implementations§
impl !Sync for Rings
impl Forget for Rings
impl Freeze for Rings
impl Move for Rings
impl RefUnwindSafe for Rings
impl Unpin for Rings
impl UnsafeUnpin for Rings
impl UnwindSafe for Rings
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