How to use the lightdock.scoring.functions.ScoringFunction function in lightdock

To help you get started, we’ve selected a few lightdock examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github brianjimenez / lightdock / lightdock / scoring / sipper / driver.py View on Github external
oda_file_name = DEFAULT_LIGHTDOCK_PREFIX % (molecule.structure_file_names[0] + '.oda')
        if os.path.exists(oda_file_name):
            log.info('ODA %s file found' % oda_file_name)
            with open(oda_file_name) as oda_input:
                oda_values = []
                lines = oda_input.readlines()[2:]
                for line in lines:
                    try:
                        fields = line.split()
                        oda_values.append(float(fields[3]))
                    except ValueError:
                        pass
        return oda_values


class SIPPER(ScoringFunction):
    def __init__(self, weight=1.0):
        super(SIPPER, self).__init__(weight)
        self.energy = sipper_energy

    def __call__(self, receptor, receptor_coordinates, ligand, ligand_coordinates):
        """Computes the pyDock scoring energy using receptor and ligand which are
        instances of DockingModel
        """
        energy = csipper.calculate_sipper(receptor_coordinates, ligand_coordinates, self.energy,
                                          receptor.indexes, ligand.indexes,
                                          receptor.atoms_per_residue, ligand.atoms_per_residue,
                                          len(receptor.atoms_per_residue), len(ligand.atoms_per_residue),
                                          receptor.oda, ligand.oda)
        return energy * self.weight
github brianjimenez / lightdock / lightdock / scoring / dfire2 / driver.py View on Github external
def evaluate_energy(self, receptor, receptor_coordinates, ligand, ligand_coordinates):
        coordinates = np.append(receptor_coordinates.coordinates, ligand_coordinates.coordinates).reshape((-1, 3))
        energy, interface_receptor, interface_ligand = calculate_dfire2(self.res_index, 
                                                                        self.atom_index, 
                                                                        coordinates, 
                                                                        self.potential.energy,
                                                                        self.molecule_length, 
                                                                        DEFAULT_CONTACT_RESTRAINTS_CUTOFF)
        
        # Code to consider contacts in the interface
        perc_receptor_restraints = ScoringFunction.restraints_satisfied(receptor.restraints, set(interface_receptor))
        perc_ligand_restraints = ScoringFunction.restraints_satisfied(ligand.restraints, set(interface_ligand))
        return energy + perc_receptor_restraints * energy + perc_ligand_restraints * energy
github brianjimenez / lightdock / lightdock / scoring / vdw / driver.py View on Github external
def __call__(self, receptor, receptor_coordinates, ligand, ligand_coordinates):
        """Computes the truncated VdW energy using receptor and ligand which are
        instances of the DockingModel class"""
        vdw_energy, interface_receptor, interface_ligand = cvdw.calculate_vdw(receptor_coordinates, ligand_coordinates,
                                                                              receptor.vdw_energy, ligand.vdw_energy, 
                                                                              receptor.vdw_radii, ligand.vdw_radii,
                                                                              DEFAULT_CONTACT_RESTRAINTS_CUTOFF)
        energy = vdw_energy * -1.0 * self.weight
        perc_receptor_restraints = ScoringFunction.restraints_satisfied(receptor.restraints, set(interface_receptor))
        perc_ligand_restraints = ScoringFunction.restraints_satisfied(ligand.restraints, set(interface_ligand))
        return energy + perc_receptor_restraints * energy + perc_ligand_restraints * energy
github brianjimenez / lightdock / lightdock / scoring / pisa / driver.py View on Github external
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:
                    try:
                        parsed_restraints[res_id].append(atom_index)
                    except:
                        parsed_restraints[res_id] = [atom_index]
        try:
            return DockingModel(pisa_objects, molecule.copy_coordinates(), parsed_restraints, n_modes=molecule.n_modes.copy())
        except AttributeError:
            return DockingModel(pisa_objects, molecule.copy_coordinates(), parsed_restraints)


class PISA(ScoringFunction):
    """Implements PISA scoring function"""
    def __init__(self, weight=1.0):
        super(PISA, self).__init__(weight)
        self.potential = PISAPotential()

    def __call__(self, receptor, receptor_coordinates, ligand, ligand_coordinates):
        energy, interface_receptor, interface_ligand = calculate_pisa(receptor, receptor_coordinates, 
                                                                      ligand, ligand_coordinates, 
                                                                      self.potential.pisa_energy,
                                                                      DEFAULT_CONTACT_RESTRAINTS_CUTOFF)
        perc_receptor_restraints = ScoringFunction.restraints_satisfied(receptor.restraints, interface_receptor)
        perc_ligand_restraints = ScoringFunction.restraints_satisfied(ligand.restraints, interface_ligand)
        return energy + perc_receptor_restraints * energy + perc_ligand_restraints * energy


# Needed to dynamically load the scoring functions from command line
github brianjimenez / lightdock / lightdock / scoring / dfire2 / driver.py View on Github external
def evaluate_energy(self, receptor, receptor_coordinates, ligand, ligand_coordinates):
        coordinates = np.append(receptor_coordinates.coordinates, ligand_coordinates.coordinates).reshape((-1, 3))
        energy, interface_receptor, interface_ligand = calculate_dfire2(self.res_index, 
                                                                        self.atom_index, 
                                                                        coordinates, 
                                                                        self.potential.energy,
                                                                        self.molecule_length, 
                                                                        DEFAULT_CONTACT_RESTRAINTS_CUTOFF)
        
        # Code to consider contacts in the interface
        perc_receptor_restraints = ScoringFunction.restraints_satisfied(receptor.restraints, set(interface_receptor))
        perc_ligand_restraints = ScoringFunction.restraints_satisfied(ligand.restraints, set(interface_ligand))
        return energy + perc_receptor_restraints * energy + perc_ligand_restraints * energy
github brianjimenez / lightdock / lightdock / scoring / pisa / driver.py View on Github external
def __call__(self, receptor, receptor_coordinates, ligand, ligand_coordinates):
        energy, interface_receptor, interface_ligand = calculate_pisa(receptor, receptor_coordinates, 
                                                                      ligand, ligand_coordinates, 
                                                                      self.potential.pisa_energy,
                                                                      DEFAULT_CONTACT_RESTRAINTS_CUTOFF)
        perc_receptor_restraints = ScoringFunction.restraints_satisfied(receptor.restraints, interface_receptor)
        perc_ligand_restraints = ScoringFunction.restraints_satisfied(ligand.restraints, interface_ligand)
        return energy + perc_receptor_restraints * energy + perc_ligand_restraints * energy
github brianjimenez / lightdock / lightdock / scoring / cpydock / driver.py View on Github external
else:
                sasa.append(-1.0)
        sasa = np.array(sasa)
        hydrogens = np.array([0 if atom.is_hydrogen() else 1 for atom in atoms])
        log.info('Done.')

        reference_points = ModelAdapter.load_reference_points(molecule)
        try:
            return CPyDockModel(atoms, coordinates, parsed_restraints, elec_charges, vdw_energies, vdw_radii, des_energy, des_radii,
                                sasa, hydrogens, reference_points=reference_points, n_modes=molecule.n_modes.copy())
        except AttributeError:
            return CPyDockModel(atoms, coordinates, parsed_restraints, elec_charges, vdw_energies, vdw_radii, des_energy, des_radii,
                                sasa, hydrogens, reference_points=reference_points)


class CPyDock(ScoringFunction):
    def __init__(self, weight=1.0):
        super(CPyDock, self).__init__(weight)
        try:
            with open(parameters.vdw_input_file) as vdw_file:
                self.scoring_vdw_weight = float(vdw_file.readline())
        except (IOError, ValueError) as e:
            log.warning('Error (%s), using default VDW cutoff' % str(e))
            self.scoring_vdw_weight = parameters.scoring_vdw_weight
        log.info('PyDock VDW cutoff is: %3.2f' % self.scoring_vdw_weight)

    def __call__(self, receptor, receptor_coordinates, ligand, ligand_coordinates):
        """Computes the pyDock scoring energy using receptor and ligand which are
        instances of DockingModel.
        """
        elec, vdw, solv_rec, solv_lig, interface_receptor, interface_ligand = cpydock.calculate_energy(receptor_coordinates, ligand_coordinates,
                                                                              receptor.charges, ligand.charges,
github brianjimenez / lightdock / lightdock / scoring / dfire2 / driver.py View on Github external
coordinates.append([rec_atom.x, rec_atom.y, rec_atom.z])
                    # Restraints support
                    res_id = "%s.%s.%s" % (rec_atom.chain_id, residue.name, str(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_index += 1
        try:
            return DockingModel(objects, SpacePoints(coordinates), parsed_restraints, n_modes=molecule.n_modes.copy())
        except AttributeError:
            return DockingModel(objects, SpacePoints(coordinates), parsed_restraints)


class DFIRE2(ScoringFunction):
    """Implements DFIRE2 potential"""
    def __init__(self, weight=1.0):
        super(DFIRE2, self).__init__(weight)
        self.cached = False
        self.potential = DFIRE2Potential()

    def __call__(self, receptor, receptor_coordinates, ligand, ligand_coordinates):
        if not self.cached:
            self.res_index = []
            self.atom_index = []
            for o in receptor.objects:
                self.res_index.append(o.residue_index)
                self.atom_index.append(o.atom_index)
            last = self.res_index[-1]
            for o in ligand.objects:
                self.res_index.append(o.residue_index + last)
github brianjimenez / lightdock / lightdock / scoring / sd / driver.py View on Github external
def __call__(self, receptor, receptor_coordinates, ligand, ligand_coordinates):
        """Computes the SD scoring energy using receptor and ligand which are
        instances of DockingModel
        """
        energy, interface_receptor, interface_ligand = sd.calculate_energy(receptor_coordinates, ligand_coordinates,
                                                                           receptor.charges, ligand.charges,
                                                                           receptor.vdw_energy, ligand.vdw_energy,
                                                                           receptor.vdw_radii, ligand.vdw_radii, 
                                                                           DEFAULT_CONTACT_RESTRAINTS_CUTOFF)

        perc_receptor_restraints = ScoringFunction.restraints_satisfied(receptor.restraints, set(interface_receptor))
        perc_ligand_restraints = ScoringFunction.restraints_satisfied(ligand.restraints, set(interface_ligand))
        return energy + perc_receptor_restraints * energy + perc_ligand_restraints * energy
github brianjimenez / lightdock / lightdock / scoring / vdw / driver.py View on Github external
# Prepare common model information
        vdw_energies = np.array([atom.vdw_energy for atom in atoms])
        vdw_radii = np.array([atom.vdw_radius for atom in atoms])
        coordinates = molecule.copy_coordinates()

        reference_points = ModelAdapter.load_reference_points(molecule)

        try:
            return VdWModel(atoms, coordinates, parsed_restraints, vdw_energies, vdw_radii,
                            reference_points=reference_points, n_modes=molecule.n_modes.copy())
        except AttributeError:
            return VdWModel(atoms, coordinates, parsed_restraints, vdw_energies, vdw_radii, 
                            reference_points=reference_points)


class VdW(ScoringFunction):
    def __init__(self, weight=1.0):
        super(VdW, self).__init__(weight)

    def __call__(self, receptor, receptor_coordinates, ligand, ligand_coordinates):
        """Computes the truncated VdW energy using receptor and ligand which are
        instances of the DockingModel class"""
        vdw_energy, interface_receptor, interface_ligand = cvdw.calculate_vdw(receptor_coordinates, ligand_coordinates,
                                                                              receptor.vdw_energy, ligand.vdw_energy, 
                                                                              receptor.vdw_radii, ligand.vdw_radii,
                                                                              DEFAULT_CONTACT_RESTRAINTS_CUTOFF)
        energy = vdw_energy * -1.0 * self.weight
        perc_receptor_restraints = ScoringFunction.restraints_satisfied(receptor.restraints, set(interface_receptor))
        perc_ligand_restraints = ScoringFunction.restraints_satisfied(ligand.restraints, set(interface_ligand))
        return energy + perc_receptor_restraints * energy + perc_ligand_restraints * energy