在最早期,Rosetta的mover、filter等都没有为python api流程参数控制的接口,导致部分的组件无法直接调用,只能通过xml脚本读取参数,然后生成对应的对象。
XmlObjects是在PyRosetta中直接使用xml脚本最直接的方法,特别是某些Mover没有做好Pyrosetta接口时特别有用。但是缺点是加载XmlObjects的速度并不理想,比纯粹的PyRosetta脚本启动要慢。
从字符串文本中提取信息,返回XmlObjects
from pyrosetta.rosetta.protocols import rosetta_scripts
from pyrosetta import init
# 初始化脚本:
init()
xml = rosetta_scripts.XmlObjects.create_from_string('''
<SCOREFXNS>
<ScoreFunction name="sfxn1" weights="ref2015"/>
</SCOREFXNS>
<RESIDUE_SELECTORS>
</RESIDUE_SELECTORS>
<TASKOPERATIONS>
</TASKOPERATIONS>
<FILTERS>
</FILTERS>
<MOVERS>
<SetTorsion name="setTorsion">
<Torsion residue="1,2,3,4,5" torsion_name="rama" angle="perturb" perturbation_type="gaussian" perturbation_magnitude="1.0" />
</SetTorsion>
</MOVERS>
<APPLY_TO_POSE>
</APPLY_TO_POSE>
<PROTOCOLS>
</PROTOCOLS>
<OUTPUT />
''')
PyRosetta-4 2021 [Rosetta PyRosetta4.conda.mac.cxx11thread.serialization.python37.Release 2021.26+release.b308454c455dd04f6824cc8b23e54bbb9be2cdd7 2021-07-02T13:01:54] retrieved from: http://www.pyrosetta.org
(C) Copyright Rosetta Commons Member Institutions. Created in JHU by Sergey Lyskov and PyRosetta Team.
core.init: {0} Checking for fconfig files in pwd and ./rosetta/flags
core.init: {0} Rosetta version: PyRosetta4.conda.mac.cxx11thread.serialization.python37.Release r288 2021.26+release.b308454c455 b308454c455dd04f6824cc8b23e54bbb9be2cdd7 http://www.pyrosetta.org 2021-07-02T13:01:54
core.init: {0} command: PyRosetta -ex1 -ex2aro -database /opt/miniconda3/lib/python3.7/site-packages/pyrosetta/database
basic.random.init_random_generator: {0} 'RNG device' seed mode, using '/dev/urandom', seed=-2025690693 seed_offset=0 real_seed=-2025690693 thread_index=0
basic.random.init_random_generator: {0} RandomGenerator:init: Normal mode, seed=-2025690693 RG_type=mt19937
protocols.rosetta_scripts.RosettaScriptsParser: {0} Generating XML Schema for rosetta_scripts...
protocols.rosetta_scripts.RosettaScriptsParser: {0} ...done
protocols.rosetta_scripts.RosettaScriptsParser: {0} Initializing schema validator...
protocols.rosetta_scripts.RosettaScriptsParser: {0} ...done
protocols.rosetta_scripts.RosettaScriptsParser: {0} Validating input script...
protocols.rosetta_scripts.RosettaScriptsParser: {0} ...done
protocols.rosetta_scripts.RosettaScriptsParser: {0} Parsed script:
<ROSETTASCRIPTS>
<SCOREFXNS>
<ScoreFunction name="sfxn1" weights="ref2015"/>
</SCOREFXNS>
<RESIDUE_SELECTORS/>
<TASKOPERATIONS/>
<FILTERS/>
<MOVERS>
<SetTorsion name="setTorsion">
<Torsion angle="perturb" perturbation_magnitude="1.0" perturbation_type="gaussian" residue="1,2,3,4,5" torsion_name="rama"/>
</SetTorsion>
</MOVERS>
<APPLY_TO_POSE/>
<PROTOCOLS/>
<OUTPUT/>
</ROSETTASCRIPTS>
core.scoring.ScoreFunctionFactory: {0} SCOREFUNCTION: ref2015
core.scoring.etable: {0} Starting energy table calculation
core.scoring.etable: {0} smooth_etable: changing atr/rep split to bottom of energy well
core.scoring.etable: {0} smooth_etable: spline smoothing lj etables (maxdis = 6)
core.scoring.etable: {0} smooth_etable: spline smoothing solvation etables (max_dis = 6)
core.scoring.etable: {0} Finished calculating energy tables.
basic.io.database: {0} Database file opened: scoring/score_functions/hbonds/ref2015_params/HBPoly1D.csv
basic.io.database: {0} Database file opened: scoring/score_functions/hbonds/ref2015_params/HBFadeIntervals.csv
basic.io.database: {0} Database file opened: scoring/score_functions/hbonds/ref2015_params/HBEval.csv
basic.io.database: {0} Database file opened: scoring/score_functions/hbonds/ref2015_params/DonStrength.csv
basic.io.database: {0} Database file opened: scoring/score_functions/hbonds/ref2015_params/AccStrength.csv
core.chemical.GlobalResidueTypeSet: {0} Finished initializing fa_standard residue type set. Created 984 residue types
core.chemical.GlobalResidueTypeSet: {0} Total time to initialize 0.682139 seconds.
basic.io.database: {0} Database file opened: scoring/score_functions/rama/fd/all.ramaProb
basic.io.database: {0} Database file opened: scoring/score_functions/rama/fd/prepro.ramaProb
basic.io.database: {0} Database file opened: scoring/score_functions/omega/omega_ppdep.all.txt
basic.io.database: {0} Database file opened: scoring/score_functions/omega/omega_ppdep.gly.txt
basic.io.database: {0} Database file opened: scoring/score_functions/omega/omega_ppdep.pro.txt
basic.io.database: {0} Database file opened: scoring/score_functions/omega/omega_ppdep.valile.txt
basic.io.database: {0} Database file opened: scoring/score_functions/P_AA_pp/P_AA
basic.io.database: {0} Database file opened: scoring/score_functions/P_AA_pp/P_AA_n
core.scoring.P_AA: {0} shapovalov_lib::shap_p_aa_pp_smooth_level of 1( aka low_smooth ) got activated.
basic.io.database: {0} Database file opened: scoring/score_functions/P_AA_pp/shapovalov/10deg/kappa131/a20.prop
core.scoring.etable: {0} Starting energy table calculation
core.scoring.etable: {0} smooth_etable: changing atr/rep split to bottom of energy well
core.scoring.etable: {0} smooth_etable: spline smoothing lj etables (maxdis = 6)
core.scoring.etable: {0} smooth_etable: spline smoothing solvation etables (max_dis = 6)
core.scoring.etable: {0} Finished calculating energy tables.
basic.io.database: {0} Database file opened: scoring/score_functions/PairEPotential/pdb_pair_stats_fine
basic.io.database: {0} Database file opened: scoring/score_functions/InterchainPotential/interchain_env_log.txt
basic.io.database: {0} Database file opened: scoring/score_functions/InterchainPotential/interchain_pair_log.txt
basic.io.database: {0} Database file opened: scoring/score_functions/EnvPairPotential/env_log.txt
basic.io.database: {0} Database file opened: scoring/score_functions/EnvPairPotential/cbeta_den.txt
basic.io.database: {0} Database file opened: scoring/score_functions/EnvPairPotential/pair_log.txt
basic.io.database: {0} Database file opened: scoring/score_functions/EnvPairPotential/cenpack_log.txt
core.scoring.ramachandran: {0} shapovalov_lib::shap_rama_smooth_level of 4( aka highest_smooth ) got activated.
basic.io.database: {0} Database file opened: scoring/score_functions/rama/shapovalov/kappa25/all.ramaProb
basic.io.database: {0} Database file opened: scoring/score_functions/rama/flat/avg_L_rama.dat
core.scoring.ramachandran: {0} Reading custom Ramachandran table from scoring/score_functions/rama/flat/avg_L_rama.dat.
basic.io.database: {0} Database file opened: scoring/score_functions/rama/flat/sym_all_rama.dat
core.scoring.ramachandran: {0} Reading custom Ramachandran table from scoring/score_functions/rama/flat/sym_all_rama.dat.
basic.io.database: {0} Database file opened: scoring/score_functions/rama/flat/sym_G_rama.dat
core.scoring.ramachandran: {0} Reading custom Ramachandran table from scoring/score_functions/rama/flat/sym_G_rama.dat.
basic.io.database: {0} Database file opened: scoring/score_functions/rama/flat/sym_P_rama.dat
core.scoring.ramachandran: {0} Reading custom Ramachandran table from scoring/score_functions/rama/flat/sym_P_rama.dat.
basic.io.database: {0} Database file opened: scoring/score_functions/rama/flat/avg_L_rama_str.dat
core.scoring.ramachandran: {0} Reading custom Ramachandran table from scoring/score_functions/rama/flat/avg_L_rama_str.dat.
basic.io.database: {0} Database file opened: scoring/score_functions/rama/flat/sym_all_rama_str.dat
core.scoring.ramachandran: {0} Reading custom Ramachandran table from scoring/score_functions/rama/flat/sym_all_rama_str.dat.
basic.io.database: {0} Database file opened: scoring/score_functions/rama/flat/sym_G_rama_str.dat
core.scoring.ramachandran: {0} Reading custom Ramachandran table from scoring/score_functions/rama/flat/sym_G_rama_str.dat.
basic.io.database: {0} Database file opened: scoring/score_functions/rama/flat/sym_P_rama_str.dat
core.scoring.ramachandran: {0} Reading custom Ramachandran table from scoring/score_functions/rama/flat/sym_P_rama_str.dat.
protocols.jd2.parser.ScoreFunctionLoader: {0} defined score function "sfxn1" with weights "ref2015"
protocols.rosetta_scripts.RosettaScriptsParser: {0} Defined mover named "setTorsion" of type SetTorsion
protocols.rosetta_scripts.ParsedProtocol: {0} ParsedProtocol mover with the following settings
提取Filter、Mover、Selector、SimpleMetric、TaskOperation的语法语句
# get a mover:
mover_ = xml.get_mover("setTorsion")
mover_
# 如此类推:
# filter_ = xml.get_filter(name)
# selector_ = xml.get_residue_selector(name)
# score_ = xml.get_score_function(name)
# sm_ = xml.get_simple_metric(name)
# tf_ = xml.get_task_operation(name)
<pyrosetta.rosetta.protocols.simple_moves.SetTorsion at 0x7fc5f0380bf0>
#列表式所选内容。
xml.list_movers()
# 如此类推:
# xml.list_filters()
# xml.list_residue_selectors()
# xml.list_score_functions()
# xml.list_simple_metrics()
# xml.list_task_operations()
vector1_std_string[ParsedProtocol, null, setTorsion]
从字符串文本中提取信息,返回XmlObjects
from pyrosetta.rosetta.protocols import rosetta_scripts
xml = rosetta_scripts.XmlObjects.create_from_file('./data/Example2-MinMover.xml')
protocols.rosetta_scripts.RosettaScriptsParser: {0} Generating XML Schema for rosetta_scripts...
protocols.rosetta_scripts.RosettaScriptsParser: {0} ...done
protocols.rosetta_scripts.RosettaScriptsParser: {0} Initializing schema validator...
protocols.rosetta_scripts.RosettaScriptsParser: {0} ...done
protocols.rosetta_scripts.RosettaScriptsParser: {0} Validating input script...
protocols.rosetta_scripts.RosettaScriptsParser: {0} ...done
protocols.rosetta_scripts.RosettaScriptsParser: {0} Parsed script:
<ROSETTASCRIPTS>
<SCOREFXNS>
<ScoreFunction name="molmech" weights="mm_std_fa_elec_dslf_fa13"/>
<ScoreFunction name="r15_cart" weights="ref2015">
<Reweight scoretype="pro_close" weight="0.0"/>
<Reweight scoretype="cart_bonded" weight="0.625"/>
</ScoreFunction>
</SCOREFXNS>
<RESIDUE_SELECTORS/>
<TASKOPERATIONS/>
<FILTERS/>
<MOVERS>
<MinMover bb="1" cartesian="F" chi="true" name="min_torsion" scorefxn="molmech"/>
<MinMover bb="1" cartesian="T" chi="true" name="min_cart" scorefxn="r15_cart"/>
</MOVERS>
<APPLY_TO_POSE/>
<PROTOCOLS>
<Add mover="min_cart"/>
</PROTOCOLS>
<OUTPUT scorefxn="r15_cart"/>
</ROSETTASCRIPTS>
core.scoring.ScoreFunctionFactory: {0} SCOREFUNCTION: ref2015
core.mm.MMLJLibrary: {0} MM lj sets added: 105
core.mm.MMTorsionLibrary: {0} MM torsion sets added fully assigned: 1039; wildcard: 48 and 1 virtual parameter.
protocols.jd2.parser.ScoreFunctionLoader: {0} defined score function "molmech" with weights "mm_std_fa_elec_dslf_fa13"
protocols.jd2.parser.ScoreFunctionLoader: {0} defined score function "r15_cart" with weights "ref2015"
protocols.jd2.parser.ScoreFunctionLoader: {0} setting r15_cart weight pro_close to 0
protocols.jd2.parser.ScoreFunctionLoader: {0} setting r15_cart weight cart_bonded to 0.625
core.energy_methods.CartesianBondedEnergy: {0} Initializing IdealParametersDatabase with default Ks=300 , 80 , 80 , 10 , 80
basic.io.database: {0} Database file opened: scoring/score_functions/bondlength_bondangle/default-lengths.txt
core.energy_methods.CartesianBondedEnergy: {0} Read 759 bb-independent lengths.
basic.io.database: {0} Database file opened: scoring/score_functions/bondlength_bondangle/default-angles.txt
core.energy_methods.CartesianBondedEnergy: {0} Read 1434 bb-independent angles.
basic.io.database: {0} Database file opened: scoring/score_functions/bondlength_bondangle/default-torsions.txt
core.energy_methods.CartesianBondedEnergy: {0} Read 1 bb-independent torsions.
basic.io.database: {0} Database file opened: scoring/score_functions/bondlength_bondangle/default-improper.txt
core.energy_methods.CartesianBondedEnergy: {0} Read 529 bb-independent improper tors.
protocols.minimization_packing.MinMover: {0} Options chi, bb: 1, 1 omega: 1
protocols.rosetta_scripts.RosettaScriptsParser: {0} Defined mover named "min_torsion" of type MinMover
protocols.minimization_packing.MinMover: {0} Options chi, bb: 1, 1 omega: 1
protocols.rosetta_scripts.RosettaScriptsParser: {0} Defined mover named "min_cart" of type MinMover
protocols.rosetta_scripts.ParsedProtocol: {0} ParsedProtocol mover with the following settings
protocols.rosetta_scripts.ParsedProtocol: {0} Added mover "min_cart"
详见: https://new.rosettacommons.org/docs/latest/scripting_documentation/RosettaScripts/RosettaScripts
RosettaScript大而全,Python API灵活速度快!