コード例 #1
0
    def __init__(self, parent, enableUi, File=""):
        f = QGLFormat()
        f.setStencil(True)
        f.setRgba(True)
        f.setDepth(True)
        f.setDoubleBuffer(True)
        QGLWidget.__init__(self, f, parent=parent)
        self.setMinimumSize(500, 500)
        self._enableUi = enableUi
        self.pymol = pymol2.PyMOL()  # _pymolPool.getInstance()
        self.pymol.start()
        self.cmd = self.pymol.cmd
        # self.toPymolName = self.pymol.toPymolName ### Attribute Error
        self._pymolProcess()
        if not self._enableUi:
            self.pymol.cmd.set("internal_gui", 0)
            self.pymol.cmd.set("internal_feedback", 0)
            self.pymol.cmd.button("double_left", "None", "None")
            self.pymol.cmd.button("single_right", "None", "None")

        self.pymol.cmd.load(File)
        self.pymol.reshape(self.width(), self.height())
        self._timer = QtCore.QTimer()
        self._timer.setSingleShot(True)
        self._timer.timeout.connect(self._pymolProcess)
        self.resizeGL(self.width(), self.height())
        #globalSettings.settingsChanged.connect(self._updateGlobalSettings)
        self._updateGlobalSettings()
コード例 #2
0
ファイル: __init__.py プロジェクト: phenylazide/Fragmenstein
 def _get_attachment_from_pdbblock(self) -> Union[None, Chem.Mol]:
     """
     Yes, yes, I see the madness in using pymol to get an atom for rdkit to make a pose for pyrosetta.
     Hence why `find_attachment` will replace it.
     todo `_get_attachment_from_pdbblock` --> `find_attachment`
     """
     self.journal.debug(f'{self.long_name} - getting attachemnt atom')
     if not self.covalent_resn:
         return None
     else:
         if isinstance(self.covalent_resi, str):
             resi, chain = re.match('(\d+)(\w)',
                                    self.covalent_resi).groups()
             resi = int(resi)
         else:
             resi = self.covalent_resi
             chain = None
         with pymol2.PyMOL() as pymol:
             pymol.cmd.read_pdbstr(self.apo_pdbblock, 'prot')
             if self.covalent_resn == 'CYS':
                 name = 'SG'
             else:
                 raise NotImplementedError('only done for cys atm')
             try:
                 if chain is not None:
                     pdb = pymol.cmd.get_pdbstr(
                         f'resi {resi} and name {name} and chain {chain}')
                 else:
                     pdb = pymol.cmd.get_pdbstr(
                         f'resi {resi} and name {name}')
             except:
                 pdb = pymol.cmd.get_pdbstr(f'resi {resi} and name {name}')
             return Chem.MolFromPDBBlock(pdb)
コード例 #3
0
    def make_pse(self, filename: str = 'combo.pse'):
        """
        Save a pse in the relevant folder.

        :param filename:
        :return:
        """
        assert '.pse' in filename, f'{filename} not .pse file'
        with pymol2.PyMOL() as pymol:
            for hit in self.hits:
                hit_name = hit.GetProp('_Name')
                pymol.cmd.read_molstr(Chem.MolToMolBlock(hit), hit_name)
                if hit_name in self.fragmenstein.unmatched:
                    pymol.cmd.color('black', f'element C and {hit_name}')
                else:
                    pymol.cmd.color('white', f'element C and {hit_name}')
            if self.fragmenstein.positioned_mol is not None:
                pymol.cmd.read_molstr(Chem.MolToMolBlock(self.fragmenstein.positioned_mol), 'placed')
                pymol.cmd.color('magenta', f'element C and placed')
            if self.minimised_mol is not None:
                pymol.cmd.read_molstr(Chem.MolToMolBlock(self.minimised_mol), 'minimised')
                pymol.cmd.color('green', f'element C and minimised')
            if self.minimised_pdbblock is not None:
                pymol.cmd.read_pdbstr(self.minimised_pdbblock, 'min_protein')
                pymol.cmd.color('gray50', f'element C and min_protein')
                pymol.cmd.hide('sticks', 'min_protein')
            if self.unminimised_pdbblock is not None:
                pymol.cmd.read_pdbstr(self.unminimised_pdbblock, 'unmin_protein')
                pymol.cmd.color('gray20', f'element C and unmin_protein')
                pymol.cmd.hide('sticks', 'unmin_protein')
                pymol.cmd.disable('unmin_protein')
            pymol.cmd.zoom('byres (placed expand 4)')
            pymol.cmd.show('line', 'byres (placed around 4)')
            pymol.cmd.save(os.path.join(self.work_path, self.long_name, filename))
コード例 #4
0
 def make_pse(self, filename='test.pse'):
     assert '.pse' in filename, 'Must be a pymol pse extension!'
     with pymol2.PyMOL() as pymol:
         tints = iter([
             'wheat', 'palegreen', 'lightblue', 'paleyellow', 'lightpink',
             'palecyan', 'lightorange', 'bluewhite'
         ])
         #pymol.cmd.bg_color('white')
         for h, hit in enumerate(self.hits):
             pymol.cmd.read_molstr(Chem.MolToMolBlock(hit, kekulize=False),
                                   f'hit{h}')
             pymol.cmd.color(next(tints), f'hit{h} and name C*')
         pymol.cmd.read_molstr(
             Chem.MolToMolBlock(self.scaffold, kekulize=False), f'scaffold')
         pymol.cmd.color('tv_blue', f'scaffold and name C*')
         pymol.cmd.read_molstr(
             Chem.MolToMolBlock(self.chimera, kekulize=False), f'chimera')
         pymol.cmd.color('cyan', f'chimera and name C*')
         pymol.cmd.read_molstr(
             Chem.MolToMolBlock(self.positioned_mol, kekulize=False),
             f'followup')
         pymol.cmd.color('tv_green', f'followup and name C*')
         pymol.cmd.hide('sticks')
         pymol.cmd.hide('cartoon')  # there should not be....
         pymol.cmd.show('lines', 'not polymer')
         pymol.cmd.show('sticks', 'followup or chimera')
         pymol.cmd.save(filename)
コード例 #5
0
    def dehydrate_file(self,
                       infile: str,
                       outfile: str,
                       water=False,
                       ligand=False):
        """
        Create a mutant protein based on a list of mutations on a PDB file path.

        :param infile: str
        :param outfile: str the file to save the mod as.
        :param mutations: list of string in the single letter format (A234P) without "p.".
        :param chain: str chain id in the pdb loaded.
        :return:

        **PyMOL session**: self-contained.
        """
        with pymol2.PyMOL() as self.pymol:
            self.pymol.cmd.set('fetch_path', self.temp_folder)
            self.pymol.cmd.load(infile)
            if water:
                self.pymol.cmd.remove('solvent')
            if ligand:
                self.pymol.cmd.remove(' or '.join(
                    [f'resn {l}' for l in self.boring_ligand]))
            self.pymol.cmd.save(outfile)
            self.pymol.cmd.delete('all')
        return 1
コード例 #6
0
def create_animations(user_rand):
    try:
        # pymol.finish_launching(['pymol', '-q'])  # pymol: -q quiet launch, -c no gui, -e fullscreen
        # cmd = pymol.cmd
        p1 = pymol2.PyMOL()
        p1.start()
        cmd = p1.cmd

        # load input
        cmd.reinitialize()
        sleep(0.5)
        cmd.load(temp + user_rand + "/file_upload_pdb.pdb")
        cmd.load_traj(temp + user_rand + "/file_upload_dcd.dcd")

        # create the animations:
        update_simulation_status('Creates the animations', user_rand)
        create_movies_from_different_angles(
            cmd, user_rand, temp + user_rand + "/file_upload_pdb.pdb",
            temp + user_rand +
            "/file_upload_dcd.dcd")  # create movies in media/movies folder

        # complete simulation:
        update_simulation_status('Done!', user_rand)

    except Exception as e:  # mainly for "pymol.CmdException"
        print(str(e))
        update_simulation_status(
            'An error occurred while creating the animations. Please try again later.',
            user_rand)
        return
コード例 #7
0
    def sdf_to_pdb(self, infile: str, reffile: str) -> str:
        """
        A special class method to convert a sdf to pdb but with the atom index shifted so that the pdb can be cat'ed.

        :param infile: sdf file
        :param reffile: pdb file for the indices.
        :return: PDB block

        **PyMOL session**: self-contained.
        """
        with pymol2.PyMOL() as self.pymol:
            self.pymol.cmd.set('fetch_path', self.temp_folder)
            combofile = infile.replace('.sdf', '_combo.pdb')
            minusfile = infile.replace('.sdf', '_ref.pdb')
            self.pymol.cmd.load(infile, 'ligand')
            self.pymol.cmd.alter('all', 'chain="Z"')
            self.pymol.cmd.load(reffile, 'apo')
            self.pymol.cmd.alter('all', 'segi=""')
            self.pymol.cmd.sort()
            self.pymol.cmd.create('combo', 'apo or ligand')
            self.pymol.cmd.save(combofile, 'combo')
            self.pymol.cmd.save(minusfile, 'apo')
            with open(minusfile) as fh:
                ref = fh.readlines()
            with open(combofile) as fh:
                combo = fh.readlines()
            ligand = ''.join([
                line for line in combo
                if line not in ref and line.strip() != ''
            ])
            os.remove(combofile)
            os.remove(minusfile)
            return ligand
コード例 #8
0
def load_mem_pose(filename, opm_filename, params_paths=None):
    with pymol2.PyMOL() as pymol:
        #     pymol.cmd.load('SLC38A3_phyre.pdb', 'S38A3')
        pymol.cmd.load(filename, 'S38A3')
        # pymol.cmd.remove('resi 1-68 or resi 245-282 or resi 494-504')
        #     pymol.cmd.remove('resi 138-207 or resi 318-392')
        map_pdbblock = pymol.cmd.get_pdbstr()
        pymol.cmd.load(opm_filename, 'OPM')
        pymol.cmd.align('S38A3', 'OPM')
        pymol.cmd.remove('resn MEM')  # make sure its not there!
        pymol.cmd.delete('OPM')
        holo_pdbblock = pymol.cmd.get_pdbstr('polymer')
        lig_pdbblock = pymol.cmd.get_pdbstr('not polymer')
    #     pymol.cmd.save('test.pdb')
    pose = pyrosetta.Pose()
    if params_paths:
        pyrosetta.generate_nonstandard_residue_set(pose, params_paths)
    # pyrosetta.rosetta.core.import_pose.pose_from_file(pose, 'phyre.gln_Na.PO4.loop_r.pdb')
    pyrosetta.rosetta.core.import_pose.pose_from_pdbstring(pose, holo_pdbblock)

    addmem = pyrosetta.rosetta.protocols.membrane.AddMembraneMover(
        'from_structure')
    addmem.apply(pose)
    pyrosetta.rosetta.protocols.membrane.AqueousPoreFinder().apply(pose)
    ligpose = pyrosetta.Pose()
    pyrosetta.generate_nonstandard_residue_set(ligpose, params_paths)
    # pyrosetta.rosetta.core.import_pose.pose_from_file(pose, 'phyre.gln_Na.PO4.loop_r.pdb')
    pyrosetta.rosetta.core.import_pose.pose_from_pdbstring(
        ligpose, lig_pdbblock)
    pose.append_pose_by_jump(ligpose, pose.total_residue())
    return pose
コード例 #9
0
 def is_satisfactory(self, resi: int):
     with pymol2.PyMOL() as pymol:
         pymol.cmd.read_pdbstr(self.coordinates, 'given_protein')
         residex = defaultdict(list)
         note = 'custom protein'
         for atom in pymol.cmd.get_model('name CA').atom:
             residex[atom.chain].append(atom.resi)
         if len(residex) == 1 and 'A' not in residex:
             note += ' - chain moved to A'
             pymol.cmd.alter('given_protein', 'chain="A"')
             pymol.cmd.sort()
             move = list(residex.values())[0]
             residex = {'A': move}
             self.coordinates = pymol.cmd.get_pdbstr()
         if not self.chain_definitions:
             self.chain_definitions = [{
                 'chain': chain,
                 'uniprot': "XXX",
                 'x': min(residex[chain]),
                 'y': max(residex[chain]),
                 'offset': 0,
                 'range': f'0-9999',
                 'name': self.code,
                 'description': note
             } for chain in residex]
         assert pymol.cmd.select(
             'given_protein'), 'Given protein had no valid data to load'
         assert pymol.cmd.select('chain A'), 'Given protein has no chain A'
         assert pymol.cmd.select(
             f'chain A and resi {resi}'
         ), f'Given protein has no residue {resi} in chain A'
         for name in ('N', 'CA', 'C'):
             assert pymol.cmd.select(f'chain A and resi {resi} and name {name}'), \
                 f'Given protein has no {name} atom in residue {resi} in chain A'
コード例 #10
0
    def distance_hits(cls, pdb_filenames: List[str],
                      target_resi: int,
                      target_chain: str,
                      target_atomname: str,
                      ligand_resn='LIG') -> List[float]:
        """
        See closest hit for info.

        :param pdb_filenames:
        :param target_resi:
        :param target_chain:
        :param target_atomname:
        :param ligand_resn:
        :return:
        """
        distances = []
        with pymol2.PyMOL() as pymol:
            for hit in pdb_filenames:
                pymol.cmd.load(hit)
                distances.append(min(
                    [pymol.cmd.distance(f'chain {target_chain} and resi {target_resi} and name {target_atomname}',
                                        f'resn {ligand_resn} and name {atom.name}') for atom in
                     pymol.cmd.get_model(f'resn {ligand_resn}').atom]))
                pymol.cmd.delete('*')
        return distances
コード例 #11
0
ファイル: forms.py プロジェクト: TechnionYP5779/SimuMole
    def change_relative_position(x1, y1, z1, x2, y2, z2, degXY_1, degYZ_1,
                                 degXY_2, degYZ_2, user_rand):
        """
        Save PDB file that represents the 2 PDB files after you change the positions and running pdb_fixer
        """
        # change positions
        filename_1, filename_2, pdb, temp = '_1_', '_2_', '.pdb', 'media/files/' + user_rand + '/'
        filename_1_movement, filename_2_movement = filename_1 + '__movement', filename_2 + '__movement'
        translate_pdb(temp + filename_1 + pdb,
                      temp + filename_1_movement + pdb, x1, y1, z1, degXY_1,
                      degYZ_1)
        translate_pdb(temp + filename_2 + pdb,
                      temp + filename_2_movement + pdb, x2, y2, z2, degXY_2,
                      degYZ_2)

        # fix pdb
        fix_pdb(temp + filename_1_movement + pdb)
        fix_pdb(temp + filename_2_movement + pdb)

        # merge to single pdb file
        # pymol.finish_launching(['pymol', '-q'])  # pymol: -q quiet launch, -c no gui, -e fullscreen
        # cmd = pymol.cmd
        while (not (os.path.isfile(temp + "both_1_2" + pdb))):
            p1 = pymol2.PyMOL()
            p1.start()
            cmd = p1.cmd

            cmd.reinitialize()
            sleep(0.5)
            cmd.load(temp + filename_1_movement + pdb)
            cmd.load(temp + filename_2_movement + pdb)
            cmd.zoom()
            cmd.save(temp + "both_1_2" + pdb)
コード例 #12
0
 def make_steps_pse(self, filename: str='step.pse'):
     assert '.pse' in filename, f'{filename} not .pse file'
     with pymol2.PyMOL() as pymol:
         for hit in self.hits:
             pymol.cmd.read_molstr(Chem.MolToMolBlock(hit, kekulize=False), hit.GetProp('_Name'))
         for i, mod in enumerate(self.modifications):
             pymol.cmd.read_molstr(Chem.MolToMolBlock(mod, kekulize=False), f'step{i}')
         pymol.cmd.save(os.path.join(self.work_path, self.long_name, filename))
コード例 #13
0
ファイル: _utility.py プロジェクト: LaYeqa/Fragmenstein
    def make_pse(self,
                 filename='test.pse',
                 extra_mols: Optional[Chem.Mol] = None):
        """
        This is specifically for debugging the full fragment merging mode.
        For general use. Please use the Victor method ``make_pse``.

        :param filename:
        :return:
        """
        assert '.pse' in filename, 'Must be a pymol pse extension!'
        import pymol2
        with pymol2.PyMOL() as pymol:
            tints = iter([
                'wheat', 'palegreen', 'lightblue', 'paleyellow', 'lightpink',
                'palecyan', 'lightorange', 'bluewhite'
            ])
            # pymol.cmd.bg_color('white')
            for h, hit in enumerate(self.hits):
                pymol.cmd.read_molstr(Chem.MolToMolBlock(hit, kekulize=False),
                                      f'hit{h}')
                pymol.cmd.color(next(tints), f'hit{h} and name C*')
            if 'scaffold' in self.modifications:
                pymol.cmd.read_molstr(
                    Chem.MolToMolBlock(self.modifications['scaffold'],
                                       kekulize=False), f'scaffold')
                pymol.cmd.color('tv_blue', f'scaffold and name C*')
            if 'chimera' in self.modifications:
                pymol.cmd.read_molstr(
                    Chem.MolToMolBlock(self.modifications['chimera'],
                                       kekulize=False), f'chimera')
                pymol.cmd.color('cyan', f'chimera and name C*')
            if self.positioned_mol:
                pymol.cmd.read_molstr(
                    Chem.MolToMolBlock(self.positioned_mol, kekulize=False),
                    f'followup')
                pymol.cmd.color('tv_green', f'followup and name C*')
            if self.mol_options:
                for i, mol in enumerate(self.mol_options):
                    pymol.cmd.read_molstr(
                        Chem.MolToMolBlock(mol, kekulize=False), f'opt{i}')
                    pymol.cmd.color('grey50', f'opt{i} and name C*')
            pymol.cmd.hide('sticks')
            pymol.cmd.hide('cartoon')  # there should not be....
            pymol.cmd.show('lines', 'not polymer')
            if 'chimera' in self.modifications:
                pymol.cmd.show('sticks', 'chimera')
            if self.positioned_mol:
                pymol.cmd.show('sticks', 'followup')
            if extra_mols:
                for mol in extra_mols:
                    name = mol.GetProp('_Name')
                    pymol.cmd.read_molstr(
                        Chem.MolToMolBlock(mol, kekulize=False), name)
                    pymol.cmd.color('magenta', f'{name} and name C*')
            pymol.cmd.save(filename)
コード例 #14
0
 def chain_removal_block(self, block: str, chains: List):
     """
     ** PyMOL session **: self - contained.
     """
     with pymol2.PyMOL() as self.pymol:
         self.pymol.cmd.read_pdbstr(block, 'blockprotein')
         for chain in chains:
             self.pymol.cmd.remove(f'chain {chain}')
         self.raw_pdb = self.pymol.cmd.get_pdbstr()
     return self
コード例 #15
0
def fix_pdb(in_filename, out_filename=None):
    with pymol2.PyMOL() as pymol:
        pymol.cmd.load(in_filename, 'S38A3')
        pymol.cmd.alter('chain A', 'resv+=69-1')
        pymol.cmd.sort()
        pymol.cmd.alter('chain A and resi 245-9999', 'resv+=283-245')
        pymol.cmd.sort()
        if out_filename is not None:
            pymol.cmd.save(out_filename)
        return pymol.cmd.get_pdbstr()
コード例 #16
0
 def make_steps_pse(self, filename: str = 'step.pse'):
     import pymol2
     assert '.pse' in filename, f'{filename} not .pse file'
     with pymol2.PyMOL() as pymol:
         for hit in self.hits:
             pymol.cmd.read_molstr(Chem.MolToMolBlock(hit, kekulize=False),
                                   hit.GetProp('_Name'))
         for label, mod in self.modifications:
             pymol.cmd.read_molstr(Chem.MolToMolBlock(mod, kekulize=False),
                                   re.sub('[^\w_]', '_', label))
         pymol.cmd.save(
             os.path.join(self.work_path, self.long_name, filename))
コード例 #17
0
    def testMultiInstance(self):
        import pymol
        import pymol2

        p1 = pymol2.PyMOL()
        p2 = pymol2.PyMOL()
        p3 = pymol  # singleton

        p1.start()
        p2.start()

        p1.cmd.fragment('ala')
        p2.cmd.fragment('trp')
        p3.cmd.fragment('ile')  # singleton

        self.assertEqual(p1.cmd.count_atoms(), 10)
        self.assertEqual(p2.cmd.count_atoms(), 24)
        self.assertEqual(p3.cmd.count_atoms(), 19)  # singleton

        p1.stop()
        p2.stop()
コード例 #18
0
    def correct_file(cls, filename: str, write: bool = True):
        import pymol2
        with pymol2.PyMOL() as pymol:
            pymol.cmd.load(filename, 'prot')
            ss = cls().parse_pymol(pymol.cmd)
        with open(filename, 'r') as fh:
            block = fh.read()

        if write:
            with open(filename, 'w') as fh:
                fh.write(ss + block)
        return ss + block
コード例 #19
0
 def __init__(self):
     self.glarea = self.create_glarea()
     self.pymol = pymol2.PyMOL(self.glarea)
     self.slab = 50
     self.zoom = 1.0
     self.angle = 0.0
     self.sprite = None
     self.zfactor = 0.005
     self.Zero_pointerx = 0
     self.Zero_pointery = 0
     self.ZeroX = 0
     self.ZeroY = 0
     self.clicado = False
コード例 #20
0
    def __init__(self, parent, enable_ui, filename="", unit_cell=False):
        f = QGLFormat()
        f.setStencil(True)
        f.setRgba(True)
        f.setDepth(True)
        f.setDoubleBuffer(True)
        QGLWidget.__init__(self, f, parent=parent)
        self.setMinimumSize(250, 250)
        self._enable_ui = enable_ui

        # set pymol invocation options
        self.pymol = pymol2.PyMOL()  # _pymolPool.getInstance()
        self.pymol.invocation.options.quiet = 1
        del (self.pymol._COb, self.pymol.cmd)
        self.pymol._COb = _cmd._new(self.pymol, self.pymol.invocation.options)
        self.pymol.cmd = pymol2.cmd2.Cmd(self.pymol, self.pymol._COb)

        self.pymol.start()

        # other initialisation
        self.cmd = self.pymol.cmd
        self.model_name = os.path.basename(os.path.splitext(filename)[0])
        self.zoom_level = 1
        # self.toPymolName = self.pymol.toPymolName ### Attribute Error
        self._pymolProcess()

        if not self._enable_ui:
            self.pymol.cmd.set("internal_gui", 0)
            self.pymol.cmd.set("internal_feedback", 0)
            self.pymol.cmd.button("double_left", "None", "None")
            self.pymol.cmd.button("single_right", "None", "None")

        #self.pymol.start()

        self.pymol.cmd.bg_color(color="white")
        self.load(filename)
        self.pymol.cmd.do("set antialias, 1")
        self.pymol.cmd.do("set ray_trace_mode, 1")
        self.pymol.cmd.do("show_as spheres")
        self.pymol.cmd.do("set sphere_mode, 4")
        self.pymol.cmd.do("set internal_gui=0")
        self.pymol.cmd.do("zoom center, {}".format(self.zoom_level))
        self._show_cell(unit_cell)
        self.pymol.reshape(self.width(), self.height())
        self.pymol.cmd.viewport(self.width(), self.height())
        self._timer = QtCore.QTimer()
        self._timer.setSingleShot(True)
        self._timer.timeout.connect(self._pymolProcess)
        self.resizeGL(self.width(), self.height())
        #globalSettings.settingsChanged.connect(self._updateGlobalSettings)
        self._updateGlobalSettings()
コード例 #21
0
 def create_apo(cls, template_pdbfilename: str):
     with pymol2.PyMOL() as pymol:
         pymol.cmd.load(template_pdbfilename)
         pymol.cmd.remove('solvent')
         pymol.cmd.remove(
             'resn DMS'
         )  # should run it through P Curran\s list of artefacts!
         apo = pymol.cmd.get_pdbstr('not resn LIG')
     pose = pyrosetta.Pose()
     pyrosetta.rosetta.core.import_pose.pose_from_pdbstring(pose, apo)
     scorefxn = pyrosetta.get_fa_scorefxn()
     relax = pyrosetta.rosetta.protocols.relax.FastRelax(scorefxn, 5)
     relax.apply(pose)
     pose.dump_pdb(cls.apo_pdbfilename)
コード例 #22
0
    def combine(self, probe_name: str, probe_resn: str = 'MMX') -> PDBBlocks:
        """
        The probe_resn needs to be untaken by PDB codes for rosetta. see ``replace`` for more.
        Adding -load_PDB_components false during the first initialisation of pyrosetta circumvents this,
        but means that native ligands need to declared.

        :param probe_name:
        :param probe_resn:
        :return:
        """
        with pymol2.PyMOL() as pymol:
            pymol.cmd.read_pdbstr(self.template.no_ligand, 'nolig')
            pymol.cmd.load(f'{probe_name}.pdb')
            return self.fill_PDBBlocks(pymol, probe_resn)
コード例 #23
0
    def chain_removal_file(self, infile, outfile, chains):
        """
        Create a mutant protein based on a list of mutations on a PDB file path.
        :param infile: str
        :param outfile: str the file to save the mod as.
        :param chains: lsit of str chain id in the pdb loaded.
        :return:

        **PyMOL session**: self-contained.
        """
        with pymol2.PyMOL() as self.pymol:
            self.pymol.cmd.set('fetch_path', self.temp_folder)
            self.pymol.cmd.load(infile)
            self._chain_removal(outfile, chains)
        return 1
コード例 #24
0
    def create_simulation(self):
        # pymol.finish_launching(['pymol', '-q'])  # pymol: -q quiet launch, -c no gui, -e fullscreen
        # self.cmd = pymol.cmd
        p1 = pymol2.PyMOL()
        p1.start()
        self.cmd = p1.cmd

        # define input files to 'create_simulation_pdb':
        if self.num_of_proteins == '2':
            input_coor_name = 'both_1_2'
        else:
            input_coor_name = '_1_'

        try:
            # run OpenMM:
            input_coor_name = self.temp + input_coor_name + pdb
            fix_pdb(input_coor_name)
            scr(input_coor_name, self.temperature, self.time_step_number,
                self.user_rand)

            # save the DCD file using PyMOL
            self.cmd.reinitialize()
            sleep(0.5)
            self.cmd.load(input_coor_name)
            self.cmd.load_traj(self.temp + 'trajectory.dcd')

        except Exception as e:  # mainly for "pymol.CmdException"
            print(str(e))
            update_simulation_status(
                'An error occurred while creating the simulation. Please try again later.',
                self.user_rand)
            return

        try:
            # create the animations:
            update_simulation_status('Creates the animations', self.user_rand)
            create_movies_from_different_angles(
                self.cmd, self.user_rand, input_coor_name, self.temp +
                'trajectory.dcd')  # create movies in media/movies folder
        except Exception as e:  # mainly for "pymol.CmdException"
            print(str(e))
            update_simulation_status(
                'An error occurred while creating the animations. Please try again later.',
                self.user_rand)
            return

        # complete simulation:
        update_simulation_status('Done!', self.user_rand)
コード例 #25
0
 def make_pse(self,
              filename: str = 'combo.pse',
              extra_mols: Optional[Chem.Mol] = None):
     """
     Save a pse in the relevant folder. This is the Victor one.
     """
     assert '.pse' in filename, f'{filename} not .pse file'
     if extra_mols is None:
         extra_mols = []
     # ------------------------
     import pymol2
     with pymol2.PyMOL() as pymol:
         for hit in self.hits:
             hit_name = hit.GetProp('_Name')
             pymol.cmd.read_molstr(Chem.MolToMolBlock(hit), hit_name)
             if self.monster is None:
                 pymol.cmd.color('grey50', f'element C and {hit_name}')
             elif hit_name in self.monster.unmatched:
                 pymol.cmd.color('black', f'element C and {hit_name}')
             else:
                 pymol.cmd.color('white', f'element C and {hit_name}')
         if self.monster is not None and self.monster.positioned_mol is not None:
             pymol.cmd.read_molstr(
                 Chem.MolToMolBlock(self.monster.positioned_mol), 'placed')
             pymol.cmd.color('magenta', f'element C and placed')
             pymol.cmd.zoom('byres (placed expand 4)')
             pymol.cmd.show('line', 'byres (placed around 4)')
         if self.minimised_mol is not None:
             pymol.cmd.read_molstr(Chem.MolToMolBlock(self.minimised_mol),
                                   'minimised')
             pymol.cmd.color('green', f'element C and minimised')
         if self.minimised_pdbblock is not None:
             pymol.cmd.read_pdbstr(self.minimised_pdbblock, 'min_protein')
             pymol.cmd.color('gray50', f'element C and min_protein')
             pymol.cmd.hide('sticks', 'min_protein')
         if self.unminimised_pdbblock is not None:
             pymol.cmd.read_pdbstr(self.unminimised_pdbblock,
                                   'unmin_protein')
             pymol.cmd.color('gray20', f'element C and unmin_protein')
             pymol.cmd.hide('sticks', 'unmin_protein')
             pymol.cmd.disable('unmin_protein')
         for mol in extra_mols:
             name = mol.GetProp('_Name')
             pymol.cmd.read_molstr(Chem.MolToMolBlock(mol, kekulize=False),
                                   name)
             pymol.cmd.color('magenta', f'{name} and name C*')
         pymol.cmd.save(
             os.path.join(self.work_path, self.long_name, filename))
コード例 #26
0
def pdb_and_dcd_match(pdb_file_name, dcd_file_name, user_rand):
    # pymol.finish_launching(['pymol', '-q'])  # pymol: -q quiet launch, -c no gui, -e fullscreen
    # cmd = pymol.cmd
    p1 = pymol2.PyMOL()
    p1.start()
    cmd = p1.cmd

    try:
        cmd.reinitialize()
        sleep(0.5)
        cmd.load(temp + user_rand + '/' + pdb_file_name)
        cmd.load_traj(temp + user_rand + '/' + dcd_file_name)
        return True
    except Exception as e:
        print(str(e))
        return False
コード例 #27
0
 def dehydrate_block(self,
                     block: str,
                     water: bool = False,
                     ligand: bool = False):
     """
     **PyMOL session**: self-contained.
     """
     with pymol2.PyMOL() as self.pymol:
         self.pymol.cmd.read_pdbstr(block, 'blockprotein')
         if water:
             self.pymol.cmd.remove('solvent')
         if ligand:
             self.pymol.cmd.remove(' or '.join(
                 [f'resn {l}' for l in self.boring_ligand]))
         self.raw_pdb = self.pymol.cmd.get_pdbstr()
     return self
コード例 #28
0
ファイル: result_table.py プロジェクト: asarnow/whatsmyblob
def render_mrc_pdb_overlays(mrc_filename: str = None,
                            result_folder: str = 'test_folder') -> None:
    if mrc_filename is None:
        mrc_filename = glob.glob(os.path.join(result_folder, '*.mrc'))[0]
    filename_density = os.path.join(result_folder, mrc_filename)
    pymol = pymol2.PyMOL()
    pymol.start()
    for pdb_filename in glob.glob(os.path.join(result_folder, '*.pdb')):
        root_file, _ = os.path.splitext(pdb_filename)
        pymol.cmd.do('reinitialize')
        pymol.cmd.do('bg_color white')
        pymol.cmd.do('hide all')
        pymol.cmd.do('show cartoon')
        pymol.cmd.do('load %s' % filename_density)
        pymol.cmd.do('load %s' % pdb_filename)
        pymol.cmd.do("matrix_copy %s, %s" % (pdb_filename, filename_density))
        pymol.cmd.do('png %s' % root_file + ".png")
コード例 #29
0
    def prepare_template(self) -> PDBBlocks:
        """
        Part of instatiation for ``self.template``.

        :return: a PDBBlocks namedtuple (all, no_ligand, only_ligand).
        """
        with pymol2.PyMOL() as pymol:
            if len(self.code) == 4:
                pymol.cmd.fetch(self.code)
            elif '.pdb' in self.code:  # file.
                pymol.cmd.load(self.code)
            else:
                raise ValueError
            pymol.cmd.remove('solvent')
            pymol.cmd.h_add('*')
            pymol.cmd.alter('all', 'segi=""')
            pymol.cmd.sort()
            return self.fill_PDBBlocks(pymol, self.ref_resn)
コード例 #30
0
    def __init__(self,
                 parent,
                 enableUi=True,
                 File="",
                 play=False,
                 sequence=False):
        #enableUi=True
        f = QGLFormat()
        f.setStencil(True)
        f.setRgba(True)
        f.setDepth(True)
        f.setDoubleBuffer(True)
        self.play = play
        self.nFrames = 0
        QGLWidget.__init__(self, f, parent=parent)
        self.setMinimumSize(200, 150)
        self._enableUi = enableUi
        self.pymol = pymol2.PyMOL()  # _pymolPool.getInstance()
        self.pymol.start()
        self.cmd = self.pymol.cmd
        self.toPymolName = self.pymol.toPymolName  ### Attribute Error
        self._pymolProcess()

        if not self._enableUi:
            self.pymol.cmd.set("internal_gui", 0)
            self.pymol.cmd.set("internal_feedback", 1)
            self.pymol.cmd.button("double_left", "None", "None")
            self.pymol.cmd.button("single_right", "None", "None")

        self.pymol.cmd.set("internal_gui_mode", "0")
        self.pymol.cmd.set("internal_feedback", "0")
        if sequence:
            self.pymol.cmd.set("seq_view", "1")
        if File is not "":
            self.nFrames += 1
            self.pymol.cmd.load(File, 'p', self.nFrames)

        self.pymol.reshape(self.width(), self.height())
        self._timer = QtCore.QTimer()
        self._timer.setSingleShot(True)
        self._timer.timeout.connect(self._pymolProcess)
        self.resizeGL(self.width(), self.height())
        #globalSettings.settingsChanged.connect(self._updateGlobalSettings)
        self._updateGlobalSettings()