Пример #1
0
def save_lightdock_structure(structure):
    """Saves the structure parsed by LightDock"""
    log.info("Saving processed structure to PDB file...")
    for structure_index, file_name in enumerate(structure.structure_file_names):
        moved_file_name = os.path.join(os.path.dirname(file_name),
                                       DEFAULT_LIGHTDOCK_PREFIX % os.path.basename(file_name))
        write_pdb_to_file(structure, moved_file_name, structure[structure_index])
    log.info("Done.")
Пример #2
0
 def test_write_pdb_to_file(self):
     atoms, residues, chains = parse_complex_from_file(self.golden_data_path + '1PPE_l_u.pdb')
     protein = Complex(chains)
     assert atoms == protein.atoms
     
     write_pdb_to_file(protein, self.test_path + '1PPE_l_u.pdb.parsed', protein.atom_coordinates[0])
     
     assert filecmp.cmp(self.golden_data_path + '1PPE_l_u.pdb.parsed', self.test_path + '1PPE_l_u.pdb.parsed')
Пример #3
0
 def test_null_rotation(self):
     protein = Complex(chains=self.chains2)
     q = Quaternion()
     protein.rotate(q)
     write_pdb_to_file(protein, self.test_path + 'rotated.pdb',
                       protein.atom_coordinates[0])
     assert filecmp.cmp(self.golden_data_path + 'two_residues.pdb',
                        self.test_path + 'rotated.pdb')
Пример #4
0
    def test_write_pdb_to_file(self):
        atoms, _, chains = parse_complex_from_file(self.golden_data_path /
                                                   '1PPE_l_u.pdb')
        protein = Complex(chains)
        assert atoms == protein.atoms

        write_pdb_to_file(protein, self.test_path / '1PPE_l_u.pdb.parsed',
                          protein.atom_coordinates[0])

        assert filecmp.cmp(self.golden_data_path / '1PPE_l_u.pdb.parsed',
                           self.test_path / '1PPE_l_u.pdb.parsed')
Пример #5
0
def save_lightdock_structure(structure):
    """Saves the structure parsed by LightDock"""
    log.info("Saving processed structure to PDB file...")
    for structure_index, file_name in enumerate(
            structure.structure_file_names):
        moved_file_name = os.path.join(
            os.path.dirname(file_name),
            DEFAULT_LIGHTDOCK_PREFIX % os.path.basename(file_name))
        write_pdb_to_file(structure, moved_file_name,
                          structure[structure_index])
    log.info("Done.")
Пример #6
0
    def test_parse_pdb_noh(self):
        atoms_to_ignore = ['H']
        atoms, _, chains = parse_complex_from_file(
            self.golden_data_path / '1PPE_lig.pdb.H', atoms_to_ignore)
        protein = Complex(chains)
        assert atoms == protein.atoms

        write_pdb_to_file(protein, self.test_path / 'parsed_1PPE_lig.pdb.H',
                          protein.atom_coordinates[0])

        assert filecmp.cmp(self.golden_data_path / 'parsed_1PPE_lig.pdb.H',
                           self.test_path / 'parsed_1PPE_lig.pdb.H')
Пример #7
0
 def test_rotation_180_degrees_y_axis_origin_is_0(self):
     """Expected file has been generated with Chimera fixing the rotation to the
     center of coordinates and modifying the column of atom name to have the
     same padding as the write_pdb_file function.
     """
     protein = Complex(chains=self.chains2)
     q = Quaternion(0, 0.0, 1.0, 0)
     
     protein.rotate(q)
     
     write_pdb_to_file(protein, self.test_path+'rotated.pdb', protein.atom_coordinates[0])
     assert filecmp.cmp(self.golden_data_path+'two_residues_y_180.pdb', self.test_path+'rotated.pdb')
Пример #8
0
    def test_rotation_180_degrees_y_axis_origin_is_0(self):
        """Expected file has been generated with Chimera fixing the rotation to the
        center of coordinates and modifying the column of atom name to have the
        same padding as the write_pdb_file function.
        """
        protein = Complex(chains=self.chains2)
        q = Quaternion(0, 0.0, 1.0, 0)

        protein.rotate(q)

        write_pdb_to_file(protein, self.test_path + 'rotated.pdb',
                          protein.atom_coordinates[0])
        assert filecmp.cmp(self.golden_data_path + 'two_residues_y_180.pdb',
                           self.test_path + 'rotated.pdb')
Пример #9
0
def save_lightdock_structure(structure):
    """Saves the structure parsed by LightDock"""
    log.info("Saving processed structure to PDB file...")
    for structure_index, file_name in enumerate(
            structure.structure_file_names):
        moved_file_name = Path(file_name).parent / Path(
            DEFAULT_LIGHTDOCK_PREFIX % Path(file_name).name)
        if moved_file_name.exists():
            raise LightDockError(
                f"{moved_file_name} already exists, please delete previous setup generated files"
            )
        write_pdb_to_file(structure, moved_file_name,
                          structure[structure_index])
    log.info("Done.")
Пример #10
0
    def test_rotation_90_degrees_y_axis_90_degrees_x_axis_origin_is_0(self):
        """Expected file has been generated with Chimera fixing the rotation to the
        center of coordinates and modifying the column of atom name to have the
        same padding as the write_pdb_file function.
        """
        protein = Complex(chains=self.chains2)
        # Heading 90degrees (Y axis)
        q1 = Quaternion(0.7071, 0.0, 0.7071, 0.0)
        # Attitude 90degrees (X axis)
        q2 = Quaternion(0.7071, 0.0, 0.0, 0.7071)
        q = q1 * q2

        protein.rotate(q)

        write_pdb_to_file(protein, self.test_path / 'rotated.pdb',
                          protein.atom_coordinates[0])
        assert filecmp.cmp(
            self.golden_data_path / 'two_residues_y_90_x_90.pdb',
            self.test_path / 'rotated.pdb')
Пример #11
0
 def test_null_rotation(self):
     protein = Complex(chains=self.chains2)
     q = Quaternion()
     protein.rotate(q)
     write_pdb_to_file(protein, self.test_path+'rotated.pdb', protein.atom_coordinates[0])
     assert filecmp.cmp(self.golden_data_path+'two_residues.pdb', self.test_path+'rotated.pdb')
Пример #12
0
    for step in xrange(0, num_steps + 1):
        try:
            # Parse each stored step file
            file_name = 'gso_%d.out' % step
            translation, rotation, nm_rec, nm_lig = parse_file(
                file_name, glowworm_id)

            receptor_pose = receptor.atom_coordinates[0].clone()
            ligand_pose = ligand.atom_coordinates[0].clone()

            num_rec_nmodes = len(nm_rec)
            if num_rec_nmodes:
                for i in range(num_rec_nmodes):
                    receptor_pose.coordinates += nmodes_rec[i] * nm_rec[i]
            num_lig_nmodes = len(nm_lig)
            if num_lig_nmodes:
                for i in range(num_lig_nmodes):
                    ligand_pose.coordinates += nmodes_lig[i] * nm_lig[i]

            # We rotate first, ligand it's at initial position
            ligand_pose.rotate(rotation)
            ligand_pose.translate(translation)

            output_file_name = 'trajectory_%s_step_%s.pdb' % (glowworm_id,
                                                              step)
            write_pdb_to_file(receptor, output_file_name, receptor_pose)
            write_pdb_to_file(ligand, output_file_name, ligand_pose)
            log.info("Generated trajectory for step %s" % (step))
        except TypeError:
            pass
Пример #13
0
    protein_anm.calcModes(n_modes=n_modes)
    print('Normal modes calculated')

    atoms, residues, chains = parse_complex_from_file(pdb_structure)
    lightdock_structures = [{'atoms': atoms, 'residues': residues, 'chains': chains, 'file_name': pdb_structure}]
    lightdock_structure = Complex.from_structures(lightdock_structures)
    print('Structure read by lightdock')

    num_atoms_prody = len(protein.protein)
    num_atoms_lightdock = len(atoms)

    if num_atoms_prody != num_atoms_lightdock:
        raise SystemExit("Number of atoms is different")

    protein_anm_ext, protein_all = extendModel(protein_anm, ca_atoms, protein, norm=True)

    modes = []
    for i in range(n_modes):
        nm = protein_anm_ext.getEigvecs()[:, i].reshape((num_atoms_lightdock, 3))
        modes.append(nm)

    coordinates = lightdock_structure.atom_coordinates[0].coordinates
    for i in range(n_modes):
        lightdock_structure.atom_coordinates[0].coordinates += modes[i] * factor

    output_file = 'anm_' + pdb_structure
    write_pdb_to_file(lightdock_structure, output_file, lightdock_structure[0])

    print('Structure written to %s' % output_file)
    print('Done.')
Пример #14
0
    protein_anm.calcModes(n_modes=n_modes)
    print 'Normal modes calculated'

    atoms, residues, chains = parse_complex_from_file(pdb_structure)
    lightdock_structures = [{'atoms': atoms, 'residues': residues, 'chains': chains, 'file_name': pdb_structure}]
    lightdock_structure = Complex.from_structures(lightdock_structures)
    print 'Structure read by lightdock'

    num_atoms_prody = len(protein.protein)
    num_atoms_lightdock = len(atoms)

    if num_atoms_prody != num_atoms_lightdock:
        raise SystemExit("Number of atoms is different")

    protein_anm_ext, protein_all = extendModel(protein_anm, ca_atoms, protein, norm=True)

    modes = []
    for i in range(n_modes):
        nm = protein_anm_ext.getEigvecs()[:, i].reshape((num_atoms_lightdock, 3))
        modes.append(nm)

    coordinates = lightdock_structure.atom_coordinates[0].coordinates
    for i in range(n_modes):
        lightdock_structure.atom_coordinates[0].coordinates += modes[i] * factor

    output_file = 'anm_' + pdb_structure
    write_pdb_to_file(lightdock_structure, output_file, lightdock_structure[0])

    print 'Structure written to %s' % output_file
    print 'Done.'
Пример #15
0
    # 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(glowworms):
        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(DEFAULT_NMODES_REC):
                rec_extent = np.array([float(x) for x in glowworm.pose[7:7 + DEFAULT_NMODES_REC]])
                receptor_pose.coordinates += nmodes_rec[nm] * rec_extent[nm]
        if nmodes_lig.any():
            for nm in range(DEFAULT_NMODES_LIG):
                lig_extent = np.array([float(x) for x in glowworm.pose[-DEFAULT_NMODES_LIG:]])
                ligand_pose.coordinates += nmodes_lig[nm] * lig_extent[nm]

        # We rotate first, ligand it's at initial position
        rotation = Quaternion(glowworm.pose[3], glowworm.pose[4], glowworm.pose[5], glowworm.pose[6])
        ligand_pose.rotate(rotation)
        ligand_pose.translate([glowworm.pose[0], glowworm.pose[1], glowworm.pose[2]])

        write_pdb_to_file(receptor, os.path.join(destination_path, 'top_%s.pdb' % str(i+1)), receptor_pose)
        write_pdb_to_file(ligand,  os.path.join(destination_path, 'top_%s.pdb' % str(i+1)), ligand_pose)
    log.info("Generated %d conformations" % args.top)
                raise SystemExit
        if len(lig_extents):
            try:
                for nm in range(num_anm_lig):
                    ligand_pose.coordinates += nmodes_lig[nm] * lig_extents[i][
                        nm]
            except ValueError:
                log.error("Problem found on calculating ANM for ligand:")
                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:
                log.error("Problem found on calculating ANM for ligand:")
                log.error(
                    "If you have used anm_lig different than default, please use --setup"
                )
                raise SystemExit

        # We rotate first, ligand it's at initial position
        ligand_pose.rotate(rotations[i])
        ligand_pose.translate(translations[i])

        write_pdb_to_file(
            receptor, os.path.join(destination_path, 'lightdock_%s.pdb' % i),
            receptor_pose)
        write_pdb_to_file(
            ligand, os.path.join(destination_path, 'lightdock_%s.pdb' % i),
            ligand_pose)
    log.info("Generated %d conformations" % num_conformations)
            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:
                log.error("Problem found on calculating ANM for receptor:")
                log.error("If you have used anm_rec different than default, please use --setup")
                raise SystemExit
        if len(lig_extents):
            try:
                for nm in range(num_anm_lig):
                    ligand_pose.coordinates += nmodes_lig[nm] * lig_extents[i][nm]
            except ValueError:
                log.error("Problem found on calculating ANM for ligand:")
                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:
                log.error("Problem found on calculating ANM for ligand:")
                log.error("If you have used anm_lig different than default, please use --setup")
                raise SystemExit

        # We rotate first, ligand it's at initial position
        ligand_pose.rotate(rotations[i])
        ligand_pose.translate(translations[i])

        write_pdb_to_file(receptor, os.path.join(destination_path, 'lightdock_%s.pdb' % i), receptor_pose)
        write_pdb_to_file(ligand,  os.path.join(destination_path, 'lightdock_%s.pdb' % i), ligand_pose)
    log.info("Generated %d conformations" % num_conformations)
Пример #18
0
                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
            rotation = Quaternion(glowworm.pose[3], glowworm.pose[4],
                                  glowworm.pose[5], glowworm.pose[6])
            ligand_pose.rotate(rotation)
            ligand_pose.translate(
                [glowworm.pose[0], glowworm.pose[1], glowworm.pose[2]])

            write_pdb_to_file(
                receptor,
                os.path.join(destination_path, 'top_%s.pdb' % str(i + 1)),
                receptor_pose)
            write_pdb_to_file(
                ligand,
                os.path.join(destination_path, 'top_%s.pdb' % str(i + 1)),
                ligand_pose)
    log.info("Generated %d conformations" % args.top)
        nmodes_lig = None

    for step in xrange(0, num_steps+1):
        try:
            # Parse each stored step file
            file_name = 'gso_%d.out' % step
            translation, rotation, nm_rec, nm_lig = parse_file(file_name, glowworm_id)

            receptor_pose = receptor.atom_coordinates[0].clone()
            ligand_pose = ligand.atom_coordinates[0].clone()

            num_rec_nmodes = len(nm_rec)
            if num_rec_nmodes:
                for i in range(num_rec_nmodes):
                    receptor_pose.coordinates += nmodes_rec[i] * nm_rec[i]
            num_lig_nmodes = len(nm_lig)
            if num_lig_nmodes:
                for i in range(num_lig_nmodes):
                    ligand_pose.coordinates += nmodes_lig[i] * nm_lig[i]

            # We rotate first, ligand it's at initial position
            ligand_pose.rotate(rotation)
            ligand_pose.translate(translation)

            output_file_name = 'trajectory_%s_step_%s.pdb' % (glowworm_id, step)
            write_pdb_to_file(receptor, output_file_name, receptor_pose)
            write_pdb_to_file(ligand, output_file_name, ligand_pose)
            log.info("Generated trajectory for step %s" % (step))
        except TypeError:
            pass