Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
#!/usr/bin/env python
"""Calculates few statistics about the result of the simulation"""
import sys
import os
from lightdock.util.logger import LoggingManager
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure
log = LoggingManager.get_logger('stats')
def usage():
"""Displays usage parameters and exists with error"""
log.error("Wrong arguments")
raise SystemExit("usage: %s number_of_steps number_of_glowworms" % (sys.argv[0]))
def parse_command_line():
# Arguments parsing
if len(sys.argv) != 3:
usage()
try:
num_steps = int(sys.argv[1])
except Exception, e:
log.error(str(e))
import argparse
import numpy as np
from lightdock.util.parser import SetupCommandLineParser
from lightdock.prep.simulation import read_input_structure, save_lightdock_structure, \
calculate_starting_positions, prepare_results_environment, \
create_setup_file, calculate_anm, parse_restraints_file, \
get_restraints
from lightdock.constants import DEFAULT_LIGHTDOCK_PREFIX, DEFAULT_ELLIPSOID_DATA_EXTENSION, \
DEFAULT_NMODES_REC, DEFAULT_REC_NM_FILE, DEFAULT_NMODES_LIG, DEFAULT_LIG_NM_FILE
from lightdock.mathutil.ellipsoid import MinimumVolumeEllipsoid
from lightdock.util.logger import LoggingManager
from lightdock.error.lightdock_errors import LightDockError
log = LoggingManager.get_logger('lightdock_setup')
if __name__ == "__main__":
try:
parser = SetupCommandLineParser()
args = parser.args
# Read input structures
receptor = read_input_structure(args.receptor_pdb, args.noxt, args.noh, args.verbose_parser)
ligand = read_input_structure(args.ligand_pdb, args.noxt, args.noh, args.verbose_parser)
# Move structures to origin
rec_translation = receptor.move_to_origin()
lig_translation = ligand.move_to_origin()
"""Cluster LightDock final swarm results using an hierarchical algorithm"""
import os
import argparse
import math
import numpy as np
import scipy.cluster.hierarchy as hier
import Bio.PDB
from lightdock.constants import CLUSTER_ANALYSIS_FILE, DEFAULT_SWARM_FOLDER, DEFAULT_RMSD_EXTENSION, \
NUMPY_FILE_SAVE_EXTENSION, EVALUATION_FILE, SCORING_FILE, GSO_OUTPUT_FILE, LIGHTDOCK_PDB_FILE, \
CLUSTER_DEFAULT_NAME, CLUSTER_REPRESENTATIVES_FILE
from lightdock.util.logger import LoggingManager
from lightdock.util.analysis import read_rmsd_and_contacts_data, read_lightdock_output
log = LoggingManager.get_logger('lgd_cluster_hierarchical')
POPULATION_THRESHOLD = 10
def parse_command_line():
"""
Parses command line arguments
"""
parser = argparse.ArgumentParser(prog='cluster_poses')
parser.add_argument("swarm_id", help="swarm to consider for clustering", type=int, metavar="swarm_id")
parser.add_argument("steps", help="steps to consider", type=int, metavar="steps")
parser.add_argument("-f", "--file_name", help="lightdock output file to consider", dest="result_file")
parser.add_argument("-p", "--ponderated", help="Structures selection takes into account cluster population",
dest="ponderated", action="store_true")
from lightdock.util.parser import CommandLineParser
from lightdock.prep.simulation import get_setup_from_file, create_simulation_info_file, read_input_structure, \
load_starting_positions, get_default_box
from lightdock.gso.algorithm import LightdockGSOBuilder
from lightdock.mathutil.lrandom import MTGenerator
from lightdock.gso.parameters import GSOParameters
from lightdock.constants import DEFAULT_SCORING_FUNCTION, DEFAULT_SWARM_FOLDER, \
DEFAULT_REC_NM_FILE, DEFAULT_LIG_NM_FILE, NUMPY_FILE_SAVE_EXTENSION, \
DEFAULT_NMODES_REC, DEFAULT_NMODES_LIG
from lightdock.parallel.kraken import Kraken
from lightdock.parallel.util import GSOClusterTask
from lightdock.scoring.multiple import ScoringConfiguration
from lightdock.structure.nm import read_nmodes
log = LoggingManager.get_logger('lightdock')
def set_gso(number_of_glowworms, adapters, scoring_functions, initial_positions, seed,
step_translation, step_rotation, configuration_file=None,
use_anm=False, nmodes_step=0.1, anm_rec=DEFAULT_NMODES_REC, anm_lig=DEFAULT_NMODES_LIG,
local_minimization=False):
"""Creates a lightdock GSO simulation object"""
bounding_box = get_default_box(use_anm, anm_rec, anm_lig)
random_number_generator = MTGenerator(seed)
if configuration_file:
gso_parameters = GSOParameters(configuration_file)
else:
gso_parameters = GSOParameters()
builder = LightdockGSOBuilder()
"""Module to calculate normal modes of a given protein.
It uses the awesome Prody library
"""
import numpy as np
from prody import parsePDB, ANM, extendModel, confProDy
from lightdock.error.lightdock_errors import NormalModesCalculationError
from lightdock.util.logger import LoggingManager
# Disable ProDy output
confProDy(verbosity='none')
log = LoggingManager.get_logger('ANM')
def calculate_nmodes(pdb_file_name, n_modes, molecule):
"""Calculates Normal modes for a given molecule"""
prody_molecule = parsePDB(pdb_file_name)
# Try first for proteins
backbone_atoms = prody_molecule.select('name CA')
if not backbone_atoms:
# If previous step has failed, maybe we're dealing with DNA
backbone_atoms = prody_molecule.select("nucleic and name C4'")
if not backbone_atoms:
raise NormalModesCalculationError("Error selecting backbone atoms (protein or DNA)")
molecule_anm = ANM('molecule backbone')
molecule_anm.buildHessian(backbone_atoms)
molecule_anm.calcModes(n_modes=n_modes)
#!/usr/bin/env python
"""Calculates the reference points of the simulation"""
import os
import argparse
from lightdock.constants import DEFAULT_LIST_EXTENSION, DEFAULT_REFERENCE_POINTS_EXTENSION
from lightdock.error.lightdock_errors import MinimumVolumeEllipsoidError
from lightdock.mathutil.ellipsoid import MinimumVolumeEllipsoid
from lightdock.pdbutil.PDBIO import parse_complex_from_file, create_pdb_from_points
from lightdock.structure.complex import Complex
from lightdock.util.logger import LoggingManager
script_name = 'reference_points'
log = LoggingManager.get_logger(script_name)
def parse_command_line():
parser = argparse.ArgumentParser(prog=script_name)
parser.add_argument("structure", help="structure to calculate reference points", metavar="structure")
parser.add_argument("--noxt", help="Remove OXT atoms", dest="noxt", action='store_true', default=False)
return parser.parse_args()
def get_pdb_files(input_file_name):
"""Get a list of the PDB files in the input_file_name"""
structure_file_names = []
with open(input_file_name) as input_file:
for line in input_file:
structure_file_name = line.rstrip(os.linesep)
if os.path.exists(structure_file_name):
import os
import sys
from lightdock.util.logger import LoggingManager
from lightdock.pdbutil.PDBIO import parse_complex_from_file
from lightdock.structure.complex import Complex
from lightdock.gso.boundaries import Boundary, BoundingBox
from lightdock.mathutil.lrandom import MTGenerator
from lightdock.gso.parameters import GSOParameters
from lightdock.mathutil.cython.quaternion import Quaternion
from lightdock.scoring.dfire.driver import DFIRE, DFIREAdapter
from lightdock.gso.algorithm import GSO
from lightdock.gso.searchspace.landscape import DockingLandscapePosition
from lightdock.gso.swarm import Swarm
log = LoggingManager.get_logger('relightdock')
MAX_TRANSLATION = 30 # In Angstroms
MAX_ROTATION = 1.0 # Quaternion default value for its components
DEFAULT_TRANSLATION_STEP = 0.5 # Normalized step
DEFAULT_ROTATION_STEP = 0.5 # Normalized SLERP step. 1 means full jump, 0 means no movement
GSO_SEED = 324324 # Seed for the random number generator in the GSO algorithm
STARTING_POINTS_SEED = 324324
def parse_output_file(lightdock_output):
translations = []
rotations = []
luciferin = []
neighbors = []
vision_range = []
scoring = []
import numpy as np
import freesasa
from freesasa import Structure
from lightdock.scoring.functions import ScoringFunction, ModelAdapter
from lightdock.structure.model import DockingModel
import lightdock.scoring.cpydock.energy.c.cpydock as cpydock
import lightdock.scoring.cpydock.energy.parameters as parameters
from lightdock.util.logger import LoggingManager
import lightdock.scoring.cpydock.data.amber as amber
import lightdock.scoring.cpydock.data.vdw as vdw
import lightdock.scoring.cpydock.data.solvation as solvation
from lightdock.constants import DEFAULT_CONTACT_RESTRAINTS_CUTOFF
log = LoggingManager.get_logger('cpydock')
freesasa.setVerbosity(freesasa.silent)
class CPyDockModel(DockingModel):
"""Prepares the structure necessary for the C-implementation of the pyDock scoring function"""
def __init__(self, objects, coordinates, restraints, charges,
vdw_energy, vdw_radii, des_energy, des_radii, sasa, hydrogens,
reference_points=None, n_modes=None):
super(CPyDockModel, self).__init__(objects, coordinates, restraints, reference_points)
self.charges = charges
self.vdw_energy = vdw_energy
self.vdw_radii = vdw_radii
self.des_energy = des_energy
self.des_radii = des_radii
self.sasa = sasa
self.hydrogens = hydrogens
#!/usr/bin/env python
"""Calculates the diameter of a given PDB structure"""
import argparse
from scipy import spatial
import numpy as np
from lightdock.pdbutil.PDBIO import parse_complex_from_file
from lightdock.structure.complex import Complex
from lightdock.util.logger import LoggingManager
log = LoggingManager.get_logger('diameter')
def parse_command_line():
parser = argparse.ArgumentParser(prog='calculate_diameter')
parser.add_argument("pdb", help="PDB file for structure to calculate maximum diameter")
args = parser.parse_args()
return args
if __name__ == "__main__":
args = parse_command_line()
atoms, residues, chains = parse_complex_from_file(args.pdb)
structure = Complex(chains, atoms, structure_file_name=args.pdb)
distances_matrix = spatial.distance.squareform(spatial.distance.pdist(structure.representative()))
ligand_max_diameter = np.max(distances_matrix)