rust-sasa-python 0.2.3__tar.gz → 0.2.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -659,7 +659,7 @@ dependencies = [
659
659
 
660
660
  [[package]]
661
661
  name = "rust-sasa-python"
662
- version = "0.2.3"
662
+ version = "0.2.5"
663
663
  dependencies = [
664
664
  "nalgebra",
665
665
  "pdbtbx",
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "rust-sasa-python"
3
- version = "0.2.3"
3
+ version = "0.2.5"
4
4
  edition = "2024"
5
5
 
6
6
  # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rust-sasa-python
3
- Version: 0.2.3
3
+ Version: 0.2.5
4
4
  Classifier: Programming Language :: Rust
5
5
  Classifier: Programming Language :: Python :: Implementation :: CPython
6
6
  Classifier: Programming Language :: Python :: Implementation :: PyPy
@@ -20,7 +20,7 @@ A high-performance **Python library** for computing SASA (Solvent Accessible Sur
20
20
 
21
21
  ## Features
22
22
 
23
- - 🦀 **Pure Rust Backend**: Leverages Rust's performance and safety.
23
+ - 🦀 **Powered by [RustSASA](https://github.com/maxall41/RustSASA)**: Leverages Rust's performance and safety.
24
24
  - ⚡️ **Ludicrous Speed**: **46X** faster than Biopython, **7X** faster than Freesasa.
25
25
  - 🐍 **Pythonic Interface**: Clean, intuitive API.
26
26
  - 🔧 **Configurable**: Customizable probe radius and sampling points.
@@ -4,7 +4,7 @@ A high-performance **Python library** for computing SASA (Solvent Accessible Sur
4
4
 
5
5
  ## Features
6
6
 
7
- - 🦀 **Pure Rust Backend**: Leverages Rust's performance and safety.
7
+ - 🦀 **Powered by [RustSASA](https://github.com/maxall41/RustSASA)**: Leverages Rust's performance and safety.
8
8
  - ⚡️ **Ludicrous Speed**: **46X** faster than Biopython, **7X** faster than Freesasa.
9
9
  - 🐍 **Pythonic Interface**: Clean, intuitive API.
10
10
  - 🔧 **Configurable**: Customizable probe radius and sampling points.
@@ -4,9 +4,12 @@ use pyo3::exceptions::PyRuntimeError;
4
4
  use pyo3::prelude::*;
5
5
  use rust_sasa::options::SASAOptions;
6
6
  use rust_sasa::{Atom, SASAProcessor, calculate_sasa_internal as calculate_sasa_internal_internal};
7
- use rust_sasa::{AtomLevel, ChainLevel, ProteinLevel, ResidueLevel}; // As in long long
7
+ use rust_sasa::{AtomLevel, ChainLevel, ProteinLevel, ResidueLevel};
8
+ use simd::simd_sum; // As in long long
8
9
  use std::collections::HashMap;
9
10
 
11
+ mod simd;
12
+
10
13
  #[pyclass]
11
14
  #[derive(Clone)]
12
15
  pub struct Protein {
@@ -302,10 +305,11 @@ pub fn calculate_sasa_internal(
302
305
  ) -> PyResult<Vec<f32>> {
303
306
  let atoms: Vec<Atom> = atoms_in
304
307
  .into_iter()
305
- .map(|(pos, radius, index)| Atom {
308
+ .enumerate()
309
+ .map(|(index, (pos, radius, parent_id))| Atom {
306
310
  position: Point3::new(pos.0, pos.1, pos.2),
307
311
  id: index,
308
- parent_id: None,
312
+ parent_id: Some(parent_id as isize),
309
313
  radius,
310
314
  })
311
315
  .collect();
@@ -337,13 +341,13 @@ fn calculate_sasa_internal_at_residue_level(
337
341
 
338
342
  let mut residue_sasa = Vec::new();
339
343
  for (parent_id, sasa_values) in residue_groups {
340
- let local_sum = sasa_values.iter().sum::<f32>();
344
+ let local_sum = simd_sum(sasa_values.as_slice());
341
345
 
342
346
  residue_sasa.push(Residue {
343
347
  chain_id: "UNK".to_string(),
344
348
  residue_name: "UNK".to_string(),
345
349
  residue_number: parent_id as u32,
346
- sasa: local_sum / sasa_values.len() as f32,
350
+ sasa: local_sum,
347
351
  });
348
352
  }
349
353
 
@@ -0,0 +1,33 @@
1
+ const LANES: usize = 16;
2
+ #[allow(clippy::needless_range_loop)]
3
+ pub fn simd_sum(values: &[f32]) -> f32 {
4
+ let chunks = values.chunks_exact(LANES);
5
+ let remainder = chunks.remainder();
6
+
7
+ let sum = chunks.fold([0.0f32; LANES], |mut acc, chunk| {
8
+ let chunk: [f32; LANES] = chunk.try_into().unwrap();
9
+ for i in 0..LANES {
10
+ acc[i] += chunk[i];
11
+ }
12
+ acc
13
+ });
14
+
15
+ let remainder: f32 = remainder.iter().copied().sum();
16
+
17
+ let mut reduced = 0.0f32;
18
+ for i in 0..LANES {
19
+ reduced += sum[i];
20
+ }
21
+ reduced + remainder
22
+ }
23
+
24
+ pub(crate) fn serialize_chain_id(s: &str) -> isize {
25
+ let mut result = 0;
26
+ for c in s.chars() {
27
+ if c.is_ascii_alphabetic() {
28
+ let position = c.to_ascii_uppercase() as isize - 64;
29
+ result = result * 10 + position;
30
+ }
31
+ }
32
+ result
33
+ }