Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
data_file = open(data_file_name)
data = data_file.readlines()
data_file.close()
potentials = [[None for i in range(22)] for j in range(22)] # @UnusedVariable
try:
for x in range(22):
for y in range(22):
potentials[x][y] = float(data[x + 1].strip().split()[y + 1])
except Exception, e:
raise PotentialsParsingError('Error parsing %s file. Details: %s' % (data_file_name, str(e)))
return potentials
class TOBIAdapter(ModelAdapter):
"""Adapts a given Complex to a DockingModel object suitable for this
TOBI scoring function.
"""
def _get_docking_model(self, molecule, restraints):
"""Builds a suitable docking model for this scoring function"""
residues = [residue for chain in molecule.chains for residue in chain.residues]
tobi_residues = []
list_of_coordinates = []
parsed_restraints = {}
for structure in range(molecule.num_structures):
coordinates = []
for residue in residues:
try:
residue_index = TOBIPotential.recognized_residues.index(residue.name)
def _read_potentials(self, data_file_name):
"""Reads DFIRE data potentials"""
dfire_energy = np.empty((168, 168, 20), dtype=np.double)
infile = open(data_file_name).readlines()
count = 0
for x in range(168):
for y in range(168):
for z in range(20):
dfire_energy[x][y][z] = np.double(infile[count].strip())
count += 1
return dfire_energy
class DFIREAdapter(ModelAdapter):
"""Adapts a given Complex to a DockingModel object suitable for this
DFIRE scoring function.
"""
def _get_docking_model(self, molecule, restraints):
"""Builds a suitable docking model for this scoring function"""
r3_to_numerical = {}
for x in range(len(DFIREPotential.RES_3)):
r3_to_numerical[DFIREPotential.RES_3[x]] = x
atomnumber = {}
for x in range(len(DFIREPotential.RES_3)):
for y in range(len(DFIREPotential.atoms_in_residues[DFIREPotential.RES_3[x]])):
name = '%s%s' % (DFIREPotential.RES_3[x], DFIREPotential.atoms_in_residues[DFIREPotential.RES_3[x]][y])
atomnumber[name] = y
class DFIRE2Potential(object):
"""Loads DFIRE2 potentials information"""
def __init__(self):
data_path = os.path.dirname(os.path.realpath(__file__)) + '/data/'
self.energy = np.load(data_path + 'dfire2_energies.npy').ravel()
class DFIRE2Object(object):
def __init__(self, residue_index, atom_index):
self.residue_index = residue_index
self.atom_index = atom_index
class DFIRE2Adapter(ModelAdapter, DFIRE2Potential):
"""Adapts a given Complex to a DockingModel object suitable for this
DFIRE2 scoring function.
"""
def _get_docking_model(self, molecule, restraints):
"""Builds a suitable docking model for this scoring function"""
objects = []
coordinates = []
parsed_restraints = {}
atom_index = 0
for residue in molecule.residues:
for rec_atom in residue.atoms:
rec_atom_type = rec_atom.residue_name + ' ' + rec_atom.name
if rec_atom_type in DFIRE2_ATOM_TYPES:
objects.append(DFIRE2Object(residue.number, DFIRE2_ATOM_TYPES[rec_atom_type]))
coordinates.append([rec_atom.x, rec_atom.y, rec_atom.z])
"""Template scoring function"""
from lightdock.structure.model import DockingModel
from lightdock.scoring.functions import ModelAdapter, ScoringFunction
class TemplateAdapter(ModelAdapter):
"""Adapts a given Complex to a DockingModel object suitable for this
'Template' scoring function.
"""
def _get_docking_model(self, molecule, restraints):
"""Builds a suitable docking model for this scoring function"""
# In model_objects we can store any coordinates object (atoms, beans, etc.)
model_objects = []
for residue in molecule.residues:
for rec_atom in residue.atoms:
model_objects.append(rec_atom)
try:
return DockingModel(model_objects, molecule.copy_coordinates(), restraints, n_modes=molecule.n_modes.copy())
except AttributeError:
return DockingModel(model_objects, molecule.copy_coordinates(), restraints)
def __init__(self, objects, coordinates, restraints, charges, vdw_energy, vdw_radii,
reference_points=None, n_modes=None):
super(DNAModel, self).__init__(objects, coordinates, restraints, reference_points)
self.charges = 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 DNAModel(self.objects, self.coordinates.copy(), self.restraints,
self.charges, self.vdw_energy, self.vdw_radii,
reference_points=self.reference_points.copy())
class DNAAdapter(ModelAdapter):
"""Adapts a given Complex to a DockingModel object suitable for this scoring function."""
to_translate = {'HIS':'HID', 'THY':'DT', 'ADE':'DA', 'CYT':'DC', 'GUA':'DG'}
def _get_docking_model(self, molecule, restraints):
atoms = molecule.atoms
parsed_restraints = {}
# Assign properties to atoms
for atom_index, atom in enumerate(atoms):
res_id = "%s.%s.%s" % (atom.chain_id, atom.residue_name, str(atom.residue_number))
if restraints and res_id in restraints:
try:
parsed_restraints[res_id].append(atom_index)
except:
parsed_restraints[res_id] = [atom_index]
res_name = atom.residue_name
"""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())
class SDAdapter(ModelAdapter):
"""Adapts a given Complex to a DockingModel object suitable for this scoring function."""
def _get_docking_model(self, molecule, restraints):
atoms = molecule.atoms
parsed_restraints = {}
# Assign properties to atoms
for atom_index, atom in enumerate(atoms):
res_name = atom.residue_name
if res_name == "HIS":
res_name = 'HID'
res_id = "%s.%s.%s" % (atom.chain_id, atom.residue_name, str(atom.residue_number))
if restraints and res_id in restraints:
try:
parsed_restraints[res_id].append(atom_index)
except:
parsed_restraints[res_id] = [atom_index]
atom_id = "%s-%s" % (res_name, atom.name)
if (res_name == "ASP" and atom_name == "CB") or (res_name == "GLU" and atom_name == "CG"):
return 30
if ((res_name == "ASP" and atom_name == "CG")
or (res_name == "GLU" and atom_name == "CD")
or (res_name == "GLU" and atom_name == "CD1")):
return 31
if (atom_name == "OXT"
or (res_name == "ASP" and (atom_name == "OD1" or atom_name == "OD2"))
or (res_name == "GLU" and (atom_name == "OE1" or atom_name == "OE2"))
or (res_name == "GLU" and (atom_name == "OE11" or atom_name == "OE21"))
or (res_name == "GLU" and atom_name == "OE") or atom_name == "OX2"):
return 32
return -1
class PISAAdapter(ModelAdapter):
"""Adapts a given Complex to a DockingModel object suitable for this
PISA scoring function.
"""
def _get_docking_model(self, molecule, restraints):
"""Builds a suitable docking model for this scoring function"""
pisa_objects = []
coordinates = []
parsed_restraints = {}
for atom_index, atom in enumerate(molecule.atoms):
atom_type = PISAPotential.get_atom_type(atom.name, atom.residue_name)
if atom_type != -1:
atom.pisa_type = atom_type
pisa_objects.append(atom)
coordinates.append([atom.x, atom.y, atom.z])
res_id = "%s.%s.%s" % (atom.chain_id, atom.residue_name, str(atom.residue_number))
if restraints and res_id in restraints:
def __init__(self, objects, coordinates, restraints, energy, indexes, atoms_per_residue,
oda=None, reference_points=None, n_modes=None):
super(SIPPERModel, self).__init__(objects, coordinates, restraints, reference_points)
self.energy = energy
self.indexes = indexes
self.atoms_per_residue = atoms_per_residue
self.oda = oda
self.n_modes = n_modes
def clone(self):
"""Creates a copy of the current model"""
return SIPPERModel(self.objects, self.coordinates.copy(), self.restraints, self.energy, self.indexes,
self.atoms_per_residue, self.oda, reference_points=self.reference_points.copy())
class SIPPERAdapter(ModelAdapter):
"""Adapts a given Complex to a DockingModel object suitable for this
SIPPER scoring function.
"""
def _get_docking_model(self, molecule, restraints):
atoms = molecule.atoms
energy = sipper_energy
parsed_restraints = {}
indexes = np.array([res_to_index[residue.name] for residue in molecule.residues])
coordinates = molecule.copy_coordinates()
atoms_per_residue = np.array([len(residue.atoms) for residue in molecule.residues])
for atom_index, atom in enumerate(atoms):
res_id = "%s.%s.%s" % (atom.chain_id, atom.residue_name, str(atom.residue_number))
if restraints and res_id in restraints:
try:
parsed_restraints[res_id].append(atom_index)