Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""Parses Atomic coordinates entries from PDB files"""
import math
from lightdock.error.lightdock_errors import PDBParsingError, PDBParsingWarning
from lightdock.structure.atom import Atom, HetAtom
from lightdock.structure.residue import Residue
from lightdock.structure.chain import Chain
from lightdock.util.logger import LoggingManager
log = LoggingManager.get_logger('pdb')
def cstrip(string):
"""Remove unwanted symbols from string."""
return string.strip(' \t\n\r')
def read_atom_line(line, line_type='', atoms_to_ignore=[]):
"""Parses a PDB file line starting with 'ATOM' or 'HETATM'"""
element = cstrip(line[76:78])
try:
x = float(line[30:38])
y = float(line[38:46])
z = float(line[46:54])
if math.isnan(x) or math.isnan(y) or math.isnan(z):
import json
import time
from lightdock.prep.poses import calculate_initial_poses
from lightdock.constants import DEFAULT_POSITIONS_FOLDER, DEFAULT_SWARM_FOLDER, DEFAULT_LIST_EXTENSION, \
DEFAULT_LIGHTDOCK_PREFIX, DEFAULT_NMODES_REC, DEFAULT_NMODES_LIG, DEFAULT_REC_NM_FILE, DEFAULT_LIG_NM_FILE, \
MIN_EXTENT, MAX_EXTENT, DEFAULT_SETUP_FILE, DEFAULT_LIGHTDOCK_INFO, DEFAULT_POSITIONS_FOLDER, \
DEFAULT_STARTING_PREFIX, MAX_TRANSLATION, MAX_ROTATION
from lightdock.util.logger import LoggingManager
from lightdock.pdbutil.PDBIO import parse_complex_from_file, write_pdb_to_file
from lightdock.structure.complex import Complex
from lightdock.structure.nm import calculate_nmodes, write_nmodes
from lightdock.gso.boundaries import Boundary, BoundingBox
from lightdock.error.lightdock_errors import LightDockError
log = LoggingManager.get_logger('lightdock_setup')
def get_pdb_files(input_file):
"""Get a list of the PDB files in the input_file"""
file_names = []
with open(input_file) as input:
for line in input:
file_name = line.rstrip(os.linesep)
if os.path.exists(file_name):
file_names.append(file_name)
return file_names
def read_input_structure(pdb_file_name, ignore_oxt=True, ignore_hydrogens=False, verbose_parser=False):
"""Reads the input structure.
import argparse
import os
import numpy as np
from lightdock.error.lightdock_errors import LightDockError
from lightdock.util.logger import LoggingManager
from lightdock.constants import DEFAULT_LIST_EXTENSION, DEFAULT_LIGHTDOCK_PREFIX, \
DEFAULT_NMODES_REC, DEFAULT_NMODES_LIG, DEFAULT_REC_NM_FILE, DEFAULT_LIG_NM_FILE
from lightdock.pdbutil.PDBIO import parse_complex_from_file, write_pdb_to_file
from lightdock.structure.complex import Complex
from lightdock.mathutil.cython.quaternion import Quaternion
from lightdock.structure.nm import read_nmodes
from lightdock.prep.simulation import get_setup_from_file
from lightdock.util.parser import CommandLineParser, get_lightdock_structures
log = LoggingManager.get_logger('generate_conformations')
def parse_output_file(lightdock_output, num_anm_rec, num_anm_lig):
translations = []
rotations = []
receptor_ids = []
ligand_ids = []
rec_extents = []
lig_extents = []
data_file = open(lightdock_output)
lines = data_file.readlines()
data_file.close()
counter = 0
for line in lines:
def __init__(self, tasks, num_cpus=0, profiling=False):
self.log = LoggingManager.get_logger('kraken')
try:
self.num_processes = int(num_cpus)
if self.num_processes < 1:
raise ValueError()
if self.num_processes > cpu_count():
self.log.warning("Number of cores (%d) larger than available." % self.num_processes)
raise ValueError()
except (ValueError, TypeError):
self.log.warning("Number of cores has not been specified or is incorrect. Using available cores.")
self.num_processes = cpu_count()
self.log.info("Kraken has %d tentacles (cpu cores)" % self.num_processes)
self.tasks = tasks
self.num_tasks = len(tasks)
self.tentacles = []
Reference: SwarmDock and the use of Normal Models in Protein-Protein Docking
https://www.ncbi.nlm.nih.gov/pmc/articles/PMC2996808/
"""
import numpy as np
from lightdock.scoring.functions import ScoringFunction, ModelAdapter
from lightdock.structure.model import DockingModel
import lightdock.scoring.sd.energy.c.sd as sd
from lightdock.util.logger import LoggingManager
from lightdock.scoring.sd.data.amber import amber_types, masses, charges
import lightdock.scoring.sd.data.vdw as vdw
from lightdock.constants import DEFAULT_CONTACT_RESTRAINTS_CUTOFF
log = LoggingManager.get_logger('sd')
class SDModel(DockingModel):
"""Prepares the structure necessary for the C-implementation"""
def __init__(self, objects, coordinates, restraints,
elec_charges, vdw_energy, vdw_radii, reference_points=None, n_modes=None):
super(SDModel, self).__init__(objects, coordinates, restraints, reference_points)
self.charges = elec_charges
self.vdw_energy = vdw_energy
self.vdw_radii = vdw_radii
self.n_modes = n_modes
def clone(self):
"""Creates a copy of the current model"""
return SDModel(self.objects, self.coordinates.copy(), self.restraints, self.charges.copy(), self.vdw_energy.copy(),
self.vdw_radii.copy(), reference_points=self.reference_points.copy())
"""Generates the simulated trajectory of a given glowworm in a swarm"""
import argparse
import os
import numpy as np
from lightdock.constants import DEFAULT_NMODES_REC, DEFAULT_NMODES_LIG, DEFAULT_REC_NM_FILE, DEFAULT_LIG_NM_FILE
from lightdock.structure.nm import read_nmodes
from lightdock.util.logger import LoggingManager
from lightdock.mathutil.cython.quaternion import Quaternion
from lightdock.error.lightdock_errors import LightDockError
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
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("glowworm_id", help="glowworm to consider", type=int, metavar="glowworm_id")
parser.add_argument("steps", help="steps to consider", type=int, metavar="steps")
parser.add_argument("receptor_pdb", help="Receptor LightDock parsed PDB structure", type=valid_file,
metavar="receptor_pdb")
parser.add_argument("ligand_pdb", help="Ligand LightDock parsed PDB structure", type=valid_file,
#!/usr/bin/env python
"""Calculates the ranking files depending of different metrics"""
import os
import argparse
from lightdock.constants import DEFAULT_SWARM_FOLDER, GSO_OUTPUT_FILE, EVALUATION_FILE, SCORING_FILE, \
LIGHTDOCK_PDB_FILE, CLUSTER_REPRESENTATIVES_FILE
from lightdock.util.logger import LoggingManager
from lightdock.util.analysis import read_rmsd_and_contacts_data, read_lightdock_output, write_ranking_to_file, \
read_cluster_representatives_file
log = LoggingManager.get_logger('lgd_rank')
def parse_command_line():
parser = argparse.ArgumentParser(prog='lgd_rank')
parser.add_argument("num_swarms", help="number of swarms to consider", type=int, metavar="num_swarms")
parser.add_argument("steps", help="steps to consider", type=int, metavar="steps")
parser.add_argument("-c", "--clashes_cutoff", help="clashes cutoff", dest="clashes_cutoff", type=float)
parser.add_argument("-f", "--file_name", help="lightdock output file to consider", dest="result_file")
parser.add_argument("--ignore_clusters", help="Ignore cluster information", dest="ignore_clusters",
action="store_true")
return parser.parse_args()
if __name__ == "__main__":
try:
# Parse command line
import os
import argparse
import numpy as np
import math
from lightdock.constants import DEFAULT_SWARM_FOLDER, CLUSTER_REPRESENTATIVES_FILE, \
GSO_OUTPUT_FILE, DEFAULT_POSITIONS_FOLDER, DEFAULT_BILD_STARTING_PREFIX, CLUSTERS_CENTERS_FILE, \
DEFAULT_STARTING_PREFIX
from lightdock.prep.poses import create_file_from_poses
from lightdock.util.logger import LoggingManager
from lightdock.util.analysis import read_lightdock_output
from lightdock.prep.geometry import create_bild_file
from lightdock.pdbutil.PDBIO import create_pdb_from_points
log = LoggingManager.get_logger('lgd_prepare_new_simulation')
def parse_command_line():
parser = argparse.ArgumentParser(prog='lgd_prepare_new_simulation')
parser.add_argument("swarm", help="swarm to consider", type=int, metavar="swarm")
parser.add_argument("steps", help="steps to consider", type=int, metavar="steps")
parser.add_argument("destination", help="destination folder", metavar="destination")
parser.add_argument("-nm", "--nm", help="Keep normal modes in starting positions if exist",
dest="nm", action="store_true")
return parser.parse_args()
def read_cluster_representative_data(file_name):
glowworms = []
with open(file_name) as input_file:
for line in input_file:
import argparse
import os
import numpy as np
import importlib
from lightdock.util.logger import LoggingManager
from lightdock.constants import DEFAULT_NMODES_REC, DEFAULT_NMODES_LIG, \
DEFAULT_REC_NM_FILE, DEFAULT_LIG_NM_FILE, DEFAULT_SCORING_FUNCTION
from lightdock.pdbutil.PDBIO import parse_complex_from_file
from lightdock.structure.complex import Complex
from lightdock.mathutil.cython.quaternion import Quaternion
from lightdock.structure.nm import read_nmodes
from scipy.optimize import fmin_powell
log = LoggingManager.get_logger('minimizer')
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 valid_integer_number(ivalue):
"""Checks for a valid integer"""
try:
ivalue = int(ivalue)
except:
raise argparse.ArgumentTypeError("%s is an invalid value" % ivalue)
if ivalue <= 0:
#!/usr/bin/env python
"""Calculates the ranking file by scoring intra-swarm"""
from __future__ import print_function
import sys
import os
import argparse
from lightdock.util.logger import LoggingManager
from lightdock.constants import DEFAULT_SWARM_FOLDER, GSO_OUTPUT_FILE
from lightdock.util.analysis import read_ranking_file
from lightdock.util.analysis import read_lightdock_output
from lightdock.util.analysis import write_ranking_to_file
log = LoggingManager.get_logger('lgd_rank_swarm')
def parse_command_line():
parser = argparse.ArgumentParser(prog='lgd_rank_swarm')
parser.add_argument("num_swarms", help="number of swarms to consider", type=int, metavar="num_swarms")
parser.add_argument("steps", help="steps to consider", type=int, metavar="steps")
return parser.parse_args()
if __name__ == '__main__':
try:
CURRENT_FOLDER = os.getcwd()
args = parse_command_line()
for swarm_id in range(args.num_swarms):