How to use the lightdock.pdbutil.PDBIO.parse_complex_from_file 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 / support / lgd_calculate_scoring.py View on Github external
parser.add_argument("receptor", help="PDB receptor")
    parser.add_argument("ligand", help="PDB ligand")
    script_args = parser.parse_args()
    return script_args


if __name__ == "__main__":
    args = parse_command_line()

    try:
        scoring_function_module = "lightdock.scoring.%s.driver" % args.scoring_function
        module = importlib.import_module(scoring_function_module)
    except ImportError:
        raise SystemExit("Scoring function not found or not available")

    atoms, residues, chains = parse_complex_from_file(args.receptor)
    receptor = Complex(chains, atoms, structure_file_name=args.receptor)
    atoms, residues, chains = parse_complex_from_file(args.ligand)
    ligand = Complex(chains, atoms, structure_file_name=args.ligand)

    CurrentScoringFunction = getattr(module, "DefinedScoringFunction")
    CurrentModelAdapter = getattr(module, "DefinedModelAdapter")

    adapter = CurrentModelAdapter(receptor, ligand)
    scoring_function = CurrentScoringFunction()

    energy = scoring_function(adapter.receptor_model,  adapter.receptor_model.coordinates[0],
                              adapter.ligand_model, adapter.ligand_model.coordinates[0])
    print args.scoring_function, ': ', energy
github brianjimenez / lightdock / bin / post / lgd_calculate_reference_points.py View on Github external
args = parse_command_line()

        atoms_to_ignore = []
        if args.noxt:
            atoms_to_ignore.append('OXT')

        structures = []
        file_names = []
        file_name, file_extension = os.path.splitext(args.structure)
        if file_extension == DEFAULT_LIST_EXTENSION:
            file_names.extend(get_pdb_files(args.structure))
        else:
            file_names.append(args.structure)
        for file_name in file_names:
            log.info("Reading %s PDB file..." % file_name)
            atoms, residues, chains = parse_complex_from_file(file_name, atoms_to_ignore)
            structures.append({'atoms': atoms, 'residues': residues, 'chains': chains, 'file_name': file_name})
            log.info("%s atoms, %s residues read." % (len(atoms), len(residues)))

        molecule = Complex.from_structures(structures)
        try:
            ellipsoid = MinimumVolumeEllipsoid(molecule.atom_coordinates[0].coordinates)
        except MinimumVolumeEllipsoidError, e:
            log.error("Impossible to calculate minimum volume ellipsoid. Reason: %s" % str(e))
            raise SystemExit("%s finished with error" % script_name)

        output_file_name = molecule.structure_file_names[0] + DEFAULT_REFERENCE_POINTS_EXTENSION
        with open(output_file_name, 'w') as output:
            for point in ellipsoid.poles:
                output.write(get_point_respresentation(point) + os.linesep)
            output.write(get_point_respresentation(ellipsoid.center) + os.linesep)
        log.info('Points written to %s' % output_file_name)
github brianjimenez / lightdock / bin / support / lgd_calculate_scoring.py View on Github external
script_args = parser.parse_args()
    return script_args


if __name__ == "__main__":
    args = parse_command_line()

    try:
        scoring_function_module = "lightdock.scoring.%s.driver" % args.scoring_function
        module = importlib.import_module(scoring_function_module)
    except ImportError:
        raise SystemExit("Scoring function not found or not available")

    atoms, residues, chains = parse_complex_from_file(args.receptor)
    receptor = Complex(chains, atoms, structure_file_name=args.receptor)
    atoms, residues, chains = parse_complex_from_file(args.ligand)
    ligand = Complex(chains, atoms, structure_file_name=args.ligand)

    CurrentScoringFunction = getattr(module, "DefinedScoringFunction")
    CurrentModelAdapter = getattr(module, "DefinedModelAdapter")

    adapter = CurrentModelAdapter(receptor, ligand)
    scoring_function = CurrentScoringFunction()

    energy = scoring_function(adapter.receptor_model,  adapter.receptor_model.coordinates[0],
                              adapter.ligand_model, adapter.ligand_model.coordinates[0])
    print args.scoring_function, ': ', energy
github brianjimenez / lightdock / bin / post / lgd_generate_trajectory.py View on Github external
if __name__ == "__main__":
    # Parse arguments
    args = parse_command_line()

    # Load setup configuration if provided
    setup = get_setup_from_file(args.setup_file) if args.setup_file else None

    num_anm_rec = DEFAULT_NMODES_REC
    num_anm_lig = DEFAULT_NMODES_LIG
    if setup and setup['use_anm']:
        num_anm_rec = setup['anm_rec']
        num_anm_lig = setup['anm_lig']
    
    # 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))
github brianjimenez / lightdock / bin / support / lgd_calculate_diameter.py View on Github external
log = LoggingManager.get_logger('diameter')


def parse_command_line():
    parser = argparse.ArgumentParser(prog='calculate_diameter')
    parser.add_argument("pdb", help="PDB file for structure to calculate maximum diameter")
    args = parser.parse_args()
    return args


if __name__ == "__main__":
    args = parse_command_line()

    atoms, residues, chains = parse_complex_from_file(args.pdb)
    structure = Complex(chains, atoms, structure_file_name=args.pdb)
    distances_matrix = spatial.distance.squareform(spatial.distance.pdist(structure.representative()))
    ligand_max_diameter = np.max(distances_matrix)

    print ligand_max_diameter
github brianjimenez / lightdock / bin / support / lgd_calculate_surface_density.py View on Github external
"""
    Parses command line arguments
    """
    parser = argparse.ArgumentParser(prog='surface_density')
    parser.add_argument("pdb1", help="PDB file for receptor structure")
    parser.add_argument("pdb2", help="PDB file for ligand structure")
    parser.add_argument("points", type=int, default=400, help="The number of points on the surface")
    args = parser.parse_args()
    return args


if __name__ == "__main__":
    args = parse_command_line()

    # Read receptor and calculate max radius
    atoms, residues, chains = parse_complex_from_file(args.pdb1)
    structure = Complex(chains, atoms, structure_file_name=args.pdb1)
    distances_matrix = spatial.distance.squareform(spatial.distance.pdist(structure.representative()))
    radius1 = np.max(distances_matrix)/2.

    # Read ligand and calculate max radius
    atoms, residues, chains = parse_complex_from_file(args.pdb2)
    structure = Complex(chains, atoms, structure_file_name=args.pdb2)
    distances_matrix = spatial.distance.squareform(spatial.distance.pdist(structure.representative()))
    radius2 = np.max(distances_matrix)/2.

    # Calculate the area of the sphere of radius (Rl + Rr)
    density_area = (4*np.pi*(radius1+radius2)**2)/args.points

    if density_area > MIN_SURFACE_DENSITY:
        log.warning("Surface density is below recommended, please increase the number of points on the surface.")
github brianjimenez / lightdock / bin / support / lgd_calculate_surface_density.py View on Github external
parser.add_argument("points", type=int, default=400, help="The number of points on the surface")
    args = parser.parse_args()
    return args


if __name__ == "__main__":
    args = parse_command_line()

    # Read receptor and calculate max radius
    atoms, residues, chains = parse_complex_from_file(args.pdb1)
    structure = Complex(chains, atoms, structure_file_name=args.pdb1)
    distances_matrix = spatial.distance.squareform(spatial.distance.pdist(structure.representative()))
    radius1 = np.max(distances_matrix)/2.

    # Read ligand and calculate max radius
    atoms, residues, chains = parse_complex_from_file(args.pdb2)
    structure = Complex(chains, atoms, structure_file_name=args.pdb2)
    distances_matrix = spatial.distance.squareform(spatial.distance.pdist(structure.representative()))
    radius2 = np.max(distances_matrix)/2.

    # Calculate the area of the sphere of radius (Rl + Rr)
    density_area = (4*np.pi*(radius1+radius2)**2)/args.points

    if density_area > MIN_SURFACE_DENSITY:
        log.warning("Surface density is below recommended, please increase the number of points on the surface.")

    print ';'.join([str(x) for x in [radius1, radius2, density_area]])
github brianjimenez / lightdock / bin / post / lgd_generate_trajectory.py View on Github external
num_anm_rec = DEFAULT_NMODES_REC
    num_anm_lig = DEFAULT_NMODES_LIG
    if setup and setup['use_anm']:
        num_anm_rec = setup['anm_rec']
        num_anm_lig = setup['anm_lig']
    
    # 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:
github brianjimenez / lightdock / bin / post / lgd_local_minimization.py View on Github external
parser.add_argument("glowworm", help="glowworm to minimize", type=valid_integer_number)
    # Scoring function
    parser.add_argument("-s", "--scoring_function", help="scoring function used", dest="scoring_function")
    args = parser.parse_args()

    # Read receptor structure
    structure = args.receptor_structure
    log.info("Reading %s receptor PDB file..." % structure)
    atoms, residues, chains = parse_complex_from_file(structure)
    receptor = Complex(chains, atoms, residues, structure_file_name=structure)
    log.info("%s atoms, %s residues read." % (len(atoms), len(residues)))

    # Read ligand structure
    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'))
github brianjimenez / lightdock / bin / post / lgd_top.py View on Github external
num_anm_lig = setup['anm_lig']

    # Receptor
    structures = []
    for structure in get_lightdock_structures(args.receptor_structures):
        log.info("Reading %s receptor PDB file..." % structure)
        atoms, residues, chains = parse_complex_from_file(structure)
        structures.append({'atoms': atoms, 'residues': residues, 'chains': chains, 'file_name': structure})
        log.info("%s atoms, %s residues read." % (len(atoms), len(residues)))
    receptor = Complex.from_structures(structures)

    # Ligand
    structures = []
    for structure in get_lightdock_structures(args.ligand_structures):
        log.info("Reading %s ligand PDB file..." % structure)
        atoms, residues, chains = parse_complex_from_file(structure)
        structures.append({'atoms': atoms, 'residues': residues, 'chains': chains, 'file_name': structure})
        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):