Skip to content

Commit

Permalink
Scoring functions api fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
alchemistcai committed Jun 20, 2023
1 parent 0095a6f commit 7963145
Show file tree
Hide file tree
Showing 44 changed files with 482 additions and 167 deletions.
8 changes: 1 addition & 7 deletions bin/lgd_generate_glowworm_positions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,12 @@
import os
from lightdock.pdbutil.PDBIO import create_pdb_from_points
from lightdock.util.logger import LoggingManager
from lightdock.util.parser import valid_file


log = LoggingManager.get_logger("generate_glowworm_positions")


def valid_file(file_name):
"""Checks if it is a valid file"""
if not os.path.exists(file_name):
raise argparse.ArgumentTypeError("The file does not exist")
return file_name


def parse_output_file(lightdock_output):
glowworm_translations = []

Expand Down
8 changes: 1 addition & 7 deletions bin/lgd_generate_trajectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,12 @@
from lightdock.pdbutil.PDBIO import parse_complex_from_file, write_pdb_to_file
from lightdock.structure.complex import Complex
from lightdock.prep.simulation import get_setup_from_file
from lightdock.util.parser import valid_file


log = LoggingManager.get_logger("lgd_generate_trajectory")


def valid_file(file_name):
"""Checks if it is a valid file"""
if not os.path.exists(file_name):
raise argparse.ArgumentTypeError("The file does not exist")
return file_name


def parse_command_line():
parser = argparse.ArgumentParser(prog="lgd_generate_trajectory")
parser.add_argument(
Expand Down
8 changes: 1 addition & 7 deletions bin/lgd_move_anm.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from lightdock.pdbutil.PDBIO import parse_complex_from_file, write_pdb_to_file
from lightdock.structure.complex import Complex
from lightdock.util.logger import LoggingManager
from lightdock.util.parser import valid_file
from lightdock.constants import DEFAULT_EXTENT_MU, DEFAULT_EXTENT_SIGMA

log = LoggingManager.get_logger("lgd_move_anm")
Expand All @@ -18,13 +19,6 @@
RANDOM_SEED = 324324


def valid_file(file_name):
"""Checks if it is a valid file"""
if not os.path.exists(file_name):
raise argparse.ArgumentTypeError("The file does not exist")
return file_name


def parse_command_line():
parser = argparse.ArgumentParser(prog="lgd_move_anm")
parser.add_argument(
Expand Down
4 changes: 2 additions & 2 deletions bin/lgd_rank.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ def parse_command_line():
args = parse_command_line()

solutions = []
contacts = []
rmsds = []
contacts = {}
rmsds = {}
if os.path.isfile(EVALUATION_FILE):
contacts, rmsds = read_rmsd_and_contacts_data(EVALUATION_FILE)

Expand Down
68 changes: 34 additions & 34 deletions lightdock/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,73 +4,73 @@
DEFAULT_NUM_SWARMS = 400
DEFAULT_NUM_GLOWWORMS = 200

"""GSO algorithm constants"""
# Maximum translation allowed at initialization (in Angstroms)
# GSO algorithm constants
MAX_TRANSLATION = 30
# Quaternion default value for its components
"""Maximum translation allowed at initialization (in Angstroms)"""
MAX_ROTATION = 1.0
# Default generic GSO step (does only apply to J* functions
"""Quaternion default value for its components"""
DEFAULT_STEP_SIZE = 0.03
# Interpolation step for translation (in %)
"""Default generic GSO step (does only apply to J* functions"""
DEFAULT_TRANSLATION_STEP = 0.5
# Normalized SLERP step. 1 means full jump, 0 means no movement
"""Interpolation step for translation (in %)"""
DEFAULT_ROTATION_STEP = 0.5
# Seed for the random number generator in the GSO algorithm
"""Normalized SLERP step. 1 means full jump, 0 means no movement"""
GSO_SEED = 324324
# Seed for the random number generator used for calculating starting points
"""Seed for the random number generator in the GSO algorithm"""
STARTING_POINTS_SEED = 324324
"""Seed for the random number generator used for calculating starting points"""

"""Normal modes"""
# Default number of normal modes to consider for receptor
# Normal modes
DEFAULT_NMODES_REC = 10
# Default number of normal modes to consider for ligand
"""Default number of normal modes to consider for receptor"""
DEFAULT_NMODES_LIG = 10
# Default RMSD interval at which conformations will be sampled through ANM
"""Default number of normal modes to consider for ligand"""
DEFAULT_ANM_RMSD = 0.5
# Default mean and std for the Normal distribution for random ANM extents
"""Default RMSD interval at which conformations will be sampled through ANM"""
DEFAULT_EXTENT_MU = 0.0
"""Default mean for the Normal distribution for random ANM extents"""
DEFAULT_EXTENT_SIGMA = 1.0
"""Default std for the Normal distribution for random ANM extents"""
# Boundaries, this does not affect to modes generation
MIN_EXTENT = 0.0
MAX_EXTENT = 1.0
# Seed for the random number generator used for calculating normal modes extent
STARTING_NM_SEED = 324324
"""Seed for the random number generator used for calculating normal modes extent"""
# When interpolating, which
DEFAULT_NMODES_STEP = 0.5
DEFAULT_REC_NM_FILE = "lightdock_rec.nm"
DEFAULT_LIG_NM_FILE = "lightdock_lig.nm"

"""Scoring function constants"""
# LightDock default scoring function if none is specified
# Scoring function constants
DEFAULT_SCORING_FUNCTION = "fastdfire"
# Threshold for an atomic-pair to be considered a contact (in Angstroms)
"""LightDock default scoring function if none is specified"""
DEFAULT_ATOMIC_CONTACT = 3.9
# Threshold for an atomic-pair to be considered a contact in restraints definition (in Angstroms)
"""Threshold for an atomic-pair to be considered a contact (in Angstroms)"""
DEFAULT_CONTACT_RESTRAINTS_CUTOFF = 3.9
"""Threshold for an atomic-pair to be considered a contact in restraints definition (in Angstroms)"""

"""Default file extensions"""
# Default file extensions
DEFAULT_REFERENCE_POINTS_EXTENSION = ".vol"
DEFAULT_LIST_EXTENSION = ".list"
DEFAULT_RMSD_EXTENSION = ".rmsd"
NUMPY_FILE_SAVE_EXTENSION = ".npy"
DEFAULT_REPRESENTATIVES_EXTENSION = ".repr"
DEFAULT_ELLIPSOID_DATA_EXTENSION = ".xyz"

"""Default file names and folders"""
# Folder which contains the initial_positions files for each swarm
# Default file names and folders
DEFAULT_POSITIONS_FOLDER = "init"
# Simulation default output file
"""Folder which contains the initial_positions files for each swarm"""
GSO_OUTPUT_FILE = "gso_%s.out"
# Folder where GSO execution for a given swarm will be stored
"""Simulation default output file"""
DEFAULT_SWARM_FOLDER = "swarm_"
# Stores simulation step information
"""Folder where GSO execution for a given swarm will be stored"""
DEFAULT_SETUP_FILE = "setup.json"
"""Stores simulation step information"""
DEFAULT_PDB_STARTING_PREFIX = "starting_positions"
DEFAULT_BILD_STARTING_PREFIX = "starting_poses"
DEFAULT_STARTING_PREFIX = "initial_positions"
# A special PDB file containing all swarm centers over the receptor surface
# centered at origin of coordinates (use together with LightDock receptor parsed PDB)
SWARM_CENTERS_FILE = "swarm_centers.pdb"
"""A special PDB file containing all swarm centers over the receptor surface centered at origin of coordinates (use together with LightDock receptor parsed PDB)"""

RANKING_FILE = "solutions.list"
RANKING_BY_RMSD_FILE = "rank_by_rmsd.list"
Expand All @@ -82,20 +82,20 @@
LIGHTDOCK_PDB_FILE = "lightdock_%s.pdb"
CLUSTER_DEFAULT_NAME = "cluster"
CLUSTER_REPRESENTATIVES_FILE = CLUSTER_DEFAULT_NAME + DEFAULT_REPRESENTATIVES_EXTENSION
# Each independent simulation generates a new file:
DEFAULT_LIGHTDOCK_INFO = "lightdock.info"
"""Each independent simulation generates a new file"""
DEFAULT_MASK_FILE = "lightdock_%s_mask" + NUMPY_FILE_SAVE_EXTENSION

"""Swarm calculations"""
# Total SASA will be divided by this number
# Swarm calculations
DEFAULT_SURFACE_DENSITY = 50.0
# Swarm radius for the boundary of possible translations of initial poses
"""Total SASA will be divided by this number"""
DEFAULT_SWARM_RADIUS = 10.0
# If this value is 0.0, swarm distance is estimated using the ligand max diameter
"""Swarm radius for the boundary of possible translations of initial poses"""
DEFAULT_SWARM_DISTANCE = 0.0
# Number of swarms to keep when applying restraints
"""If this value is 0.0, swarm distance is estimated using the ligand max diameter"""
DEFAULT_SWARMS_PER_RESTRAINT = 20
# Number of sampling points per centroid in automatic swarm calculation
"""Number of swarms to keep when applying restraints"""
DEFAULT_SPHERES_PER_CENTROID = 100
# Cutoff for filtering swarms too close to the surface
"""Number of sampling points per centroid in automatic swarm calculation"""
SWARM_DISTANCE_TO_SURFACE_CUTOFF = 3.0
"""Cutoff for filtering swarms too close to the surface"""
4 changes: 2 additions & 2 deletions lightdock/gso/boundaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ def get_boundary_of_dimension(self, dimension_index):
"""Gets the Boundary of the dimension with dimension_index"""
return self.boundaries[dimension_index]

def __repr__(self):
return " ".join([str(b) for b in self.boundaries])
def __repr__(self) -> str:
return " ".join(str(b) for b in self.boundaries)
6 changes: 2 additions & 4 deletions lightdock/gso/coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,8 @@ def move(self, other, step=1.0):
def __repr__(self):
"""Coordinate representation"""
# Path for equivalent representation from Python 2.7
coord = ["{:.12g}".format(f) for f in self._values]
return "(%s)" % ", ".join(
["{}.0".format(f) if "." not in f else f for f in coord]
)
coord = (f"{f:.12g}" for f in self._values)
return "(%s)" % ", ".join(f"{f}.0" if "." not in f else f for f in coord)

def __len__(self):
return self.dimension
Expand Down
28 changes: 10 additions & 18 deletions lightdock/gso/glowworm.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(self, landscape_positions, gso_parameters):

def search_neighbors(self, glowworms):
"""Searches in a list of glowworms for neighbors of this glowworm"""
squared_vision_range = self.vision_range * self.vision_range
squared_vision_range = self.vision_range ** 2
self.neighbors = [
glowworm
for glowworm in glowworms
Expand All @@ -51,10 +51,8 @@ def compute_luciferin(self):
"""Updates luciferin of the current glowworm and returns its value"""
if self.moved or self.step == 0:
self.scoring = sum(
[
landscape_position.evaluate_objective_function()
for landscape_position in self.landscape_positions
]
landscape_position.evaluate_objective_function()
for landscape_position in self.landscape_positions
)
self.luciferin = (1.0 - self.rho) * self.luciferin + self.gamma * self.scoring
self.step += 1
Expand All @@ -74,16 +72,12 @@ def distance2(self, other, scoring_id=0):

def compute_probability_moving_toward_neighbor(self):
"""Computes the probability of this glowworm to move towards any of his neighbors"""
self.probabilities = []

total_sum = 0.0
for neighbor in self.neighbors:
difference = neighbor.luciferin - self.luciferin
self.probabilities.append(difference)
total_sum += difference

for i in range(len(self.neighbors)):
self.probabilities[i] /= total_sum
differences = [
neighbor.luciferin - self.luciferin for neighbor in self.neighbors
]
total_sum = sum(differences)
self.probabilities = [difference / total_sum for difference in differences]

def select_random_neighbor(self, random_number):
"""Selects a neighbor in the neighbors list using accumulated probabilities of
Expand Down Expand Up @@ -133,10 +127,8 @@ def update_vision_range(self):
def minimize(self):
"""Minimizes the glowworm's landscape position and updates its scoring"""
self.scoring = sum(
[
landscape_position.minimize()
for landscape_position in self.landscape_positions
]
landscape_position.minimize()
for landscape_position in self.landscape_positions
)

def __repr__(self):
Expand Down
6 changes: 6 additions & 0 deletions lightdock/gso/searchspace/cython/j1.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""J1: peaks function"""


def j1(x: float, y: float) -> float:
"""J1: peaks function"""
...
6 changes: 6 additions & 0 deletions lightdock/gso/searchspace/cython/j2.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""J2: Rastrigin's function"""


def j2(x: float, y: float) -> float:
"""J2: Rastrigin's function"""
...
6 changes: 6 additions & 0 deletions lightdock/gso/searchspace/cython/j3.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""J3: circles function"""


def j3(x: float, y: float) -> float:
"""J3: circles function"""
...
6 changes: 6 additions & 0 deletions lightdock/gso/searchspace/cython/j4.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""J4: staircase function"""


def j4(x: float, y: float) -> float:
"""J4: staircase function"""
...
6 changes: 6 additions & 0 deletions lightdock/gso/searchspace/cython/j5.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""J5: plateaus function"""


def j5(x: float, y: float) -> float:
"""J5: plateaus function"""
...
5 changes: 3 additions & 2 deletions lightdock/gso/swarm.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""The set of swarms of glowworm agents used in the algorithm"""

from operator import attrgetter
from pathlib import Path
from lightdock.gso.glowworm import Glowworm


Expand Down Expand Up @@ -62,9 +63,9 @@ def get_size(self):
def save(self, step, destination_path, file_name=""):
"""Saves actual population status to a file"""
if file_name:
dest_file_name = "%s/%s" % (destination_path, file_name)
dest_file_name = Path(destination_path) / file_name
else:
dest_file_name = "%s/gso_%d.out" % (destination_path, step)
dest_file_name = Path(destination_path) / f"gso_{step:d}.out"

dest_file = open(dest_file_name, "w")
dest_file.write(str(self))
Expand Down
44 changes: 44 additions & 0 deletions lightdock/mathutil/cython/cutil.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from typing import Iterable


def sum_of_squares(values: Iterable[float]) -> float:
"""
Calculates the sum of squares of each value in values
"""
...


def norm(values: Iterable[float]) -> float:
"""
Calculates the norm of the given values
"""
...


def float_equals(a: float, b: float, precision: float = 1e-7) -> bool:
"""
Compares two floats for equality given precision
"""
...


def sum_of_square_difference(v1: Iterable[float], v2: Iterable[float]) -> float:
"""
Calculates the sum of the square differences of the components of
v1 and v2 vectors.
"""
...


def distance(x1: float, y1: float, z1: float, x2: float, y2: float, z2: float) -> float:
"""
Calculates the distance between point 1 and point 2.
"""
...


def distance2(x1: float, y1: float, z1: float, x2: float, y2: float, z2: float) -> float:
"""
Calculates the distance^2 between point 1 and point 2.
"""
...
Loading

0 comments on commit 7963145

Please sign in to comment.