@@ -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///
1818pub 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///
9486pub 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
179158mod 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 }
0 commit comments