You are here

Adding a residue type to a residue type set

3 posts / 0 new
Last post
Adding a residue type to a residue type set
#1

I would like to load a residue type from a string of a params file and not a filename.

I can generate a mutable residue type, but get stuck there:

pose = pyrosetta.rosetta.core.pose.Pose()
rts = pose.residue_type_set_for_pose()

# topo : str akin to doing topo = open('XXX.params').read()
buffer = pyrosetta.rosetta.std.stringbuf(topo)
stream = pyrosetta.rosetta.std.istream(buffer)
new = pyrosetta.rosetta.core.chemical.read_topology_file(stream, 'XXX', rts) # no idea what the second argument does

The `new` residue type is not included in rts as proven by `rts.name_map( 'XXX' )` and that is where I go stuck.

I cannot seem to add the new residue type to an residue type set. These appear to be frozen sets, with no add, append, extend, push etc. `pyrosetta.rosetta.core.chemical.ResidueTypeSetCache` seems promising, but it is unclear to me how to make that a `ResidueTypeSet` from it that can be fed into pose.

The `new` residue type is a `pyrosetta.rosetta.core.chemical.MutableResidueType` and not a `pyrosetta.rosetta.core.chemical.ResidueType`. The former does not inherit the latter —how does one convert the latter to the former?

This is obviously a minor problem as I current write to the params string to disk, read it and delete it. But I have stumbled across this issue three times —the testing method in my RDKit to Params module, in an internal webserver (with uploaded params) and in a high throughput fragment screen module— so as it seems like something simple I thought I'd best ask! Thanks!

Category: 
Post Situation: 
Wed, 2020-07-08 08:14
matteoferla

The global residue type set is considered to be fixed. Modifying it has various consistency and thread safety implications. If you want to add a new ResidueType to a global residue type set, you need to do that through command line parameters.

Instead, if you want to use an on-the-fly generated residue type, you need to add it to the PoseResidueTypeSet for the particular pose you're using it with. There's some convenience functions in (I believe) the pyrosetta.toolbox.load_ligand  module. In particular, you can take a look at the implementation of pose_from_params() on how it's accomplished.

Basically, you can create a blank pose (or use an existing one) grab the PoseResidueTypeSet for that pose from the modifiable_residue_type_set_for_conf() function on its conformation(), add your new ResidueType to that ResidueTypeSet (the ResidueType addition functions should take a MutableResidueType), then call reset_residue_type_set_for_conf() with the modified residue type set. (Note that changing the ResidueTypeSet returned by modifiable_residue_type_set_for_conf() doesn't actually change what the Pose sees - you need to explicitly set a new one.)

You can then use that Pose and the code will (hopefully) grab the ResidueType from the Pose's ResidueTypeSet. (e.g. if you want to load a PDB from file, just pass in the Pose with the modified ResidueTypeSet to the PDB loading functions which take a Pose parameter, and it should use the ResidueTypeSet attached to the Pose.)

Thu, 2020-07-09 08:20
rmoretti

Great. `modifiable_residue_type_set_for_conf` was exactly was I was after! Now I can add params as strings ("paramsblock", below) without writing a single temp file!

import pyrosetta, nglview
pyrosetta.init(extra_options='-no_optH false -mute all -load_PDB_components false')

paramsblock = '''bla bla'''

pose = pyrosetta.Pose()
# add paramsblock
rts = pose.conformation().modifiable_residue_type_set_for_conf(pyrosetta.rosetta.core.chemical.FULL_ATOM_t)
buffer = pyrosetta.rosetta.std.stringbuf(paramsblock)
stream = pyrosetta.rosetta.std.istream(buffer)
new = pyrosetta.rosetta.core.chemical.read_topology_file(stream, 'LIG', rts) # no idea what the second argument 
rts.add_base_residue_type(new)
# add new residue
lig = pyrosetta.rosetta.core.conformation.ResidueFactory.create_residue( rts.name_map( 'LIG' ) )
pose.append_residue_by_jump(lig, 1)
# have a gander
nglview.show_rosetta(pose)
# Bingo!

Thanks!

Fri, 2020-07-10 02:20
matteoferla