Rigid-body refinement against SAXS data¶
This tool allows you to perform custom rigid-body optimizations on your structures. Here we cover all of the arguments and settings available for the procedure, and also how to write your own configuration scripts.
Tip
The refinement can also be set up in the graphical interface, which writes the configuration script for you. Start it with:
pip install "pyausaxs[all]"
ausaxs gui
This is the recommended way to use the tool. To get started, see the rigid-body tutorial which walks through a complete refinement in the graphical interface.
Arguments¶
The optimization is fully described by a configuration script, which is the only required argument:
ausaxs rigidbody <configuration script>
The script must have one of the extensions .config, .conf, or .txt. The structure and SAXS data files are loaded by the script itself, through the load element.
The remaining command-line arguments follow the same group structure as the SAXS fitter, and can be listed with ausaxs rigidbody --help:
| Group | Arguments |
|---|---|
| base | --licence, -v/--version, --allow-unknown-atoms, --allow-unknown-residues, --offline, -t/--threads, -o/--output, --gpu/--no-gpu |
config |
-f/--file, --save, --log |
data |
--qmin, --qmax, -u/--unit, --skip, --rebin, --weighted-bins |
molecule |
--use-occupancy/--ignore-occupancy |
hydrogens |
--keep/--discard, --force-field-names |
grid |
-w/--width |
These work exactly as described for the SAXS fitter. Note that, unlike the fitter, a settings file is only used if it is given explicitly with config --file. Settings can also be changed from within the script with the settings element (see advanced elements).
Output¶
By default all output will be saved in the output/rigidbody/ folder. This location can be changed with the -o/--output argument, or with the output element of the script.
Only the files requested by the save elements of the script are written, so remember to save at least the final structure!
Configuration scripts¶
Due to the modular nature of our optimization algorithm, you can specify your very own custom routine. The rest of this page covers all options for this feature.
Syntax¶
A script consists of a sequence of elements, one per line. Everything after a # is a comment. Arguments can be given in one of two forms:
- Inline: written on the same line as the element, e.g.
seed 42. Values containing spaces must be quoted, e.g.print "Hello world". - Block: written over multiple lines, one named argument per line, enclosed in braces:
load { pdb data/structure.pdb saxs data/measurement.dat }
The two forms cannot be combined; an element takes its arguments either inline or in a block, never both. Unrecognised argument names and wrong argument counts are both rejected, with the error listing what the element accepts. Lists of values can be separated by either spaces or commas.
Scopes¶
A few elements (loop, optimize_once, on_improvement, and every) open a scope: a block of elements they control, which must be closed by an explicit end statement. Scopes can be nested in any way you like.
Example of scopes
loop 100
optimize_once
on_improvement
# this will be printed on every improvement
print "Iteration {iteration} accepted. New best chi2: {chi2_best}"
end
end
every 5
# save the current state every 5 iterations
save trajectory.xyz
end
loop 10
# this will run a total of 1000 times
end
end
Body names¶
Most elements refer to bodies by name. Bodies are given the default names b1, b2, ... in the order they are loaded, and can be given custom names through the load element or the rename element. The default name always remains valid, even after a body is renamed.
The copies generated by a symmetry are named after the body they belong to: b1s1 is the first symmetry of body b1, and b1s1r2 is the second copy (replica) generated by that symmetry. b1s1 is shorthand for b1s1r1. Use print {body_names} to list all available names.
Example configurations¶
A script typically consists of four parts:
- Load the structure through the
loadelement, and possibly split it into bodies. - Restrain the structure, either through manual
constrainelements or the automaticautoconstrain. - Specify how the structure is transformed: the
parameterselement generates the transformation parameters, while the optionalselectandtransformelements choose which body to transform, and how it is transformed. - Run the optimization with a
loopelement enclosing anoptimize_onceelement. Optionally, you can add someon_improvementandprintelements to get an insight into the optimization process.
Some examples are given below.
Single-chain structure optimization
output output/single_chain
load {
pdb data/structure.pdb
saxs data/measurement.dat
split 7 99 199 292
}
autoconstrain backbone
save initial_state.pdb
save trajectory.xyz
parameters {
iterations 1000
translate 10
rotate 0.5
}
print "Initial chi2: {chi2}"
loop
optimize_once
on_improvement
print {
message "{iteration}/{iterations_total}: Accepted with new chi2 {chi2}"
color green
}
save curve_%.fit
save trajectory.xyz
end
end
end
save final_state.pdb
p2 symmetry
load {
pdb data/monomer.pdb
saxs data/dimer.dat
}
symmetry p2
constrain {
first b1s1
second b1
type attract
distance 30
}
output output/symmetry
save initial_state.pdb
save trajectory.xyz
parameters {
iterations 1000
sym_translate 20
sym_rotate 1.5
}
loop
optimize_once
save full.xyz
on_improvement
print {
message "{iteration}/{iterations_total}: Accepted with new chi2 {chi2_no_penalty}"
color green
}
save trajectory.xyz
end
end
end
save final_state.pdb
Elements¶
The elements are grouped by how often you will need them. The essential elements are used by practically every script, the common elements shape most real optimizations, and the advanced elements cover more specialised needs.
Essential elements
| Element | Arguments | Description |
|---|---|---|
load |
pdb, saxs, split, names |
Load the structure and SAXS data files. |
output |
path, mode |
Set the folder all output is written to. |
parameters |
iterations, translate, rotate, translate_axes, rotate_axes, sym_translate, sym_rotate, decay |
Specify how the transformation parameters should be generated. |
loop |
name, N |
Loop over the elements in its scope N times, or copy an earlier loop. |
optimize_once |
Perform a single optimization step. Its scope contains the transformed structure. | |
end |
Mark the end of a scope. | |
save |
path |
Save various data from the current conformation. |
Common elements
| Element | Arguments | Description |
|---|---|---|
constrain |
first, second, type, iatom1, iatom2, distance |
Impose a new restraint on the structure. |
autoconstrain |
strategy |
Generate automatic constraints on the structure. |
symmetry |
bodies, symmetry |
Declare a structural symmetry. |
convert_to_symmetry |
bodies, type, tolerance |
Decompose bodies into a symmetry. |
select |
strategy or body, mask |
Specify how to select the bodies to transform. |
transform |
strategy |
Specify how to perform the transform. |
on_improvement |
Run the elements in its scope if a better conformation was found. | |
every |
N |
Run the elements in its scope once for every N iterations. |
print |
message, color |
Print a message to the terminal. |
update |
structure |
Publish the current structure to the GUI live preview. |
Advanced elements (documented in the collapsed section at the end)
| Element | Arguments | Description |
|---|---|---|
rename |
body, name |
Rename a body. |
copy |
body, name |
Duplicate a body. |
merge |
body, other bodies |
Merge a number of bodies. |
delete |
bodies |
Delete a number of bodies. |
split |
body, splits |
Split a body at the given residue ids. |
relative_hydration |
body, level |
Change the amount of hydration of a body. |
overlap_strength |
scaling, distance |
Change the strength of the overlap penalty. |
settings |
setting, value |
Change a program setting. |
seed |
seed |
Set the seed for the random number generator. |
log |
message |
Write a message to the log file. |
Essential elements¶
load¶
load { pdb <paths>, saxs <path>, split <splits>, names <names> }
pdb[string,vector<string>]: Path to the structure file(s).saxs[string]: Path to the SAXS or SANS data file. See SANS data.split[string,vector<int>]: Declare how to split the structure file into bodies.names[vector<string>]: Custom names for the loaded bodies.
This element handles all external file imports and thus supports a few different modes. It only accepts the block form.
Single file:
- If
pdbis a single path and nosplitis given, the entire structure is loaded as a single body. - If
pdbis a single path andsplit chain, the structure is split into multiple bodies based on their chainID. - If
pdbis a single path andsplitis a list of residue ids, the structure is split into multiple bodies at these ids.
Wildcards:
- If
pdbis a single path containing the character%, it is interpreted as a wildcard. Each%is one digit of zero-padding.
Example: Say you want to load the three filesfile01.pdb,file02.pdb, andfile03.pdb. Then you can usepdb file%%.pdbto load them all.
Multiple files:
- If
pdbis a list of paths, each structure is loaded as a separate body.
If the names argument is supplied, it must contain exactly one name per loaded body. See body names.
Example
Three alternative ways of loading a structure:
# one structure, split at residues 50 and 120 into three bodies with custom names
load {
pdb structure.pdb
saxs measurement.dat
split 50 120
names nterm core cterm
}
# one body per chain
load {
pdb complex.pdb
saxs measurement.dat
split chain
}
# one body per file
load {
pdb domain1.pdb domain2.pdb
saxs measurement.dat
}
Tip
Structure and data paths are resolved relative to where the program was launched, and then relative to the folder holding the configuration script. The latter lets a script reference files placed next to it no matter where it is run from.
SANS data¶
By default, the data file is fitted as SAXS data. To refine against SANS data instead, switch to neutron scattering with a settings element before load:
settings radiation neutron
load {
pdb structure.pdb
saxs measurement.dat
}
The solvent defaults to pure D₂O. For another H₂O/D₂O mixture, set neutron_solvent_density to its scattering length density in fm/ų: -0.0559 for pure H₂O, 0.6363 for pure D₂O, and linear in the D₂O fraction in between. The fraction of labile hydrogens exchanged with the solvent is set by neutron_exchange_efficiency (default 1). These settings can also be given in a settings file with config --file.
output¶
output <path> or output { path <path>, mode <mode> }
Set the folder all output is written to.
path[string]: The output folder.mode[string]: Howpathis resolved.relative: Relative to where the program was launched. This is the default.relative_config: Relative to the folder holding the configuration script.absolute: As an absolute path.
Important
The paths of save elements are fixed when they are read, so this element must come before any save element it should apply to.
parameters¶
parameters { iterations <N>, translate <x>, rotate <x>, translate_axes <axes>, rotate_axes <axes>, sym_translate <x>, sym_rotate <x>, decay <strategy> }
Specify a parameter generator for the transformations. This element only accepts the block form.
iterations[int]: The number of iterations the amplitudes decay over. This is also the default iteration count of a followingloop.translate[float]: the amplitude of body translations, in Ångström.rotate[float]: the amplitude of body rotations, in radians.translate_axes[string]: restrict body translations to the given axes, e.g.xyorz. Requires a non-zerotranslate.rotate_axes[string]: restrict body rotations to the given axes. Requires a non-zerorotate.sym_translate[float]: the amplitude of symmetry translations, in Ångström.sym_rotate[float]: the amplitude of symmetry rotations, in radians.decay[string]:linear,exponential,none.
Each amplitude is an upper bound on the magnitude of that component's contribution to a single step, scaled down over the run by the decay strategy. The four components are independent, and are disabled by leaving them out or setting them to zero. At least one must be given, except when the structure has declared symmetries: the symmetry amplitudes are then set to sensible defaults.
translateandrotatemove the real bodies themselves.sym_translateandsym_rotatemove the parameters of any declared symmetries.
The axes are those of the frame the structure was loaded in.
Which amplitudes should I set?
For a structure of independent bodies joined by constraints, use translate and rotate.
For a structure whose only freedom is a declared symmetry, use sym_translate and sym_rotate only. The symmetric copies are generated from the base body's current position, so translating or rotating the base body moves the whole assembly rigidly and does not change the scattering — spending steps on it is pure waste.
For a structure with both (e.g. a symmetric assembly whose subunit has been split into domains), set all four. Their relative sizes then express how much you trust each part of the starting model.
Tip
A good strategy is to start with big transforms and perfect the structure at the end. Note that the amplitudes decay over the run, so an over-large starting amplitude is not fatal — it merely wastes the early iterations, during which nothing is accepted. If your run only starts improving halfway through, your amplitudes were too large.
Important
All rotation amplitudes are angles in radians: rotate 3 is a rotation of nearly 172°, not 3°.
loop¶
loop <name> <N> or loop copy <name>
Open and loop over a new scope N times.
name[string]: The name to reference this loop by later.N[int]: The number of times the scope will be run.
Both arguments are optional. If N is not provided, the iterations number from the nearest preceding parameters element will be used instead; it is an error if there is none.
Remember to terminate the scope with an end statement.
Copying a loop:
loop copy <name> runs the named loop again, exactly as it was defined, including all of its contents and its number of iterations. If name is left out, the most recently named loop is copied. loop duplicate is an alias.
A copy does not open a new scope, and should not be terminated by an end statement.
Example
loop coarse 500
optimize_once
end
end
parameters {
iterations 200
rotate 0.1
}
loop refine # 200 iterations, taken from the parameters above
optimize_once
end
end
loop copy coarse # run the 500 coarse iterations once more
Tip
This is very useful for longer scripts which alternate between a few different stages, as each stage only has to be written once.
optimize_once¶
optimize_once
Generate and apply a single transform using the current set of parameters. optimize_step is an alias of this element.
This will open a new scope containing the transformed structure. When the scope ends, the structure fitness is evaluated:
- \(\chi^2\) is better than the current best: The transformed structure is kept, and will persist after the scope ends.
- \(\chi^2\) is worse: The transformed structure will be discarded when the scope ends.
Remember to terminate the scope with an end statement.
Important
This is the main element of your script: every activation runs one optimization step. Place it inside a loop, or the optimization will only run a single step.
end¶
end
Mark the end of a scope.
save¶
save <path>
Save the current conformation.
path[string]: The path to write to, relative to the output folder. The extension defines the saved data:*.pdb: Save the current structure in thepdbformat.*.xyz: Append the current structure to the specified file. This is an animation format which can be played in PyMOL.*.fit: Save the current fit, in the same format as theausaxs.fitfile from the SAXS fitter, plus a column with the residuals.*.txt: Save a report of the current fit.*.png: Save a plot of the current fit. This is written as a.plotfile; see CLI plotting.
You can use a wildcard % in the path name to avoid overwriting the same data file: out_%.pdb creates the file out_1.pdb on first activation, out_2.pdb on second activation, and so on. Each path has its own counter.
Common elements¶
constrain¶
constrain { first <body>, second <body>, type <type>, iatom1 <index>, iatom2 <index>, distance <distance> }
Create constraints between bodies.
first[string]: The name of the first body.second[string]: The name of the second body.type[string]: Declare the type of constraint.iatom1[int]: The index of the first atom.iatom2[int]: The index of the second atom.distance[float]: The target distance in Ångström.
The following options are available for the type:
bond: Constrain the backbone bond between the two bodies. The C-alpha pair is chosen automatically among the terminal residues of each body. Takes no further arguments.cm: Keep the center-of-mass distance of the two bodies at its current value. Takes no further arguments.distance: Keep the distance between atomiatom1of the first body and atomiatom2of the second body at its current value. Both atoms must be carbon atoms.attract: Penalize center-of-mass distances larger thandistance.repel: Penalize center-of-mass distances smaller thandistance.
first and second accept any body name, including those of symmetry copies. iatom1 and iatom2 are the positions of the atoms within their bodies, counted from zero in file order.
Example
One constraint of each type:
constrain {
first b1
second b2
type bond
}
constrain {
first b2
second b3
type cm
}
constrain {
first b1
second b3
type distance
iatom1 13
iatom2 40
}
# keep the symmetry copy within 30 Å of its base body
constrain {
first b1
second b1s1
type attract
distance 30
}
# but no closer than 15 Å
constrain {
first b1
second b1s1
type repel
distance 15
}
Tip
Repeat the constrain element as many times as you need to build up the constraints of your system.
autoconstrain¶
autoconstrain <strategy>
Automatically create constraints between all bodies.
strategy[string] sets the generation strategy.backbone: Go through the endpoints of each pair of bodies. If the C-alpha atoms located at these endpoints are close, create abondconstraint between them.none: Do not generate any constraints.
Tip
This element is useful for quickly linking the backbone of a split single-chain structure.
symmetry¶
symmetry <bodies> <symmetry group>
symmetry group[string]: The symmetry group to instantiate. Options:p2: Point group of order 2. Ideal for dimers.c[2-16]: Cyclic group of order [2-16].tetrahedral,octahedral,icosahedral(ort,o,i): Various polyhedral symmetries.d[2-16]: Dihedral group of order [2-16].dp[2-16]: Planar dihedral group of order [2-16].<inner>-<outer>: A composite of two symmetries, e.g.c3-p2, where the copies generated byinnerare themselves replicated byouter.
bodies[string]: The body to attach the symmetry to. This can only be left out if there is just a single body.
Declare a symmetry for a given body. Repeat the element to declare symmetries on several bodies.
If two or more bodies are given, they share a single symmetry, which replicates the group as one rigid assembly. Only point, cyclic, and polyhedral symmetries (and composites of these) are supported in this case.
Example
# a trimer of b1
symmetry b1 c3
# a dimer of the b2-b3 pair, where the copy of b2 and b3 move together as one unit
symmetry b2 b3 p2
# a dimer of trimers of b4
symmetry b4 c3-p2
Why should I declare symmetries instead of simply optimizing two copies of the same domain?
By declaring a symmetry with this element, you switch to a more efficient symmetry-aware distance calculator.
You also restrain the system to have fewer optimizable parameters over the two-copy approach, further increasing efficiency.
convert_to_symmetry¶
convert_to_symmetry <type> or convert_to_symmetry { bodies <bodies>, type <type>, tolerance <rmsd> }
bodies[string]: The bodies to decompose. Options:- single body: The body will automatically be split into the required number of subunits.
- multiple bodies: Each body is one subunit of the symmetry.
type[string]: The symmetry group to instantiate. Only point, cyclic, and polyhedral symmetries are supported.tolerance[float]: The maximum RMSD in Ångström allowed for the conversion.
Convert the bodies into the given symmetry. The result will be a single body with the requested symmetry that best resembles the original structure. If the RMSD is larger than the tolerance, the element fails.
The inline form convert_to_symmetry <type> applies to every loaded body.
Example
# a tetramer with one chain per subunit: use all four chains
load {
pdb tetramer.pdb
saxs measurement.dat
split chain
}
convert_to_symmetry c4
# the same tetramer loaded as a single body: it is split into four subunits automatically
load {
pdb tetramer.pdb
saxs measurement.dat
}
convert_to_symmetry {
bodies b1
type c4
tolerance 3
}
Tip
This is the easiest way to optimize a symmetric assembly you already have a model of: load the full assembly, convert_to_symmetry c4, and optimize the symmetry parameters.
select¶
select <strategy> or select { body <strategy>, mask <mask> }
Specify how to select the bodies to transform.
strategy[string]: The chosen strategy.random_body: Select a random body to transform. This is the default.random_constraint: Select a random constraint to transform from.sequential_body: Select each body in sequential order.sequential_constraint: Select each constraint in sequential order.random_symmetry,sequential_symmetry: Asrandom_bodyandsequential_body, but only the symmetry parameters are transformed. Inline form only.<body>: Always select this body, and transform both its position and its symmetries. Inline form only.<symmetry>: Always select this symmetry (e.g.b1s1), and transform only its parameters. Inline form only.
mask[string]: Which parts of the selected body are transformed in each step. Block form only.all: Everything. This is the default.real: Only the position of the body itself.symmetry: Only the symmetry parameters.symmetry_translation: Only the symmetry translations.symmetry_axis: Only the symmetry orientations.sequential: Alternate betweenrealandsymmetrysteps.random: Pickrealorsymmetryat random each step.sequential_real: Alternate between steps that only rotate and steps that only translate the body.sequential_symmetry: Alternate between steps of all symmetry parameters and steps of only the symmetry orientation.
Example
# move a random constraint, and everything attached to it
select random_constraint
# only optimize the first symmetry of b1
select b1s1
# visit the bodies in order, alternating between moving the body and its symmetries
select {
body sequential_body
mask sequential
}
transform¶
transform <strategy>
Specify how to apply the transformation to the bodies.
strategy[string]: The chosen strategy.rigid(orrigid_transform): All bodies connected to the chosen body will be transformed as well. This is the default.single(orsingle_transform): Only the chosen body will be transformed. This is likely to violate constraints on the transformed body with larger transformation amplitudes.
Tip
Combine the single strategy with smaller transformations, or limit it to rotations, to avoid breaking the constraints of the transformed body.
on_improvement¶
on_improvement
Open a new scope which will only be run if a better conformation (lower chi2) was found this iteration. This element must be placed directly inside an optimize_once scope.
Remember to terminate the scope with an end statement.
Tip
Place a save element in this scope to keep a history of every accepted conformation.
every¶
every <N>
Open a new scope which will run once every N iterations.
N[int]: The number of activations required before the contained scope is run.
Remember to terminate the scope with an end statement.
Tip
Use this to follow a long optimization without being overwhelmed, e.g. with a print or save element every 100 iterations.
print¶
print <message>, print <color> <message>, or print { message <message>, color <color> }
Print a message to the terminal.
message[string]: The message to be printed. May also be writtenmsg.color[string]: The color of the text, one ofblack,red,green,yellow,blue,magenta,cyan,white,lightgray,darkgray,lightred,lightgreen,lightyellow,lightblue,lightmagentaandlightcyan. May also be writtencolour.
Several runtime parameters can be printed using special keywords:
{iteration}: The current iteration number.{iterations_total}: The total iteration number.{chi2}: The current reduced \(\chi^2\) value.{chi2_best}: The best reduced \(\chi^2\) value found so far.{chi2_penalty}: The current penalty to the \(\chi^2\).{chi2_no_penalty}: The current \(\chi^2\) without penalties.{body_names}: The currently available body names.
Braces are reserved for these keywords; any other {...} is an error.
Example
print {
message "{iteration}/{iterations_total}: Chi2 is {chi2}."
color red
}
update¶
update structure
Publish the current conformation to the GUI live preview.
structure[string]: The only supported target.
Place this inside the optimization loop to update the preview as the run progresses. It does nothing if no GUI is connected, so it is safe to leave in scripts which are also run from the command line.
Tip
Place this element inside the optimize_once scope to watch every sampled conformation, including the rejected ones. Outside the scope, the preview only updates when a new conformation is accepted.
Advanced elements¶
These elements cover more specialised needs, and can safely be skipped when writing your first scripts.
Show the advanced elements
rename¶
rename <body> <name>
body[string]: The body to be renamed.name[string]: The new name.
Rename a given body. The new name can be used to refer to this body in other elements.
copy¶
copy <body> <name>
body[string]: The body to be copied.name[string]: The name of the new body.
Add a copy of the given body, including any symmetries it has.
merge¶
merge <body> <other bodies>
body[string]: The primary body.other bodies[string]: The bodies to be merged into the primary.
delete¶
delete <bodies>
bodies[string]: The bodies to be deleted. At least one body must remain.
split¶
split <body> <splits>
body[string]: The body to be split.splits[int]: The list of residue ids to perform the split at.
Split the given body into a number of new bodies, separated at the given residue ids. To split a structure as it is loaded, use the split argument of load instead.
relative_hydration¶
relative_hydration <body> <level>
body[string]: The body to change.level[string]: The amount of hydration relative to the other bodies. Options:min(×0.25),low(×0.5),normal(×1),high(×1.5),max(×1.75).
Change the amount of hydration generated around a body, relative to the other bodies. Repeat the element to change several bodies.
overlap_strength¶
overlap_strength <scaling> <distance>
scaling[float]: Multiply the strength of the overlap penalty by this factor.distance[float]: Only penalize overlaps closer than this distance in Ångström.
Bodies are kept from overlapping by a penalty on short interatomic distances. By default its weight falls off as \(e^{-5r}\); with this element it is scaled by scaling. If a distance \(d\) is given, the weight is instead scaling \(\cdot ((d-r)/d)^2\) for \(r < d\), and zero beyond it.
settings¶
settings <setting> <value>
setting[string]: The name of the setting, as written in a settings file.value[string]: The new value.
Change a program setting from within the script. Use ausaxs rigidbody config --save to see the available settings.
seed¶
seed <seed>
Set the seed of the random number generator.
seed[int]: The seed.
log¶
log <message>
Write a message to the log.
message[string]: The message to log.
The same substitutions available for print may be used here as well.