Skip to main content

Rings

Struct Rings 

Source
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

Source

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}
Source

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());
Source

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}
Source

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());
Source

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§

Source§

impl Drop for Rings

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Send for Rings

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.