Ejemplo n.º 1
0
def circularly_permute(pose, new_Nterm_pdb_res):
    
    lines_list = io.to_pdbstring(pose).split("\n")
    
    new_lines_list = []
    for line in lines_list:
        if line.startswith("ATOM"):
            pdb_res = int(line[22:26].split()[-1])
            if pdb_res >= new_Nterm_pdb_res:
                 new_lines_list.append(line)
    for line in lines_list:
        if line.startswith("ATOM"):
            pdb_res = int(line[22:26].split()[-1])
            if pdb_res < new_Nterm_pdb_res:
                 new_lines_list.append(line)
    for line in lines_list:
        if line.startswith("HETATM"):
            new_lines_list.append(line)
    
    out_pose = packed_pose.to_pose(io.pose_from_pdbstring("\n".join(new_lines_list)))
    
    # Renumber pdb
    for i, s in enumerate(out_pose.sequence(), start=1):
        if s == "Z":
            out_pose.pdb_info().set_resinfo(res=i, chain_id="B", pdb_res=i)
            out_pose.residue(i).chain(2)
        else:
            out_pose.pdb_info().set_resinfo(res=i, chain_id="A", pdb_res=i)
            out_pose.residue(i).chain(1)
    
    return out_pose
Ejemplo n.º 2
0
        def setUp(self, local_dir=workdir):

            if not os.path.isdir(local_dir):
                os.mkdir(local_dir)

            poses = [io.pose_from_sequence("TEST" * i) for i in range(1, 4)]
            for i, pose in enumerate(poses, start=1):
                with open(os.path.join(local_dir, "tmp_{0}.pdb".format(i)),
                          "w") as f:
                    f.write(io.to_pdbstring(pose))
Ejemplo n.º 3
0
        def view(i=0):

            _viewer = py3Dmol.view(*self.window_size)
            _pose = self.poses[i]
            _pdbstring = self.pdbstrings[i]

            if _pose:
                _viewer.addModels(io.to_pdbstring(_pose), "pdb")
            else:
                _viewer.addModels(_pdbstring, "pdb")
            _viewer.zoomTo()

            for module in self.modules:
                _viewer = module.apply(viewer=_viewer,
                                       pose=_pose,
                                       pdbstring=_pdbstring)

            self._clear_output()

            if _pose:
                _logger.debug("Decoy {0}: {1}".format(i,
                                                      _pose.pdb_info().name()))

            return _viewer.show()
Ejemplo n.º 4
0
def init(packed_and_poses_and_pdbs=None,
         window_size=None,
         modules=None,
         delay=None,
         continuous_update=None,
         *args,
         **kwargs):
    """
    Initialize the Viewer object.

    Parameters
    ----------
    first : required
        `packed_and_poses_and_pdbs`

        `PackedPose`, `Pose`, or `str` of a valid path to a .pdb file, or a `list`, `set`, or `tuple` of these objects.

    second : optional
        `window_size`

        `list` or `tuple` of `int` or `float` values for the (width, height) dimensions of the displayed window screen size.
        Default: (1200, 800)

    third : optional
        `modules`
        
        `list` of instantiated visualization modules to run upon changing amongst `packed_and_poses_and_pdbs` objects
        with the slider, matching the namespace pyrosetta.distributed.viewer.set*
        Default: []

    fourth : optional
        `delay`
        
        `float` time delay in seconds before rendering the Viewer in a Jupyter notebook, which is useful to prevent
        overburdening the Jupyter notebook client if `for` looping over quick modifications to a `Pose`.
        Default: 0.25

    fifth : optional
        `continuous_update`
        
        `True` or `False`. When using the interactive slider widget, `False` restricts rendering to mouse release events.
        Default: False

    Returns
    -------
    A Viewer instance.
    """

    _default_window_size = (1200, 800)
    _default_modules = []
    _default_delay = 0.25  # seconds
    _default_continuous_update = False

    @functools.singledispatch
    def to_pose(obj):
        raise ViewerInputError(obj)

    to_pose.register(type(None), lambda obj: None)
    to_pose.register(PackedPose, lambda obj: io.to_pose(obj))
    to_pose.register(Pose, lambda obj: obj)
    to_pose.register(str, lambda obj: None)

    @functools.singledispatch
    def to_pdbstring(obj):
        raise ViewerInputError(obj)

    to_pdbstring.register(type(None))

    def _(obj):
        raise ViewerInputError(obj)

    to_pdbstring.register(PackedPose, lambda obj: io.to_pdbstring(obj))
    to_pdbstring.register(Pose, lambda obj: io.to_pdbstring(obj))

    @to_pdbstring.register(str)
    def _(obj):
        if not os.path.isfile(obj):
            raise ViewerInputError(obj)
        else:
            with open(obj, "r") as f:
                return f.read()

    if isinstance(packed_and_poses_and_pdbs, (list, set, tuple)):
        poses, pdbstrings = map(
            list,
            zip(*[(to_pose(p), to_pdbstring(p))
                  for p in packed_and_poses_and_pdbs]))
    else:
        poses = [to_pose(packed_and_poses_and_pdbs)]
        pdbstrings = [to_pdbstring(packed_and_poses_and_pdbs)]

    @functools.singledispatch
    def to_window_size(obj):
        _logger.warning(
            "Input argument 'window_size' cannot be parsed. Setting 'window_size' to default."
        )
        return _default_window_size

    to_window_size.register(type(None), lambda obj: _default_window_size)

    @to_window_size.register(tuple)
    @to_window_size.register(list)
    def _(obj):
        assert len(
            obj
        ) == 2, "Input argument 'window_size' must be a list or tuple of length 2."
        return obj

    window_size = to_window_size(window_size)

    if not modules:
        modules = _default_modules
    assert isinstance(
        modules,
        list), "Input argument 'modules' should be an instance of list."

    @functools.singledispatch
    def to_delay(obj):
        _logger.warning(
            "Input argument 'delay' should be an instance of float. Setting 'delay' to default."
        )
        return _default_delay

    to_delay.register(type(None), lambda obj: _default_delay)
    to_delay.register(int, lambda obj: float(obj))

    @to_delay.register(str)
    def _(obj):
        try:
            _delay = float(obj)
        except ValueError:
            _logger.warning(
                "Input argument 'delay' cannot be parsed. Setting 'delay' to default."
            )
            _delay = _default_delay
        return _delay

    delay = to_delay(delay)

    if not continuous_update:
        continuous_update = _default_continuous_update
    assert type(
        continuous_update
    ) == bool, "Input argument 'continuous_update' must be boolean."

    return Viewer(poses=poses,
                  pdbstrings=pdbstrings,
                  window_size=window_size,
                  modules=modules,
                  delay=delay,
                  continuous_update=continuous_update,
                  *args,
                  **kwargs)
Ejemplo n.º 5
0
def main():

    notebook_flags = """
    -out:level 300 
    -ignore_unrecognized_res 1
    -ex2 1
    -ex1aro 1
    -extra_res_fa HBI.fa.params
    -extra_res_cen HBI.cen.params
    """
    pyrosetta.distributed.dask.init_notebook(notebook_flags)

    new_Nterm_pdb_res = [35, 63, 89, 106]

    for pdb in ["mFAP2a", "mFAP2b"]:

        pose = pyrosetta.io.pose_from_file(os.path.join("pdbs/mFAP_pdbs", f"{pdb}.pdb"))

        for new_Nterm in new_Nterm_pdb_res:
            
            tmp_pose = pose.clone()
            out_pose = circularly_permute(tmp_pose, new_Nterm)
            
            scorefxn = pyrosetta.create_score_function("ref2015")
            
            Nterminus_selector = pyrosetta.rosetta.core.select.residue_selector.ResidueIndexSelector("1A-2A")
            Cterminus_selector = pyrosetta.rosetta.core.select.residue_selector.ResidueIndexSelector("114A-115A")
            termini_selector = pyrosetta.rosetta.core.select.residue_selector.OrResidueSelector(Nterminus_selector, Cterminus_selector)
            not_termini_selector = pyrosetta.rosetta.core.select.residue_selector.NotResidueSelector(termini_selector)
            tf = pyrosetta.rosetta.core.pack.task.TaskFactory()
            tf.push_back(pyrosetta.rosetta.core.pack.task.operation.InitializeFromCommandline())
            tf.push_back(pyrosetta.rosetta.core.pack.task.operation.IncludeCurrent())
            tf.push_back(pyrosetta.rosetta.core.pack.task.operation.NoRepackDisulfides())
            tf.push_back(pyrosetta.rosetta.core.pack.task.operation.OperateOnResidueSubset(
                pyrosetta.rosetta.core.pack.task.operation.PreventRepackingRLT(), not_termini_selector))
            mmf = pyrosetta.rosetta.core.select.movemap.MoveMapFactory()
            mmf.all_bb(setting=False)
            mmf.all_bondangles(setting=False)
            mmf.all_bondlengths(setting=False)
            mmf.all_chi(setting=False)
            mmf.all_jumps(setting=False)
            mmf.set_cartesian(setting=False)
            enable = pyrosetta.rosetta.core.select.movemap.move_map_action.mm_enable
            mmf.add_chi_action(action=enable, selector=termini_selector)
            mmf.add_bb_action(action=enable, selector=termini_selector)
            fast_relax = pyrosetta.rosetta.protocols.relax.FastRelax(scorefxn_in=scorefxn, standard_repeats=1)
            fast_relax.cartesian(False)
            fast_relax.set_task_factory(tf)
            fast_relax.set_movemap_factory(mmf)
            fast_relax.minimize_bond_angles(False)
            fast_relax.minimize_bond_lengths(False)
            fast_relax.min_type("dfpmin_armijo_nonmonotone")
            fast_relax.apply(out_pose)
            
            outdir = "circularly_permuted_relaxed_pdbs"
            if not os.path.isdir(outdir):
                os.mkdir(outdir)
            new_name = "cp" + str(new_Nterm) + "-" + str(new_Nterm - 1) + f"_{pdb}.pdb"
            
            # Output pose with a TER line at cutpoint
            cutpoint = int(re.search("SRAAQLLPGTWQ", out_pose.sequence()).start() + 1)
            lines_list = io.to_pdbstring(out_pose).split("\n")
            cont = True
            new_lines_list = []
            for line in lines_list:
                if line.startswith("ATOM") or line.startswith("HETATM"):
                    pdb_res = int(line[22:26].split()[-1])
                    if (pdb_res == cutpoint) and cont:
                        new_lines_list.append("TER")
                        cont = False
                    new_lines_list.append(line)
                elif line.startswith("TER"):
                    new_lines_list.append(line)
            with open(os.path.join(outdir, new_name), "w") as f:
                f.write("\n".join(new_lines_list))