Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "lightdock"
version = "0.3.2"
version = "0.3.3"
authors = ["Brian Jimenez Garcia <br.jimenezgarcia@gmail.com>"]
edition = "2021"
license = "GPL-3.0-only"
Expand Down
18 changes: 9 additions & 9 deletions src/dfire.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::constants::{INTERFACE_CUTOFF, MEMBRANE_PENALTY_SCORE};
use super::constants::{INTERFACE_CUTOFF2, MEMBRANE_PENALTY_SCORE};
use super::qt::Quaternion;
use super::scoring::{membrane_intersection, satisfied_restraints, Score};
use pdbtbx::PDB;
Expand Down Expand Up @@ -280,13 +280,7 @@ impl Score for DFIRE {

// Get the proper ligand pose
for (i_atom, coordinate) in ligand_coordinates.iter_mut().enumerate() {
// First rotate
let rotated_coordinate = rotation.rotate(coordinate.to_vec());
// Then tranlate
coordinate[0] = rotated_coordinate[0] + translation[0];
coordinate[1] = rotated_coordinate[1] + translation[1];
coordinate[2] = rotated_coordinate[2] + translation[2];
// ANM
// ANM is applied first, as normal modes are in the original ligand frame
if self.use_anm && self.ligand.num_anm > 0 {
for i_nm in 0usize..self.ligand.num_anm {
// (num_anm, num_atoms, 3) -> 1d
Expand All @@ -299,6 +293,12 @@ impl Score for DFIRE {
* lig_nmodes[i_nm];
}
}
// First rotate
let rotated_coordinate = rotation.rotate(coordinate.to_vec());
// Then translate
coordinate[0] = rotated_coordinate[0] + translation[0];
coordinate[1] = rotated_coordinate[1] + translation[1];
coordinate[2] = rotated_coordinate[2] + translation[2];
}
// Receptor only needs to use ANM
for (i_atom, coordinate) in receptor_coordinates.iter_mut().enumerate() {
Expand Down Expand Up @@ -336,7 +336,7 @@ impl Score for DFIRE {
let d = dist.sqrt() * 2.0 - 1.0;
let dfire_bin = DIST_TO_BINS[d as usize] - 1;
score += self.potential[atoma * 169 * 20 + atomb * 20 + dfire_bin];
if d <= INTERFACE_CUTOFF {
if dist <= INTERFACE_CUTOFF2 {
interface_receptor[i] = 1;
interface_ligand[j] = 1;
}
Expand Down
14 changes: 7 additions & 7 deletions src/dna.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,13 +424,7 @@ impl Score for DNA {

// Get the proper ligand pose
for (i_atom, coordinate) in ligand_coordinates.iter_mut().enumerate() {
// First rotate
let rotated_coordinate = rotation.rotate(coordinate.to_vec());
// Then tranlate
coordinate[0] = rotated_coordinate[0] + translation[0];
coordinate[1] = rotated_coordinate[1] + translation[1];
coordinate[2] = rotated_coordinate[2] + translation[2];
// ANM
// ANM is applied first, as normal modes are in the original ligand frame
if self.use_anm && self.ligand.num_anm > 0 {
for i_nm in 0usize..self.ligand.num_anm {
// (num_anm, num_atoms, 3) -> 1d
Expand All @@ -443,6 +437,12 @@ impl Score for DNA {
* lig_nmodes[i_nm];
}
}
// First rotate
let rotated_coordinate = rotation.rotate(coordinate.to_vec());
// Then translate
coordinate[0] = rotated_coordinate[0] + translation[0];
coordinate[1] = rotated_coordinate[1] + translation[1];
coordinate[2] = rotated_coordinate[2] + translation[2];
}
// Receptor only needs to use ANM
for (i_atom, coordinate) in receptor_coordinates.iter_mut().enumerate() {
Expand Down
14 changes: 7 additions & 7 deletions src/pydock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,13 +439,7 @@ impl Score for PYDOCK {

// Get the proper ligand pose
for (i_atom, coordinate) in ligand_coordinates.iter_mut().enumerate() {
// First rotate
let rotated_coordinate = rotation.rotate(coordinate.to_vec());
// Then tranlate
coordinate[0] = rotated_coordinate[0] + translation[0];
coordinate[1] = rotated_coordinate[1] + translation[1];
coordinate[2] = rotated_coordinate[2] + translation[2];
// ANM
// ANM is applied first, as normal modes are in the original ligand frame
if self.use_anm && self.ligand.num_anm > 0 {
for i_nm in 0usize..self.ligand.num_anm {
// (num_anm, num_atoms, 3) -> 1d
Expand All @@ -458,6 +452,12 @@ impl Score for PYDOCK {
* lig_nmodes[i_nm];
}
}
// First rotate
let rotated_coordinate = rotation.rotate(coordinate.to_vec());
// Then translate
coordinate[0] = rotated_coordinate[0] + translation[0];
coordinate[1] = rotated_coordinate[1] + translation[1];
coordinate[2] = rotated_coordinate[2] + translation[2];
}
// Receptor only needs to use ANM
for (i_atom, coordinate) in receptor_coordinates.iter_mut().enumerate() {
Expand Down
1 change: 0 additions & 1 deletion src/qt.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use super::constants::LINEAR_THRESHOLD;
use rand::Rng;
use std::f64;
use std::f64::consts::PI;
use std::ops;

Expand Down
131 changes: 131 additions & 0 deletions tests/scoring_geometry.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
//! Tests for the ligand pose and the interface calculated by the scoring functions
use lightdock::dfire::DFIRE;
use lightdock::dna::DNA;
use lightdock::pydock::PYDOCK;
use lightdock::qt::Quaternion;
use std::fs;

fn open(path: &str) -> pdbtbx::PDB {
pdbtbx::open(path, pdbtbx::StrictnessLevel::Medium)
.unwrap()
.0
}

/// Writes a structure made of a single alpha carbon at the origin
fn single_atom(name: &str, chain: char) -> String {
let path = format!("{}/{}.pdb", env!("CARGO_TARGET_TMPDIR"), name);
let line = format!(
"ATOM 1 CA ALA {} 1 0.000 0.000 0.000 1.00 0.00 C\n",
chain
);
fs::write(&path, line).unwrap();
path
}

/// A ligand mode shifting every atom 2 A along x, under a 180 degrees rotation around z,
/// must move the ligand 2 A towards -x
macro_rules! anm_rotates_with_ligand {
($name:ident, $function:ident, $receptor:expr, $ligand:expr) => {
#[test]
fn $name() {
let mode: Vec<f64> = (0..open($ligand).atom_count())
.flat_map(|_| vec![2.0, 0.0, 0.0])
.collect();
let build = |modes: Vec<f64>, num_anm: usize| {
$function::new(
open($receptor),
vec![],
vec![],
vec![],
0,
open($ligand),
vec![],
vec![],
modes,
num_anm,
num_anm > 0,
)
};
let rotation = Quaternion::new(0.0, 0.0, 0.0, 1.0);

let flexible = build(mode, 1).energy(&[0.0, 0.0, 0.0], &rotation, &[], &[1.0]);
let expected = build(vec![], 0).energy(&[-2.0, 0.0, 0.0], &rotation, &[], &[]);

assert!((flexible - expected).abs() < 1e-8);
}
};
}

/// Restraints on both partners triple the score only if their atoms are in contact
macro_rules! contact_cutoff {
($name:ident, $function:ident) => {
#[test]
fn $name() {
let receptor = single_atom(concat!(stringify!($name), "_receptor"), 'A');
let ligand = single_atom(concat!(stringify!($name), "_ligand"), 'B');
let build = |rec_restraints: Vec<String>, lig_restraints: Vec<String>| {
$function::new(
open(&receptor),
rec_restraints,
vec![],
vec![],
0,
open(&ligand),
lig_restraints,
vec![],
vec![],
0,
false,
)
};
let free = build(vec![], vec![]);
let restrained = build(vec!["A.ALA.1".to_string()], vec!["B.ALA.1".to_string()]);

for (distance, in_contact) in [
(2.0, true),
(3.0, true),
(3.89, true),
(3.91, false),
(5.0, false),
] {
let translation = [distance, 0.0, 0.0];
let rotation = Quaternion::default();
let score = free.energy(&translation, &rotation, &[], &[]);
let biased = restrained.energy(&translation, &rotation, &[], &[]);
let factor = if in_contact { 3.0 } else { 1.0 };

assert!(score != 0.0, "score is zero at {} A", distance);
assert!(
(biased - factor * score).abs() < 1e-8,
"wrong contact at {} A: score {} restrained {}",
distance,
score,
biased
);
}
}
};
}

anm_rotates_with_ligand!(
dfire_anm_rotates_with_ligand,
DFIRE,
"tests/2oob/2oob_receptor.pdb",
"tests/2oob/2oob_ligand.pdb"
);
anm_rotates_with_ligand!(
dna_anm_rotates_with_ligand,
DNA,
"tests/1azp/1azp_receptor.pdb",
"tests/1azp/1azp_ligand.pdb"
);
anm_rotates_with_ligand!(
pydock_anm_rotates_with_ligand,
PYDOCK,
"tests/1azp/1azp_receptor.pdb",
"tests/1azp/1azp_ligand.pdb"
);

contact_cutoff!(dfire_contact_cutoff, DFIRE);
contact_cutoff!(dna_contact_cutoff, DNA);
contact_cutoff!(pydock_contact_cutoff, PYDOCK);
Loading