Skip to content

Commit 362fdf0

Browse files
authored
use PDB as argument for commands (#68)
* update commands to use `PDB` instead of path * clean test data
1 parent 4da8c10 commit 362fdf0

File tree

5 files changed

+57
-96
lines changed

5 files changed

+57
-96
lines changed

src/cli.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
1+
use haddock_restraints::load_pdb;
2+
13
pub fn handle_ti(input: &str, cutoff: &f64, pml: &Option<String>) {
2-
let _ = haddock_restraints::true_interface(input, cutoff, pml);
4+
let pdb = load_pdb(input).unwrap();
5+
let _ = haddock_restraints::true_interface(pdb, cutoff, pml);
36
}
47

58
pub fn handle_gen_tbl(input: &str, pml: &Option<String>) {
69
haddock_restraints::gen_tbl(input, pml)
710
}
811
pub fn handle_unambig_ti(input: &str, cutoff: &f64, pml: &Option<String>) {
9-
let _ = haddock_restraints::unambig_ti(input, cutoff, pml);
12+
let pdb = load_pdb(input).unwrap();
13+
let _ = haddock_restraints::unambig_ti(pdb, cutoff, pml);
1014
}
1115
pub fn handle_restraint_bodies(input: &str, pml: &Option<String>) {
12-
let _ = haddock_restraints::restraint_bodies(input, pml);
16+
let pdb = load_pdb(input).unwrap();
17+
let _ = haddock_restraints::restraint_bodies(pdb, pml);
1318
}
1419

1520
pub fn handle_list_interface(input: &str, cutoff: &f64) {
16-
let _ = haddock_restraints::list_interface(input, cutoff);
21+
let pdb = load_pdb(input).unwrap();
22+
let _ = haddock_restraints::list_interface(pdb, cutoff);
1723
}
1824

1925
pub fn handle_generate_z_restraints(
@@ -23,6 +29,7 @@ pub fn handle_generate_z_restraints(
2329
grid_size: &usize,
2430
grid_spacing: &f64,
2531
) {
32+
let pdb = load_pdb(input).unwrap();
2633
let _ =
27-
haddock_restraints::generate_z_restraints(input, output, residues, grid_size, grid_spacing);
34+
haddock_restraints::generate_z_restraints(pdb, output, residues, grid_size, grid_spacing);
2835
}

src/core/commands/restraint.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,7 @@ use crate::*;
2929
/// 5. Generates AIRs using the created interactors.
3030
/// 6. Prints the generated AIR table to stdout.
3131
///
32-
pub fn restraint_bodies(input_file: &str, pml: &Option<String>) -> Result<String, Box<dyn Error>> {
33-
// Read PDB file
34-
let pdb = match load_pdb(input_file) {
35-
Ok(pdb) => pdb,
36-
Err(e) => {
37-
panic!("Error opening PDB file: {:?}", e);
38-
}
39-
};
40-
32+
pub fn restraint_bodies(pdb: pdbtbx::PDB, pml: &Option<String>) -> Result<String, Box<dyn Error>> {
4133
// Find in-contiguous chains
4234
let bodies = find_bodies(&pdb);
4335
let mut gaps = create_iter_body_gaps(&bodies);
@@ -105,7 +97,10 @@ pub fn restraint_bodies(input_file: &str, pml: &Option<String>) -> Result<String
10597
#[cfg(test)]
10698
mod tests {
10799

100+
use std::io::{BufReader, Cursor};
101+
108102
use super::*;
103+
109104
#[test]
110105
fn test_restraint_bodies() {
111106
let expected_tbl = r"assign ( resid 1 and segid A and name CA ) ( resid 4 and segid A and name CA ) 10.2 0.0 0.0
@@ -114,8 +109,15 @@ assign ( resid 2 and segid A and name CA ) ( resid 8 and segid A and name CA ) 1
114109
115110
";
116111

117-
let opt: Option<String> = None;
118-
match restraint_bodies("tests/data/gaps.pdb", &opt) {
112+
let content = std::fs::read_to_string("tests/data/gaps.pdb").unwrap();
113+
let mut opts = pdbtbx::ReadOptions::new();
114+
opts.set_format(pdbtbx::Format::Pdb)
115+
.set_level(pdbtbx::StrictnessLevel::Loose);
116+
let cursor = Cursor::new(content.into_bytes());
117+
let reader = BufReader::new(cursor);
118+
let (pdb, _) = opts.read_raw(reader).unwrap();
119+
120+
match restraint_bodies(pdb, &None) {
119121
Ok(tbl) => assert_eq!(tbl, expected_tbl),
120122
Err(_e) => (),
121123
}

src/core/commands/ti.rs

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,10 @@ use std::error::Error;
1616
/// A `Result<String, Box<dyn Error>>` which is Ok(String) if the function completes successfully, or an Error if something goes wrong.
1717
///
1818
pub fn true_interface(
19-
input_file: &str,
19+
pdb: pdbtbx::PDB,
2020
cutoff: &f64,
2121
pml: &Option<String>,
2222
) -> Result<String, Box<dyn Error>> {
23-
// Read PDB file
24-
let pdb = match load_pdb(input_file) {
25-
Ok(pdb) => pdb,
26-
Err(e) => {
27-
panic!("Error opening PDB file: {:?}", e);
28-
}
29-
};
30-
3123
let true_interface = get_true_interface(&pdb, *cutoff);
3224
let chains_in_contact = get_chains_in_contact(&pdb, *cutoff);
3325

@@ -92,16 +84,10 @@ pub fn true_interface(
9284
/// A Result<String, Box<dyn Error>> containing the generated TBL (Topological Restraints List) if successful.
9385
///
9486
pub fn unambig_ti(
95-
input_file: &str,
87+
pdb: pdbtbx::PDB,
9688
cutoff: &f64,
9789
pml: &Option<String>,
9890
) -> Result<String, Box<dyn Error>> {
99-
let pdb = match load_pdb(input_file) {
100-
Ok(pdb) => pdb,
101-
Err(e) => {
102-
panic!("Error opening PDB file: {:?}", e);
103-
}
104-
};
10591
let pairs = get_closest_residue_pairs(&pdb, *cutoff);
10692

10793
let mut interactors: Vec<Interactor> = Vec::new();
@@ -156,14 +142,7 @@ pub fn unambig_ti(
156142
/// A `Result<(), Box<dyn Error>>` which is Ok(()) if the function completes successfully,
157143
/// or an Error if something goes wrong.
158144
///
159-
pub fn list_interface(input_file: &str, cutoff: &f64) -> Result<(), Box<dyn Error>> {
160-
let pdb = match load_pdb(input_file) {
161-
Ok(pdb) => pdb,
162-
Err(e) => {
163-
panic!("Error opening PDB file: {:?}", e);
164-
}
165-
};
166-
145+
pub fn list_interface(pdb: pdbtbx::PDB, cutoff: &f64) -> Result<(), Box<dyn Error>> {
167146
let true_interface = get_true_interface(&pdb, *cutoff);
168147

169148
for (chain_id, residues) in true_interface.iter() {
@@ -179,6 +158,7 @@ pub fn list_interface(input_file: &str, cutoff: &f64) -> Result<(), Box<dyn Erro
179158
mod tests {
180159

181160
use super::*;
161+
use std::io::{BufReader, Cursor};
182162

183163
#[test]
184164
fn test_true_interface() {
@@ -212,8 +192,16 @@ assign ( resid 47 and segid B )
212192
213193
"#;
214194

195+
let content = std::fs::read_to_string("tests/data/complex.pdb").unwrap();
196+
let mut opts = pdbtbx::ReadOptions::new();
197+
opts.set_format(pdbtbx::Format::Pdb)
198+
.set_level(pdbtbx::StrictnessLevel::Loose);
199+
let cursor = Cursor::new(content.into_bytes());
200+
let reader = BufReader::new(cursor);
201+
let (pdb, _) = opts.read_raw(reader).unwrap();
202+
215203
let opt: Option<String> = None;
216-
match true_interface("tests/data/complex.pdb", &3.0, &opt) {
204+
match true_interface(pdb, &3.0, &opt) {
217205
Ok(tbl) => assert_eq!(tbl, expected_tbl),
218206
Err(_e) => (),
219207
};
@@ -250,19 +238,35 @@ assign ( resid 47 and segid B )
250238
251239
"#;
252240

241+
let content = std::fs::read_to_string("tests/data/complex_BA.pdb").unwrap();
242+
let mut opts = pdbtbx::ReadOptions::new();
243+
opts.set_format(pdbtbx::Format::Pdb)
244+
.set_level(pdbtbx::StrictnessLevel::Loose);
245+
let cursor = Cursor::new(content.into_bytes());
246+
let reader = BufReader::new(cursor);
247+
let (pdb, _) = opts.read_raw(reader).unwrap();
248+
253249
let opt: Option<String> = None;
254-
match true_interface("tests/data/complex_BA.pdb", &3.0, &opt) {
250+
match true_interface(pdb, &3.0, &opt) {
255251
Ok(tbl) => assert_eq!(tbl, expected_tbl),
256252
Err(_e) => (),
257253
};
258254
}
259255

260256
#[test]
261257
fn test_unambigti() {
258+
let content = std::fs::read_to_string("tests/data/two_res.pdb").unwrap();
259+
let mut opts = pdbtbx::ReadOptions::new();
260+
opts.set_format(pdbtbx::Format::Pdb)
261+
.set_level(pdbtbx::StrictnessLevel::Loose);
262+
let cursor = Cursor::new(content.into_bytes());
263+
let reader = BufReader::new(cursor);
264+
let (pdb, _) = opts.read_raw(reader).unwrap();
265+
262266
let opt: Option<String> = None;
263267
let expected_tbl = "assign ( resid 2 and segid A and name CA ) ( resid 10 and segid B and name CA ) 9.1 2.0 0.0\n\n";
264268

265-
match unambig_ti("tests/data/two_res.pdb", &5.0, &opt) {
269+
match unambig_ti(pdb, &5.0, &opt) {
266270
Ok(tbl) => assert_eq!(tbl, expected_tbl),
267271
Err(_e) => (),
268272
}

src/core/commands/z.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,12 @@ use std::{collections::HashMap, error::Error};
33

44
// TODO: Docstring
55
pub fn generate_z_restraints(
6-
input_file: &str,
6+
pdb: pdbtbx::PDB,
77
output_file: &str,
88
selections: &[Vec<isize>],
99
grid_size: &usize,
1010
grid_spacing: &f64,
1111
) -> Result<(), Box<dyn Error>> {
12-
let pdb = match load_pdb(input_file) {
13-
Ok(pdb) => pdb,
14-
Err(e) => {
15-
panic!("Error opening PDB file: {:?}", e);
16-
}
17-
};
18-
1912
// // DEVELOPMENT, move the pdb to the origin --------------------------------------------------
2013
// let mut debug_pdb = pdb.clone();
2114
// move_to_origin(&mut debug_pdb);

tests/data/complex.pdb

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,3 @@
1-
REMARK FILENAME="emscoring_1.pdb"
2-
REMARK ===============================================================
3-
REMARK HADDOCK stats for emscoring_1.pdb
4-
REMARK ===============================================================
5-
REMARK HADDOCK score: -54.1511
6-
REMARK ===============================================================
7-
REMARK initial structure 1 - ../0_topoaa/complexyrrk72_y_haddock.pdb
8-
REMARK ===============================================================
9-
REMARK total,bonds,angles,improper,dihe,vdw,elec,air,cdih,coup,rdcs,vean,dani,xpcs,rg
10-
REMARK energies: -106.18, 0, 0, 0, 0, -30.4344, -75.7457, 0, 0, 0, 0, 0, 0, 0, 0
11-
REMARK ===============================================================
12-
REMARK bonds,angles,impropers,dihe,air,cdih,coup,rdcs,vean,dani,xpcs
13-
REMARK rms-dev.: 0,0,0,0,0,0,0, 0, 0, 0, 0
14-
REMARK ===============================================================
15-
REMARK air,cdih,coup,rdcs,vean,dani,xpcs
16-
REMARK >0.3,>5,>1,>0,>5,>0.2,>0.2
17-
REMARK violations.: 0, 0, 0, 0, 0, 0, 0
18-
REMARK ===============================================================
19-
REMARK CVpartition#,violations,rms
20-
REMARK AIRs cross-validation: 0, 0, 0
21-
REMARK ===============================================================
22-
REMARK NCS energy: 0
23-
REMARK ===============================================================
24-
REMARK Symmetry energy: 0
25-
REMARK ===============================================================
26-
REMARK Membrane restraining energy: 0
27-
REMARK ===============================================================
28-
REMARK Local cross-correlation: 0.0000
29-
REMARK ===============================================================
30-
REMARK Desolvation energy: -8.56748
31-
REMARK Internal energy free molecules: -4515.85
32-
REMARK Internal energy complex: -4364.86
33-
REMARK Binding energy: 36.2429
34-
REMARK ===============================================================
35-
REMARK buried surface area: 802.679
36-
REMARK ===============================================================
37-
REMARK Total HADDOCK score without restraints: -54.1511
38-
REMARK ===============================================================
39-
REMARK water - chain-A: 0 0 0
40-
REMARK water - chain-B: 0 0 0
41-
REMARK ===============================================================
42-
REMARK water - water: 0 0 0
43-
REMARK ===============================================================
44-
REMARK DATE:22-Aug-2024 15:23:46 created by user: unknown
45-
REMARK VERSION:1.3U
461
ATOM 1 N LEU A 929 26.117 -5.693 15.769 1.00 29.81 N
472
ATOM 2 CA LEU A 929 27.153 -4.857 15.061 1.00 29.93 C
483
ATOM 3 C LEU A 929 26.486 -3.835 14.143 1.00 29.74 C

0 commit comments

Comments
 (0)