Package: pyrosetta-help
pyrosetta helper functionsSome functions that I keep using over and over as a Python module.Installationpip3installpyrosetta-helpColabsHere are some Colabs notebooks I have put together for AlphaFold2 analyses:Run PyRosetta in ColabAnalysis of dimer output from ColabFold in ColabMigrate a ligand in ColabAdd missing loops by cannibilising AlphaFold2Stretch out an alphafold pose — ToDoAdd OPM dots to show membrane — ToDoCleaner Pip install for pyrosettaWhereas one can create a conda environment easy fully loaded with fun, e.g.CONDA_OVERRIDE_GLIBC=2.35condacreate-n👾👾👾python=3.8-y\-cconda-forge\-chttps://👾👾👾:👾👾👾@west.rosettacommons.org/pyrosetta/conda/release/\-cschrodinger\-cplotly\pyrosettapymol-bundlerdkitplotlydaskWere the alien emoji are redacting the username and password.Installing withpipis more problematic. As of Febuary 2022 either of the following fail because the authentication on
the 302 redirect causes issue:pipinstallhttps://👾👾👾:👾👾👾@https://graylab.jhu.edu/download/PyRosetta4/archive/release/
pipinstallhttps://👾👾👾:👾👾👾@https://graylab.jhu.edu/download/PyRosetta4/archive/release/PyRosetta4.Release.python39.mac.wheel/latest.htmlAs a resultpyrosetta_helphas two functions,install_pyrosettaandcheck_pyrosetta,
which aim to help this. Thesetup.pyalso registers a command (install_pyrosetta) to make it possible too.pipinstallpyrosetta-help
install_pyrosetta-u👾👾👾-p👾👾👾In Python, the modulepyrosetta_helpneeds to be reloaded afterwards.importpyrosetta_helpasph# this will give a warning because there's no pyrosettaprint(ph.check_pyrosetta())# False, there is no pyrosettaph.install_pyrosetta('👾👾👾','👾👾👾')fromimportlibimportreloadreload(ph)No plain text username+password combinations are stored in this repository.
But the inputted values are SHA256-hashed and compared to a hash of the correct Rosetta and PyRosetta credentials.
If the former are used a clear error message will be shown as Rosetta has a different set of credentials.Hit: The pyrosetta username and password are in the format likeboltzmann+constant, notSomeThingUser+qwerty.(This will however not stop people from asking, ae)If the credentials are incorrect an error is raised, unlesshash_comparison_required=False.install_pyrosetta(username=username,password=password,path=None,hash_comparison_required=True)In the case of a ReadTheDocs confuguration, addingpyrosetta_helpto therequirements.txtfile and
then adding inbuildsof the.readthedocs.ymlfile the following:builds:...jobs:post_install:-install_pyrosettaAnd then adding in advanced options the private environment variablesPYROSETTA_USERNAMEandPYROSETTA_PASSWORD,
will result in a sucessful build.Starting upA few helper functions.get_logger, get_log_entriesThe functionconfigure_logger, simply adds a stringIO handler to the log and captures the log.
The functionget_log_entries, spits out entries of a given level.make_option_stringThis just converts the key:value pairs to a command line string for the pyrosetta init.Bools are converted,None results in a value argument,Tuples are converted to xx:xx type argumentsDictionaries are converted to xx:xx type arguments (multiple, if multiple keys in the nested dictionary)importpyrosettaimportpyrosetta_helpasph# capture to loglogger=ph.configure_logger()# give CLI attributes in a civilised waypyrosetta.distributed.maybe_init(extra_options=ph.make_option_string(no_optH=False,ex1=None,ex2=None,#mute='all',ignore_unrecognized_res=True,load_PDB_components=False,ignore_waters=False))# ...# show relevant errorprint(ph.get_log_entries('ERROR'))Common operationsImport a file, while dealing with the param filesimportpyrosetta_helpasphpose=ph.pose_from_file('combined.relaxed2.pdb',params_filenames=['35G.params','CMP.params','ATP.params','NME.params'])I have somewhere one that via rdkit_to_params starts with a dict of residue:SMILES. TODO find.Get pandas dataframe of scoreimportpyrosetta_helpasphscores=ph.pose2pandas(pose)scores.loc[scores.total_score>10][['residue','total_score']]Convert a selector to a list of str of NGL selector style[resn]resi:chainimportpyrosetta_helpasphligand=pyrosetta.rosetta.core.chemical.ResidueProperty.LIGANDlig_sele=pyrosetta.rosetta.core.select.residue_selector.ResiduePropertySelector(ligand)ph.clarify_selector(lig_sele,pose)Local relax, etc.importpyrosetta_helpasphmap_filename:str=ph.download_map('1A2A')# cryoEM require EMD codesed=ph.prep_ED(pose,map_filename)local_scorefxn=ph.get_local_scorefxn()local_relax=ph.get_local_relax()local_relax.apply(pose)Note,ph.add_bfactor_from_scoreis unstable!score_mutantsGiven a list of mutants and pose, score them. scorefunction terms, interface, movement etc.importpyrosetta_helpasphmodel=ph.MutantScorer(pose,modelname='test')model.scorefxn=pyrosetta.create_score_function('ref2015')model.strict_about_starting_residue=Truedata=model.score_mutations(['p.Met1Gly','p.Ser29Glu'],chain='V',interfaces=(('isolated','V_ABCDEFGHIJKLMNOPQRSTWXYZ'),),#preminimize=True,distance=12,cycles=5)importpandasaspdscores=pd.DataFrame(data)ph.extend_scores(scores)The functionextend_scoresadds 6 columns, specifying which terms is the biggest changer.BlueprinterA key component of using Remodel is a blueprint.
This module makes a blueprint. See doc string of classBlueprinterinblueprint_makerfor more.frompyrosetta_helpimportBlueprinterblue=Blueprinter.from_pose(pose)blue[20:25]='NATAA'# wobbleblue.wobble_span(20,25)# same as above.delblue[15:20]# requires preceeding and suceeding residues to be NATAA though!blue.del_span(15,20)# same as above, but wobbles the preceeding and suceeding 1 residuesblue[22]='PIKAA W'# requires wobbleblue.mutate(22,'W')# same as above, but wobbles the preceeding and suceeding residuesTo set it:blue.set('mut.blu')This equivalent to the following (handy if something needs manual correction)blue.write('mut.blu')blue.bluprint='mut.blu'# which calls `pyrosetta.rosetta.basic.options.set_file_option('remodel:blueprint', 'mut.blu')`# so do not forget `mover.register_options()`!This can therefore be used as normal:pyrosetta.rosetta.basic.options.set_boolean_option('remodel:quick_and_dirty',True)pyrosetta.rosetta.basic.options.set_string_option('remodel:generic_aa','G')rm=pyrosetta.rosetta.protocols.forge.remodel.RemodelMover()rm.register_options()rm.dr_cycles(5)# default 3rm.max_linear_chainbreak(0.2)# default 0.07rm.redesign_loop_neighborhood(False)rm.apply(pose)WeightWatcherA class to easily look at the weights for the terms of different scorefunctions.
It has various functionalities.frompyrosetta_help.weightsimportWeightWatcherww=WeightWatcher()# List available scorefunctions:print(ww.possible_scorefxn_names)# dynamic attribute# Find a scorefunction that mentions a word:ww.find_metion('foo')# Get the comment block of a scorefunction:print(ww.get_scorefxn_comments('ref2015'))# Get a scorefunction by name by calling the appropriate options first.# NB. calling a different one will change the options.scorefxn=ww.get_scorefxn('beta_nov16')# Get weights dictionary (including ref) for a scorefunction or a name of oneweights=ww.get_weights('beta_nov16')# Get a pandas table of the weightsweight_table=ww.compare(['ref2015','beta_nov16'],different_only=True)It also has the class attributeterm_meanings,
which is a handy dictionary to convert a score term name into a description.
E.g. converts "fa_atr" -> "Lennard-Jones attractive between atoms
in different residues (r^6 term, London dispersion forces)." etc.
Taken from Rosetta documentations, with some edits on some terms.ChainOpsThis class works around a list of dict that contain details of each chain in an model. The key keys are:number (pose chain number)chain (PDB chain letter)gene_name (gene name)the instance can be subscripted with any of those three, returning the dict of that chain.from pyrosetta_help import ChainOpsTo get a single chain pose:chain_pose = chain_ops.get_pose_of_chain(pose, 'B')Transmogrifer/Murinizer deals with alignments between species.
The RosettaCM stuff is elsewhere. To do: MOVE OVERThe chain details started off by themselves, seemetadata_assembly notesOther snippetsThese could quickly be made into classes... but heyphoshosite plus to pyrosettadistance matrix of chainsLegal disclaimerI (Matteo Ferla) am not affiliated with PyRosetta or Rosetta Commons, I am just an avid user.
My usage does not constitute an endorsement of PyRosetta by the BRC, NIHR, Wellcome Trust, the University of Oxford,
the United Kingdom of Great Britain + Northern Ireland + all its dependencies etc. etc.