Exemple #1
0
 def setUpClass(self):
     self.queue = get_queue()
     self.shape = (5, 4, 3)
     self.size = 5 * 4 * 3
     self.values = {
         "interaction_cutoff": 1,
         "nrestraints": 3,
         "shape_x": self.shape[2],
         "shape_y": self.shape[1],
         "shape_z": self.shape[0],
         "llength": 1,
         "nreceptor_coor": 3,
         "nligand_coor": 2,
     }
     self.p = Kernels(self.queue.context, self.values)
Exemple #2
0
    def setUpClass(cls):
        cls.dv = DisVis()
        cls.gdv = DisVis()

        cls.gdv.queue = get_queue()

        receptor = PDB.fromfile(join('data', 'O14250.pdb'))
        ligand = PDB.fromfile(join('data', 'Q9UT97.pdb'))
        restraints = parse_restraints(join('data', 'restraints.dat'), receptor,
                                      ligand)
        rselect, lselect = parse_interaction_selection(
            join('data', 'selection.res'), receptor, ligand)

        # Identity rotation and rotation around z-axis
        rotations = np.asarray([[[1, 0, 0], [0, 1, 0], [0, 0, 1]],
                                [[0, -1, 0], [1, 0, 0], [0, 0, 1]]],
                               dtype=np.float64)

        cls.dv.receptor = receptor
        cls.gdv.receptor = receptor
        cls.dv.ligand = ligand
        cls.gdv.ligand = ligand
        cls.dv.distance_restraints = restraints
        cls.gdv.distance_restraints = restraints
        cls.dv.rotations = rotations
        cls.gdv.rotations = rotations

        cls.dv.occupancy_analysis = True
        cls.gdv.occupancy_analysis = True

        cls.dv.receptor_interaction_selection = rselect
        cls.dv.ligand_interaction_selection = lselect
        cls.gdv.receptor_interaction_selection = rselect
        cls.gdv.ligand_interaction_selection = lselect

        cls.dv._initialize()
        cls.dv._cpu_init()
        cls.gdv._initialize()
        cls.gdv._gpu_init()
Exemple #3
0
    def setUpClass(cls):
        cls.dv = DisVis()
        cls.gdv = DisVis()

        cls.gdv.queue = get_queue()

        receptor = PDB.fromfile(join('data', 'O14250.pdb'))
        ligand = PDB.fromfile(join('data', 'Q9UT97.pdb'))
        restraints = parse_restraints(join('data', 'restraints.dat'), receptor, ligand)
        rselect, lselect = parse_interaction_selection(join('data',
            'selection.res'), receptor, ligand)

        # Identity rotation and rotation around z-axis
        rotations = np.asarray([[[1, 0, 0], [0, 1, 0], [0, 0, 1]],
                                [[0, -1, 0], [1, 0, 0], [0, 0, 1]]], dtype=np.float64)

        cls.dv.receptor = receptor
        cls.gdv.receptor = receptor
        cls.dv.ligand = ligand
        cls.gdv.ligand = ligand
        cls.dv.distance_restraints = restraints
        cls.gdv.distance_restraints = restraints
        cls.dv.rotations = rotations
        cls.gdv.rotations = rotations

        cls.dv.occupancy_analysis = True
        cls.gdv.occupancy_analysis = True

        cls.dv.receptor_interaction_selection = rselect
        cls.dv.ligand_interaction_selection = lselect
        cls.gdv.receptor_interaction_selection = rselect
        cls.gdv.ligand_interaction_selection = lselect

        cls.dv._initialize()
        cls.dv._cpu_init()
        cls.gdv._initialize()
        cls.gdv._gpu_init()
Exemple #4
0
 def setUp(self):
     self.queue = get_queue()
     self.kernels = Kernels(self.queue.context)
Exemple #5
0
def main():

    args = parse_args()

    mkdir_p(args.directory)
    joiner = Joiner(args.directory)

    logging.basicConfig(filename=joiner('disvis.log'),
                        level=logging.INFO,
                        format='%(asctime)s %(message)s')

    time0 = time()

    queue = None
    if args.gpu:
        from disvis.helpers import get_queue
        queue = get_queue()
        if queue is None:
            raise ValueError("No GPU queue was found.")

    write('Reading fixed model from: {:s}'.format(args.receptor.name))
    receptor = PDB.fromfile(args.receptor)
    write('Reading scanning model from: {:s}'.format(args.ligand.name))
    ligand = PDB.fromfile(args.ligand)

    write('Reading in rotations.')
    q, weights, a = proportional_orientations(args.angle)
    rotmat = quat_to_rotmat(q)
    write('Requested rotational sampling density: {:.2f}'.format(args.angle))
    write('Real rotational sampling density: {:.2f}'.format(a))
    write('Number of rotations: {:d}'.format(rotmat.shape[0]))

    write('Reading in restraints from file: {:s}'.format(args.restraints.name))
    distance_restraints = parse_restraints(args.restraints, receptor, ligand)
    write('Number of distance restraints: {:d}'.format(
        len(distance_restraints)))

    # If the interaction restraints cutoff is not specified, only calculate the
    # interactions and occupancy grids for complexes consistent with at least 1
    # restraints or more, with a limit of three.
    if args.interaction_restraints_cutoff is None:
        args.interaction_restraints_cutoff = max(
            len(distance_restraints) - 3, 1)

    pdb1_sel = pdb2_sel = None
    if args.interaction_selection is not None:
        write('Reading in interaction selection from file: {:s}'.format(
            args.interaction_selection.name))
        pdb1_sel, pdb2_sel = parse_interaction_selection(
            args.interaction_selection, receptor, ligand)

        write('Number of receptor residues: {:d}'.format(pdb1_sel.natoms))
        write('Number of ligand residues: {:d}'.format(pdb2_sel.natoms))

    write('Voxel spacing set to: {:.2f}'.format(args.voxelspacing))
    write('Interaction radius set to: {:.2f}'.format(args.interaction_radius))
    write('Minimum required interaction volume: {:.2f}'.format(
        args.min_interaction))
    write('Maximum allowed volume of clashes: {:.2f}'.format(args.max_clash))
    if args.occupancy_analysis:
        write('Performing occupancy analysis')

    if queue is None:
        # CPU-version
        if args.nproc > 1:
            try:
                dv = mp_cpu_disvis(receptor, ligand, rotmat, weights,
                                   distance_restraints, pdb1_sel, pdb2_sel,
                                   args)
            except Queue.Empty:
                msg = (
                    'ERROR: Queue.Empty exception raised while processing job, '
                    'stopping execution ...')
                write(msg)
                exit(-1)
        else:
            dv = run_disvis(queue, receptor, ligand, rotmat, weights,
                            distance_restraints, pdb1_sel, pdb2_sel, args)
    else:
        # GPU-version
        write('Using GPU accelerated search.')
        dv = run_disvis(queue, receptor, ligand, rotmat, weights,
                        distance_restraints, pdb1_sel, pdb2_sel, args)

    # write out accessible interaction space
    fname = joiner('accessible_interaction_space.mrc')
    write('Writing accessible interaction space to: {:s}'.format(fname))
    dv.accessible_interaction_space.tofile(fname)

    # write out accessible complexes
    accessible_complexes = dv.accessible_complexes
    norm = sum(accessible_complexes)
    digits = len(str(int(norm))) + 1
    cum_complexes = np.cumsum(np.asarray(accessible_complexes)[::-1])[::-1]
    with open(joiner('accessible_complexes.out'),
              'w') as f_accessible_complexes:
        write('Writing number of accessible complexes to: {:s}'.format(
            f_accessible_complexes.name))
        header = '# consistent restraints | accessible complexes |' +\
                 'relative | cumulative accessible complexes | relative\n'
        f_accessible_complexes.write(header)
        for n, acc in enumerate(accessible_complexes):
            f_accessible_complexes.write('{0:3d} {2:{1}d} {3:8.6f} {4:{1}d} {5:8.6f}\n'\
                    .format(n, digits, int(acc), acc/norm,
                    int(cum_complexes[n]), cum_complexes[n]/norm))

    # writing out violations
    violations = dv.violations
    cum_violations = violations[::-1].cumsum(axis=0)[::-1]
    with open(joiner('violations.out'), 'w') as f_viol:
        write('Writing violations to file: {:s}'.format(f_viol.name))
        num_violations = violations.sum(axis=1)
        nrestraints = num_violations.shape[0]
        header = ('# row represents the number of consistent restraints\n'
                  '# column represents how often that restraint is violated\n')
        f_viol.write(header)
        header = ('   ' + '{:8d}' * nrestraints +
                  '\n').format(*range(1, nrestraints + 1))
        f_viol.write(header)
        for n, line in enumerate(cum_violations):
            f_viol.write('{:<2d} '.format(n + 1))
            for word in line:
                if num_violations[n] > 0:
                    percentage_violated = word / cum_complexes[n + 1]
                else:
                    percentage_violated = 0
                f_viol.write('{:8.4f}'.format(percentage_violated))
            f_viol.write('\n')

    # Give user indication for false positives.
    # Determine minimum number of false positives.
    nrestraints = len(distance_restraints)
    n = 1
    while accessible_complexes[-n] == 0:
        n += 1
    if n > 1:
        msg = ('Not all restraints are consistent. '
               'Number of false-positive restraints present '
               'is at least: {:d}'.format(n - 1))
        write(msg)

    # next give possible false-positives based on the percentage of violations
    # and their associated Z-score
    if n == 1:
        n = None
    else:
        n = -n + 1
    percentage_violated = cum_violations[:n] / np.asarray(
        cum_complexes[1:n]).reshape(-1, 1)
    average_restraint_violation = percentage_violated.mean(axis=0)
    std_restraint_violation = percentage_violated.std(axis=0)
    zscore_violations = (
        (average_restraint_violation - average_restraint_violation.mean()) /
        average_restraint_violation.std())
    ind_false_positives = np.flatnonzero(zscore_violations >= 1.0)
    nfalse_positives = ind_false_positives.size
    if nfalse_positives > 0:
        ind_false_positives += 1
        write(('Possible false-positive restraints (z-score > 1.0):' +\
                ' {:d}'*nfalse_positives).format(*tuple(ind_false_positives)))

    with open(joiner('z-score.out'), 'w') as f:
        write('Writing z-score of each restraint to {:s}'.format(f.name))
        for n in xrange(zscore_violations.shape[0]):
            f.write('{:2d} {:6.3f} {:6.3f} {:6.3f}\n'.format(
                n + 1, average_restraint_violation[n],
                std_restraint_violation[n], zscore_violations[n]))

    # Write all occupancy grids to MRC-files if requested
    if args.occupancy_analysis:
        for n, vol in dv.occupancy_grids.iteritems():
            # Normalize the occupancy grid
            if cum_complexes[n] > 0:
                vol._array /= cum_complexes[n]
            vol.tofile(joiner('occupancy_{:d}.mrc'.format(n)))

    # Write out interaction analysis
    # the interaction_matrix gives the number of interactions between each
    # residue of the receptor and ligand for complexes consistent with exactly
    # N restraints.
    interaction_matrix = dv.interaction_matrix
    if interaction_matrix is not None:

        ## Save interaction matrix
        #f = joiner('interaction_matrix.npy')
        #write('Writing interaction-matrix to: {:s}'.format(f))
        #np.save(f, interaction_matrix)

        # Save contacted receptor and ligand residue interaction for each analyzed number
        # of consistent restraints
        write('Writing contacted receptor residue interactions to files.')
        # Take the cumsum in order to give the number of interactions for complexes
        # with at least N restraints.
        receptor_cum_interactions = interaction_matrix.sum(
            axis=1)[::-1].cumsum(axis=0)[::-1]
        ligand_cum_interactions = interaction_matrix.sum(axis=2)[::-1].cumsum(
            axis=0)[::-1]
        fname = joiner('receptor_interactions.txt')
        with open(fname, 'w') as f:
            # Write header
            f.write('#resi')
            for consistent_restraints in xrange(
                    args.interaction_restraints_cutoff, nrestraints + 1):
                f.write(' {:>6d}'.format(consistent_restraints))
            f.write('\n')

            for n, resi in enumerate(pdb1_sel.data['resi']):
                f.write('{:<5d}'.format(resi))
                for consistent_restraints in xrange(
                        args.interaction_restraints_cutoff, nrestraints + 1):
                    index = consistent_restraints - args.interaction_restraints_cutoff
                    interactions = receptor_cum_interactions[index, n]
                    cum_complex = cum_complexes[consistent_restraints]
                    if cum_complex > 0:
                        relative_interactions = interactions / cum_complex
                    else:
                        relative_interactions = 0
                    f.write(' {:6.3f}'.format(relative_interactions))
                f.write('\n')

        fname = joiner('ligand_interactions.txt')
        with open(fname, 'w') as f:
            # Write header
            f.write('#resi')
            for consistent_restraints in xrange(
                    args.interaction_restraints_cutoff, nrestraints + 1):
                f.write(' {:>6d}'.format(consistent_restraints))
            f.write('\n')

            for n, resi in enumerate(pdb2_sel.data['resi']):
                f.write('{:<5d}'.format(resi))
                for consistent_restraints in xrange(
                        args.interaction_restraints_cutoff, nrestraints + 1):
                    index = consistent_restraints - args.interaction_restraints_cutoff
                    interactions = ligand_cum_interactions[index, n]
                    cum_complex = cum_complexes[consistent_restraints]
                    if cum_complex > 0:
                        relative_interactions = interactions / cum_complex
                    else:
                        relative_interactions = 0
                    f.write(' {:6.3f}'.format(relative_interactions))
                f.write('\n')

    # time indication
    seconds = int(round(time() - time0))
    m, s = divmod(seconds, 60)
    write('Total time passed: {:d}m {:2d}s'.format(m, s))
Exemple #6
0
 def setUp(self):
     self.queue = get_queue()
     self.kernels = Kernels(self.queue.context)
Exemple #7
0
def main():

    args = parse_args()

    mkdir_p(args.directory)
    joiner = Joiner(args.directory)

    logging.basicConfig(filename=joiner('disvis.log'),
            level=logging.INFO, format='%(asctime)s %(message)s')

    time0 = time()

    queue = None
    if args.gpu:
        from disvis.helpers import get_queue
        queue = get_queue()
        if queue is None:
            raise ValueError("No GPU queue was found.")

    write('Reading fixed model from: {:s}'.format(args.receptor.name))
    receptor = PDB.fromfile(args.receptor)
    write('Reading scanning model from: {:s}'.format(args.ligand.name))
    ligand = PDB.fromfile(args.ligand)

    write('Reading in rotations.')
    q, weights, a = proportional_orientations(args.angle)
    rotmat = quat_to_rotmat(q)
    write('Requested rotational sampling density: {:.2f}'.format(args.angle))
    write('Real rotational sampling density: {:.2f}'.format(a))
    write('Number of rotations: {:d}'.format(rotmat.shape[0]))

    write('Reading in restraints from file: {:s}'.format(args.restraints.name))
    distance_restraints = parse_restraints(args.restraints, receptor, ligand)
    write('Number of distance restraints: {:d}'.format(len(distance_restraints)))

    # If the interaction restraints cutoff is not specified, only calculate the
    # interactions and occupancy grids for complexes consistent with at least 1
    # restraints or more, with a limit of three.
    if args.interaction_restraints_cutoff is None:
        args.interaction_restraints_cutoff = max(len(distance_restraints) - 3, 1)

    pdb1_sel = pdb2_sel = None
    if args.interaction_selection is not None:
        write('Reading in interaction selection from file: {:s}'
                .format(args.interaction_selection.name))
        pdb1_sel, pdb2_sel = parse_interaction_selection(
                args.interaction_selection, receptor, ligand)

        write('Number of receptor residues: {:d}'.format(pdb1_sel.natoms))
        write('Number of ligand residues: {:d}'.format(pdb2_sel.natoms))

    write('Voxel spacing set to: {:.2f}'.format(args.voxelspacing))
    write('Interaction radius set to: {:.2f}'.format(args.interaction_radius))
    write('Minimum required interaction volume: {:.2f}'.format(args.min_interaction))
    write('Maximum allowed volume of clashes: {:.2f}'.format(args.max_clash))
    if args.occupancy_analysis:
        write('Performing occupancy analysis')

    if queue is None:
        # CPU-version
        if args.nproc > 1:
            try:
                dv = mp_cpu_disvis(receptor, ligand, rotmat, weights,
                        distance_restraints, pdb1_sel, pdb2_sel, args)
            except Queue.Empty:
                msg = ('ERROR: Queue.Empty exception raised while processing job, '
                       'stopping execution ...')
                write(msg)
                exit(-1)
        else:
            dv = run_disvis(queue, receptor, ligand, rotmat, weights,
                    distance_restraints, pdb1_sel, pdb2_sel, args)
    else:
        # GPU-version
        write('Using GPU accelerated search.')
        dv = run_disvis(queue, receptor, ligand, rotmat, weights,
                         distance_restraints, pdb1_sel, pdb2_sel, args)

    # write out accessible interaction space
    fname = joiner('accessible_interaction_space.mrc')
    write('Writing accessible interaction space to: {:s}'.format(fname))
    dv.accessible_interaction_space.tofile(fname)

    # write out accessible complexes
    accessible_complexes = dv.accessible_complexes
    norm = sum(accessible_complexes)
    digits = len(str(int(norm))) + 1
    cum_complexes = np.cumsum(np.asarray(accessible_complexes)[::-1])[::-1]
    with open(joiner('accessible_complexes.out'), 'w') as f_accessible_complexes:
        write('Writing number of accessible complexes to: {:s}'.format(f_accessible_complexes.name))
        header = '# consistent restraints | accessible complexes |' +\
                 'relative | cumulative accessible complexes | relative\n'
        f_accessible_complexes.write(header)
        for n, acc in enumerate(accessible_complexes):
            f_accessible_complexes.write('{0:3d} {2:{1}d} {3:8.6f} {4:{1}d} {5:8.6f}\n'\
                    .format(n, digits, int(acc), acc/norm,
                    int(cum_complexes[n]), cum_complexes[n]/norm))

    # writing out violations
    violations = dv.violations
    cum_violations = violations[::-1].cumsum(axis=0)[::-1]
    with open(joiner('violations.out'), 'w') as f_viol:
        write('Writing violations to file: {:s}'.format(f_viol.name))
        num_violations = violations.sum(axis=1)
        nrestraints = num_violations.shape[0]
        header = ('# row represents the number of consistent restraints\n'
                  '# column represents how often that restraint is violated\n')
        f_viol.write(header)
        header = ('   ' + '{:8d}'*nrestraints + '\n').format(*range(1, nrestraints + 1))
        f_viol.write(header)
        for n, line in enumerate(cum_violations):
            f_viol.write('{:<2d} '.format(n+1))
            for word in line:
                if num_violations[n] > 0:
                    percentage_violated = word/cum_complexes[n+1]
                else:
                    percentage_violated = 0
                f_viol.write('{:8.4f}'.format(percentage_violated))
            f_viol.write('\n')

    # Give user indication for false positives.
    # Determine minimum number of false positives.
    nrestraints = len(distance_restraints)
    n = 1
    while accessible_complexes[-n] == 0:
        n += 1
    if n > 1:
        msg = ('Not all restraints are consistent. '
               'Number of false-positive restraints present '
               'is at least: {:d}'.format(n - 1))
        write(msg)

    # next give possible false-positives based on the percentage of violations
    # and their associated Z-score
    if n == 1:
        n = None
    else:
        n = -n + 1
    percentage_violated = cum_violations[:n]/np.asarray(cum_complexes[1:n]).reshape(-1, 1)
    average_restraint_violation = percentage_violated.mean(axis=0)
    std_restraint_violation = percentage_violated.std(axis=0)
    zscore_violations = ((average_restraint_violation - average_restraint_violation.mean())
            / average_restraint_violation.std())
    ind_false_positives = np.flatnonzero(zscore_violations >= 1.0)
    nfalse_positives = ind_false_positives.size
    if nfalse_positives > 0:
        ind_false_positives += 1
        write(('Possible false-positive restraints (z-score > 1.0):' +\
                ' {:d}'*nfalse_positives).format(*tuple(ind_false_positives)))

    with open(joiner('z-score.out'), 'w') as f:
        write('Writing z-score of each restraint to {:s}'.format(f.name))
        for n in xrange(zscore_violations.shape[0]):
            f.write('{:2d} {:6.3f} {:6.3f} {:6.3f}\n'.format(n+1,
                    average_restraint_violation[n], std_restraint_violation[n],
                    zscore_violations[n]))


    # Write all occupancy grids to MRC-files if requested
    if args.occupancy_analysis:
        for n, vol in dv.occupancy_grids.iteritems():
            # Normalize the occupancy grid
            if cum_complexes[n] > 0:
                vol._array /= cum_complexes[n]
            vol.tofile(joiner('occupancy_{:d}.mrc'.format(n)))

    # Write out interaction analysis
    # the interaction_matrix gives the number of interactions between each
    # residue of the receptor and ligand for complexes consistent with exactly
    # N restraints.
    interaction_matrix = dv.interaction_matrix
    if interaction_matrix is not None:

        ## Save interaction matrix
        #f = joiner('interaction_matrix.npy')
        #write('Writing interaction-matrix to: {:s}'.format(f))
        #np.save(f, interaction_matrix)

        # Save contacted receptor and ligand residue interaction for each analyzed number
        # of consistent restraints
        write('Writing contacted receptor residue interactions to files.')
        # Take the cumsum in order to give the number of interactions for complexes
        # with at least N restraints.
        receptor_cum_interactions = interaction_matrix.sum(axis=1)[::-1].cumsum(axis=0)[::-1]
        ligand_cum_interactions = interaction_matrix.sum(axis=2)[::-1].cumsum(axis=0)[::-1]
        fname = joiner('receptor_interactions.txt')
        with open(fname, 'w') as f:
            # Write header
            f.write('#resi')
            for consistent_restraints in xrange(args.interaction_restraints_cutoff, nrestraints + 1):
                f.write(' {:>6d}'.format(consistent_restraints))
            f.write('\n')

            for n, resi in enumerate(pdb1_sel.data['resi']):
                f.write('{:<5d}'.format(resi))
                for consistent_restraints in xrange(args.interaction_restraints_cutoff, nrestraints + 1):
                    index = consistent_restraints - args.interaction_restraints_cutoff
                    interactions = receptor_cum_interactions[index, n]
                    cum_complex = cum_complexes[consistent_restraints]
                    if cum_complex > 0:
                        relative_interactions = interactions / cum_complex
                    else:
                        relative_interactions = 0
                    f.write(' {:6.3f}'.format(relative_interactions))
                f.write('\n')

        fname = joiner('ligand_interactions.txt')
        with open(fname, 'w') as f:
            # Write header
            f.write('#resi')
            for consistent_restraints in xrange(args.interaction_restraints_cutoff, nrestraints + 1):
                f.write(' {:>6d}'.format(consistent_restraints))
            f.write('\n')

            for n, resi in enumerate(pdb2_sel.data['resi']):
                f.write('{:<5d}'.format(resi))
                for consistent_restraints in xrange(args.interaction_restraints_cutoff, nrestraints + 1):
                    index = consistent_restraints - args.interaction_restraints_cutoff
                    interactions = ligand_cum_interactions[index, n]
                    cum_complex = cum_complexes[consistent_restraints]
                    if cum_complex > 0:
                        relative_interactions = interactions / cum_complex
                    else:
                        relative_interactions = 0
                    f.write(' {:6.3f}'.format(relative_interactions))
                f.write('\n')

    # time indication
    seconds = int(round(time() - time0))
    m, s = divmod(seconds, 60)
    write('Total time passed: {:d}m {:2d}s'.format(m, s))