Skip to content

Commit

Permalink
add subsets [wip]
Browse files Browse the repository at this point in the history
  • Loading branch information
rvhonorato committed Sep 3, 2024
1 parent e803afb commit 8203d24
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 20 deletions.
21 changes: 6 additions & 15 deletions examples/restraints.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,22 @@
"passive": [],
"structure": "2oob.pdb",
"target": [
2
3
],
"passive_from_active": true,
"passive_from_active": false,
"filter_buried": true
},
{
"id": 2,
"chain": "B",
"active": [
68
],
"passive": [],
"target": [
1
]
},
{
"id": 3,
"chain": "B",
"active": [],
"passive": [],
"passive_atoms": ["CA"],
"target": [
1
],
"structure": "2oob.pdb",
"surface_as_passive": true
"surface_as_passive": true,
"filter_buried": true
}
]
]
2 changes: 2 additions & 0 deletions src/air.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ impl Air {

// let header = append_header(i);
// tbl.push_str(&header);
//
println!("{:?}", interactor);

let target_res = interactor::collect_residues(partners);
let block = interactor.create_block(target_res);
Expand Down
63 changes: 58 additions & 5 deletions src/interactor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ pub struct Interactor {

/// Optional list of passive atom names.
passive_atoms: Option<Vec<String>>,

/// Set of target interactor IDs.
target: HashSet<u16>,

/// Optional target distance for interactions.
Expand Down Expand Up @@ -512,7 +514,7 @@ impl Interactor {

for resnum in _active {
let atom_str = format_atom_string(&self.active_atoms);

// (name H3 or name O4 or name C4 or name C5 or name C6 or name C7)
let mut assign_str = format!(
"assign ( resid {} and segid {}{} {})",
resnum,
Expand All @@ -528,6 +530,7 @@ impl Interactor {
block.push_str(assign_str.as_str());

// panic!("Target res: {:?}", target_res);
// println!("{:?}", self.passive_atoms);

let res_lines: Vec<String> = passive_res
.iter()
Expand Down Expand Up @@ -691,11 +694,17 @@ pub fn format_distance_string(
///
pub fn format_atom_string(atoms: &Option<Vec<String>>) -> String {
match atoms {
Some(atoms) => {
let atoms: Vec<String> = atoms.iter().map(|x| format!(" and name {}", x)).collect();
atoms.join("")
Some(atoms) if atoms.len() > 1 => {
let atoms: String = atoms
.iter()
.map(|x| format!("name {}", x))
.collect::<Vec<String>>()
.join(" or ");

format!(" and ({})", atoms)
}
None => "".to_string(),
Some(atoms) if atoms.len() == 1 => format!(" and name {}", atoms[0]),
_ => "".to_string(),
}
}

Expand Down Expand Up @@ -828,6 +837,50 @@ mod tests {
assert_eq!(observed, block);
}

#[test]
fn test_create_block_oneline_atom_subset() {
let mut interactor = Interactor::new(1);
interactor.set_active(vec![1]);
interactor.set_chain("A");
interactor.set_active_atoms(vec!["CA".to_string(), "CB".to_string()]);

let observed = interactor.create_block(vec![PassiveResidues {
chain_id: "B",
res_number: Some(2),
wildcard: "",
}]);

let block =
"assign ( resid 1 and segid A and (name CA or name CB) ) ( resid 2 and segid B ) 2.0 2.0 0.0\n\n";

assert_eq!(observed, block);
}

#[test]
fn test_create_block_multiline_atom_subset() {
let mut interactor = Interactor::new(1);
interactor.set_active(vec![1]);
interactor.set_chain("A");
interactor.set_active_atoms(vec!["CA".to_string(), "CB".to_string()]);
interactor.set_passive_atoms(vec!["CA".to_string(), "CB".to_string()]);
let observed = interactor.create_block(vec![
PassiveResidues {
chain_id: "B",
res_number: Some(2),
wildcard: "",
},
PassiveResidues {
chain_id: "B",
res_number: Some(3),
wildcard: "",
},
]);

let block = "assign ( resid 1 and segid A and (name CA or name CB) )\n (\n ( resid 2 and segid B and (name CA or name CB) )\n or\n ( resid 3 and segid B and (name CA or name CB) )\n ) 2.0 2.0 0.0\n\n";

assert_eq!(observed, block);
}

#[test]
fn test_create_block_active_atoms() {
let mut interactor = Interactor::new(1);
Expand Down

0 comments on commit 8203d24

Please sign in to comment.