How to use the lightdock.structure.nm.read_nmodes 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 / bin / post / lgd_generate_conformations.py View on Github external
log.warning("Number of conformations is bigger than found solutions (%s > %s)" % (num_conformations,
                                                                                          found_conformations))
        log.warning("Clipping number of conformations to %s" % found_conformations)
        num_conformations = found_conformations

    # Destination path is the same as the lightdock output
    destination_path = os.path.dirname(args.lightdock_output)

    # If normal modes used, need to read them
    nmodes_rec = nmodes_lig = None
    if len(rec_extents):
        nm_path = os.path.abspath(os.path.dirname(args.receptor_structures))
        nmodes_rec = read_nmodes(os.path.join(nm_path, DEFAULT_REC_NM_FILE + '.npy'))
    if len(lig_extents):
        nm_path = os.path.abspath(os.path.dirname(args.ligand_structures))
        nmodes_lig = read_nmodes(os.path.join(nm_path, DEFAULT_LIG_NM_FILE + '.npy'))

    for i in range(num_conformations):
        receptor_pose = receptor.atom_coordinates[receptor_ids[i]].clone()
        ligand_pose = ligand.atom_coordinates[ligand_ids[i]].clone()

        # Use normal modes if provided:
        if len(rec_extents):
            try:
                for nm in range(num_anm_rec):
                    receptor_pose.coordinates += nmodes_rec[nm] * rec_extents[i][nm]
            except ValueError:
                log.error("Problem found on calculating ANM for receptor:")
                log.error("Number of atom coordinates is: %s" % str(receptor_pose.coordinates.shape))
                log.error("Number of ANM is: %s" % str(nmodes_rec.shape))
                raise SystemExit
            except IndexError:
github brianjimenez / lightdock / bin / post / lgd_generate_conformations.py View on Github external
found_conformations = len(translations)
    num_conformations = args.glowworms
    if num_conformations > found_conformations:
        log.warning("Number of conformations is bigger than found solutions (%s > %s)" % (num_conformations,
                                                                                          found_conformations))
        log.warning("Clipping number of conformations to %s" % found_conformations)
        num_conformations = found_conformations

    # Destination path is the same as the lightdock output
    destination_path = os.path.dirname(args.lightdock_output)

    # If normal modes used, need to read them
    nmodes_rec = nmodes_lig = None
    if len(rec_extents):
        nm_path = os.path.abspath(os.path.dirname(args.receptor_structures))
        nmodes_rec = read_nmodes(os.path.join(nm_path, DEFAULT_REC_NM_FILE + '.npy'))
    if len(lig_extents):
        nm_path = os.path.abspath(os.path.dirname(args.ligand_structures))
        nmodes_lig = read_nmodes(os.path.join(nm_path, DEFAULT_LIG_NM_FILE + '.npy'))

    for i in range(num_conformations):
        receptor_pose = receptor.atom_coordinates[receptor_ids[i]].clone()
        ligand_pose = ligand.atom_coordinates[ligand_ids[i]].clone()

        # Use normal modes if provided:
        if len(rec_extents):
            try:
                for nm in range(num_anm_rec):
                    receptor_pose.coordinates += nmodes_rec[nm] * rec_extents[i][nm]
            except ValueError:
                log.error("Problem found on calculating ANM for receptor:")
                log.error("Number of atom coordinates is: %s" % str(receptor_pose.coordinates.shape))
github brianjimenez / lightdock / bin / post / lgd_generate_trajectory.py View on Github external
# Read receptor
    log.info("Reading %s receptor PDB file..." % args.receptor_pdb)
    atoms, residues, chains = parse_complex_from_file(args.receptor_pdb)
    receptor = Complex(chains, atoms)
    log.info("%s atoms, %s residues read." % (len(atoms), len(residues)))
    
    # Read ligand
    log.info("Reading %s ligand PDB file..." % args.ligand_pdb)
    atoms, residues, chains = parse_complex_from_file(args.ligand_pdb)
    ligand = Complex(chains, atoms)
    log.info("%s atoms, %s residues read." % (len(atoms), len(residues)))

    try:
        nm_path = os.path.abspath(os.path.dirname(args.receptor_pdb))
        nmodes_rec = read_nmodes(os.path.join(nm_path, DEFAULT_REC_NM_FILE + '.npy'))
    except:
        nmodes_rec = None
    try:
        nm_path = os.path.abspath(os.path.dirname(args.ligand_pdb))
        nmodes_lig = read_nmodes(os.path.join(nm_path, DEFAULT_LIG_NM_FILE + '.npy'))
    except:
        nmodes_lig = None

    for step in xrange(0, args.steps+1):
        try:
            # Parse each stored step file
            file_name = 'gso_%d.out' % step
            if os.path.exists(file_name):
                translation, rotation, rec_extent, lig_extent = parse_output_file(file_name, args.glowworm_id, 
                                                                                  num_anm_rec, num_anm_lig)
                receptor_pose = receptor.atom_coordinates[0].clone()
github brianjimenez / lightdock / bin / post / lgd_local_minimization.py View on Github external
ligand = Complex(chains, atoms, residues, structure_file_name=structure)
    log.info("%s atoms, %s residues read." % (len(atoms), len(residues)))

    # Output file
    translations, rotations, receptor_ids, ligand_ids, rec_extents, lig_extents = parse_output_file(args.lightdock_output)

    # Destination path is the same as the lightdock output
    destination_path = os.path.dirname(args.lightdock_output)

    # If normal modes used, need to read them
    if len(rec_extents):
        nm_path = os.path.abspath(os.path.dirname(args.receptor_structure))
        nmodes_rec = read_nmodes(os.path.join(nm_path, DEFAULT_REC_NM_FILE + '.npy'))
    if len(lig_extents):
        nm_path = os.path.abspath(os.path.dirname(args.ligand_structure))
        nmodes_lig = read_nmodes(os.path.join(nm_path, DEFAULT_LIG_NM_FILE + '.npy'))

    initial_rec_extents = list([float(x) for x in rec_extents[args.glowworm]])
    initial_lig_extents = list([float(x) for x in lig_extents[args.glowworm]])

    # Prepare scoring function
    scoring_function, adapters = set_scoring_function(args.scoring_function, receptor, ligand)

    optimization_vector = []
    optimization_vector.extend(translations[args.glowworm])
    q = rotations[args.glowworm]
    optimization_vector.extend([q.w, q.x, q.y, q.z])
    optimization_vector.extend(initial_rec_extents)
    optimization_vector.extend(initial_lig_extents)
    optimization_vector = np.array(optimization_vector)

    # Minimize using Powell algorythm
github brianjimenez / lightdock / bin / post / lgd_local_minimization.py View on Github external
structure = args.ligand_structure
    log.info("Reading %s ligand PDB file..." % structure)
    atoms, residues, chains = parse_complex_from_file(structure)
    ligand = Complex(chains, atoms, residues, structure_file_name=structure)
    log.info("%s atoms, %s residues read." % (len(atoms), len(residues)))

    # Output file
    translations, rotations, receptor_ids, ligand_ids, rec_extents, lig_extents = parse_output_file(args.lightdock_output)

    # Destination path is the same as the lightdock output
    destination_path = os.path.dirname(args.lightdock_output)

    # If normal modes used, need to read them
    if len(rec_extents):
        nm_path = os.path.abspath(os.path.dirname(args.receptor_structure))
        nmodes_rec = read_nmodes(os.path.join(nm_path, DEFAULT_REC_NM_FILE + '.npy'))
    if len(lig_extents):
        nm_path = os.path.abspath(os.path.dirname(args.ligand_structure))
        nmodes_lig = read_nmodes(os.path.join(nm_path, DEFAULT_LIG_NM_FILE + '.npy'))

    initial_rec_extents = list([float(x) for x in rec_extents[args.glowworm]])
    initial_lig_extents = list([float(x) for x in lig_extents[args.glowworm]])

    # Prepare scoring function
    scoring_function, adapters = set_scoring_function(args.scoring_function, receptor, ligand)

    optimization_vector = []
    optimization_vector.extend(translations[args.glowworm])
    q = rotations[args.glowworm]
    optimization_vector.extend([q.w, q.x, q.y, q.z])
    optimization_vector.extend(initial_rec_extents)
    optimization_vector.extend(initial_lig_extents)
github brianjimenez / lightdock / bin / simulation / docking_mpi.py View on Github external
parsed_lightdock_ligand = os.path.join(os.path.dirname(args.ligand_pdb),
                                       DEFAULT_LIGHTDOCK_PREFIX % os.path.basename(args.ligand_pdb))
        ligand = read_input_structure(parsed_lightdock_ligand, args.noxt, args.noh, args.verbose_parser)

        # CRITICAL to not break compatibility with previous results
        receptor.move_to_origin()
        ligand.move_to_origin()

        if args.use_anm:
            try:
                receptor.n_modes = read_nmodes("%s%s" % (DEFAULT_REC_NM_FILE, NUMPY_FILE_SAVE_EXTENSION) )
            except:
                log.warning("No ANM found for receptor molecule")
                receptor.n_modes = None
            try:
                ligand.n_modes = read_nmodes("%s%s" % (DEFAULT_LIG_NM_FILE, NUMPY_FILE_SAVE_EXTENSION) )
            except:
                log.warning("No ANM found for ligand molecule")
                ligand.n_modes = None

        starting_points_files = load_starting_positions(args.swarms, args.glowworms, args.use_anm,
                                                        args.anm_rec, args.anm_lig)

        comm.Barrier()

        num_workers = comm.size
        for worker_id in xrange(num_workers):
            if worker_id == minion_id:
                starting_points_files = glob.glob('init/initial_positions*.dat')
                scoring_functions, adapters = set_scoring_function(parser, receptor, ligand, minion_id)
                for id_swarm in xrange(parser.args.swarms):
                    if worker_id == (id_swarm % num_workers):
github brianjimenez / lightdock / bin / post / lgd_generate_trajectory.py View on Github external
log.info("%s atoms, %s residues read." % (len(atoms), len(residues)))
    
    # Read ligand
    log.info("Reading %s ligand PDB file..." % args.ligand_pdb)
    atoms, residues, chains = parse_complex_from_file(args.ligand_pdb)
    ligand = Complex(chains, atoms)
    log.info("%s atoms, %s residues read." % (len(atoms), len(residues)))

    try:
        nm_path = os.path.abspath(os.path.dirname(args.receptor_pdb))
        nmodes_rec = read_nmodes(os.path.join(nm_path, DEFAULT_REC_NM_FILE + '.npy'))
    except:
        nmodes_rec = None
    try:
        nm_path = os.path.abspath(os.path.dirname(args.ligand_pdb))
        nmodes_lig = read_nmodes(os.path.join(nm_path, DEFAULT_LIG_NM_FILE + '.npy'))
    except:
        nmodes_lig = None

    for step in xrange(0, args.steps+1):
        try:
            # Parse each stored step file
            file_name = 'gso_%d.out' % step
            if os.path.exists(file_name):
                translation, rotation, rec_extent, lig_extent = parse_output_file(file_name, args.glowworm_id, 
                                                                                  num_anm_rec, num_anm_lig)
                receptor_pose = receptor.atom_coordinates[0].clone()
                ligand_pose = ligand.atom_coordinates[0].clone()

                if nmodes_rec is not None:
                    try:
                        for nm in range(num_anm_rec):
github brianjimenez / lightdock / bin / simulation / docking_multiprocessing.py View on Github external
# Read input structures (use parsed ones)
        parsed_lightdock_receptor = os.path.join(os.path.dirname(args.receptor_pdb),
                                       DEFAULT_LIGHTDOCK_PREFIX % os.path.basename(args.receptor_pdb))
        receptor = read_input_structure(parsed_lightdock_receptor, args.noxt, args.noh, args.verbose_parser)
        parsed_lightdock_ligand = os.path.join(os.path.dirname(args.ligand_pdb),
                                       DEFAULT_LIGHTDOCK_PREFIX % os.path.basename(args.ligand_pdb))
        ligand = read_input_structure(parsed_lightdock_ligand, args.noxt, args.noh, args.verbose_parser)

        # CRITICAL to not break compatibility with previous results
        receptor.move_to_origin()
        ligand.move_to_origin()

        if args.use_anm:
            try:
                receptor.n_modes = read_nmodes("%s%s" % (DEFAULT_REC_NM_FILE, NUMPY_FILE_SAVE_EXTENSION) )
            except:
                log.warning("No ANM found for receptor molecule")
                receptor.n_modes = None
            try:
                ligand.n_modes = read_nmodes("%s%s" % (DEFAULT_LIG_NM_FILE, NUMPY_FILE_SAVE_EXTENSION) )
            except:
                log.warning("No ANM found for ligand molecule")
                ligand.n_modes = None

        starting_points_files = load_starting_positions(args.swarms, args.glowworms, args.use_anm,
                                                        args.anm_rec, args.anm_lig)

        scoring_functions, adapters = set_scoring_function(parser, receptor, ligand)

        tasks = prepare_gso_tasks(parser, adapters, scoring_functions, starting_points_files)
github brianjimenez / lightdock / bin / post / lgd_top.py View on Github external
predictions = read_ranking_file(args.lightdock_ranking_file)

    # Destination path is the same as the lightdock output
    destination_path = os.path.dirname(args.lightdock_ranking_file)

    # If normal modes used, need to read them
    nmodes_rec = nmodes_lig = None
    nm_path = os.path.abspath(os.path.dirname(args.receptor_structures))
    # Check NM file for receptor
    nm_rec_file = os.path.join(nm_path, DEFAULT_REC_NM_FILE + '.npy')
    if os.path.exists(nm_rec_file):
        nmodes_rec = read_nmodes(nm_rec_file)
    # Check NM file for ligand
    nm_lig_file = os.path.join(nm_path, DEFAULT_LIG_NM_FILE + '.npy')
    if os.path.exists(nm_lig_file):
        nmodes_lig = read_nmodes(nm_lig_file)

    for i, glowworm in enumerate(predictions):
        if i < args.top:
            receptor_pose = receptor.atom_coordinates[glowworm.receptor_id].clone()
            ligand_pose = ligand.atom_coordinates[glowworm.ligand_id].clone()
            # Use normal modes if provided:
            if nmodes_rec.any():
                for nm in range(num_anm_rec):
                    rec_extent = np.array([float(x) for x in glowworm.pose[7:7 + num_anm_rec]])
                    receptor_pose.coordinates += nmodes_rec[nm] * rec_extent[nm]
            if nmodes_lig.any():
                for nm in range(num_anm_lig):
                    lig_extent = np.array([float(x) for x in glowworm.pose[-num_anm_lig:]])
                    ligand_pose.coordinates += nmodes_lig[nm] * lig_extent[nm]

            # We rotate first, ligand it's at initial position
github brianjimenez / lightdock / bin / post / lgd_top.py View on Github external
log.info("%s atoms, %s residues read." % (len(atoms), len(residues)))
    ligand = Complex.from_structures(structures)

    # Read ranking file
    predictions = read_ranking_file(args.lightdock_ranking_file)

    # Destination path is the same as the lightdock output
    destination_path = os.path.dirname(args.lightdock_ranking_file)

    # If normal modes used, need to read them
    nmodes_rec = nmodes_lig = None
    nm_path = os.path.abspath(os.path.dirname(args.receptor_structures))
    # Check NM file for receptor
    nm_rec_file = os.path.join(nm_path, DEFAULT_REC_NM_FILE + '.npy')
    if os.path.exists(nm_rec_file):
        nmodes_rec = read_nmodes(nm_rec_file)
    # Check NM file for ligand
    nm_lig_file = os.path.join(nm_path, DEFAULT_LIG_NM_FILE + '.npy')
    if os.path.exists(nm_lig_file):
        nmodes_lig = read_nmodes(nm_lig_file)

    for i, glowworm in enumerate(predictions):
        if i < args.top:
            receptor_pose = receptor.atom_coordinates[glowworm.receptor_id].clone()
            ligand_pose = ligand.atom_coordinates[glowworm.ligand_id].clone()
            # Use normal modes if provided:
            if nmodes_rec.any():
                for nm in range(num_anm_rec):
                    rec_extent = np.array([float(x) for x in glowworm.pose[7:7 + num_anm_rec]])
                    receptor_pose.coordinates += nmodes_rec[nm] * rec_extent[nm]
            if nmodes_lig.any():
                for nm in range(num_anm_lig):