cosmol-viewer 0.1.1.dev2__tar.gz → 0.1.1.dev3__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.

Potentially problematic release.


This version of cosmol-viewer might be problematic. Click here for more details.

Files changed (25) hide show
  1. {cosmol_viewer-0.1.1.dev2 → cosmol_viewer-0.1.1.dev3}/Cargo.lock +5 -5
  2. {cosmol_viewer-0.1.1.dev2 → cosmol_viewer-0.1.1.dev3}/Cargo.toml +1 -1
  3. {cosmol_viewer-0.1.1.dev2 → cosmol_viewer-0.1.1.dev3}/PKG-INFO +1 -1
  4. {cosmol_viewer-0.1.1.dev2 → cosmol_viewer-0.1.1.dev3}/crates/core/src/parser/sdf.rs +68 -11
  5. {cosmol_viewer-0.1.1.dev2 → cosmol_viewer-0.1.1.dev3}/crates/python/src/shapes.rs +5 -0
  6. {cosmol_viewer-0.1.1.dev2 → cosmol_viewer-0.1.1.dev3}/pyproject.toml +1 -1
  7. {cosmol_viewer-0.1.1.dev2 → cosmol_viewer-0.1.1.dev3}/crates/core/Cargo.toml +0 -0
  8. {cosmol_viewer-0.1.1.dev2 → cosmol_viewer-0.1.1.dev3}/crates/core/src/lib.rs +0 -0
  9. {cosmol_viewer-0.1.1.dev2 → cosmol_viewer-0.1.1.dev3}/crates/core/src/parser/mod.rs +0 -0
  10. {cosmol_viewer-0.1.1.dev2 → cosmol_viewer-0.1.1.dev3}/crates/core/src/scene.rs +0 -0
  11. {cosmol_viewer-0.1.1.dev2 → cosmol_viewer-0.1.1.dev3}/crates/core/src/shader/bg_fragment.glsl +0 -0
  12. {cosmol_viewer-0.1.1.dev2 → cosmol_viewer-0.1.1.dev3}/crates/core/src/shader/bg_vertex.glsl +0 -0
  13. {cosmol_viewer-0.1.1.dev2 → cosmol_viewer-0.1.1.dev3}/crates/core/src/shader/canvas.rs +0 -0
  14. {cosmol_viewer-0.1.1.dev2 → cosmol_viewer-0.1.1.dev3}/crates/core/src/shader/fragment.glsl +0 -0
  15. {cosmol_viewer-0.1.1.dev2 → cosmol_viewer-0.1.1.dev3}/crates/core/src/shader/mod.rs +0 -0
  16. {cosmol_viewer-0.1.1.dev2 → cosmol_viewer-0.1.1.dev3}/crates/core/src/shader/vertex.glsl +0 -0
  17. {cosmol_viewer-0.1.1.dev2 → cosmol_viewer-0.1.1.dev3}/crates/core/src/shapes/mod.rs +0 -0
  18. {cosmol_viewer-0.1.1.dev2 → cosmol_viewer-0.1.1.dev3}/crates/core/src/shapes/molecules.rs +0 -0
  19. {cosmol_viewer-0.1.1.dev2 → cosmol_viewer-0.1.1.dev3}/crates/core/src/shapes/sphere.rs +0 -0
  20. {cosmol_viewer-0.1.1.dev2 → cosmol_viewer-0.1.1.dev3}/crates/core/src/shapes/stick.rs +0 -0
  21. {cosmol_viewer-0.1.1.dev2 → cosmol_viewer-0.1.1.dev3}/crates/core/src/utils.rs +0 -0
  22. {cosmol_viewer-0.1.1.dev2 → cosmol_viewer-0.1.1.dev3}/crates/python/Cargo.toml +0 -0
  23. {cosmol_viewer-0.1.1.dev2 → cosmol_viewer-0.1.1.dev3}/crates/python/build.rs +0 -0
  24. {cosmol_viewer-0.1.1.dev2 → cosmol_viewer-0.1.1.dev3}/crates/python/src/lib.rs +0 -0
  25. {cosmol_viewer-0.1.1.dev2 → cosmol_viewer-0.1.1.dev3}/crates/python/src/parser.rs +0 -0
@@ -699,7 +699,7 @@ dependencies = [
699
699
 
700
700
  [[package]]
701
701
  name = "cosmol_viewer"
702
- version = "0.1.1-nightly.2"
702
+ version = "0.1.1-nightly.3"
703
703
  dependencies = [
704
704
  "bytemuck",
705
705
  "cosmol_viewer_core",
@@ -717,7 +717,7 @@ dependencies = [
717
717
 
718
718
  [[package]]
719
719
  name = "cosmol_viewer_core"
720
- version = "0.1.1-nightly.2"
720
+ version = "0.1.1-nightly.3"
721
721
  dependencies = [
722
722
  "bytemuck",
723
723
  "eframe",
@@ -731,7 +731,7 @@ dependencies = [
731
731
 
732
732
  [[package]]
733
733
  name = "cosmol_viewer_gui"
734
- version = "0.1.1-nightly.2"
734
+ version = "0.1.1-nightly.3"
735
735
  dependencies = [
736
736
  "bytemuck",
737
737
  "cosmol_viewer_core",
@@ -765,7 +765,7 @@ dependencies = [
765
765
 
766
766
  [[package]]
767
767
  name = "cosmol_viewer_wasm"
768
- version = "0.1.1-nightly.2"
768
+ version = "0.1.1-nightly.3"
769
769
  dependencies = [
770
770
  "cosmol_viewer_core",
771
771
  "eframe",
@@ -3160,7 +3160,7 @@ dependencies = [
3160
3160
 
3161
3161
  [[package]]
3162
3162
  name = "test"
3163
- version = "0.1.1-nightly.2"
3163
+ version = "0.1.1-nightly.3"
3164
3164
  dependencies = [
3165
3165
  "cosmol_viewer",
3166
3166
  "cosmol_viewer_core",
@@ -1,6 +1,6 @@
1
1
  [workspace.package]
2
2
  edition = "2024"
3
- version = "0.1.1-nightly.2"
3
+ version = "0.1.1-nightly.3"
4
4
  authors = ["9028 wjt@cosmol.org"]
5
5
  repository = "https://github.com/COSMol-repl/COSMol-viewer"
6
6
  homepage = "https://github.com/COSMol-repl/COSMol-viewer"
@@ -1,5 +1,5 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cosmol-viewer
3
- Version: 0.1.1.dev2
3
+ Version: 0.1.1.dev3
4
4
  Summary: Molecular visualization tools
5
5
  Author-email: 95028 <wjt@cosmol.org>
@@ -14,7 +14,7 @@ pub struct Atom {
14
14
  }
15
15
 
16
16
  pub type Molecule = Vec<Atom>;
17
- pub type MoleculeData = Vec<Molecule>;
17
+ pub type MoleculeData = Vec<Molecule>;
18
18
 
19
19
  #[derive(Default)]
20
20
  pub struct ParserOptions {
@@ -23,7 +23,7 @@ pub struct ParserOptions {
23
23
  pub onemol: bool,
24
24
  }
25
25
 
26
- pub fn parse_sdf(sdf: &str, options: &ParserOptions) -> MoleculeData {
26
+ pub fn parse_sdf(sdf: &str, options: &ParserOptions) -> MoleculeData {
27
27
  let lines: Vec<&str> = sdf.lines().collect();
28
28
  if lines.len() > 3 && lines[3].len() > 38 {
29
29
  let version = lines[3][34..39].trim();
@@ -36,7 +36,22 @@ pub fn parse_sdf(sdf: &str, options: &ParserOptions) -> MoleculeData {
36
36
  }
37
37
  }
38
38
 
39
- fn parse_v2000(mut lines: Vec<&str>, options: &ParserOptions) -> MoleculeData {
39
+ fn parse_v2000(mut lines: Vec<&str>, options: &ParserOptions) -> MoleculeData {
40
+ let model_count = count_models(&lines);
41
+ // 多个分子但用户没开启
42
+ if model_count > 0 && !options.multimodel {
43
+ panic!(
44
+ "Found multiple molecules but 'multimodel' is false. Please enable 'multimodel = true' to parse all molecules."
45
+ );
46
+ }
47
+
48
+ // 用户开启了但其实只有一个
49
+ if model_count == 0 && options.multimodel {
50
+ panic!(
51
+ "Only one molecule found, but 'multimodel = true' was set. Consider setting 'multimodel = false' to avoid confusion."
52
+ );
53
+ }
54
+
40
55
  let mut molecules = vec![vec![]];
41
56
  let mut current = 0;
42
57
 
@@ -80,10 +95,21 @@ fn parse_v2000(mut lines: Vec<&str>, options: &ParserOptions) -> MoleculeData {
80
95
 
81
96
  for i in 0..bond_count {
82
97
  let line = lines[offset + i];
83
- let from = line[0..3].trim().parse::<usize>().unwrap_or(0).saturating_sub(1);
84
- let to = line[3..6].trim().parse::<usize>().unwrap_or(0).saturating_sub(1);
98
+ let from = line[0..3]
99
+ .trim()
100
+ .parse::<usize>()
101
+ .unwrap_or(0)
102
+ .saturating_sub(1);
103
+ let to = line[3..6]
104
+ .trim()
105
+ .parse::<usize>()
106
+ .unwrap_or(0)
107
+ .saturating_sub(1);
85
108
  let order = line[6..].trim().parse::<f32>().unwrap_or(1.0);
86
- if let (Some(f), Some(t)) = (serial_to_index.get(from).and_then(|x| *x), serial_to_index.get(to).and_then(|x| *x)) {
109
+ if let (Some(f), Some(t)) = (
110
+ serial_to_index.get(from).and_then(|x| *x),
111
+ serial_to_index.get(to).and_then(|x| *x),
112
+ ) {
87
113
  molecules[current][f].bonds.push(t);
88
114
  molecules[current][f].bond_order.push(order);
89
115
  molecules[current][t].bonds.push(f);
@@ -109,7 +135,23 @@ fn parse_v2000(mut lines: Vec<&str>, options: &ParserOptions) -> MoleculeData {
109
135
  molecules
110
136
  }
111
137
 
112
- fn parse_v3000(mut lines: Vec<&str>, options: &ParserOptions) -> MoleculeData {
138
+ fn parse_v3000(mut lines: Vec<&str>, options: &ParserOptions) -> MoleculeData {
139
+ let model_count = count_models(&lines);
140
+
141
+ // 多个分子但用户没开启
142
+ if model_count > 0 && !options.multimodel {
143
+ panic!(
144
+ "Found multiple molecules but 'multimodel' is false. Please enable 'multimodel = true' to parse all molecules."
145
+ );
146
+ }
147
+
148
+ // 用户开启了但其实只有一个
149
+ if model_count == 0 && options.multimodel {
150
+ panic!(
151
+ "Only one molecule found, but 'multimodel = true' was set. Consider setting 'multimodel = false' to avoid confusion."
152
+ );
153
+ }
154
+
113
155
  let mut molecules = vec![vec![]];
114
156
  let mut current = 0;
115
157
 
@@ -119,8 +161,14 @@ fn parse_v3000(mut lines: Vec<&str>, options: &ParserOptions) -> MoleculeData {
119
161
  }
120
162
 
121
163
  let counts: Vec<_> = lines[5][13..].split_whitespace().collect();
122
- let atom_count = counts.get(0).and_then(|s| s.parse::<usize>().ok()).unwrap_or(0);
123
- let bond_count = counts.get(1).and_then(|s| s.parse::<usize>().ok()).unwrap_or(0);
164
+ let atom_count = counts
165
+ .get(0)
166
+ .and_then(|s| s.parse::<usize>().ok())
167
+ .unwrap_or(0);
168
+ let bond_count = counts
169
+ .get(1)
170
+ .and_then(|s| s.parse::<usize>().ok())
171
+ .unwrap_or(0);
124
172
  let mut offset = 7;
125
173
 
126
174
  let mut serial_to_index = vec![None; atom_count];
@@ -161,7 +209,10 @@ fn parse_v3000(mut lines: Vec<&str>, options: &ParserOptions) -> MoleculeData {
161
209
  let from = parts[2].parse::<usize>().unwrap_or(0).saturating_sub(1);
162
210
  let to = parts[3].parse::<usize>().unwrap_or(0).saturating_sub(1);
163
211
  let order = parts[1].parse::<f32>().unwrap_or(1.0);
164
- if let (Some(f), Some(t)) = (serial_to_index.get(from).and_then(|x| *x), serial_to_index.get(to).and_then(|x| *x)) {
212
+ if let (Some(f), Some(t)) = (
213
+ serial_to_index.get(from).and_then(|x| *x),
214
+ serial_to_index.get(to).and_then(|x| *x),
215
+ ) {
165
216
  molecules[current][f].bonds.push(t);
166
217
  molecules[current][f].bond_order.push(order);
167
218
  molecules[current][t].bonds.push(f);
@@ -191,7 +242,13 @@ fn parse_v3000(mut lines: Vec<&str>, options: &ParserOptions) -> MoleculeData {
191
242
  fn capitalize(s: &str) -> String {
192
243
  let mut chars = s.chars();
193
244
  match chars.next() {
194
- Some(first) => first.to_ascii_uppercase().to_string() + &chars.as_str().to_ascii_lowercase(),
245
+ Some(first) => {
246
+ first.to_ascii_uppercase().to_string() + &chars.as_str().to_ascii_lowercase()
247
+ }
195
248
  None => String::new(),
196
249
  }
197
250
  }
251
+
252
+ fn count_models(lines: &[&str]) -> usize {
253
+ lines.iter().filter(|line| line.trim() == "$$$$").count()
254
+ }
@@ -94,4 +94,9 @@ impl PyMolecules {
94
94
  inner: Molecules::new(molecule_data.inner.clone())
95
95
  }
96
96
  }
97
+
98
+ pub fn centered(mut slf: PyRefMut<'_, Self>) -> PyRefMut<'_, Self> {
99
+ slf.inner = slf.inner.clone().centered();
100
+ slf
101
+ }
97
102
  }
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "cosmol-viewer"
3
- version = "0.1.1.dev2"
3
+ version = "0.1.1.dev3"
4
4
  description = "Molecular visualization tools"
5
5
  authors = [{name = "95028", email = "wjt@cosmol.org"}]
6
6