Skip to content

Commit

Permalink
stub to generate restraints [wip]
Browse files Browse the repository at this point in the history
  • Loading branch information
rvhonorato committed Aug 12, 2024
1 parent 6011618 commit 24238f0
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
54 changes: 52 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ mod structure;
use air::Air;
use core::panic;
use interactor::Interactor;
use std::collections::HashMap;
use std::fs::File;
use std::io::BufWriter;
use std::path::Path;
Expand Down Expand Up @@ -266,6 +267,8 @@ fn generate_z_restraints(
let atoms1: Vec<pdbtbx::Atom>;
let atoms2: Vec<pdbtbx::Atom>;

let mut restraints: HashMap<isize, Vec<structure::Bead>> = HashMap::new();

if selections.len() >= 2 {
(atoms1, atoms2) = structure::find_furthest_selections(selections, &pdb);
} else {
Expand Down Expand Up @@ -296,8 +299,8 @@ fn generate_z_restraints(
let half_length = (max_z - min_z) / 2.0;

// Project endpoints onto global Z-axis
let start_z = center1.z.min(center2.z);
let end_z = center1.z.max(center2.z);
// let start_z = center1.z.min(center2.z);
// let end_z = center1.z.max(center2.z);
// let start = nalgebra::Vector3::new(0.0, 0.0, start_z);
// let end = nalgebra::Vector3::new(0.0, 0.0, end_z);

Expand All @@ -309,6 +312,9 @@ fn generate_z_restraints(
let grid_beads1 = structure::generate_grid_beads(-half_length, *grid_size, *grid_spacing);
let grid_beads2 = structure::generate_grid_beads(half_length, *grid_size, *grid_spacing);

restraints.insert(0, grid_beads1.clone());
restraints.insert(1, grid_beads2.clone());

// let atoms3 = structure::get_atoms_from_resnumbers(&pdb, &selections[2]);
// let center_atoms3 = structure::calculate_geometric_center(&atoms3);
// let grid_beads3 = structure::generate_grid_beads(center_atoms3.z, *grid_size, *grid_spacing);
Expand All @@ -322,6 +328,50 @@ fn generate_z_restraints(

structure::write_beads_pdb(&all_beads, "z_beads.pdb")?;

let mut interactors: Vec<Interactor> = Vec::new();
let mut counter = 0;
selections
.iter()
.enumerate()
.for_each(|(index, selection)| {
let beads = restraints.get(&(index as isize)).unwrap();
// Get the z coordinates of the first bead
let z = beads[0].position.z;
//

selection.iter().for_each(|resnum| {
let mut interactor_i = Interactor::new(counter);
counter += 1;
let mut interactor_j = Interactor::new(counter);
interactor_j.add_target(counter - 1);
interactor_i.add_target(counter);
counter += 1;

interactor_i.set_chain("A");
interactor_i.set_active(vec![*resnum as i16]);
interactor_i.set_active_atoms(vec!["CA".to_string()]);
interactor_i.set_lower_margin(0.0);
interactor_i.set_upper_margin(0.0);
interactor_i.set_target_distance(2.0);

interactor_j.set_chain("S");
interactor_j.set_active_atoms(vec!["SHA".to_string()]);
interactor_j.set_wildcard(format!("attr z gt {:?}", z).as_str());

interactors.push(interactor_i);
interactors.push(interactor_j);
});
});

// interactors.iter().for_each(|interactor| {
// println!("Interactor: {:?}", interactor);
// });

let air = Air::new(interactors);
let tbl = air.gen_tbl().unwrap();

println!("{}", tbl);

Ok(())
}

Expand Down
3 changes: 2 additions & 1 deletion src/structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ use rand::SeedableRng;
use std::fs::File;
use std::io::Write;

#[derive(Clone)]
pub struct Bead {
position: Vector3<f64>,
pub position: Vector3<f64>,
}

pub fn neighbor_search(
Expand Down

0 comments on commit 24238f0

Please sign in to comment.