Skip to content
This repository has been archived by the owner on Oct 28, 2024. It is now read-only.

Commit

Permalink
Utility to get Coords (#24)
Browse files Browse the repository at this point in the history
* test the conversion

* add two direfct coordinate tests
  • Loading branch information
zachcp authored Oct 23, 2024
1 parent 95ae306 commit 69e80b6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/pymolparsing/parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,16 @@ pub struct CoordSet {
pub symmetry: Option<Vec<(((i32, i32, i32), (i32, i32, i32)), String)>>,
}

impl CoordSet {
/// coords are stored in a 1D vector of x,y,z,x,y,x,z,x,y,z
///returns as a Vec<[x,y,z]>
pub fn get_coords_as_vec(&self) -> Vec<[f32; 3]> {
self.coord
.chunks(3)
.map(|chunk| [chunk[0], chunk[1], chunk[2]])
.collect()
}
}
/// Custom Value
///
/// needed for the settings triplet.
Expand Down Expand Up @@ -422,6 +432,7 @@ impl PyObjectMolecule {
);
atom.unwrap()
}

/// Get unique chain names
pub fn get_chains(&self) -> Vec<String> {
self.atom
Expand Down
1 change: 1 addition & 0 deletions src/pymolparsing/psedata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ impl PSEData {
// https://github.com/schrodinger/pymol-open-source/blob/master/layer1/Color.cpp#L415
unimplemented!()
}

/// session is where all the action happens
pub fn get_session_names(&self) -> Vec<String> {
self.names
Expand Down
14 changes: 13 additions & 1 deletion tests/test_pse_parsing.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use itertools::assert_equal;
use pseutils::pymolparsing::colors::Color;
use pseutils::pymolparsing::parsing::{CustomValue, SettingsEnum};
use pseutils::pymolparsing::parsing::{CoordSet, CustomValue, SettingsEnum};
use pseutils::pymolparsing::representation::RepBitmask;
use pseutils::PSEData;
const TEST_OUTPUT_DIR: &str = "./test_temporary";
Expand Down Expand Up @@ -38,6 +39,17 @@ fn test_pdb_00() {
let mols = psedata.get_molecule_data();
assert_eq!(mols.len(), 1);

// check coordinates. theres 1 mon and 1519 atoms
let coord_sets: Vec<&CoordSet> = mols.iter().flat_map(|mol| mol.coord_set.iter()).collect();
assert_eq!(coord_sets.len(), 1);

let coords_01 = coord_sets[0].get_coords_as_vec();
assert_eq!(coords_01.len(), 1519);

let coords_01_atom_01 = coords_01;
assert_equal(coords_01_atom_01[0], [50.873, 32.978, 2.387]);
assert_equal(coords_01_atom_01[1518], [52.372, 15.397, -15.323]);

let atom01 = mols[0].get_atom(0);
assert!(atom01.x() == 50.87300109863281);
assert!(atom01.y() == 32.97800064086914);
Expand Down

0 comments on commit 69e80b6

Please sign in to comment.